use of org.apache.activemq.artemis.core.security.Role in project wildfly by wildfly.
the class ElytronSecurityManager method validateUserAndRole.
@Override
public boolean validateUserAndRole(String username, String password, Set<Role> roles, CheckType checkType) {
if (defaultUser.equals(username) && defaultPassword.equals(password))
return true;
final SecurityIdentity identity = this.authenticate(username, password);
if (identity == null) {
return false;
}
final Set<String> filteredRoles = new HashSet<>();
for (Role role : roles) {
if (checkType.hasRole(role)) {
String name = role.getName();
filteredRoles.add(name);
}
}
return identity.getRoles().containsAny(filteredRoles);
}
use of org.apache.activemq.artemis.core.security.Role in project wildfly by wildfly.
the class SecurityRoleAttributeHandler method applyUpdateToRuntime.
@Override
protected boolean applyUpdateToRuntime(OperationContext context, ModelNode operation, String attributeName, ModelNode newValue, ModelNode currentValue, HandbackHolder<Set<Role>> handbackHolder) throws OperationFailedException {
final ActiveMQServer server = getActiveMQServer(context, operation);
if (server != null) {
final PathAddress address = PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR));
final String match = address.getElement(address.size() - 2).getValue();
final String roleName = address.getLastElement().getValue();
final Set<Role> newRoles = new HashSet<Role>();
final Set<Role> roles = server.getSecurityRepository().getMatch(match);
handbackHolder.setHandback(roles);
for (final Role role : roles) {
if (!roleName.equals(role.getName())) {
newRoles.add(role);
}
}
final Resource resource = context.readResource(PathAddress.EMPTY_ADDRESS);
final ModelNode subModel = resource.getModel();
final Role updatedRole = SecurityRoleDefinition.transform(context, roleName, subModel);
newRoles.add(updatedRole);
server.getSecurityRepository().addMatch(match, newRoles);
}
return false;
}
use of org.apache.activemq.artemis.core.security.Role in project wildfly by wildfly.
the class SecurityRoleRemove method removeRole.
static void removeRole(ActiveMQServer server, String match, String roleName) {
if (server != null) {
final Set<Role> roles = server.getSecurityRepository().getMatch(match);
final Set<Role> newRoles = new HashSet<Role>();
for (final Role role : roles) {
if (!roleName.equals(role.getName())) {
newRoles.add(role);
}
}
server.getSecurityRepository().addMatch(match, newRoles);
}
}
use of org.apache.activemq.artemis.core.security.Role in project wildfly by wildfly.
the class ServerAdd method processSecuritySettings.
/**
* Process the security settings.
*
* @param configuration the ActiveMQ configuration
* @param params the detyped operation parameters
*/
static void processSecuritySettings(final OperationContext context, final Configuration configuration, final ModelNode params) throws OperationFailedException {
if (params.get(SECURITY_SETTING).isDefined()) {
for (final Property property : params.get(SECURITY_SETTING).asPropertyList()) {
final String match = property.getName();
final ModelNode config = property.getValue();
if (config.hasDefined(CommonAttributes.ROLE)) {
final Set<Role> roles = new HashSet<Role>();
for (final Property role : config.get(CommonAttributes.ROLE).asPropertyList()) {
roles.add(SecurityRoleDefinition.transform(context, role.getName(), role.getValue()));
}
configuration.getSecurityRoles().put(match, roles);
}
}
}
}
use of org.apache.activemq.artemis.core.security.Role in project wildfly by wildfly.
the class WildFlySecurityManager method validateUserAndRole.
@Override
public boolean validateUserAndRole(final String username, final String password, final Set<Role> roles, final CheckType checkType) {
if (defaultUser.equals(username) && defaultPassword.equals(password))
return true;
if (securityDomainContext == null)
throw MessagingLogger.ROOT_LOGGER.securityDomainContextNotSet();
final Subject subject = new Subject();
// The authentication call here changes the subject and that subject must be used later. That is why we don't call validateUser(String, String) here.
boolean authenticated = securityDomainContext.getAuthenticationManager().isValid(new SimplePrincipal(username), password, subject);
if (authenticated) {
authenticated = AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
@Override
public Boolean run() {
final SimplePrincipal principal = new SimplePrincipal(username);
// push a new security context if there is not one.
final SecurityContext currentSecurityContext = SecurityContextAssociation.getSecurityContext();
final SecurityContext securityContext;
if (currentSecurityContext == null) {
try {
securityContext = SecurityContextFactory.createSecurityContext(principal, password, subject, securityDomainContext.getAuthenticationManager().getSecurityDomain());
} catch (Exception e) {
throw new RuntimeException(e);
}
} else {
securityContext = currentSecurityContext;
securityContext.getUtil().createSubjectInfo(principal, password, subject);
}
SecurityContextAssociation.setSecurityContext(securityContext);
final Set<Principal> principals = new HashSet<Principal>();
for (Role role : roles) {
if (checkType.hasRole(role)) {
principals.add(new SimplePrincipal(role.getName()));
}
}
final boolean authenticated = securityDomainContext.getAuthorizationManager().doesUserHaveRole(new SimplePrincipal(username), principals);
// restore the previous security context if any
SecurityContextAssociation.setSecurityContext(currentSecurityContext);
return authenticated;
}
});
}
return authenticated;
}
Aggregations