1 16 17 package org.apache.axis.handlers ; 18 19 import org.apache.axis.AxisFault; 20 import org.apache.axis.MessageContext; 21 import org.apache.axis.components.logger.LogFactory; 22 import org.apache.axis.security.AuthenticatedUser; 23 import org.apache.axis.security.SecurityProvider; 24 import org.apache.axis.security.simple.SimpleSecurityProvider; 25 import org.apache.axis.utils.Messages; 26 import org.apache.commons.logging.Log; 27 28 29 40 public class SimpleAuthenticationHandler extends BasicHandler { 41 protected static Log log = 42 LogFactory.getLog(SimpleAuthenticationHandler.class.getName()); 43 44 47 public void invoke(MessageContext msgContext) throws AxisFault { 48 if (log.isDebugEnabled()) { 49 log.debug("Enter: SimpleAuthenticationHandler::invoke"); 50 } 51 52 SecurityProvider provider = (SecurityProvider)msgContext.getProperty(MessageContext.SECURITY_PROVIDER); 53 if (provider == null) { 54 provider = new SimpleSecurityProvider(); 55 msgContext.setProperty(MessageContext.SECURITY_PROVIDER, provider); 56 } 57 58 if (provider != null) { 59 String userID = msgContext.getUsername(); 60 if (log.isDebugEnabled()) { 61 log.debug( Messages.getMessage("user00", userID) ); 62 } 63 64 if ( userID == null || userID.equals("")) 66 throw new AxisFault( "Server.Unauthenticated", 67 Messages.getMessage("cantAuth00", userID), 68 null, null ); 69 70 String passwd = msgContext.getPassword(); 71 if (log.isDebugEnabled()) { 72 log.debug( Messages.getMessage("password00", passwd) ); 73 } 74 75 AuthenticatedUser authUser = provider.authenticate(msgContext); 76 77 if ( authUser == null) 79 throw new AxisFault( "Server.Unauthenticated", 80 Messages.getMessage("cantAuth01", userID), 81 null, null ); 82 83 if (log.isDebugEnabled()) { 84 log.debug( Messages.getMessage("auth00", userID) ); 85 } 86 87 msgContext.setProperty(MessageContext.AUTHUSER, authUser); 88 } 89 90 if (log.isDebugEnabled()) { 91 log.debug("Exit: SimpleAuthenticationHandler::invoke"); 92 } 93 } 94 }; 95 | Popular Tags |