Callback[] callbacks = new Callback[2]; callbacks[0] = new NameCallback("Username: "); callbacks[1] = new PasswordCallback("Password: ", false); try { callbackHandler.handle(callbacks); } catch (IOException ioe) { throw new LoginException(ioe.getMessage()); } catch (UnsupportedCallbackException uce) { throw new LoginException(uce.getMessage() + " not available to obtain information from user"); user = ((NameCallback) callbacks[0]).getName(); char[] tmpPassword = ((PasswordCallback) callbacks[1]).getPassword(); if (tmpPassword == null) { tmpPassword = new char[0]; throw new FailedLoginException("user name is null"); throw new FailedLoginException("User does exist"); throw new FailedLoginException("Password does not match");
context = open(); } catch (NamingException ne) { FailedLoginException ex = new FailedLoginException("Error opening LDAP connection"); ex.initCause(ne); throw ex; throw new FailedLoginException("User " + username + " not found in LDAP."); close(context); FailedLoginException ex = new FailedLoginException("Error parsing absolute name as URI."); ex.initCause(e); throw ex; throw new FailedLoginException("User found, but LDAP entry malformed: " + username); throw new FailedLoginException("Password does not match for user: " + username); FailedLoginException ex = new FailedLoginException("Error contacting LDAP"); ex.initCause(e); throw ex; } catch (NamingException e) { close(context); FailedLoginException ex = new FailedLoginException("Error contacting LDAP"); ex.initCause(e); throw ex;
throw new LoginException("No CallbackHandler specified"); Callback callbacks[] = new Callback[2]; callbacks[0] = new NameCallback("Username: "); callbacks[1] = new PasswordCallback("Password: ", false); String password = null; try { callbackHandler.handle(callbacks); username = ((NameCallback) callbacks[0]).getName(); password = new String(((PasswordCallback) callbacks[1]).getPassword()); } catch (IOException e) { throw new LoginException(e.toString()); } catch (UnsupportedCallbackException e) { throw new LoginException(e.toString()); } else { throw new FailedLoginException("Username or password is incorrect");
throw new LoginException("Error: no CallbackHandler available, required to hold authentication information from the user"); callbacks[0] = new NameCallback("User name: "); callbacks[1] = new PasswordCallback("Password: ", false); String userName; char[] passwd; try { callbackHandler.handle(callbacks); userName = ((NameCallback) callbacks[0]).getName(); char[] tmpPassword = ((PasswordCallback) callbacks[1]).getPassword(); if (tmpPassword == null) { ((PasswordCallback) callbacks[1]).clearPassword(); } catch (IOException ioe) { throw new LoginException(ioe.toString()); } catch (UnsupportedCallbackException uce) { throw new LoginException("Error: " + uce.getCallback().toString() + " not available to hold authentication information"); throw new FailedLoginException("Authentication failed");
@Override public boolean login() throws LoginException { val nameCallback = new NameCallback("username"); val passwordCallback = new PasswordCallback("password", false); try { callbackHandler.handle(new Callback[]{nameCallback, passwordCallback}); } catch (final Exception e) { LOGGER.error(e.getMessage(), e); throw new FailedLoginException(e.getMessage()); } val username = nameCallback.getName(); val password = new String(passwordCallback.getPassword()); if (accounts.containsKey(username)) { this.succeeded = accounts.get(username).equals(password); subject.getPrincipals().add(new StaticPrincipal(username)); return true; } this.succeeded = false; return false; }
for (int i = 0; i < callbacks.length; i++) { if (callbacks[i] instanceof NameCallback) { ((NameCallback) callbacks[i]).setName(params[0]); } else if (callbacks[i] instanceof PasswordCallback) { ((PasswordCallback) callbacks[i]).setPassword((params[1].toCharArray())); } else { throw new UnsupportedCallbackException(callbacks[i]); throw new FailedLoginException("User doesn't have role defined");
@Test public void testLoginExternalCodecUnauthenticated() throws LoginException { LoginContext context = new LoginContext("LDAPLoginExternalPasswordCodec", callbacks -> { for (int i = 0; i < callbacks.length; i++) { if (callbacks[i] instanceof NameCallback) { ((NameCallback) callbacks[i]).setName("first"); } else if (callbacks[i] instanceof PasswordCallback) { ((PasswordCallback) callbacks[i]).setPassword("nosecret".toCharArray()); } else { throw new UnsupportedCallbackException(callbacks[i]); } } }); try { context.login(); } catch (FailedLoginException le) { assertEquals(le.getMessage(), "Password does not match for user: first"); return; } fail("Should have failed authenticating"); } }
public boolean login() throws LoginException { throw new LoginException("Error: no CallbackHandler available " + "to garner authentication information from the user"); callbacks[0] = new LocalNameCallback(factory, "user name: "); callbacks[1] = new LocalPasswordCallback(factory, "password: ", false); callbackHandler.handle(callbacks); username = ((NameCallback) callbacks[0]).getName(); char[] tmpPassword = ((PasswordCallback) callbacks[1]).getPassword(); if (tmpPassword == null) { ((PasswordCallback) callbacks[1]).clearPassword(); ((LocalNameCallback) callbacks[0]).unexport(); ((LocalPasswordCallback) callbacks[1]).unexport(); } catch (final IOException ioe) { throw (LoginException) new LoginException().initCause(ioe); } catch (final UnsupportedCallbackException uce) { throw new LoginException("Error: " + uce.getCallback().toString() + " not available to garner authentication information " + "from the user"); throw new FailedLoginException("User Name Incorrect"); } else if (usernameCorrect) { throw new FailedLoginException("Password Incorrect"); } else { throw new FailedLoginException("User Name or Password Incorrect");
System.out.println("Login Module - login called"); if (callbackHandler == null) { throw new LoginException("Oops, callbackHandler is null"); } Callback[] callbacks = new Callback[2]; callbacks[0] = new NameCallback("name:"); callbacks[1] = new PasswordCallback("password:", false); try { callbackHandler.handle(callbacks); } catch (IOException e) { throw new LoginException("Oops, IOException calling handle on callbackHandler"); } catch (UnsupportedCallbackException e) { throw new LoginException("Oops, UnsupportedCallbackException calling handle on callbackHandler"); } NameCallback nameCallback = (NameCallback) callbacks[0]; PasswordCallback passwordCallback = (PasswordCallback) callbacks[1]; String name = nameCallback.getName(); String password = new String(passwordCallback.getPassword()); if ("sohanb".equals(name) && "welcome".equals(password)) { System.out.println("Success! You get to log in!"); user = new JMXPrincipal(name); succeeded = true; return succeeded; } else { System.out.println("Failure! You don't get to log in"); succeeded = false; throw new FailedLoginException("Sorry! No login for you."); }
/** * Checks whether the user should be or has been locked out. */ public boolean login() throws LoginException { NameCallback user = new NameCallback("User name:"); Callback[] callbacks = new Callback[]{user}; try { handler.handle(callbacks); } catch (Exception e) { throw (LoginException)new LoginException("Unable to process callback: "+e.getMessage()).initCause(e); } if(callbacks.length != 1) { throw new IllegalStateException("Number of callbacks changed by server!"); } user = (NameCallback) callbacks[0]; username = user.getName(); if(username != null) { LoginHistory history; synchronized (userData) { history = userData.get(username); } if(history != null && !history.isLoginAllowed(lockoutDuration, failurePeriod, failureCount)) { username = null; throw new FailedLoginException("Maximum login failures exceeded; try again later"); } } return false; }
throw new LoginException ("No callback handler"); callbackHandler.handle(callbacks); String webUserName = ((NameCallback)callbacks[0]).getName(); Object webCredential = null; webCredential = ((PasswordCallback)callbacks[2]).getPassword(); //use standard PasswordCallback throw new FailedLoginException(); throw new FailedLoginException(); return true; else throw new FailedLoginException(); throw new LoginException (e.toString()); throw new LoginException (e.toString());
/** * 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(uce.getMessage() + " Unable to obtain client certificates."); } X509Certificate[] certificates = ((CertificateCallback)callbacks[0]).getCertificates(); username = getUserNameForCertificates(certificates); if (username == null) { throw new FailedLoginException("No user for client certificate: " + getDistinguishedName(certificates)); } if (debug) { LOG.debug("Certificate for user: " + username); } succeeded = true; return true; }
protected boolean doLogin() throws LoginException { Callback[] callbacks = new Callback[2]; callbacks[0] = new NameCallback("Username: "); callbacks[1] = new PublickeyCallback(); callbackHandler.handle(callbacks); } catch (IOException ioException) { throw new LoginException(ioException.getMessage()); } catch (UnsupportedCallbackException unsupportedCallbackException) { throw new LoginException(unsupportedCallbackException.getMessage() + " not available to obtain information from user."); user = Util.doRFC2254Encoding(((NameCallback) callbacks[0]).getName()); throw new LoginException("Can't connect to the LDAP server: " + e.getMessage()); throw new LoginException("Authentication failed"); } else { logger.warn("Public key authentication failed for user {}: {}", user, e.getMessage(), e); throw new LoginException("Public key authentication failed for user " + user + ": " + e.getMessage());
public boolean login() throws LoginException { Callback[] callbacks = new Callback[1]; callbacks[0] = new CertificateCallback(); try { handler.handle(callbacks); } catch (IOException ioe) { throw (LoginException) new LoginException().initCause(ioe); } catch (UnsupportedCallbackException uce) { throw (LoginException) new LoginException().initCause(uce); } assert callbacks.length == 1; X509Certificate certificate = ((CertificateCallback)callbacks[0]).getCertificate(); if (certificate == null) { throw new FailedLoginException(); } principal = certificate.getSubjectX500Principal(); if(!users.containsKey(principal.getName())) { throw new FailedLoginException(); } return true; }
@Test public void testEmptyPassword() throws Exception { LoginContext context = new LoginContext("LDAPLogin", new CallbackHandler() { @Override public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { for (int i = 0; i < callbacks.length; i++) { if (callbacks[i] instanceof NameCallback) { ((NameCallback) callbacks[i]).setName("first"); } else if (callbacks[i] instanceof PasswordCallback) { ((PasswordCallback) callbacks[i]).setPassword("".toCharArray()); } else { throw new UnsupportedCallbackException(callbacks[i]); } } } }); try { context.login(); fail("Should have thrown a FailedLoginException"); } catch (FailedLoginException fle) { assertEquals("Password cannot be null or empty", fle.getMessage()); } context.logout(); }
private static void checkSuccess(boolean success, String msg) throws LoginException { if (!success) { throw new FailedLoginException(msg); } }
throw new LoginException("Failed to create principal: "+ e.getMessage()); throw new LoginException("Failed to create principal: "+ e.getMessage()); FailedLoginException fle = new FailedLoginException("Password Incorrect/Password Required"); if( ex != null ) fle.initCause(ex);
@Override public final FailedLoginException noMatchingUsernameFoundInRoles() { final FailedLoginException result = new FailedLoginException(String.format(noMatchingUsernameFoundInRoles$str())); final StackTraceElement[] st = result.getStackTrace(); result.setStackTrace(Arrays.copyOfRange(st, 1, st.length)); return result; } private static final String failedToLookupDataSourceMessage = "PBOX00064: Error looking up DataSource from %s";
private boolean performLogin() throws LoginException { try { UnixUser user = _pam.authenticate(_username, _password); _principal = new PamPrincipal(user); _authSucceeded = true; return true; } catch (PAMException ex) { LoginException le = new FailedLoginException("Invalid username or password"); le.initCause(ex); throw le; } }
le.initCause(e); throw le; throw new FailedLoginException(ive.getLocalizedMessage()); le.initCause(e); throw le; le.initCause(e); throw le; PicketBoxLogger.LOGGER.debugBadPasswordForUsername(username); if( ex != null && this.throwValidateError) fle.initCause(ex); throw fle;