Search in sources :

Example 1 with RoleAssignee

use of org.qi4j.library.shiro.domain.permissions.RoleAssignee in project qi4j-sdk by Qi4j.

the class PasswordRealmMixin method doGetAuthorizationInfo.

@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
    UnitOfWork uow = module.newUnitOfWork();
    try {
        String username = getAvailablePrincipal(principals).toString();
        RoleAssignee roleAssignee = findRoleAssignee(uow, username);
        if (roleAssignee == null) {
            LOG.debug("No authorization info for {}", username);
            return null;
        }
        LOG.debug("Found role assignee for {}: {}", username, roleAssignee);
        Set<String> roleNames = roleAssignee.roleNames();
        Set<String> permissionStrings = roleAssignee.permissionStrings();
        LOG.debug("Found role assignee has the following roles: {}", roleNames);
        LOG.debug("Found role assignee has the following permissions: {}", permissionStrings);
        SimpleAuthorizationInfo atzInfo = new SimpleAuthorizationInfo(roleNames);
        atzInfo.setStringPermissions(permissionStrings);
        return atzInfo;
    } finally {
        uow.discard();
    }
}
Also used : UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork) SimpleAuthorizationInfo(org.apache.shiro.authz.SimpleAuthorizationInfo) RoleAssignee(org.qi4j.library.shiro.domain.permissions.RoleAssignee)

Aggregations

SimpleAuthorizationInfo (org.apache.shiro.authz.SimpleAuthorizationInfo)1 UnitOfWork (org.qi4j.api.unitofwork.UnitOfWork)1 RoleAssignee (org.qi4j.library.shiro.domain.permissions.RoleAssignee)1