use of javax.security.enterprise.credential.UsernamePasswordCredential in project quickstart by wildfly.
the class TestAuthenticationMechanism method validateRequest.
@Override
public AuthenticationStatus validateRequest(HttpServletRequest request, HttpServletResponse response, HttpMessageContext httpMessageContext) throws AuthenticationException {
final String username = request.getHeader(USERNAME_HEADER);
final String password = request.getHeader(PASSWORD_HEADER);
if (username != null && password != null) {
UsernamePasswordCredential upc = new UsernamePasswordCredential(username, password);
CredentialValidationResult cvr = identityStoreHandler.validate(upc);
if (cvr.getStatus() == Status.VALID) {
return httpMessageContext.notifyContainerAboutLogin(cvr.getCallerPrincipal(), cvr.getCallerGroups());
} else {
return challenge(response, httpMessageContext);
}
}
return challenge(response, httpMessageContext);
}
use of javax.security.enterprise.credential.UsernamePasswordCredential in project wildfly by wildfly.
the class TestAuthenticationMechanism method validateRequest.
@Override
public AuthenticationStatus validateRequest(HttpServletRequest request, HttpServletResponse response, HttpMessageContext httpMessageContext) throws AuthenticationException {
final String username = request.getHeader(USERNAME_HEADER);
final String password = request.getHeader(PASSWORD_HEADER);
final boolean challenge = Boolean.parseBoolean(request.getParameter("challenge"));
if (username != null && password != null) {
UsernamePasswordCredential upc = new UsernamePasswordCredential(username, password);
CredentialValidationResult cvr = identityStoreHandler.validate(upc);
if (cvr.getStatus() == Status.VALID) {
return httpMessageContext.notifyContainerAboutLogin(cvr.getCallerPrincipal(), cvr.getCallerGroups());
} else {
return challenge(response, httpMessageContext);
}
}
if (challenge || httpMessageContext.isProtected()) {
return challenge(response, httpMessageContext);
}
return httpMessageContext.doNothing();
}
use of javax.security.enterprise.credential.UsernamePasswordCredential in project Payara by payara.
the class RealmIdentityStore method login.
protected Subject login(UsernamePasswordCredential credential, String realmName) {
String username = credential.getCaller();
char[] password = credential.getPassword().getValue();
Subject subject = new Subject();
privileged(() -> subject.getPrivateCredentials().add(new PasswordCredential(username, password, getValidRealm(realmName))));
WebAndEjbToJaasBridge.login(subject, PasswordCredential.class);
return subject;
}
use of javax.security.enterprise.credential.UsernamePasswordCredential in project Payara by payara.
the class RealmIdentityStore method validate.
protected CredentialValidationResult validate(UsernamePasswordCredential credential, String realmName) {
try {
Subject subject = login(credential, realmName);
Set<String> groups = subject.getPrincipals(Group.class).stream().map(g -> g.getName()).collect(toSet());
if (!groups.isEmpty()) {
return new CredentialValidationResult(new CallerPrincipal(credential.getCaller()), groups);
}
} catch (LoginException ex) {
return INVALID_RESULT;
}
return INVALID_RESULT;
}
use of javax.security.enterprise.credential.UsernamePasswordCredential in project quickstart by wildfly.
the class ElytronIdentityStore method validate.
@Override
public CredentialValidationResult validate(Credential credential) {
if (credential instanceof UsernamePasswordCredential) {
UsernamePasswordCredential upc = (UsernamePasswordCredential) credential;
SecurityIdentity result;
try {
result = securityDomain.authenticate(upc.getCaller(), new PasswordGuessEvidence(upc.getPassword().getValue()));
} catch (RealmUnavailableException e) {
return NOT_VALIDATED_RESULT;
} catch (SecurityException e) {
return INVALID_RESULT;
}
final HashSet<String> groups = new HashSet<>();
result.getRoles().forEach(groups::add);
return new CredentialValidationResult(result.getPrincipal().getName(), groups);
}
return INVALID_RESULT;
}
Aggregations