Java Code Examples for org.apache.shiro.subject.PrincipalCollection#oneByType()

The following examples show how to use org.apache.shiro.subject.PrincipalCollection#oneByType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KnoxPamRealm.java    From knox with Apache License 2.0 6 votes vote down vote up
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
  Set<String> roles = new LinkedHashSet<>();

  UnixUserPrincipal user = principals.oneByType(UnixUserPrincipal.class);
  if (user != null) {
    roles.addAll(user.getUnixUser().getGroups());
  }
  SecurityUtils.getSubject().getSession().setAttribute(SUBJECT_USER_ROLES, roles);
  SecurityUtils.getSubject().getSession().setAttribute(SUBJECT_USER_GROUPS, roles);

  /* Coverity Scan CID 1361682 */
  String userName = null;

  if (user != null) {
    userName = user.getName();
  }

  gatewayLog.lookedUpUserRoles(roles, userName);
  return new SimpleAuthorizationInfo(roles);
}
 
Example 2
Source File: PamRealm.java    From zeppelin with Apache License 2.0 5 votes vote down vote up
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
  Set<String> roles = new LinkedHashSet<>();

  UserPrincipal user = principals.oneByType(UserPrincipal.class);

  if (user != null){
    roles.addAll(user.getUnixUser().getGroups());
  }

  return new SimpleAuthorizationInfo(roles);
}