use of javax.security.sasl.RealmCallback in project alluxio by Alluxio.
the class PlainSaslClientCallbackHandlerTest method unsupportCallback.
/**
* 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);
}
use of javax.security.sasl.RealmCallback in project apex-core by apache.
the class DefaultCallbackHandler method processCallback.
protected void processCallback(Callback callback) throws IOException, UnsupportedCallbackException {
if (callback instanceof NameCallback) {
NameCallback namecb = (NameCallback) callback;
namecb.setName(context.getValue(SecurityContext.USER_NAME));
} else if (callback instanceof PasswordCallback) {
PasswordCallback passcb = (PasswordCallback) callback;
passcb.setPassword(context.getValue(SecurityContext.PASSWORD));
} else if (callback instanceof RealmCallback) {
RealmCallback realmcb = (RealmCallback) callback;
realmcb.setText(context.getValue(SecurityContext.REALM));
} else if (callback instanceof TextOutputCallback) {
TextOutputCallback textcb = (TextOutputCallback) callback;
if (textcb.getMessageType() == TextOutputCallback.INFORMATION) {
logger.info(textcb.getMessage());
} else if (textcb.getMessageType() == TextOutputCallback.WARNING) {
logger.warn(textcb.getMessage());
} else if (textcb.getMessageType() == TextOutputCallback.ERROR) {
logger.error(textcb.getMessage());
} else {
logger.debug("Auth message type {}, message {}", textcb.getMessageType(), textcb.getMessage());
}
} else {
throw new UnsupportedCallbackException(callback);
}
}
use of javax.security.sasl.RealmCallback in project apex-core by apache.
the class DefaultCallbackHandlerTest method testHandler.
@Test
public void testHandler() {
DefaultCallbackHandler handler = new DefaultCallbackHandler();
SecurityContext context = new SecurityContext();
handler.setup(context);
Callback[] callbacks = new Callback[3];
callbacks[0] = new NameCallback("UserName:");
callbacks[1] = new PasswordCallback("Password:", false);
callbacks[2] = new RealmCallback("Realm:");
try {
handler.handle(callbacks);
Assert.assertEquals("Username", "user1", ((NameCallback) callbacks[0]).getName());
Assert.assertEquals("Password", "pass", new String(((PasswordCallback) callbacks[1]).getPassword()));
Assert.assertEquals("Realm", "default", ((RealmCallback) callbacks[2]).getText());
} catch (IOException e) {
Assert.fail(e.getMessage());
} catch (UnsupportedCallbackException e) {
Assert.fail(e.getMessage());
}
}
use of javax.security.sasl.RealmCallback in project wildfly by wildfly.
the class RealmDirectLoginModule method getUsersPassword.
/**
* @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;
}
use of javax.security.sasl.RealmCallback in project wildfly by wildfly.
the class RealmDirectLoginModule method validatePassword.
@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;
}
}
Aggregations