Web Service之Handler的验证和授权

本文介绍了如何使用Handler在Web Service中实现验证和授权。通过自定义AuthenticationHandler和AuthorizationHandler,确保只有授权的用户能访问服务。详细阐述了在服务端和客户端的配置及代码实现过程。
摘要由CSDN通过智能技术生成

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() ;

        //将创建的安全级别设置到当前的

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值