1 46 47 package org.mr.kernel.security.authentication; 48 49 50 import javax.jms.JMSSecurityException ; 51 import javax.security.auth.Subject ; 52 53 import org.mr.kernel.security.*; 54 import org.apache.commons.logging.Log; 55 import org.apache.commons.logging.LogFactory; 56 57 65 public class MantaAuthenticationImpl implements org.mr.kernel.security.MantaAuthentication, SecurityConstants, SecurityConfigurationPaths { 66 private Log _logger; 67 68 80 public SessionID authenticate(String username, String password) throws JMSSecurityException { 81 if (username == null || "".equals(username)){ 82 if (getLogger().isErrorEnabled()) 83 getLogger().error("[authenticate] Invalid argument: username"); 84 throw new JMSSecurityException ("Invalid argument: username"); 85 } 86 87 if (getLogger().isInfoEnabled()) 88 getLogger().info("[authenticate] A request to authenticate user " + username + " has been recieved"); 89 90 try { 91 Subject subject = MantaACLAuthenticationManager.getInstance().isAuthenticated(username, password); 93 if (subject == null) 94 throw new JMSSecurityException ("authentication failed"); 95 96 if (getLogger().isInfoEnabled()) 98 getLogger().info("[authenticate] Creating a new session for user " + username); 99 100 SessionID sessionID = new SessionID(); 101 UserPrincipal principal = new UserPrincipal(username); 103 104 if (getLogger().isInfoEnabled()) 106 getLogger().info("[authenticate] Adding session ID " + sessionID.toString() + " for user " + username + " to the session manager"); 107 108 SessionManager.getInstance().addSession(principal, sessionID); 109 return sessionID; 110 } 111 catch (MaximumNumberOfSessionsPerUserReached mnospur){ 112 if (getLogger().isErrorEnabled()) 113 getLogger().error(mnospur.getMessage()); 114 throw new JMSSecurityException (mnospur.getMessage()); 115 } 116 catch (MantaSecurityException mse){ 117 throw new JMSSecurityException (mse.getMessage()); 118 } 119 } 120 121 130 public void logout(SessionID sessionID) throws JMSSecurityException { 131 if (sessionID == null){ 132 if (getLogger().isErrorEnabled()) 133 getLogger().error("[logout] Invalid argument: sessionID"); 134 throw new JMSSecurityException ("Invalid argument: sessionID"); 135 } 136 if (getLogger().isInfoEnabled()) 138 getLogger().info("[authenticate] Removing session ID " + sessionID.toString() + " from the session manager"); 139 140 SessionManager.getInstance().removeSession(sessionID); 141 } 142 143 148 public Log getLogger(){ 149 if (_logger == null){ 150 _logger = LogFactory.getLog(getClass().getName()); 151 } 152 return _logger; 153 } 154 } 155 | Popular Tags |