本文整理匯總了Java中org.apache.shiro.authz.SimpleAuthorizationInfo.setObjectPermissions方法的典型用法代碼示例。如果您正苦於以下問題:Java SimpleAuthorizationInfo.setObjectPermissions方法的具體用法?Java SimpleAuthorizationInfo.setObjectPermissions怎麽用?Java SimpleAuthorizationInfo.setObjectPermissions使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.shiro.authz.SimpleAuthorizationInfo
的用法示例。
在下文中一共展示了SimpleAuthorizationInfo.setObjectPermissions方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: doGetAuthorizationInfo
import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
/**
* {@inheritDoc}
* <p>This default implementation handles built-in groups (all, anonymous, registered, etc.), delegating
* to loadAuthorizationInfo method the actual loading of application-specific groups.</p>
*
* @return
*/
public AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
Object principal = principals.getPrimaryPrincipal();
Set<String> groups = new HashSet<String>();
groups.add(SecurityLogic.getAllGroup(portofinoConfiguration));
if (principal == null) {
groups.add(SecurityLogic.getAnonymousGroup(portofinoConfiguration));
} else if (principal instanceof Serializable) {
groups.add(SecurityLogic.getRegisteredGroup(portofinoConfiguration));
groups.addAll(loadAuthorizationInfo((Serializable) principal));
} else {
throw new AuthorizationException("Invalid principal: " + principal);
}
SimpleAuthorizationInfo info = new SimpleAuthorizationInfo(groups);
if(groups.contains(SecurityLogic.getAdministratorsGroup(portofinoConfiguration))) {
info.addStringPermission("*");
}
Permission permission = new GroupPermission(groups);
info.setObjectPermissions(Collections.singleton(permission));
return info;
}
示例2: doGetAuthorizationInfo
import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals)
{
Set<String> roles = Sets.newHashSet("user");
Set<Permission> permissions = Sets.newHashSet();
Collection<AllowAllUser> principalsCollection = principals.byType(AllowAllUser.class);
if (principalsCollection.isEmpty()) {
throw new AuthorizationException("No principals!");
}
for (AllowAllUser user : principalsCollection) {
for (UserGroup userGroup : groups) {
if (userGroup.representedByGroupStrings(user.getGroups())) {
permissions.addAll(userGroup.getPermissions());
break;
}
}
}
SimpleAuthorizationInfo authorizationInfo = new SimpleAuthorizationInfo(roles);
authorizationInfo.setObjectPermissions(permissions);
return authorizationInfo;
}
示例3: doGetAuthorizationInfo
import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals)
{
Set<String> roles = Sets.newHashSet("user");
Set<Permission> permissions = Sets.newHashSet();
Collection<AllowAllUser> principalsCollection = principals.byType(AllowAllUser.class);
if (principalsCollection.isEmpty()) {
throw new AuthorizationException("No principals!");
}
for (AllowAllUser user : principalsCollection) {
for (UserGroup userGroup : groups) {
if (userGroup.representedByGroupStrings(user.getGroups())) {
permissions.addAll(userGroup.getPermissions());
break;
}
}
}
SimpleAuthorizationInfo authorizationInfo = new SimpleAuthorizationInfo(roles);
authorizationInfo.setObjectPermissions(permissions);
return authorizationInfo;
}