AXIS访问xfire服务端,身份验证的问题!!! 在CSDN挂了2天没人回答!!
我使用xifre开发的服务端,服务端添加了身份验证(验证用户名,和密码)
身份验证代码如下:
public class AuthenticationHandler extends AbstractHandler { Properties props = new Properties(); SimpleDateFormat time=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); private DAOUtil dao; public void invoke(MessageContext cfx) throws Exception { InterfaceLogger log = new InterfaceLogger(); String url = this.getClass().getClassLoader().getResource("validate.properties").toString().substring(5); InputStream in = new BufferedInputStream (new FileInputStream(url));props.load(in);String flag = props.getProperty("flag");String psd = props.getProperty("password");String uname = props.getProperty("username");if(flag.equals("false"))return; HttpServletRequest request = XFireServletController.getRequest(); OperationInfo o = (OperationInfo) cfx.getService().getServiceInfo().getOperations().iterator().next(); String service = o.getService().getServiceClass().getName()+"."+o.getMethod().getName(); //生成接口访问日志 log.setContent(cfx.getCurrentMessage().getBody().toString()); log.setIp(request.getRemoteAddr()); log.setLog_time(time.format(new Date())); log.setName(service); log.setType("*******"); //将日志存入到session中 cfx.getSession().put(cfx.getId(), log); if (cfx.getInMessage().getHeader() == null) {throw new org.codehaus.xfire.fault.XFireFault("请求必须包含验证信息",org.codehaus.xfire.fault.XFireFault.SENDER);}Element token = cfx.getInMessage().getHeader().getChild("AuthenticationToken");if (token == null) {throw new org.codehaus.xfire.fault.XFireFault("请求必须包含身份验证信息",org.codehaus.xfire.fault.XFireFault.SENDER);}String username = token.getChild("Username").getValue();String password = token.getChild("Password").getValue();log.setUser_name(username);try {// 进行身份验证 ,只有abcd@1234的用户为授权用户if (username.equals(uname) && password.equals(psd)) // 这语句不显示System.out.println("身份验证通过");elsethrow new Exception();} catch (Exception e) {log.setEnd_time(time.format(new Date()));dao.getSqlMapClientTemplate().insert("logger", log);throw new org.codehaus.xfire.fault.XFireFault("非法的用户名和密码",org.codehaus.xfire.fault.XFireFault.SENDER);}}