use of org.apache.qpid.server.connection.ConnectionPrincipal in project qpid-broker-j by apache.
the class AuthenticationResultCacherTest method setUp.
@Before
public void setUp() throws Exception {
_connection = mock(AMQPConnection.class);
when(_connection.getRemoteSocketAddress()).thenReturn(new InetSocketAddress("example.com", 9999));
_subject = new Subject(true, Collections.singleton(new ConnectionPrincipal(_connection)), Collections.emptySet(), Collections.emptySet());
_authenticationResultCacher = new AuthenticationResultCacher(10, 10 * 60L, 2);
_loadCallCount = 0;
_loader = new Callable<AuthenticationResult>() {
@Override
public AuthenticationResult call() throws Exception {
_loadCallCount += 1;
return _successfulAuthenticationResult;
}
};
}
use of org.apache.qpid.server.connection.ConnectionPrincipal 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.connection.ConnectionPrincipal in project qpid-broker-j by apache.
the class ConnectionAndUserPredicate method evaluate.
@Override
public final boolean evaluate(final ILoggingEvent event) {
String userPrincipalString = "";
String connectionString = "";
String remoteContainerName = "";
final Subject subject = Subject.getSubject(AccessController.getContext());
final Set<SocketConnectionPrincipal> connectionPrincipals = subject.getPrincipals(SocketConnectionPrincipal.class);
final Set<AuthenticatedPrincipal> userPrincipals = subject.getPrincipals(AuthenticatedPrincipal.class);
if (!connectionPrincipals.isEmpty()) {
final SocketConnectionPrincipal socketConnectionPrincipal = connectionPrincipals.iterator().next();
connectionString = socketConnectionPrincipal.getName();
if (socketConnectionPrincipal instanceof ConnectionPrincipal) {
remoteContainerName = ((ConnectionPrincipal) socketConnectionPrincipal).getConnection().getRemoteContainerName();
if (remoteContainerName == null) {
remoteContainerName = "";
}
}
}
if (!userPrincipals.isEmpty()) {
userPrincipalString = new GenericPrincipal(userPrincipals.iterator().next()).toExternalForm();
}
return _usernamePattern.matcher(userPrincipalString).matches() && _connectionNamePattern.matcher(connectionString).matches() && _remoteContainerIdPattern.matcher(remoteContainerName).matches();
}
use of org.apache.qpid.server.connection.ConnectionPrincipal 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.connection.ConnectionPrincipal in project qpid-broker-j by apache.
the class RuleBasedAccessControl method authorise.
/**
* Check if an operation is authorised by asking the configuration object about the access
* control rules granted to the current thread's {@link Subject}. If there is no current
* user the plugin will abstain.
*/
@Override
public Result authorise(LegacyOperation operation, ObjectType objectType, ObjectProperties properties) {
InetAddress addressOfClient = null;
final Subject subject = Subject.getSubject(AccessController.getContext());
// Abstain if there is no subject/principal associated with this thread
if (subject == null || subject.getPrincipals().size() == 0) {
return Result.DEFER;
}
Set<ConnectionPrincipal> principals = subject.getPrincipals(ConnectionPrincipal.class);
if (!principals.isEmpty()) {
SocketAddress address = principals.iterator().next().getConnection().getRemoteSocketAddress();
if (address instanceof InetSocketAddress) {
addressOfClient = ((InetSocketAddress) address).getAddress();
}
}
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Checking " + operation + " " + objectType + " " + (addressOfClient == null ? "" : addressOfClient));
}
try {
return _ruleSet.check(subject, operation, objectType, properties, addressOfClient);
} catch (Exception e) {
LOGGER.error("Unable to check " + operation + " " + objectType + " " + (addressOfClient == null ? "" : addressOfClient), e);
return Result.DENIED;
}
}
Aggregations