public byte[] handleUserRealmPasswordCallbacks() throws AuthenticationMechanismException { realmChoiceCallBack = skipRealmCallbacks || realms == null || realms.length <= 1 ? null : new RealmChoiceCallback("User realm: ", realms, 0, false); realmCallback = skipRealmCallbacks ? null : realm != null ? new RealmCallback("User realm: ", realm) : new RealmCallback("User realm: "); nameCallback = username != null && ! username.isEmpty() ? new NameCallback("User name: ", username) : new NameCallback("User name: "); byte[] digest = getPredigestedSaltedPassword(); if (digest != null) return digest; digest = getSaltedPasswordFromTwoWay(); if (digest != null) return digest; digest = getSaltedPasswordFromPasswordCallback(); if (digest != null) return digest; throw log.mechCallbackHandlerDoesNotSupportCredentialAcquisition(null); }
@Override protected boolean validatePassword(String inputPassword, String expectedPassword) { if (digestCredential != null) { return digestCredential.verifyHA1(expectedPassword.getBytes(UTF_8)); } switch (validationMode) { case DIGEST: String inputHashed = hashUtil.generateHashedHexURP(getUsername(), securityRealm.getName(), inputPassword.toCharArray()); return expectedPassword.equals(inputHashed); case PASSWORD: return expectedPassword.equals(inputPassword); case VALIDATION: RealmCallback rcb = new RealmCallback("Realm", securityRealm.getName()); NameCallback ncb = new NameCallback("User Name", getUsername()); EvidenceVerifyCallback evc = new EvidenceVerifyCallback(new PasswordGuessEvidence(inputPassword.toCharArray())); try { handle(new Callback[]{rcb, ncb, evc}); return evc.isVerified(); } catch (LoginException e) { return false; } default: return false; } }
/** * Tests that an exception is thrown in case an unsupported callback is used. */ @Test public void unsupportCallback() throws Exception { mThrown.expect(UnsupportedCallbackException.class); mThrown.expectMessage(RealmCallback.class + " is unsupported."); Callback[] callbacks = new Callback[3]; callbacks[0] = new NameCallback("Username:"); callbacks[1] = new PasswordCallback("Password:", true); callbacks[2] = new RealmCallback("Realm:"); String user = "alluxio-user-2"; String password = "alluxio-user-2-password"; CallbackHandler clientCBHandler = new PlainSaslClientCallbackHandler(user, password); clientCBHandler.handle(callbacks); }
protected boolean authenticate(String realmName, String username, char[] password) throws HttpAuthenticationException { RealmCallback realmCallback = realmName != null ? new RealmCallback("User realm", realmName) : null; NameCallback nameCallback = new NameCallback("Remote Authentication Name", username); nameCallback.setName(username);
/** * @see org.jboss.security.auth.spi.UsernamePasswordLoginModule#getUsersPassword() */ @Override protected String getUsersPassword() throws LoginException { if (validationMode == ValidationMode.VALIDATION) { return null; } RealmCallback rcb = new RealmCallback("Realm", securityRealm.getName()); NameCallback ncb = new NameCallback("User Name", getUsername()); String password = null; switch (validationMode) { case DIGEST: CredentialCallback cc = new CredentialCallback(PasswordCredential.class, ALGORITHM_DIGEST_MD5); handle(new Callback[]{rcb, ncb, cc}); PasswordCredential passwordCredential = (PasswordCredential) cc.getCredential(); DigestPassword digestPassword = passwordCredential.getPassword(DigestPassword.class); password = ByteIterator.ofBytes(digestPassword.getDigest()).hexEncode().drainToString(); break; case PASSWORD: PasswordCallback pcb = new PasswordCallback("Password", false); handle(new Callback[]{rcb, ncb, pcb}); password = String.valueOf(pcb.getPassword()); break; } return password; }
handleCallbacks(nameCallback, authorizeCallback); } else { final RealmCallback realmCallback = new RealmCallback("User realm", authenticationRealm); handleCallbacks(realmCallback, nameCallback, authorizeCallback);
final NameCallback nameCallback = authenticationId != null && ! authenticationId.isEmpty() ? new OptionalNameCallback("User name", authenticationId) : new OptionalNameCallback("User name"); final RealmCallback realmCallback = new RealmCallback("User realm");
public byte[] handleUserRealmPasswordCallbacks() throws AuthenticationMechanismException { realmChoiceCallBack = skipRealmCallbacks || realms == null || realms.length <= 1 ? null : new RealmChoiceCallback("User realm: ", realms, 0, false); realmCallback = skipRealmCallbacks ? null : realm != null ? new RealmCallback("User realm: ", realm) : new RealmCallback("User realm: "); nameCallback = username != null && ! username.isEmpty() ? new NameCallback("User name: ", username) : new NameCallback("User name: "); byte[] digest = getPredigestedSaltedPassword(); if (digest != null) return digest; digest = getSaltedPasswordFromTwoWay(); if (digest != null) return digest; digest = getSaltedPasswordFromPasswordCallback(); if (digest != null) return digest; throw log.mechCallbackHandlerDoesNotSupportCredentialAcquisition(null); }
public byte[] handleUserRealmPasswordCallbacks() throws AuthenticationMechanismException { realmChoiceCallBack = skipRealmCallbacks || realms == null || realms.length <= 1 ? null : new RealmChoiceCallback("User realm: ", realms, 0, false); realmCallback = skipRealmCallbacks ? null : realm != null ? new RealmCallback("User realm: ", realm) : new RealmCallback("User realm: "); nameCallback = username != null && ! username.isEmpty() ? new NameCallback("User name: ", username) : new NameCallback("User name: "); byte[] digest = getPredigestedSaltedPassword(); if (digest != null) return digest; digest = getSaltedPasswordFromTwoWay(); if (digest != null) return digest; digest = getSaltedPasswordFromPasswordCallback(); if (digest != null) return digest; throw log.mechCallbackHandlerDoesNotSupportCredentialAcquisition(null); }
public byte[] handleUserRealmPasswordCallbacks() throws AuthenticationMechanismException { realmChoiceCallBack = skipRealmCallbacks || realms == null || realms.length <= 1 ? null : new RealmChoiceCallback("User realm: ", realms, 0, false); realmCallback = skipRealmCallbacks ? null : realm != null ? new RealmCallback("User realm: ", realm) : new RealmCallback("User realm: "); nameCallback = username != null && ! username.isEmpty() ? new NameCallback("User name: ", username) : new NameCallback("User name: "); byte[] digest = getPredigestedSaltedPassword(); if (digest != null) return digest; digest = getSaltedPasswordFromTwoWay(); if (digest != null) return digest; digest = getSaltedPasswordFromPasswordCallback(); if (digest != null) return digest; throw log.mechCallbackHandlerDoesNotSupportCredentialAcquisition(null); }
/** * @see org.jboss.security.auth.spi.UsernamePasswordLoginModule#getUsersPassword() */ @Override protected String getUsersPassword() throws LoginException { if (validationMode == ValidationMode.VALIDATION) { return null; } RealmCallback rcb = new RealmCallback("Realm", securityRealm.getName()); NameCallback ncb = new NameCallback("User Name", getUsername()); String password = null; switch (validationMode) { case DIGEST: DigestHashCallback dhc = new DigestHashCallback("Digest"); handle(new Callback[]{rcb, ncb, dhc}); password = dhc.getHexHash(); break; case PASSWORD: PasswordCallback pcb = new PasswordCallback("Password", false); handle(new Callback[]{rcb, ncb, pcb}); password = String.valueOf(pcb.getPassword()); break; } return password; }
/** * @see org.jboss.security.auth.spi.UsernamePasswordLoginModule#getUsersPassword() */ @Override protected String getUsersPassword() throws LoginException { if (validationMode == ValidationMode.VALIDATION) { return null; } RealmCallback rcb = new RealmCallback("Realm", securityRealm.getName()); NameCallback ncb = new NameCallback("User Name", getUsername()); String password = null; switch (validationMode) { case DIGEST: DigestHashCallback dhc = new DigestHashCallback("Digest"); handle(new Callback[]{rcb, ncb, dhc}); password = dhc.getHexHash(); break; case PASSWORD: PasswordCallback pcb = new PasswordCallback("Password", false); handle(new Callback[]{rcb, ncb, pcb}); password = String.valueOf(pcb.getPassword()); break; } return password; }
@Override protected boolean validatePassword(String inputPassword, String expectedPassword) { switch (validationMode) { case DIGEST: String inputHashed = hashUtil.generateHashedHexURP(getUsername(), securityRealm.getName(), inputPassword.toCharArray()); return expectedPassword.equals(inputHashed); case PASSWORD: return expectedPassword.equals(inputPassword); case VALIDATION: RealmCallback rcb = new RealmCallback("Realm", securityRealm.getName()); NameCallback ncb = new NameCallback("User Name", getUsername()); VerifyPasswordCallback vpc = new VerifyPasswordCallback(inputPassword); try { handle(new Callback[]{rcb, ncb, vpc}); return vpc.isVerified(); } catch (LoginException e) { return false; } default: // Should not be reachable. return false; } }
@Override protected boolean validatePassword(String inputPassword, String expectedPassword) { switch (validationMode) { case DIGEST: String inputHashed = hashUtil.generateHashedHexURP(getUsername(), securityRealm.getName(), inputPassword.toCharArray()); return expectedPassword.equals(inputHashed); case PASSWORD: return expectedPassword.equals(inputPassword); case VALIDATION: RealmCallback rcb = new RealmCallback("Realm", securityRealm.getName()); NameCallback ncb = new NameCallback("User Name", getUsername()); VerifyPasswordCallback vpc = new VerifyPasswordCallback(inputPassword); try { handle(new Callback[]{rcb, ncb, vpc}); return vpc.isVerified(); } catch (LoginException e) { return false; } default: // Should not be reachable. return false; } }
@Override protected boolean validatePassword(String inputPassword, String expectedPassword) { if (digestCredential != null) { return digestCredential.verifyHA1(expectedPassword.getBytes(UTF_8)); } switch (validationMode) { case DIGEST: String inputHashed = hashUtil.generateHashedHexURP(getUsername(), securityRealm.getName(), inputPassword.toCharArray()); return expectedPassword.equals(inputHashed); case PASSWORD: return expectedPassword.equals(inputPassword); case VALIDATION: RealmCallback rcb = new RealmCallback("Realm", securityRealm.getName()); NameCallback ncb = new NameCallback("User Name", getUsername()); EvidenceVerifyCallback evc = new EvidenceVerifyCallback(new PasswordGuessEvidence(inputPassword.toCharArray())); try { handle(new Callback[]{rcb, ncb, evc}); return evc.isVerified(); } catch (LoginException e) { return false; } default: return false; } }
protected boolean authenticate(String realmName, String username, char[] password) throws HttpAuthenticationException { RealmCallback realmCallback = realmName != null ? new RealmCallback("User realm", realmName) : null; NameCallback nameCallback = new NameCallback("Remote Authentication Name", username); nameCallback.setName(username);
protected boolean authenticate(String realmName, String username, char[] password) throws HttpAuthenticationException { RealmCallback realmCallback = realmName != null ? new RealmCallback("User realm", realmName) : null; NameCallback nameCallback = new NameCallback("Remote Authentication Name", username); nameCallback.setName(username);
protected boolean authenticate(String realmName, String username, char[] password) throws HttpAuthenticationException { RealmCallback realmCallback = realmName != null ? new RealmCallback("User realm", realmName) : null; NameCallback nameCallback = new NameCallback("Remote Authentication Name", username); nameCallback.setName(username);
/** * @see org.jboss.security.auth.spi.UsernamePasswordLoginModule#getUsersPassword() */ @Override protected String getUsersPassword() throws LoginException { if (validationMode == ValidationMode.VALIDATION) { return null; } RealmCallback rcb = new RealmCallback("Realm", securityRealm.getName()); NameCallback ncb = new NameCallback("User Name", getUsername()); String password = null; switch (validationMode) { case DIGEST: CredentialCallback cc = new CredentialCallback(PasswordCredential.class, ALGORITHM_DIGEST_MD5); handle(new Callback[]{rcb, ncb, cc}); PasswordCredential passwordCredential = (PasswordCredential) cc.getCredential(); DigestPassword digestPassword = passwordCredential.getPassword(DigestPassword.class); password = ByteIterator.ofBytes(digestPassword.getDigest()).hexEncode().drainToString(); break; case PASSWORD: PasswordCallback pcb = new PasswordCallback("Password", false); handle(new Callback[]{rcb, ncb, pcb}); password = String.valueOf(pcb.getPassword()); break; } return password; }
private Account verify(String id, PasswordCredential credential) { assertMechanism(AuthMechanism.PLAIN); if (credential == null) { return null; } AuthorizingCallbackHandler ach = securityRealm.getAuthorizingCallbackHandler(AuthMechanism.PLAIN); Callback[] callbacks = new Callback[3]; callbacks[0] = new RealmCallback("Realm", securityRealm.getName()); callbacks[1] = new NameCallback("Username", id); callbacks[2] = new EvidenceVerifyCallback(new PasswordGuessEvidence(credential.getPassword())); try { ach.handle(callbacks); } catch (Exception e) { ROOT_LOGGER.debug("Failure handling Callback(s) for BASIC authentication.", e); return null; } if (((EvidenceVerifyCallback) callbacks[2]).isVerified() == false) { return null; } Principal user = new SimplePrincipal(id); Collection<Principal> userCol = Collections.singleton(user); SubjectUserInfo supplemental; try { supplemental = ach.createSubjectUserInfo(userCol); } catch (IOException e) { return null; } addInetPrincipal(supplemental.getSubject().getPrincipals()); return new RealmIdentityAccount(supplemental.getSubject(), user); }