/** * Standard JAAS override. */ @Override public boolean abort() throws LoginException { clear(); if (debug) { logger.debug("abort"); } return true; }
/** * Overriding to allow for proper initialization. Standard JAAS. */ @Override public void initialize(Subject subject, CallbackHandler callbackHandler, Map<String, ?> sharedState, Map<String, ?> options) { this.subject = subject; this.callbackHandler = callbackHandler; init(options); }
private Subject doAuthenticate(HashMap<String, ?> options, JaasCallbackHandler callbackHandler) throws LoginException { Subject mySubject = new Subject(); loginModule.initialize(mySubject, callbackHandler, null, options); loginModule.login(); loginModule.commit(); return mySubject; } }
/** * Overriding to complete login process. Standard JAAS. */ @Override public boolean commit() throws LoginException { principals.add(new UserPrincipal(username)); for (String role : getUserRoles(username)) { principals.add(new RolePrincipal(role)); } subject.getPrincipals().addAll(principals); clear(); if (debug) { logger.debug("commit"); } return true; }
/** * Overriding to allow for certificate-based login. Standard JAAS. */ @Override public boolean login() throws LoginException { Callback[] callbacks = new Callback[1]; callbacks[0] = new CertificateCallback(); try { callbackHandler.handle(callbacks); } catch (IOException ioe) { throw new LoginException(ioe.getMessage()); } catch (UnsupportedCallbackException uce) { throw new LoginException("Unable to obtain client certificates: " + uce.getMessage()); } certificates = ((CertificateCallback) callbacks[0]).getCertificates(); username = getUserNameForCertificates(certificates); if (username == null) { throw new FailedLoginException("No user for client certificate: " + getDistinguishedName(certificates)); } if (debug) { logger.debug("Certificate for user: " + username); } return true; }
/** * Performs initialization of file paths. A standard JAAS override. */ @Override public void initialize(Subject subject, CallbackHandler callbackHandler, Map<String, ?> sharedState, Map<String, ?> options) { super.initialize(subject, callbackHandler, sharedState, options); usersByDn = load(USER_FILE_PROP_NAME, "", options).invertedPropertiesMap(); regexpByUser = load(USER_FILE_PROP_NAME, "", options).regexpPropertiesMap(); rolesByUser = load(ROLE_FILE_PROP_NAME, "", options).invertedPropertiesValuesMap(); }