首页 > 代码库 > Axis2身份验证-采用Module方式验证Soap Header实现
Axis2身份验证-采用Module方式验证Soap Header实现
1.创建UserCheckModule类
import org.apache.axis2.AxisFault;import org.apache.axis2.context.ConfigurationContext;import org.apache.axis2.description.AxisDescription;import org.apache.axis2.description.AxisModule;import org.apache.axis2.modules.Module;import org.apache.neethi.Assertion;import org.apache.neethi.Policy;/** * <P>Description: TODO</P> * @ClassName: UserCheckModule */public class UserCheckModule implements Module { /** * <p>Title: init</p> * @see org.apache.axis2.modules.Module#init(org.apache.axis2.context.ConfigurationContext, org.apache.axis2.description.AxisModule) */ @Override public void init(ConfigurationContext configContext, AxisModule module) throws AxisFault { // TODO Auto-generated method stub } /** * <p>Title: engageNotify</p> * @see org.apache.axis2.modules.Module#engageNotify(org.apache.axis2.description.AxisDescription) */ @Override public void engageNotify(AxisDescription axisDescription) throws AxisFault { // TODO Auto-generated method stub } /** * <p>Title: canSupportAssertion</p> * @see org.apache.axis2.modules.Module#canSupportAssertion(org.apache.neethi.Assertion) */ @Override public boolean canSupportAssertion(Assertion assertion) { // TODO Auto-generated method stub return false; } /** * <p>Title: applyPolicy</p> * @see org.apache.axis2.modules.Module#applyPolicy(org.apache.neethi.Policy, org.apache.axis2.description.AxisDescription) */ @Override public void applyPolicy(Policy policy, AxisDescription axisDescription) throws AxisFault { // TODO Auto-generated method stub } /** * <p>Title: shutdown</p> * @see org.apache.axis2.modules.Module#shutdown(org.apache.axis2.context.ConfigurationContext) */ @Override public void shutdown(ConfigurationContext configurationContext) throws AxisFault { // TODO Auto-generated method stub }}
2.创建UserCheckHandler
import java.util.Iterator;import org.apache.axiom.om.OMElement;import org.apache.axis2.AxisFault;import org.apache.axis2.context.MessageContext;import org.apache.axis2.engine.Handler;import org.apache.axis2.handlers.AbstractHandler;public class UserCheckHandler extends AbstractHandler implements Handler { @Override public InvocationResponse invoke(MessageContext msgContext) throws AxisFault { // 获取Head OMElement fistElement = msgContext.getEnvelope().getHeader().getFirstElement(); if (fistElement!=null&&fistElement.getChildren() != null) { Iterator<?> list = (Iterator<?>) fistElement.getChildren(); String Username = ""; String Password = ""; while (list.hasNext()) { OMElement element = (OMElement) list.next(); if (element.getLocalName().equals("Username")) { Username = element.getText(); } if (element.getLocalName().equals("Password")) { Password = element.getText(); } } if (!Username.equals("toone") || !Password.equals("111111")) { throw new AxisFault(" Authentication Fail! Check username/password "); } return InvocationResponse.CONTINUE; } else { throw new AxisFault(" Authentication Fail! Check username/password "); } }}
3.创建module.xml
<?xml version="1.0" encoding="UTF-8"?><moudle name="userCheck" class="com.ehonglin.axis.module.UserCheckModule"> <InFlow> <handler name="InFlowLogHandler" class="com.ehonglin.axis.module.UserCheckHandler"> <order phase="userCheckPhase"/> </handler> </InFlow></moudle>
4.修改axis.xml
5.在services.xml中使用userCheck
<?xml version="1.0" encoding="UTF-8"?><service name="EmptyBoxService" targetNamespace="http://tempuri.org/"> <description>web service</description> <schema schemaNamespace="http://tempuri.org/"/> <module ref="userCheck"/> <parameter name="ServiceObjectSupplier"> org.apache.axis2.extensions.spring.receivers.SpringServletContextObjectSupplier </parameter> <parameter name="SpringBeanName">emptyBoxService</parameter> <messageReceivers> <messageReceiver mep="http://www.w3.org/ns/wsdl/in-only" class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver" /> <messageReceiver mep="http://www.w3.org/ns/wsdl/in-out" class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" /> </messageReceivers></service>
Axis2身份验证-采用Module方式验证Soap Header实现
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。