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