Search in sources :

Example 1 with ManagementConnectionPrincipal

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

the class ConnectionAndUserPredicateTest method testEvaluateConnectionNameForHttp.

@Test
public void testEvaluateConnectionNameForHttp() {
    ManagementConnectionPrincipal principal = mock(ManagementConnectionPrincipal.class);
    when(principal.getName()).thenReturn("foo:1234");
    _subject.getPrincipals().add(principal);
    _predicate.setConnectionNamePattern(".*:1234");
    Subject.doAs(_subject, new PrivilegedAction<Void>() {

        @Override
        public Void run() {
            assertTrue("predicate unexpectedly did not match", _predicate.evaluate(mock(ILoggingEvent.class)));
            return null;
        }
    });
    _predicate.setConnectionNamePattern(".*:4321");
    Subject.doAs(_subject, new PrivilegedAction<Void>() {

        @Override
        public Void run() {
            assertFalse("predicate unexpectedly matched", _predicate.evaluate(mock(ILoggingEvent.class)));
            return null;
        }
    });
}
Also used : ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) ManagementConnectionPrincipal(org.apache.qpid.server.security.auth.ManagementConnectionPrincipal) Test(org.junit.Test)

Example 2 with ManagementConnectionPrincipal

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

the class AbstractMessageLogger method getLogActor.

static String getLogActor() {
    final Subject subject = Subject.getSubject(AccessController.getContext());
    final SessionPrincipal sessionPrincipal = getPrincipal(subject, SessionPrincipal.class);
    String message;
    if (sessionPrincipal != null) {
        message = generateSessionActor(sessionPrincipal.getSession());
    } else {
        final ConnectionPrincipal connPrincipal = getPrincipal(subject, ConnectionPrincipal.class);
        if (connPrincipal != null) {
            message = generateConnectionActor(connPrincipal.getConnection());
        } else {
            final TaskPrincipal taskPrincipal = getPrincipal(subject, TaskPrincipal.class);
            if (taskPrincipal != null) {
                message = generateTaskMessage(taskPrincipal);
            } else {
                final ManagementConnectionPrincipal managementConnection = getPrincipal(subject, ManagementConnectionPrincipal.class);
                if (managementConnection != null) {
                    message = generateManagementConnectionMessage(managementConnection, getPrincipal(subject, AuthenticatedPrincipal.class));
                } else {
                    message = UNKNOWN_ACTOR + " ";
                }
            }
        }
    }
    return message;
}
Also used : TaskPrincipal(org.apache.qpid.server.security.auth.TaskPrincipal) SessionPrincipal(org.apache.qpid.server.connection.SessionPrincipal) ConnectionPrincipal(org.apache.qpid.server.connection.ConnectionPrincipal) ManagementConnectionPrincipal(org.apache.qpid.server.security.auth.ManagementConnectionPrincipal) Subject(javax.security.auth.Subject) ManagementConnectionPrincipal(org.apache.qpid.server.security.auth.ManagementConnectionPrincipal)

Example 3 with ManagementConnectionPrincipal

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

the class AbstractMessageLogger method getActor.

protected String getActor() {
    Subject subject = Subject.getSubject(AccessController.getContext());
    SessionPrincipal sessionPrincipal = getPrincipal(subject, SessionPrincipal.class);
    String message;
    if (sessionPrincipal != null) {
        message = generateSessionMessage(sessionPrincipal.getSession());
    } else {
        ConnectionPrincipal connPrincipal = getPrincipal(subject, ConnectionPrincipal.class);
        if (connPrincipal != null) {
            message = generateConnectionMessage(connPrincipal.getConnection());
        } else {
            TaskPrincipal taskPrincipal = getPrincipal(subject, TaskPrincipal.class);
            if (taskPrincipal != null) {
                message = generateTaskMessage(taskPrincipal);
            } else {
                ManagementConnectionPrincipal managementConnection = getPrincipal(subject, ManagementConnectionPrincipal.class);
                if (managementConnection != null) {
                    message = generateManagementConnectionMessage(managementConnection, getPrincipal(subject, AuthenticatedPrincipal.class));
                } else {
                    message = "<<UNKNOWN>> ";
                }
            }
        }
    }
    return message;
}
Also used : TaskPrincipal(org.apache.qpid.server.security.auth.TaskPrincipal) SessionPrincipal(org.apache.qpid.server.connection.SessionPrincipal) ConnectionPrincipal(org.apache.qpid.server.connection.ConnectionPrincipal) ManagementConnectionPrincipal(org.apache.qpid.server.security.auth.ManagementConnectionPrincipal) Subject(javax.security.auth.Subject) ManagementConnectionPrincipal(org.apache.qpid.server.security.auth.ManagementConnectionPrincipal)

Example 4 with ManagementConnectionPrincipal

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

the class HttpManagementActorTest method setUp.

@Before
public void setUp() throws Exception {
    super.setUp();
    _connectionPrincipal = new ManagementConnectionPrincipal() {

        @Override
        public String getType() {
            return "HTTP";
        }

        @Override
        public String getSessionId() {
            return SESSION_ID;
        }

        @Override
        public SocketAddress getRemoteAddress() {
            return new InetSocketAddress(IP, PORT);
        }

        @Override
        public SocketConnectionMetaData getConnectionMetaData() {
            return null;
        }

        @Override
        public String getName() {
            return getRemoteAddress().toString();
        }
    };
}
Also used : SocketConnectionMetaData(org.apache.qpid.server.security.auth.SocketConnectionMetaData) InetSocketAddress(java.net.InetSocketAddress) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) ManagementConnectionPrincipal(org.apache.qpid.server.security.auth.ManagementConnectionPrincipal) Before(org.junit.Before)

Example 5 with ManagementConnectionPrincipal

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

the class AuthenticationCheckFilter method doFilter.

@Override
public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException {
    HttpServletRequest httpRequest = (HttpServletRequest) request;
    HttpServletResponse httpResponse = (HttpServletResponse) response;
    boolean isPreemptiveAuthentication = false;
    try {
        Subject subject = HttpManagementUtil.getAuthorisedSubject(httpRequest);
        if (subject == null) {
            if (_allowed != null && httpRequest.getServletPath().startsWith(_allowed)) {
                subject = new Subject(true, Collections.<Principal>singleton(new ServletConnectionPrincipal(httpRequest)), Collections.emptySet(), Collections.emptySet());
            } else {
                subject = tryPreemptiveAuthentication(httpRequest);
                subject.getPrincipals(TokenCarryingPrincipal.class).forEach(p -> p.getTokens().forEach(((HttpServletResponse) response)::setHeader));
                isPreemptiveAuthentication = true;
            }
        } else {
            Set<Principal> principals = subject.getPrincipals();
            Set<Principal> newPrincipals = new LinkedHashSet<>();
            for (Principal principal : principals) {
                if (!(principal instanceof ManagementConnectionPrincipal)) {
                    newPrincipals.add(principal);
                }
            }
            subject = new Subject(false, principals, subject.getPublicCredentials(), subject.getPrivateCredentials());
            ServletConnectionPrincipal principal = new ServletConnectionPrincipal(httpRequest);
            subject.getPrincipals().add(principal);
            subject.setReadOnly();
        }
        doFilterChainAs(request, response, chain, subject);
    } catch (AccessControlException e) {
        httpResponse.sendError(HttpServletResponse.SC_FORBIDDEN);
        invalidateSession(httpRequest);
        return;
    } catch (SecurityException e) {
        httpResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED);
        invalidateSession(httpRequest);
        return;
    } finally {
        if (isPreemptiveAuthentication) {
            invalidateSession(httpRequest);
        }
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) LinkedHashSet(java.util.LinkedHashSet) ServletConnectionPrincipal(org.apache.qpid.server.management.plugin.servlet.ServletConnectionPrincipal) HttpServletResponse(javax.servlet.http.HttpServletResponse) AccessControlException(java.security.AccessControlException) Subject(javax.security.auth.Subject) Principal(java.security.Principal) ManagementConnectionPrincipal(org.apache.qpid.server.security.auth.ManagementConnectionPrincipal) ServletConnectionPrincipal(org.apache.qpid.server.management.plugin.servlet.ServletConnectionPrincipal) TokenCarryingPrincipal(org.apache.qpid.server.security.TokenCarryingPrincipal) TokenCarryingPrincipal(org.apache.qpid.server.security.TokenCarryingPrincipal) ManagementConnectionPrincipal(org.apache.qpid.server.security.auth.ManagementConnectionPrincipal)

Aggregations

ManagementConnectionPrincipal (org.apache.qpid.server.security.auth.ManagementConnectionPrincipal)5 Subject (javax.security.auth.Subject)3 ConnectionPrincipal (org.apache.qpid.server.connection.ConnectionPrincipal)2 SessionPrincipal (org.apache.qpid.server.connection.SessionPrincipal)2 TaskPrincipal (org.apache.qpid.server.security.auth.TaskPrincipal)2 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)1 InetSocketAddress (java.net.InetSocketAddress)1 SocketAddress (java.net.SocketAddress)1 AccessControlException (java.security.AccessControlException)1 Principal (java.security.Principal)1 LinkedHashSet (java.util.LinkedHashSet)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 ServletConnectionPrincipal (org.apache.qpid.server.management.plugin.servlet.ServletConnectionPrincipal)1 TokenCarryingPrincipal (org.apache.qpid.server.security.TokenCarryingPrincipal)1 SocketConnectionMetaData (org.apache.qpid.server.security.auth.SocketConnectionMetaData)1 Before (org.junit.Before)1 Test (org.junit.Test)1