use of org.jboss.security.auth.callback.SecurityAssociationCallback in project wildfly by wildfly.
the class TrustedIdentityTokenLoginModule method login.
@Override
@SuppressWarnings("unchecked")
public boolean login() throws LoginException {
// See if shared credentials exist
if (super.login() == true) {
// Setup our view of the user
Object username = sharedState.get("javax.security.auth.login.name");
if (username instanceof Principal)
identity = (Principal) username;
else {
String name = username.toString();
try {
identity = createIdentity(name);
} catch (Exception e) {
LoginException le = new LoginException();
le.initCause(e);
throw le;
}
}
return true;
}
super.loginOk = false;
if (callbackHandler == null) {
throw new LoginException();
}
SecurityAssociationCallback callback = new SecurityAssociationCallback();
Callback[] callbacks = { callback };
final String username;
try {
callbackHandler.handle(callbacks);
username = callback.getPrincipal().getName();
final Object c = callback.getCredential();
if (c instanceof SASCurrent) {
credential = (SASCurrent) c;
} else {
return false;
}
} catch (IOException e) {
LoginException le = new LoginException();
le.initCause(e);
throw le;
} catch (UnsupportedCallbackException e) {
LoginException le = new LoginException();
le.initCause(e);
throw le;
}
validateCredential(username, credential);
if (username == null) {
return false;
}
if (identity == null) {
try {
identity = createIdentity(username);
} catch (Exception e) {
LoginException le = new LoginException();
le.initCause(e);
throw le;
}
}
if (getUseFirstPass() == true) {
// Add the principal to the shared state map
sharedState.put("javax.security.auth.login.name", identity);
sharedState.put("javax.security.auth.login.password", credential);
}
super.loginOk = true;
return true;
}
use of org.jboss.security.auth.callback.SecurityAssociationCallback in project wildfly-swarm by wildfly-swarm.
the class JWTLoginModule method login.
@Override
public boolean login() throws LoginException {
SecurityAssociationCallback sac = new SecurityAssociationCallback();
try {
callbackHandler.handle(new Callback[] { sac });
JWTCredential jwtCredential = (JWTCredential) sac.getCredential();
// Validate the credential by
jwtPrincipal = validate(jwtCredential);
} catch (Exception e) {
if (logExceptions) {
log.infof(e, "Failed to validate token");
}
LoginException ex = new LoginException("Failed to validate token");
ex.initCause(e);
throw ex;
}
loginOk = true;
return true;
}
Aggregations