/**
* @inheritDoc
*
*/
public synchronized Subject authenticate(Object creds) {
AuthenticationManager am;
SecurityContext securityContext;
// wine and complain if we don't get what we expect.
if (creds == null) {
throw new SecurityException(
"JMXConnectorAuthenticator requires userid/password credentials to be passed in");
}
if (! (creds instanceof String[])) {
// only support passing in array of Strings
throw new SecurityException(
"JMXConnectorAuthenticator can only handle authentication parameter that is array of two strings, instead got " +
creds.getClass().getName());
}
String[] pair = (String[]) creds;
if( pair.length != 2 ) {
// only support passing userid + password
throw new SecurityException(
"JMXConnectorAuthenticator can only handle authentication parameter that is array of two strings, instead got " +
pair.length +" strings");
}
String user, pass;
user = pair[0];
pass = pair[1];
Principal principal = new JMXPrincipal(user);
Subject subject = new Subject();
securityContext = SecurityFactory.establishSecurityContext(securityDomainName);
am = securityContext.getAuthenticationManager();
boolean result = am.isValid(principal, pass , subject);
if( result ) {
subject.setReadOnly();
}
else {
throw new SecurityException("user authentication check failed");