1 17 package org.alfresco.filesys.server.auth.passthru; 18 19 import java.util.List ; 20 21 import net.sf.acegisecurity.AuthenticationManager; 22 import net.sf.acegisecurity.providers.ProviderManager; 23 24 import org.alfresco.config.ConfigElement; 25 import org.alfresco.filesys.server.SrvSession; 26 import org.alfresco.filesys.server.auth.ClientInfo; 27 import org.alfresco.filesys.server.auth.SrvAuthenticator; 28 import org.alfresco.filesys.server.auth.UserAccount; 29 import org.alfresco.filesys.server.config.InvalidConfigurationException; 30 import org.alfresco.filesys.server.config.ServerConfiguration; 31 import org.alfresco.filesys.server.core.SharedDevice; 32 import org.alfresco.repo.security.authentication.ntlm.NTLMAuthenticationProvider; 33 import org.alfresco.repo.security.authentication.ntlm.NTLMPassthruToken; 34 import org.apache.commons.logging.Log; 35 import org.apache.commons.logging.LogFactory; 36 37 42 public class AcegiPassthruAuthenticator extends SrvAuthenticator 43 { 44 46 private static final Log logger = LogFactory.getLog("org.alfresco.smb.protocol.auth"); 47 48 52 private static final String DefaultAuthManagerName = "authenticationManager"; 53 54 56 private AuthenticationManager m_authMgr; 57 58 61 public AcegiPassthruAuthenticator() 62 { 63 setAccessMode(SrvAuthenticator.USER_MODE); 64 setEncryptedPasswords(true); 65 } 66 67 77 public int authenticateShareConnect(ClientInfo client, SharedDevice share, String sharePwd, SrvSession sess) 78 { 79 return SrvAuthenticator.Writeable; 80 } 81 82 90 public int authenticateUser(ClientInfo client, SrvSession sess, int alg) 91 { 92 94 NTLMPassthruToken authToken = (NTLMPassthruToken) sess.getAuthenticationToken(); 95 96 if ( authToken == null) 97 return SrvAuthenticator.AUTH_DISALLOW; 98 99 101 int authSts = SrvAuthenticator.AUTH_DISALLOW; 102 byte[] hashedPassword = null; 103 104 if ( alg == NTLM1) 105 hashedPassword = client.getPassword(); 106 else if ( alg == LANMAN) 107 hashedPassword = client.getANSIPassword(); 108 else 109 { 110 112 if ( logger.isDebugEnabled()) 113 logger.debug("Invalid algorithm specified for user authentication (" + alg + ")"); 114 115 117 return SrvAuthenticator.AUTH_DISALLOW; 118 } 119 120 122 authToken.setUserAndPassword( client.getUserName(), hashedPassword, alg); 123 124 126 try 127 { 128 130 m_authMgr.authenticate( authToken); 131 132 134 if (authToken.isGuestLogon()) 135 { 136 137 139 if (allowGuest() == true) 140 { 141 142 144 authSts = SrvAuthenticator.AUTH_GUEST; 145 146 148 if (logger.isDebugEnabled()) 149 logger.debug("Acegi passthru authenticate user=" + client.getUserName() + ", GUEST"); 150 } 151 } 152 else 153 { 154 155 157 authSts = SrvAuthenticator.AUTH_ALLOW; 158 159 161 if (logger.isDebugEnabled()) 162 logger.debug("Acegi passthru authenticate user=" + client.getUserName() + ", FULL"); 163 } 164 } 165 catch ( Exception ex) 166 { 167 169 if ( logger.isErrorEnabled()) 170 logger.error("Logon failure, " + ex.getMessage()); 171 } 172 173 175 sess.setAuthenticationToken(null); 176 177 179 return authSts; 180 } 181 182 188 public UserAccount getUserDetails(String user) 189 { 190 192 return null; 193 } 194 195 201 public byte[] getChallengeKey(SrvSession sess) 202 { 203 205 NTLMPassthruToken authToken = new NTLMPassthruToken(); 206 207 209 m_authMgr.authenticate( authToken); 210 211 213 sess.setAuthenticationToken(authToken); 214 215 217 if ( logger.isDebugEnabled()) 218 logger.debug("Created new passthru token " + authToken); 219 220 222 if ( authToken.getChallenge() != null) 223 return authToken.getChallenge().getBytes(); 224 return null; 225 } 226 227 234 public void initialize(ServerConfiguration config, ConfigElement params) throws InvalidConfigurationException 235 { 236 238 super.initialize(config, params); 239 240 243 if ( config.getAuthenticationManager() == null) 244 throw new InvalidConfigurationException("Acegi authentication manager not available"); 245 246 248 if ( getAccessMode() != USER_MODE) 249 throw new InvalidConfigurationException("Acegi authenticator only works in user mode"); 250 251 254 Object authMgrObj = config.getAuthenticationManager(); 255 256 if ( authMgrObj instanceof ProviderManager) 257 { 258 260 ProviderManager providerManager = (ProviderManager) authMgrObj; 261 List providerList = providerManager.getProviders(); 262 263 if ( providerList != null) 264 { 265 267 int i = 0; 268 boolean foundProvider = false; 269 270 while ( i < providerList.size() && foundProvider == false) 271 { 272 if ( providerList.get(i++) instanceof NTLMAuthenticationProvider) 273 foundProvider = true; 274 } 275 276 if (foundProvider == false) 277 throw new InvalidConfigurationException("NTLM authentication provider is not available"); 278 279 281 m_authMgr = (AuthenticationManager) authMgrObj; 282 } 283 else 284 throw new InvalidConfigurationException("No authentication providers available"); 285 } 286 else 287 throw new InvalidConfigurationException("Required authentication manager is not configured"); 288 } 289 } 290 | Popular Tags |