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