use of org.apache.qpid.server.security.auth.AuthenticatedPrincipal in project qpid-broker-j by apache.
the class ConnectionAndUserPredicateTest method setUp.
@Before
public void setUp() throws Exception {
_predicate = new ConnectionAndUserPredicate();
_subject = new Subject(false, new HashSet<>(Collections.singleton(new AuthenticatedPrincipal(new GenericPrincipal(TEST_USER)))), Collections.emptySet(), Collections.emptySet());
}
use of org.apache.qpid.server.security.auth.AuthenticatedPrincipal in project qpid-broker-j by apache.
the class LoginLogoutReporterTest method setUp.
@Before
public void setUp() throws Exception {
_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.AuthenticatedPrincipal in project qpid-broker-j by apache.
the class UserPreferencesImpl method augmentForReplace.
private Collection<Preference> augmentForReplace(final Collection<Preference> preferences) {
HashSet<Preference> augmentedPreferences = new HashSet<>(preferences.size());
for (final Preference preference : preferences) {
Map<String, Object> attributes = new HashMap<>(preference.getAttributes());
AuthenticatedPrincipal currentUser = AuthenticatedPrincipal.getCurrentUser();
Date currentTime = new Date();
attributes.put(Preference.LAST_UPDATED_DATE_ATTRIBUTE, currentTime);
attributes.put(Preference.CREATED_DATE_ATTRIBUTE, currentTime);
attributes.put(Preference.OWNER_ATTRIBUTE, currentUser);
if (preference.getId() == null) {
attributes.put(Preference.ID_ATTRIBUTE, UUID.randomUUID());
}
augmentedPreferences.add(PreferenceFactory.fromAttributes(preference.getAssociatedObject(), attributes));
}
return augmentedPreferences;
}
use of org.apache.qpid.server.security.auth.AuthenticatedPrincipal in project qpid-broker-j by apache.
the class SubjectCreatorTest method testSaslAuthenticationSuccessReturnsSubjectWithUserAndGroupPrincipals.
@Test
public void testSaslAuthenticationSuccessReturnsSubjectWithUserAndGroupPrincipals() throws Exception {
when(_testSaslNegotiator.handleResponse(_saslResponseBytes)).thenReturn(_authenticationResult);
SubjectAuthenticationResult result = _subjectCreator.authenticate(_testSaslNegotiator, _saslResponseBytes);
final Subject actualSubject = result.getSubject();
assertEquals("Should contain one user principal and two groups ", (long) 3, (long) actualSubject.getPrincipals().size());
assertTrue(actualSubject.getPrincipals().contains(new AuthenticatedPrincipal(USERNAME_PRINCIPAL)));
assertTrue(actualSubject.getPrincipals().contains(_group1));
assertTrue(actualSubject.getPrincipals().contains(_group2));
assertTrue(actualSubject.isReadOnly());
}
use of org.apache.qpid.server.security.auth.AuthenticatedPrincipal in project qpid-broker-j by apache.
the class ProtocolEngine_1_0_0Test method testProtocolEngineWithSaslNonTLSandAnon.
@Test
public void testProtocolEngineWithSaslNonTLSandAnon() throws Exception {
final Map<String, Object> attrs = Collections.singletonMap(ConfiguredObject.NAME, getTestName());
final AnonymousAuthenticationManager anonymousAuthenticationManager = (new AnonymousAuthenticationManagerFactory()).create(null, attrs, _broker);
when(_port.getAuthenticationProvider()).thenReturn(anonymousAuthenticationManager);
when(_port.getSubjectCreator(anyBoolean(), anyString())).thenReturn(new SubjectCreator(anonymousAuthenticationManager, Collections.emptyList(), null));
allowMechanisms(AnonymousAuthenticationManager.MECHANISM_NAME);
createEngine(Transport.TCP);
_protocolEngine_1_0_0.received(QpidByteBuffer.wrap(ProtocolEngineCreator_1_0_0_SASL.getInstance().getHeaderIdentifier()));
SaslInit init = new SaslInit();
init.setMechanism(Symbol.valueOf("ANONYMOUS"));
_frameWriter.send(new SASLFrame(init));
_protocolEngine_1_0_0.received(QpidByteBuffer.wrap(ProtocolEngineCreator_1_0_0.getInstance().getHeaderIdentifier()));
Open open = new Open();
open.setContainerId("testContainerId");
_frameWriter.send(new TransportFrame((int) (short) 0, open));
verify(_virtualHost).registerConnection(any(AMQPConnection.class));
AuthenticatedPrincipal principal = (AuthenticatedPrincipal) _connection.getAuthorizedPrincipal();
assertNotNull(principal);
assertEquals(principal, new AuthenticatedPrincipal(anonymousAuthenticationManager.getAnonymousPrincipal()));
}
Aggregations