Search in sources :

Example 11 with UsernamePasswordCredential

use of javax.security.enterprise.credential.UsernamePasswordCredential in project Payara by payara.

the class SampleAuthenticationMechanism method validateRequest.

@Override
public AuthenticationStatus validateRequest(HttpServletRequest request, HttpServletResponse response, HttpMessageContext httpMessageContext) throws AuthenticationException {
    String name = request.getHeader("username");
    String password = request.getHeader("password");
    if (name == null && password == null) {
        return httpMessageContext.doNothing();
    } else {
        CredentialValidationResult loginResult = identityStoreTest.validate(new UsernamePasswordCredential(name, password));
        if (loginResult.getStatus() == VALID) {
            return httpMessageContext.notifyContainerAboutLogin(loginResult.getCallerPrincipal(), loginResult.getCallerGroups());
        } else {
            return httpMessageContext.responseUnauthorized();
        }
    }
}
Also used : CredentialValidationResult(javax.security.enterprise.identitystore.CredentialValidationResult) UsernamePasswordCredential(javax.security.enterprise.credential.UsernamePasswordCredential)

Aggregations

UsernamePasswordCredential (javax.security.enterprise.credential.UsernamePasswordCredential)11 CredentialValidationResult (javax.security.enterprise.identitystore.CredentialValidationResult)9 PasswordCredential (com.sun.enterprise.security.auth.login.common.PasswordCredential)2 Subject (javax.security.auth.Subject)2 WebAndEjbToJaasBridge (com.sun.enterprise.security.auth.WebAndEjbToJaasBridge)1 LoginContextDriver.getValidRealm (com.sun.enterprise.security.auth.login.LoginContextDriver.getValidRealm)1 LoginException (com.sun.enterprise.security.auth.login.common.LoginException)1 AppservAccessController.privileged (com.sun.enterprise.security.common.AppservAccessController.privileged)1 RealmIdentityStoreDefinition (fish.payara.security.annotations.RealmIdentityStoreDefinition)1 CertificateCredential (fish.payara.security.api.CertificateCredential)1 RealmIdentityStoreConfiguration (fish.payara.security.realm.config.RealmIdentityStoreConfiguration)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 Collectors.toSet (java.util.stream.Collectors.toSet)1 Typed (javax.enterprise.inject.Typed)1 InitialLdapContext (javax.naming.ldap.InitialLdapContext)1 LdapContext (javax.naming.ldap.LdapContext)1 CallerPrincipal (javax.security.enterprise.CallerPrincipal)1 Credential (javax.security.enterprise.credential.Credential)1 INVALID_RESULT (javax.security.enterprise.identitystore.CredentialValidationResult.INVALID_RESULT)1