Hi,
From the pac4j core engine, roles were not different from permissions; that's why only roles remain.
Over the years, the pac4j core project has tried to remain easy and focused on core and limited concepts.
That said, in Shiro, permissions exist (and I think it's the only use case among the 20 something implementations using pac4j).
So either you forget about permissions and only use roles
or
we can think of a smooth transition and specific behavior for Shiro.
For example, instead of adding permissions in your user profile, you can add a "permissions" attribute and we could rely on that when building the Shiro security context:
profile.addAttribute(Pac4jRealm.PERMISSIONS_ATTRIBUTE, Arrays.asList("PERM1", "PERM2"));
and:
@Override
protected AuthorizationInfo doGetAuthorizationInfo(final PrincipalCollection principals) {
final Set<String> roles = new HashSet<>();
final Set<String> permissions = new HashSet<>();
final Pac4jPrincipal principal = principals.oneByType(Pac4jPrincipal.class);
if (principal != null) {
final List<UserProfile> profiles = principal.getProfiles();
for (final UserProfile profile : profiles) {
if (profile != null) {
roles.addAll(profile.getRoles());
val perm = profile.getAttribute(PERMISSIONS_ATTRIBUTE);
if (perm instanceof List) {
permissions.addAll((List) perm);
} else if (perm instanceof Set) {
permissions.addAll((Set) perm);
}
}
}
}
final SimpleAuthorizationInfo simpleAuthorizationInfo = new SimpleAuthorizationInfo();
simpleAuthorizationInfo.addRoles(roles);
simpleAuthorizationInfo.addStringPermissions(permissions);
return simpleAuthorizationInfo;
}
You would only need to change the way of setting permissions.
What do you think?
Thanks.
Best regards,
Jérôme