Search in sources :

Example 66 with AuthenticationResult

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

the class OAuth2AuthenticationProviderImplTest method testFailAuthenticateViaInvalidAuthorizationCode.

public void testFailAuthenticateViaInvalidAuthorizationCode() throws Exception {
    Map<String, OAuth2MockEndpoint> mockEndpoints = new HashMap<>();
    final OAuth2MockEndpoint mockTokenEndpoint = createMockTokenEndpoint();
    mockTokenEndpoint.putExpectedParameter("code", TEST_INVALID_AUTHORIZATION_CODE);
    mockTokenEndpoint.setResponse(400, "{\"error\":\"invalid_grant\",\"error_description\":\"authorization grant is not valid\"}");
    mockEndpoints.put(TEST_TOKEN_ENDPOINT_PATH, mockTokenEndpoint);
    mockEndpoints.put(TEST_IDENTITY_RESOLVER_ENDPOINT_PATH, createMockIdentityResolverEndpoint());
    _server.setEndpoints(mockEndpoints);
    final NamedAddressSpace mockAddressSpace = mock(NamedAddressSpace.class);
    when(mockAddressSpace.getName()).thenReturn("mock");
    AuthenticationResult authenticationResult = _authProvider.authenticateViaAuthorizationCode(TEST_INVALID_AUTHORIZATION_CODE, TEST_REDIRECT_URI, mockAddressSpace);
    assertFailure(authenticationResult, "invalid_grant");
}
Also used : HashMap(java.util.HashMap) NamedAddressSpace(org.apache.qpid.server.model.NamedAddressSpace) AuthenticationResult(org.apache.qpid.server.security.auth.AuthenticationResult)

Example 67 with AuthenticationResult

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

the class CramMd5NegotiatorTest method doHandleResponseWithValidCredentials.

private void doHandleResponseWithValidCredentials(final String mechanism) throws Exception {
    AuthenticationResult firstResult = _negotiator.handleResponse(new byte[0]);
    assertEquals("Unexpected first result status", AuthenticationResult.AuthenticationStatus.CONTINUE, firstResult.getStatus());
    assertNotNull("Unexpected first result challenge", firstResult.getChallenge());
    byte[] responseBytes = SaslUtil.generateCramMD5ClientResponse(mechanism, VALID_USERNAME, new String(VALID_USERPASSWORD), firstResult.getChallenge());
    AuthenticationResult secondResult = _negotiator.handleResponse(responseBytes);
    assertEquals("Unexpected second result status", AuthenticationResult.AuthenticationStatus.SUCCESS, secondResult.getStatus());
    assertNull("Unexpected second result challenge", secondResult.getChallenge());
    assertEquals("Unexpected second result main principal", VALID_USERNAME, secondResult.getMainPrincipal().getName());
    verify(_passwordSource).getPassword(eq(VALID_USERNAME));
    AuthenticationResult thirdResult = _negotiator.handleResponse(new byte[0]);
    assertEquals("Unexpected third result status", AuthenticationResult.AuthenticationStatus.ERROR, thirdResult.getStatus());
}
Also used : AuthenticationResult(org.apache.qpid.server.security.auth.AuthenticationResult)

Example 68 with AuthenticationResult

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

the class CramMd5NegotiatorTest method doHandleResponseWithInvalidUsername.

private void doHandleResponseWithInvalidUsername(final String mechanism) throws Exception {
    AuthenticationResult firstResult = _negotiator.handleResponse(new byte[0]);
    assertEquals("Unexpected first result status", AuthenticationResult.AuthenticationStatus.CONTINUE, firstResult.getStatus());
    assertNotNull("Unexpected first result challenge", firstResult.getChallenge());
    byte[] responseBytes = SaslUtil.generateCramMD5ClientResponse(mechanism, INVALID_USERNAME, new String(VALID_USERPASSWORD), firstResult.getChallenge());
    AuthenticationResult secondResult = _negotiator.handleResponse(responseBytes);
    assertEquals("Unexpected second result status", AuthenticationResult.AuthenticationStatus.ERROR, secondResult.getStatus());
    assertNull("Unexpected second result challenge", secondResult.getChallenge());
    assertNull("Unexpected second result main principal", secondResult.getMainPrincipal());
    verify(_passwordSource).getPassword(eq(INVALID_USERNAME));
    AuthenticationResult thirdResult = _negotiator.handleResponse(new byte[0]);
    assertEquals("Unexpected third result status", AuthenticationResult.AuthenticationStatus.ERROR, thirdResult.getStatus());
}
Also used : AuthenticationResult(org.apache.qpid.server.security.auth.AuthenticationResult)

Example 69 with AuthenticationResult

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

the class ExternalNegotiatorTest method testHandleResponseNotUseFullDNValidExternalPrincipal.

public void testHandleResponseNotUseFullDNValidExternalPrincipal() throws Exception {
    ExternalAuthenticationManager<?> externalAuthenticationManager = mock(ExternalAuthenticationManager.class);
    when(externalAuthenticationManager.getUseFullDN()).thenReturn(false);
    X500Principal externalPrincipal = new X500Principal(VALID_USER_DN);
    ExternalNegotiator negotiator = new ExternalNegotiator(externalAuthenticationManager, externalPrincipal);
    AuthenticationResult firstResult = negotiator.handleResponse(new byte[0]);
    assertEquals("Unexpected first result status", AuthenticationResult.AuthenticationStatus.SUCCESS, firstResult.getStatus());
    String principalName = firstResult.getMainPrincipal().getName();
    assertEquals("Unexpected first result principal", VALID_USER_NAME, principalName);
    AuthenticationResult secondResult = negotiator.handleResponse(new byte[0]);
    assertEquals("Unexpected second result status", AuthenticationResult.AuthenticationStatus.ERROR, secondResult.getStatus());
}
Also used : X500Principal(javax.security.auth.x500.X500Principal) AuthenticationResult(org.apache.qpid.server.security.auth.AuthenticationResult)

Example 70 with AuthenticationResult

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

the class ExternalNegotiatorTest method testHandleResponseUseFullDN_No_CN_DC_In_ExternalPrincipal.

public void testHandleResponseUseFullDN_No_CN_DC_In_ExternalPrincipal() throws Exception {
    ExternalAuthenticationManager<?> externalAuthenticationManager = mock(ExternalAuthenticationManager.class);
    when(externalAuthenticationManager.getUseFullDN()).thenReturn(true);
    X500Principal externalPrincipal = new X500Principal(USERNAME_NO_CN_DC);
    ExternalNegotiator negotiator = new ExternalNegotiator(externalAuthenticationManager, externalPrincipal);
    AuthenticationResult firstResult = negotiator.handleResponse(new byte[0]);
    assertEquals("Unexpected first result status", AuthenticationResult.AuthenticationStatus.SUCCESS, firstResult.getStatus());
    String principalName = firstResult.getMainPrincipal().getName();
    assertTrue(String.format("Unexpected first result principal '%s'", principalName), USERNAME_NO_CN_DC.equalsIgnoreCase(principalName));
    AuthenticationResult secondResult = negotiator.handleResponse(new byte[0]);
    assertEquals("Unexpected second result status", AuthenticationResult.AuthenticationStatus.ERROR, secondResult.getStatus());
}
Also used : X500Principal(javax.security.auth.x500.X500Principal) 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