/** * @see javax.security.auth.spi.LoginModule#commit() * @return true if committed, false if not (likely not authenticated) * @throws LoginException */ public boolean commit() throws LoginException { if (!isAuthenticated()) { currentUser = null; setCommitted(false); return false; } setCommitted(true); currentUser.setJAASInfo(subject); return true; }
/** * @see javax.security.auth.spi.LoginModule#login() * @return true if is authenticated, false otherwise * @throws LoginException */ public boolean login() throws LoginException { try { if (callbackHandler == null) throw new LoginException("No callback handler"); Callback[] callbacks = configureCallbacks(); callbackHandler.handle(callbacks); String webUserName = ((NameCallback) callbacks[0]).getName(); Object webCredential = null; webCredential = ((ObjectCallback) callbacks[1]) .getObject(); // first check if ObjectCallback has the credential if (webCredential == null) webCredential = ((PasswordCallback) callbacks[2]).getPassword(); // use standard PasswordCallback if ((webUserName == null) || (webCredential == null)) { setAuthenticated(false); return isAuthenticated(); } UserInfo userInfo = getUserInfo(webUserName); if (userInfo == null) { setAuthenticated(false); return isAuthenticated(); } currentUser = new JAASUserInfo(userInfo); setAuthenticated(currentUser.checkCredential(webCredential)); return isAuthenticated(); } catch (IOException e) { throw new LoginException(e.toString()); } catch (UnsupportedCallbackException e) { throw new LoginException(e.toString()); } catch (Exception e) { e.printStackTrace(); throw new LoginException(e.toString()); } }