Handler的验证和授权
Handler就是一个普通的过滤器,对服务过滤,只给允许使用的用户授予操作的权限,比如银行的取款,不是每个人都能随便取款的。
在服务端的项目里面编写以下代码
AuthenticationHandler.java
import org.apache.axis.AxisFault;
import org.apache.axis.MessageContext;
import org.apache.axis.handlers.BasicHandler;
import org.apache.axis.security.AuthenticatedUser;
import org.apache.axis.security.SecurityProvider;
import org.apache.axis.security.simple.SimpleSecurityProvider;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
publicclassAuthenticationHandler extends BasicHandler {
Loglog= LogFactory.getLog(AuthenticationHandler.class) ;
//定义认证的参数信息
StringsecurityProvider= "securityProvider" ;//安全级别对象
Stringunauthenticated= "unauthenticated" ;//未认证
StringauthenticatedUser= "authenticatedUser" ;//认证
StringcanAuth= "canAuth"; //认证的用户
publicvoid invoke(MessageContextmsgcontext) throwsAxisFault {
log.info("AuthenticationHandler:invoke start") ;
//获取当前的安全服务
SecurityProviderprovider = (SecurityProvider) msgcontext.getProperty(securityProvider) ;
//判断当前的安全机制状态
if(provider == null){
//创建一个安全的级别
provider= newSimpleSecurityProvider() ;
//将创建的安全级别设置到当前的