本文整理匯總了Java中org.apache.shiro.authz.SimpleAuthorizationInfo.addObjectPermission方法的典型用法代碼示例。如果您正苦於以下問題:Java SimpleAuthorizationInfo.addObjectPermission方法的具體用法?Java SimpleAuthorizationInfo.addObjectPermission怎麽用?Java SimpleAuthorizationInfo.addObjectPermission使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.shiro.authz.SimpleAuthorizationInfo
的用法示例。
在下文中一共展示了SimpleAuthorizationInfo.addObjectPermission方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: doGetAuthorizationInfo
import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
final User user = principals.byType(User.class).iterator().next();
final List<Role> roles = user.getRoles();
SimpleAuthorizationInfo sai = new SimpleAuthorizationInfo();
for (Role role : roles) {
sai.addRole(role.name());
}
if (roles.contains(Role.ADMIN)) {
sai.addObjectPermission(ALL_PERMISSION);
}
else {
sai.addObjectPermission(new ObjectPermission(principals.oneByType(User.class), objectPermissionChecker));
}
return sai;
}
示例2: doGetAuthorizationInfo
import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
SimpleAuthorizationInfo authorizationInfo = new SimpleAuthorizationInfo();
authorizationInfo.addRole("role1");
authorizationInfo.addRole("role2");
authorizationInfo.addObjectPermission(new BitPermission("+user1+10"));
authorizationInfo.addObjectPermission(new WildcardPermission("user1:*"));
authorizationInfo.addStringPermission("+user2+10");
authorizationInfo.addStringPermission("user2:*");
return authorizationInfo;
}
示例3: testIsPermitted_true
import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
@Test
public void testIsPermitted_true() {
final ShiroPermissionResolver resolver = new ShiroPermissionResolver();
UserSourceRealm realm = new UserSourceRealm(_userSource) {
@Override
protected AuthorizationInfo getAuthorizationInfo(PrincipalCollection principals) {
SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
info.addObjectPermission(resolver.resolvePermission("Master:view"));
return info;
}
};
realm.setPermissionResolver(resolver);
assertEquals(true, realm.isPermitted(PRINCIPALS, "Master:view"));
}
示例4: testIsPermitted_false
import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
@Test
public void testIsPermitted_false() {
final ShiroPermissionResolver resolver = new ShiroPermissionResolver();
UserSourceRealm realm = new UserSourceRealm(_userSource) {
@Override
protected AuthorizationInfo getAuthorizationInfo(PrincipalCollection principals) {
SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
info.addObjectPermission(resolver.resolvePermission("Master:view"));
return info;
}
};
realm.setPermissionResolver(resolver);
assertEquals(false, realm.isPermitted(PRINCIPALS, "Master:edit"));
}
示例5: testIsPermitted_otherType
import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
@Test
public void testIsPermitted_otherType() {
final ShiroPermissionResolver resolver = new ShiroPermissionResolver();
UserSourceRealm realm = new UserSourceRealm(_userSource) {
@Override
protected AuthorizationInfo getAuthorizationInfo(PrincipalCollection principals) {
SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
info.addObjectPermission(resolver.resolvePermission("Master:view"));
return info;
}
};
realm.setPermissionResolver(resolver);
assertEquals(false, realm.isPermitted(PRINCIPALS, PERMISSION_OTHER_TYPE));
}
示例6: testIsPermittedAll_none
import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
@Test
public void testIsPermittedAll_none() {
final ShiroPermissionResolver resolver = new ShiroPermissionResolver();
UserSourceRealm realm = new UserSourceRealm(_userSource) {
@Override
protected AuthorizationInfo getAuthorizationInfo(PrincipalCollection principals) {
SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
info.addObjectPermission(resolver.resolvePermission("Master:view"));
info.addObjectPermission(resolver.resolvePermission("Source:view"));
return info;
}
};
realm.setPermissionResolver(resolver);
assertEquals(true, realm.isPermittedAll(PRINCIPALS));
}
示例7: testIsPermittedAll_true
import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
@Test
public void testIsPermittedAll_true() {
final ShiroPermissionResolver resolver = new ShiroPermissionResolver();
UserSourceRealm realm = new UserSourceRealm(_userSource) {
@Override
protected AuthorizationInfo getAuthorizationInfo(PrincipalCollection principals) {
SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
info.addObjectPermission(resolver.resolvePermission("Master:view"));
info.addObjectPermission(resolver.resolvePermission("Source:view"));
return info;
}
};
realm.setPermissionResolver(resolver);
assertEquals(true, realm.isPermittedAll(PRINCIPALS, "Master:view", "Source:view"));
}
示例8: testIsPermittedAll_false
import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
@Test
public void testIsPermittedAll_false() {
final ShiroPermissionResolver resolver = new ShiroPermissionResolver();
UserSourceRealm realm = new UserSourceRealm(_userSource) {
@Override
protected AuthorizationInfo getAuthorizationInfo(PrincipalCollection principals) {
SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
info.addObjectPermission(resolver.resolvePermission("Master:view"));
info.addObjectPermission(resolver.resolvePermission("Source:view"));
return info;
}
};
realm.setPermissionResolver(resolver);
assertEquals(false, realm.isPermittedAll(PRINCIPALS, "Master:view", "Source:edit"));
}
示例9: testCheckPermission_true
import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
@Test
public void testCheckPermission_true() {
final ShiroPermissionResolver resolver = new ShiroPermissionResolver();
UserSourceRealm realm = new UserSourceRealm(_userSource) {
@Override
protected AuthorizationInfo getAuthorizationInfo(PrincipalCollection principals) {
SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
info.addObjectPermission(resolver.resolvePermission("Master:view"));
return info;
}
};
realm.setPermissionResolver(resolver);
realm.checkPermission(PRINCIPALS, "Master:view");
}
示例10: testCheckPermission_false
import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
@Test(expectedExceptions = UnauthorizedException.class)
public void testCheckPermission_false() {
final ShiroPermissionResolver resolver = new ShiroPermissionResolver();
UserSourceRealm realm = new UserSourceRealm(_userSource) {
@Override
protected AuthorizationInfo getAuthorizationInfo(PrincipalCollection principals) {
SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
info.addObjectPermission(resolver.resolvePermission("Master:view"));
return info;
}
};
realm.setPermissionResolver(resolver);
realm.checkPermission(PRINCIPALS, "Master:edit");
}
示例11: testCheckPermission_otherType
import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
@Test(expectedExceptions = UnauthorizedException.class)
public void testCheckPermission_otherType() {
final ShiroPermissionResolver resolver = new ShiroPermissionResolver();
UserSourceRealm realm = new UserSourceRealm(_userSource) {
@Override
protected AuthorizationInfo getAuthorizationInfo(PrincipalCollection principals) {
SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
info.addObjectPermission(resolver.resolvePermission("Master:view"));
return info;
}
};
realm.setPermissionResolver(resolver);
realm.checkPermission(PRINCIPALS, PERMISSION_OTHER_TYPE);
}
示例12: testCheckPermissions_true
import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
@Test
public void testCheckPermissions_true() {
final ShiroPermissionResolver resolver = new ShiroPermissionResolver();
UserSourceRealm realm = new UserSourceRealm(_userSource) {
@Override
protected AuthorizationInfo getAuthorizationInfo(PrincipalCollection principals) {
SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
info.addObjectPermission(resolver.resolvePermission("Master:view"));
info.addObjectPermission(resolver.resolvePermission("Source:view"));
return info;
}
};
realm.setPermissionResolver(resolver);
realm.checkPermissions(PRINCIPALS, "Master:view", "Source:view");
}
示例13: testCheckPermissions_false
import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
@Test(expectedExceptions = UnauthorizedException.class)
public void testCheckPermissions_false() {
final ShiroPermissionResolver resolver = new ShiroPermissionResolver();
UserSourceRealm realm = new UserSourceRealm(_userSource) {
@Override
protected AuthorizationInfo getAuthorizationInfo(PrincipalCollection principals) {
SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
info.addObjectPermission(resolver.resolvePermission("Master:view"));
info.addObjectPermission(resolver.resolvePermission("Source:view"));
return info;
}
};
realm.setPermissionResolver(resolver);
realm.checkPermissions(PRINCIPALS, "Master:view", "Source:edit");
}
示例14: doGetAuthorizationInfo
import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
info.addObjectPermission(new AllPermission());
return info;
}