use of org.wildfly.security.sasl.util.UsernamePasswordHashUtil in project wildfly by wildfly.
the class RealmDirectLoginModule method initialize.
@Override
public void initialize(Subject subject, CallbackHandler callbackHandler, Map<String, ?> sharedState, Map<String, ?> options) {
addValidOptions(ALL_VALID_OPTIONS);
super.initialize(subject, callbackHandler, sharedState, options);
final String realm = options.containsKey(REALM_OPTION) ? (String) options.get(REALM_OPTION) : DEFAULT_REALM;
final ServiceController<?> controller = currentServiceContainer().getService(SecurityRealm.ServiceUtil.createServiceName(realm));
if (controller != null) {
securityRealm = (SecurityRealm) controller.getValue();
}
if (securityRealm == null) {
throw SecurityLogger.ROOT_LOGGER.realmNotFound(realm);
}
Set<AuthMechanism> authMechs = securityRealm.getSupportedAuthenticationMechanisms();
if (authMechs.contains(AuthMechanism.DIGEST)) {
chosenMech = AuthMechanism.DIGEST;
} else if (authMechs.contains(AuthMechanism.PLAIN)) {
chosenMech = AuthMechanism.PLAIN;
} else {
chosenMech = authMechs.iterator().next();
}
if (chosenMech == AuthMechanism.DIGEST || chosenMech == AuthMechanism.PLAIN) {
Map<String, String> mechOpts = securityRealm.getMechanismConfig(chosenMech);
if (mechOpts.containsKey(VERIFY_PASSWORD_CALLBACK_SUPPORTED) && Boolean.parseBoolean(mechOpts.get(VERIFY_PASSWORD_CALLBACK_SUPPORTED))) {
// We give this mode priority as even if digest is supported the realm supplied
// callback handler can handle the conversion comparison itself.
validationMode = ValidationMode.VALIDATION;
} else {
if (chosenMech == AuthMechanism.DIGEST) {
if (mechOpts.containsKey(DIGEST_PLAIN_TEXT) && Boolean.parseBoolean(mechOpts.get(DIGEST_PLAIN_TEXT))) {
validationMode = ValidationMode.PASSWORD;
} else {
validationMode = ValidationMode.DIGEST;
try {
hashUtil = new UsernamePasswordHashUtil();
} catch (NoSuchAlgorithmException e) {
throw new IllegalStateException(e);
}
}
} else {
validationMode = ValidationMode.PASSWORD;
}
}
} else {
validationMode = ValidationMode.NONE;
}
}
Aggregations