1 17 package org.apache.servicemix.jbi.jmx; 18 19 import javax.management.remote.JMXAuthenticator ; 20 import javax.security.auth.Subject ; 21 import javax.security.auth.login.LoginException ; 22 23 import org.apache.servicemix.jbi.security.auth.AuthenticationService; 24 import org.apache.servicemix.jbi.security.auth.impl.JAASAuthenticationService; 25 26 31 public class JaasAuthenticator implements JMXAuthenticator { 32 33 private String domain = "servicemix-domain"; 34 private AuthenticationService authenticationService = new JAASAuthenticationService(); 35 36 43 public AuthenticationService getAuthenticationService() { 44 return authenticationService; 45 } 46 47 50 public void setAuthenticationService(AuthenticationService authenticationService) { 51 this.authenticationService = authenticationService; 52 } 53 54 57 public String getDomain() { 58 return domain; 59 } 60 61 64 public void setDomain(String domain) { 65 this.domain = domain; 66 } 67 68 71 public Subject authenticate(Object credentials) throws SecurityException { 72 if (credentials instanceof String [] == false) { 73 throw new IllegalArgumentException ("Expected String[2], got " + (credentials != null ? credentials.getClass().getName() : null)); 74 } 75 String [] params = (String []) credentials; 76 if (params.length != 2) { 77 throw new IllegalArgumentException ("Expected String[2] but length was " + params.length); 78 } 79 Subject subject = new Subject (); 80 try { 81 authenticationService.authenticate(subject, domain, params[0], params[1]); 82 } catch (LoginException e) { 83 throw new SecurityException ("Authentication failed", e); 84 } catch (Exception e) { 85 throw new SecurityException ("Error occured while authenticating", e); 86 } 87 return subject; 88 } 89 90 } 91 | Popular Tags |