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");
}
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());
}
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());
}
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());
}
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());
}
Aggregations