1 16 package org.apache.juddi.auth; 17 18 import org.apache.commons.logging.Log; 19 import org.apache.commons.logging.LogFactory; 20 import org.apache.juddi.error.RegistryException; 21 import org.apache.juddi.error.UnknownUserException; 22 import org.apache.juddi.util.Config; 23 import org.jboss.security.AuthenticationManager; 24 25 import javax.naming.Context ; 26 import javax.naming.InitialContext ; 27 import javax.naming.NamingException ; 28 import java.security.Principal ; 29 30 47 public class JBossAuthenticator implements Authenticator 48 { 49 private static Log log = LogFactory.getLog(JBossAuthenticator.class); 51 52 private static final String SECURITY_DOMAIN_KEY = "juddi.securityDomain"; 54 private static final String DEFAULT_SECURITY_DOMAIN = "java:/jaas/other"; 55 56 AuthenticationManager authManager; 58 59 62 public JBossAuthenticator() 63 { 64 init(); 65 } 66 67 70 public String authenticate(final String userID, final String credential) 71 throws RegistryException 72 { 73 if (userID == null) { 74 throw new UnknownUserException("Invalid user ID = "+userID); 75 } 76 77 Principal principal = new Principal () 79 { 80 public String getName() { 81 return userID; 82 } 83 }; 84 85 if (!authManager.isValid(principal, credential)) { 86 throw new UnknownUserException("Invalid credentials"); 87 } 88 89 return userID; 90 } 91 92 93 private void init() 94 { 95 String securityDomain = Config.getStringProperty(SECURITY_DOMAIN_KEY,DEFAULT_SECURITY_DOMAIN); 96 97 try { 98 Context ctx = new InitialContext (); 100 authManager = (AuthenticationManager) ctx.lookup(securityDomain); 101 ctx.close(); 102 } catch (NamingException e) { 103 log.error("JNDI Exception looking for autentication manager: " + 104 securityDomain, e); 105 } 106 } 107 } | Popular Tags |