1 23 package com.sun.enterprise.admin.server.core.jmx.auth; 24 25 import java.util.logging.Logger ; 26 import java.util.logging.Level ; 27 import javax.management.remote.JMXAuthenticator ; 28 import javax.security.auth.Subject ; 29 30 import com.sun.enterprise.admin.common.constant.AdminConstants; 31 import com.sun.enterprise.util.i18n.StringManager; 32 33 public class ASJMXAuthenticator implements JMXAuthenticator { 34 35 private static final boolean _debug = false; 36 37 private static Logger _logger = 38 Logger.getLogger(AdminConstants.kLoggerName); 39 40 private static StringManager _strings = 41 StringManager.getManager(ASLoginDriverImpl.class); 42 43 private String realmName; 44 private LoginDriver loginDriver; 45 46 public ASJMXAuthenticator() { 47 } 48 49 public ASJMXAuthenticator(String realmName) { 50 setRealmName(realmName); 51 } 52 53 public void setRealmName(String realm) { 54 realmName = realm; 56 } 57 58 public String getRealmName() { 59 return realmName; 60 } 61 62 public LoginDriver getLoginDriver() { 63 return loginDriver; 64 } 65 66 public void setLoginDriver(LoginDriver driver) { 67 loginDriver = driver; 69 } 70 71 public Subject authenticate(Object credentials) { 72 if (credentials == null) { 73 if (_debug) { 74 System.out.println("JMXAuthenticator: Null credentials sent from the client"); 75 } 76 throwInvalidCredentialsException(); 77 } 78 if (!(credentials instanceof String [])) { 79 if (_debug) { 80 System.out.println("JMXAuthenticator: Invalid credentials sent from the client " + credentials.getClass().getName()); 81 } 82 throwInvalidCredentialsException(); 83 } 84 String [] userpass = (String [])credentials; 85 if (userpass.length != 2) { 86 if (_debug) { 87 System.out.println("JMXAuthenticator: Invalid credentials sent from client, string array of length " + userpass.length); 88 } 89 throwInvalidCredentialsException(); 90 } 91 if (_debug) { 92 System.out.println("JMX authentication request for user " 93 + userpass[0] + " and password " + userpass[1]); 94 System.out.println("Authentication realm is " + realmName); 95 } 96 97 Subject subject = null; 98 if (loginDriver != null) { 99 subject = loginDriver.login(userpass[0], userpass[1], realmName); 100 } else { 101 } 103 return subject; 104 } 105 106 private void throwInvalidCredentialsException() { 107 throw new SecurityException ( 108 _strings.getString("admin.auth.invalid.credentials")); 109 } 110 } 111 | Popular Tags |