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