Search in sources :

Example 16 with UsernamePrincipal

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

the class OAuth2PreemptiveAuthenticatorTest method createMockOAuth2AuthenticationProvider.

private OAuth2AuthenticationProvider<?> createMockOAuth2AuthenticationProvider(final HttpPort mockPort) throws URISyntaxException {
    OAuth2AuthenticationProvider authenticationProvider = mock(OAuth2AuthenticationProvider.class);
    SubjectCreator mockSubjectCreator = mock(SubjectCreator.class);
    SubjectAuthenticationResult mockSuccessfulSubjectAuthenticationResult = mock(SubjectAuthenticationResult.class);
    SubjectAuthenticationResult mockUnauthorizedSubjectAuthenticationResult = mock(SubjectAuthenticationResult.class);
    final Subject successfulSubject = new Subject(true, Collections.singleton(new AuthenticatedPrincipal(new UsernamePrincipal(TEST_AUTHORIZED_USER, null))), Collections.emptySet(), Collections.emptySet());
    final Subject unauthorizedSubject = new Subject(true, Collections.singleton(new AuthenticatedPrincipal(new UsernamePrincipal(TEST_UNAUTHORIZED_USER, null))), Collections.emptySet(), Collections.emptySet());
    AuthenticationResult mockSuccessfulAuthenticationResult = mock(AuthenticationResult.class);
    AuthenticationResult mockUnauthorizedAuthenticationResult = mock(AuthenticationResult.class);
    AuthenticationResult failedAuthenticationResult = new AuthenticationResult(AuthenticationResult.AuthenticationStatus.ERROR, new Exception("authentication failed"));
    SubjectAuthenticationResult failedSubjectAuthenticationResult = new SubjectAuthenticationResult(failedAuthenticationResult);
    when(mockPort.getSubjectCreator(any(Boolean.class), anyString())).thenReturn(mockSubjectCreator);
    when(authenticationProvider.authenticateViaAccessToken(TEST_VALID_ACCESS_TOKEN, null)).thenReturn(mockSuccessfulAuthenticationResult);
    when(authenticationProvider.authenticateViaAccessToken(TEST_INVALID_ACCESS_TOKEN, null)).thenReturn(failedAuthenticationResult);
    when(authenticationProvider.authenticateViaAccessToken(TEST_UNAUTHORIZED_ACCESS_TOKEN, null)).thenReturn(mockUnauthorizedAuthenticationResult);
    when(mockSuccessfulSubjectAuthenticationResult.getSubject()).thenReturn(successfulSubject);
    when(mockUnauthorizedSubjectAuthenticationResult.getSubject()).thenReturn(unauthorizedSubject);
    when(mockSubjectCreator.createResultWithGroups(mockSuccessfulAuthenticationResult)).thenReturn(mockSuccessfulSubjectAuthenticationResult);
    when(mockSubjectCreator.createResultWithGroups(mockUnauthorizedAuthenticationResult)).thenReturn(mockUnauthorizedSubjectAuthenticationResult);
    when(mockSubjectCreator.createResultWithGroups(failedAuthenticationResult)).thenReturn(failedSubjectAuthenticationResult);
    return authenticationProvider;
}
Also used : UsernamePrincipal(org.apache.qpid.server.security.auth.UsernamePrincipal) OAuth2AuthenticationProvider(org.apache.qpid.server.security.auth.manager.oauth2.OAuth2AuthenticationProvider) SubjectCreator(org.apache.qpid.server.security.SubjectCreator) SubjectAuthenticationResult(org.apache.qpid.server.security.auth.SubjectAuthenticationResult) Subject(javax.security.auth.Subject) URISyntaxException(java.net.URISyntaxException) AuthenticatedPrincipal(org.apache.qpid.server.security.auth.AuthenticatedPrincipal) SubjectAuthenticationResult(org.apache.qpid.server.security.auth.SubjectAuthenticationResult) AuthenticationResult(org.apache.qpid.server.security.auth.AuthenticationResult)

Example 17 with UsernamePrincipal

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

the class LoginLogoutReporterTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    _subject.getPrincipals().add(new AuthenticatedPrincipal(new UsernamePrincipal("mockusername", null)));
    when(_logger.isEnabled()).thenReturn(true);
    when(_logger.isMessageEnabled(anyString())).thenReturn(true);
    EventLogger eventLogger = new EventLogger(_logger);
    EventLoggerProvider provider = mock(EventLoggerProvider.class);
    when(provider.getEventLogger()).thenReturn(eventLogger);
    _loginLogoutReport = new LoginLogoutReporter(_subject, provider);
}
Also used : UsernamePrincipal(org.apache.qpid.server.security.auth.UsernamePrincipal) EventLoggerProvider(org.apache.qpid.server.logging.EventLoggerProvider) EventLogger(org.apache.qpid.server.logging.EventLogger) AuthenticatedPrincipal(org.apache.qpid.server.security.auth.AuthenticatedPrincipal)

Example 18 with UsernamePrincipal

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

the class AbstractScramAuthenticationManager method authenticate.

@Override
public AuthenticationResult authenticate(final String username, final String password) {
    ManagedUser user = getUser(username);
    if (user != null) {
        updateStoredPasswordFormatIfNecessary(user);
        SaltAndPasswordKeys saltAndPasswordKeys = getSaltAndPasswordKeys(username);
        try {
            byte[] saltedPassword = createSaltedPassword(saltAndPasswordKeys.getSalt(), password, saltAndPasswordKeys.getIterationCount());
            byte[] clientKey = computeHmac(saltedPassword, "Client Key");
            byte[] storedKey = MessageDigest.getInstance(getDigestName()).digest(clientKey);
            byte[] serverKey = computeHmac(saltedPassword, "Server Key");
            if (Arrays.equals(saltAndPasswordKeys.getStoredKey(), storedKey) && Arrays.equals(saltAndPasswordKeys.getServerKey(), serverKey)) {
                return new AuthenticationResult(new UsernamePrincipal(username, this));
            }
        } catch (IllegalArgumentException | NoSuchAlgorithmException | SaslException e) {
            return new AuthenticationResult(AuthenticationResult.AuthenticationStatus.ERROR, e);
        }
    }
    return new AuthenticationResult(AuthenticationResult.AuthenticationStatus.ERROR);
}
Also used : UsernamePrincipal(org.apache.qpid.server.security.auth.UsernamePrincipal) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) SaslException(javax.security.sasl.SaslException) AuthenticationResult(org.apache.qpid.server.security.auth.AuthenticationResult)

Example 19 with UsernamePrincipal

use of org.apache.qpid.server.security.auth.UsernamePrincipal 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 20 with UsernamePrincipal

use of org.apache.qpid.server.security.auth.UsernamePrincipal 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)

Aggregations

UsernamePrincipal (org.apache.qpid.server.security.auth.UsernamePrincipal)33 AuthenticationResult (org.apache.qpid.server.security.auth.AuthenticationResult)13 AuthenticatedPrincipal (org.apache.qpid.server.security.auth.AuthenticatedPrincipal)9 Principal (java.security.Principal)8 IOException (java.io.IOException)7 Subject (javax.security.auth.Subject)7 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)6 InputStream (java.io.InputStream)6 HttpURLConnection (java.net.HttpURLConnection)6 URL (java.net.URL)6 GeneralSecurityException (java.security.GeneralSecurityException)6 Map (java.util.Map)6 TrustStore (org.apache.qpid.server.model.TrustStore)6 IdentityResolverException (org.apache.qpid.server.security.auth.manager.oauth2.IdentityResolverException)6 ConnectionBuilder (org.apache.qpid.server.util.ConnectionBuilder)6 ServerScopedRuntimeException (org.apache.qpid.server.util.ServerScopedRuntimeException)6 X500Principal (javax.security.auth.x500.X500Principal)5 SaslNegotiator (org.apache.qpid.server.security.auth.sasl.SaslNegotiator)5 SubjectCreator (org.apache.qpid.server.security.SubjectCreator)4 EventLogger (org.apache.qpid.server.logging.EventLogger)3