Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,8 @@ public boolean authorize(final Subject subject,
final CheckType checkType,
final String address) {
boolean authorized = SecurityManagerUtil.authorize(subject, roles, checkType, RolePrincipal.class);
if (authorized) {
logger.trace("user is authorized");
} else {
logger.trace("user is NOT authorized");
Comment on lines -111 to -114
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would probably be best to move this block into SecurityManagerUtil.authorize itself rather than repeating it in two places.

}

logger.trace("user is authorized: {}", authorized);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion this makes the logging a bit less clear, easier to misread in a hurry.


return authorized;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,7 @@ public boolean authorize(final Subject subject,
final String address) {
boolean authorized = SecurityManagerUtil.authorize(subject, roles, checkType, rolePrincipalClass);

if (authorized) {
logger.trace("user is authorized");
} else {
logger.trace("user is NOT authorized");
}
logger.trace("user is authorized: {}", authorized);

return authorized;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import java.lang.reflect.Method;
import java.security.Principal;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

import org.apache.activemq.artemis.core.security.CheckType;
Expand Down Expand Up @@ -114,31 +113,26 @@ public int hashCode() {
* This method tries to match the RolePrincipals in the Subject with the provided Set of Roles and CheckType
*/
public static boolean authorize(final Subject subject, final Set<Role> roles, final CheckType checkType, final Class rolePrincipalClass) {
boolean authorized = false;

if (subject != null) {
Set<RolePrincipal> rolesWithPermission = getPrincipalsInRole(checkType, roles, rolePrincipalClass);

// Check the caller's roles
Set<Principal> rolesForSubject = new HashSet<>();
Set<Principal> rolesForSubject;
try {
rolesForSubject.addAll(subject.getPrincipals(rolePrincipalClass));
rolesForSubject = subject.getPrincipals(rolePrincipalClass);
} catch (Exception e) {
ActiveMQServerLogger.LOGGER.failedToFindRolesForTheSubject(e);
return false;
}
if (!rolesForSubject.isEmpty() && !rolesWithPermission.isEmpty()) {
Iterator<Principal> rolesForSubjectIter = rolesForSubject.iterator();
while (!authorized && rolesForSubjectIter.hasNext()) {
Iterator<RolePrincipal> rolesWithPermissionIter = rolesWithPermission.iterator();
Principal subjectRole = rolesForSubjectIter.next();
while (!authorized && rolesWithPermissionIter.hasNext()) {
Principal roleWithPermission = rolesWithPermissionIter.next();
authorized = subjectRole.equals(roleWithPermission);
for (Principal subjectRole : rolesForSubject) {
if (rolesWithPermission.contains(subjectRole)) {
return true;
}
}
}
}

return authorized;
return false;
}
}