Search in sources :

Example 41 with AuthenticationResult

use of org.apache.qpid.server.security.auth.AuthenticationResult in project qpid-broker-j by apache.

the class MD5AuthenticationProvider method authenticate.

@Override
public AuthenticationResult authenticate(final String username, final String password) {
    ManagedUser user = getUser(username);
    AuthenticationResult result;
    if (user != null && user.getPassword().equals(createStoredPassword(password))) {
        result = new AuthenticationResult(new UsernamePrincipal(username, this));
    } else {
        result = new AuthenticationResult(AuthenticationResult.AuthenticationStatus.ERROR);
    }
    return result;
}
Also used : UsernamePrincipal(org.apache.qpid.server.security.auth.UsernamePrincipal) AuthenticationResult(org.apache.qpid.server.security.auth.AuthenticationResult)

Example 42 with AuthenticationResult

use of org.apache.qpid.server.security.auth.AuthenticationResult in project qpid-broker-j by apache.

the class PlainAuthenticationProvider method authenticate.

@Override
public AuthenticationResult authenticate(final String username, final String password) {
    ManagedUser user = getUser(username);
    AuthenticationResult result;
    if (user != null && user.getPassword().equals(password)) {
        result = new AuthenticationResult(new UsernamePrincipal(username, this));
    } else {
        result = new AuthenticationResult(AuthenticationResult.AuthenticationStatus.ERROR);
    }
    return result;
}
Also used : UsernamePrincipal(org.apache.qpid.server.security.auth.UsernamePrincipal) AuthenticationResult(org.apache.qpid.server.security.auth.AuthenticationResult)

Example 43 with AuthenticationResult

use of org.apache.qpid.server.security.auth.AuthenticationResult in project qpid-broker-j by apache.

the class SimpleLDAPAuthenticationManagerImpl method doLDAPNameAuthentication.

private AuthenticationResult doLDAPNameAuthentication(String userId, String password) {
    final String name;
    try {
        name = getNameFromId(userId);
    } catch (NamingException e) {
        LOGGER.warn("Retrieving LDAP name for user '{}' resulted in error.", userId, e);
        return new AuthenticationResult(AuthenticationResult.AuthenticationStatus.ERROR, e);
    }
    if (name == null) {
        // The search didn't return anything, class as not-authenticated before it NPEs below
        return new AuthenticationResult(AuthenticationStatus.ERROR);
    }
    String providerAuthUrl = isSpecified(getProviderAuthUrl()) ? getProviderAuthUrl() : getProviderUrl();
    Hashtable<String, Object> env = createInitialDirContextEnvironment(providerAuthUrl);
    env.put(Context.SECURITY_AUTHENTICATION, "simple");
    env.put(Context.SECURITY_PRINCIPAL, name);
    env.put(Context.SECURITY_CREDENTIALS, password);
    InitialDirContext ctx = null;
    try {
        ctx = createInitialDirContext(env, _sslSocketFactoryOverrideClass);
        Set<Principal> groups = Collections.emptySet();
        if (isGroupSearchRequired()) {
            if (!providerAuthUrl.equals(getProviderUrl())) {
                closeSafely(ctx);
                ctx = createSearchInitialDirContext();
            }
            groups = findGroups(ctx, name);
        }
        // Authentication succeeded
        return new AuthenticationResult(new UsernamePrincipal(name, this), groups, null);
    } catch (AuthenticationException ae) {
        // Authentication failed
        return new AuthenticationResult(AuthenticationStatus.ERROR);
    } catch (NamingException e) {
        // Some other failure
        LOGGER.warn("LDAP authentication attempt for username '{}' resulted in error.", name, e);
        return new AuthenticationResult(AuthenticationResult.AuthenticationStatus.ERROR, e);
    } finally {
        if (ctx != null) {
            closeSafely(ctx);
        }
    }
}
Also used : UsernamePrincipal(org.apache.qpid.server.security.auth.UsernamePrincipal) AuthenticationException(javax.naming.AuthenticationException) NamingException(javax.naming.NamingException) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) InitialDirContext(javax.naming.directory.InitialDirContext) UsernamePrincipal(org.apache.qpid.server.security.auth.UsernamePrincipal) GroupPrincipal(org.apache.qpid.server.security.group.GroupPrincipal) Principal(java.security.Principal) AuthenticationResult(org.apache.qpid.server.security.auth.AuthenticationResult)

Example 44 with AuthenticationResult

use of org.apache.qpid.server.security.auth.AuthenticationResult in project qpid-broker-j by apache.

the class OAuth2AuthenticationProviderImpl method authenticateViaAccessToken.

@Override
public AuthenticationResult authenticateViaAccessToken(final String accessToken, final NamedAddressSpace addressSpace) {
    return _authenticationResultCacher.getOrLoad(new String[] { accessToken }, () -> {
        try {
            final Principal userPrincipal = _identityResolverService.getUserPrincipal(OAuth2AuthenticationProviderImpl.this, accessToken, addressSpace);
            OAuth2UserPrincipal oauthUserPrincipal = new OAuth2UserPrincipal(userPrincipal.getName(), accessToken, OAuth2AuthenticationProviderImpl.this);
            return new AuthenticationResult(oauthUserPrincipal);
        } catch (IOException | IdentityResolverException e) {
            LOGGER.error("Call to identity resolver failed", e);
            return new AuthenticationResult(AuthenticationResult.AuthenticationStatus.ERROR, e);
        }
    });
}
Also used : IOException(java.io.IOException) Principal(java.security.Principal) AuthenticationResult(org.apache.qpid.server.security.auth.AuthenticationResult)

Example 45 with AuthenticationResult

use of org.apache.qpid.server.security.auth.AuthenticationResult in project qpid-broker-j by apache.

the class SubjectCreatorTest method setUp.

@Override
public void setUp() {
    when(_groupManager1.getGroupPrincipalsForUser(USERNAME_PRINCIPAL)).thenReturn(Collections.singleton(_group1));
    when(_groupManager2.getGroupPrincipalsForUser(USERNAME_PRINCIPAL)).thenReturn(Collections.singleton(_group2));
    _subjectCreator = new SubjectCreator(_authenticationProvider, new HashSet<>(Arrays.asList(_groupManager1, _groupManager2)), null);
    _eventLogger = mock(EventLogger.class);
    when(_authenticationProvider.getEventLogger()).thenReturn(_eventLogger);
    _authenticationResult = new AuthenticationResult(USERNAME_PRINCIPAL);
}
Also used : EventLogger(org.apache.qpid.server.logging.EventLogger) HashSet(java.util.HashSet) SubjectAuthenticationResult(org.apache.qpid.server.security.auth.SubjectAuthenticationResult) AuthenticationResult(org.apache.qpid.server.security.auth.AuthenticationResult)

Aggregations

AuthenticationResult (org.apache.qpid.server.security.auth.AuthenticationResult)78 UsernamePrincipal (org.apache.qpid.server.security.auth.UsernamePrincipal)13 SaslNegotiator (org.apache.qpid.server.security.auth.sasl.SaslNegotiator)13 X500Principal (javax.security.auth.x500.X500Principal)12 SubjectAuthenticationResult (org.apache.qpid.server.security.auth.SubjectAuthenticationResult)9 HashMap (java.util.HashMap)6 SubjectCreator (org.apache.qpid.server.security.SubjectCreator)6 Subject (javax.security.auth.Subject)5 IOException (java.io.IOException)4 OAuth2AuthenticationProvider (org.apache.qpid.server.security.auth.manager.oauth2.OAuth2AuthenticationProvider)4 InetSocketAddress (java.net.InetSocketAddress)3 URISyntaxException (java.net.URISyntaxException)3 Principal (java.security.Principal)3 Broker (org.apache.qpid.server.model.Broker)3 NamedAddressSpace (org.apache.qpid.server.model.NamedAddressSpace)3 AuthenticatedPrincipal (org.apache.qpid.server.security.auth.AuthenticatedPrincipal)3 URI (java.net.URI)2 AccessControlException (java.security.AccessControlException)2 EventLogger (org.apache.qpid.server.logging.EventLogger)2 User (org.apache.qpid.server.model.User)2