Search in sources :

Example 21 with AuthenticatedPrincipal

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());
}
Also used : GenericPrincipal(org.apache.qpid.server.model.preferences.GenericPrincipal) Subject(javax.security.auth.Subject) HashSet(java.util.HashSet) AuthenticatedPrincipal(org.apache.qpid.server.security.auth.AuthenticatedPrincipal) Before(org.junit.Before)

Example 22 with AuthenticatedPrincipal

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);
}
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) Before(org.junit.Before)

Example 23 with AuthenticatedPrincipal

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;
}
Also used : HashMap(java.util.HashMap) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) Date(java.util.Date) HashSet(java.util.HashSet) AuthenticatedPrincipal(org.apache.qpid.server.security.auth.AuthenticatedPrincipal)

Example 24 with AuthenticatedPrincipal

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());
}
Also used : SubjectAuthenticationResult(org.apache.qpid.server.security.auth.SubjectAuthenticationResult) Subject(javax.security.auth.Subject) AuthenticatedPrincipal(org.apache.qpid.server.security.auth.AuthenticatedPrincipal) Test(org.junit.Test)

Example 25 with AuthenticatedPrincipal

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()));
}
Also used : AnonymousAuthenticationManagerFactory(org.apache.qpid.server.security.auth.manager.AnonymousAuthenticationManagerFactory) AnonymousAuthenticationManager(org.apache.qpid.server.security.auth.manager.AnonymousAuthenticationManager) AMQPConnection(org.apache.qpid.server.transport.AMQPConnection) SaslInit(org.apache.qpid.server.protocol.v1_0.type.security.SaslInit) SASLFrame(org.apache.qpid.server.protocol.v1_0.framing.SASLFrame) TransportFrame(org.apache.qpid.server.protocol.v1_0.framing.TransportFrame) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) SubjectCreator(org.apache.qpid.server.security.SubjectCreator) Open(org.apache.qpid.server.protocol.v1_0.type.transport.Open) AuthenticatedPrincipal(org.apache.qpid.server.security.auth.AuthenticatedPrincipal) Test(org.junit.Test)

Aggregations

AuthenticatedPrincipal (org.apache.qpid.server.security.auth.AuthenticatedPrincipal)27 Subject (javax.security.auth.Subject)12 UsernamePrincipal (org.apache.qpid.server.security.auth.UsernamePrincipal)11 Principal (java.security.Principal)7 ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)7 Before (org.junit.Before)6 Test (org.junit.Test)6 Date (java.util.Date)5 EventLogger (org.apache.qpid.server.logging.EventLogger)5 SubjectCreator (org.apache.qpid.server.security.SubjectCreator)5 ArrayList (java.util.ArrayList)4 AmqpPort (org.apache.qpid.server.model.port.AmqpPort)4 AMQPConnection (org.apache.qpid.server.transport.AMQPConnection)4 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 Broker (org.apache.qpid.server.model.Broker)3 GenericPrincipal (org.apache.qpid.server.model.preferences.GenericPrincipal)3 TransportFrame (org.apache.qpid.server.protocol.v1_0.framing.TransportFrame)3 SubjectAuthenticationResult (org.apache.qpid.server.security.auth.SubjectAuthenticationResult)3 URISyntaxException (java.net.URISyntaxException)2