1 22 23 package org.continuent.sequoia.common.authentication; 24 25 import javax.management.remote.JMXAuthenticator ; 26 import javax.security.auth.Subject ; 27 28 import org.continuent.sequoia.common.log.Trace; 29 30 36 public class PasswordAuthenticator implements JMXAuthenticator 37 38 { 39 40 44 public static final PasswordAuthenticator NO_AUTHENICATION = new PasswordAuthenticator( 45 null, null); 46 47 static Trace logger = Trace 48 .getLogger("org.continuent.sequoia.common.authentication"); 49 50 private String username; 51 private String password; 52 53 59 public PasswordAuthenticator(String username, String password) 60 { 61 this.username = username; 62 this.password = password; 63 } 64 65 72 public static Object createCredentials(String username, String password) 73 { 74 return new String []{username, password}; 75 } 76 77 80 public Subject authenticate(Object credentials) throws SecurityException 81 { 82 try 83 { 84 if (username == null && password == null) 85 { 86 return new Subject (); 88 } 89 90 if (credentials == null) 91 { 92 throw new SecurityException ("credentials are required"); 93 } 94 95 try 96 { 97 String [] credentialsArray = (String []) credentials; 98 if (username.equals(credentialsArray[0]) 99 && password.equals(credentialsArray[1])) 100 { 101 if (logger.isDebugEnabled()) 103 { 104 logger.debug("successfully authenitcated "); 105 } 106 return new Subject (); 107 } 108 } 109 catch (Exception e) 110 { 111 throw new SecurityException ("problems with credentials object : " 114 + e.getMessage()); 115 } 116 117 throw new SecurityException ("invalid credentials"); 119 } 120 catch (SecurityException e) 121 { 122 logger.error(e.getMessage()); 123 try 124 { 125 String clientId = java.rmi.server.RemoteServer.getClientHost(); 126 logger.warn("refused unauthorized access for client " + clientId); 127 } 128 catch (Exception ex) 129 { 130 131 } 132 throw e; 133 } 134 } 135 } 136 | Popular Tags |