本文整理匯總了Java中org.apache.shiro.authz.SimpleAuthorizationInfo.setStringPermissions方法的典型用法代碼示例。如果您正苦於以下問題:Java SimpleAuthorizationInfo.setStringPermissions方法的具體用法?Java SimpleAuthorizationInfo.setStringPermissions怎麽用?Java SimpleAuthorizationInfo.setStringPermissions使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.shiro.authz.SimpleAuthorizationInfo
的用法示例。
在下文中一共展示了SimpleAuthorizationInfo.setStringPermissions方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: doGetAuthorizationInfo
import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
@SuppressWarnings("rawtypes")
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
String username = (String) principals.getPrimaryPrincipal();
SimpleAuthorizationInfo authorizationInfo = new SimpleAuthorizationInfo();
// 根據用戶名查詢當前用戶擁有的角色
List<Map> roles = userService.findRolesByUserName(username);
Set<String> roleNames = new HashSet<String>();
for (Map role : roles) {
roleNames.add(role.get("name").toString());
}
// 將角色名稱提供給info
authorizationInfo.setRoles(roleNames);
// 根據用戶名查詢當前用戶權限
List<Map> permissions = userService.findPermissionsByUserName(username);
Set<String> permissionNames = new HashSet<String>();
for (Map permission : permissions) {
permissionNames.add(permission.get("name").toString());
}
// 將權限名稱提供給info
authorizationInfo.setStringPermissions(permissionNames);
return authorizationInfo;
}
示例2: doGetAuthorizationInfo
import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
/**
* 授權
*/
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
//Long userId = TokenManager.getUserId();
User token = (User)SecurityUtils.getSubject().getPrincipal();
SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
//根據用戶ID查詢角色(role),放入到Authorization裏。
Set<String> roleName = roleService.findRoleNameByUserId(String.valueOf(token.getUuid()));
info.setRoles(roleName);
//根據用戶ID查詢權限(permission),放入到Authorization裏。
Set<String> permissions = permissionService.findPermissionByUserId(String.valueOf(token.getUuid()));
info.setStringPermissions(permissions);
return info;
}
示例3: doGetAuthorizationInfo
import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection arg0)
{
ShiroToken token = (ShiroToken) SecurityUtils.getSubject().getPrincipal();
String username = token.getUsername();
logger.info(username + "授權...");
// 從數據庫中查找該用戶的角色和權限
SimpleAuthorizationInfo sainfo = new SimpleAuthorizationInfo();
Set<String> roles = new HashSet<String>();
roles.add("admin");
//roles.add("role1");
Set<String> permissions = new HashSet<String>();
permissions.add("add");
permissions.add("delete");
sainfo.setRoles(roles);
sainfo.setStringPermissions(permissions);
return sainfo;
}
示例4: doGetAuthorizationInfo
import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
// 根據用戶名查找角色,請根據需求實現
String username = (String) principals.getPrimaryPrincipal();
User user = userService.findByName(username);
SimpleAuthorizationInfo authorizationInfo = new SimpleAuthorizationInfo();
SimplePrincipalCollection principalCollection = (SimplePrincipalCollection) principals;
principalCollection.clear();
principalCollection.add(user, getName());
RolePermission rolePermission = user.new RolePermission();
authorizationInfo.setRoles(rolePermission.getRoleSet());
authorizationInfo.setStringPermissions(rolePermission.getPermissionSet());
return authorizationInfo;
}
示例5: doGetAuthorizationInfo
import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
//null usernames are invalid
if (principals == null) {
throw new AuthorizationException("PrincipalCollection method argument cannot be null.");
}
String username = (String) getAvailablePrincipal(principals);
java.util.Set<String> roles = redisManager.smembers(user_roles_KeyPrefix + username);
SimpleAuthorizationInfo info = new SimpleAuthorizationInfo(roles);
if (permissionsLookupEnabled) {
java.util.List<java.lang.String> permissionsList = redisManager.hmget(roles_permissions_Key, roles.toArray(new String[0]));
Set<String> permissionsSet = new HashSet<String>(permissionsList.size());
permissionsSet.addAll(permissionsList);
info.setStringPermissions(permissionsSet);
}
return info;
}
示例6: doGetAuthorizationInfo
import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
/**
*
* @param principalCollection
* @return
*/
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
final User user = (User) this.getAvailablePrincipal(principalCollection);
final List<GroupPermission> permissions = this.accountService
.loadUserPermissions(user.getUsername());
final Set<String> keys = permissions
.parallelStream()
.map(GroupPermission::getPermissionKey)
.collect(Collectors.toSet());
// creates the basic authorization info
final SimpleAuthorizationInfo authInfo = new SimpleAuthorizationInfo();
authInfo.setStringPermissions(keys);
return authInfo;
}
示例7: queryForAuthorizationInfo
import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
/**
* Get groups from LDAP.
*
* @param principals
* the principals of the Subject whose AuthenticationInfo should
* be queried from the LDAP server.
* @param ldapContextFactory
* factory used to retrieve LDAP connections.
* @return an {@link AuthorizationInfo} instance containing information
* retrieved from the LDAP server.
* @throws NamingException
* if any LDAP errors occur during the search.
*/
@Override
public AuthorizationInfo queryForAuthorizationInfo(final PrincipalCollection principals,
final LdapContextFactory ldapContextFactory) throws NamingException {
if (!isAuthorizationEnabled()) {
return null;
}
final Set<String> roleNames = getRoles(principals, ldapContextFactory);
if (log.isDebugEnabled()) {
log.debug("RolesNames Authorization: " + roleNames);
}
SimpleAuthorizationInfo simpleAuthorizationInfo = new SimpleAuthorizationInfo(roleNames);
Set<String> stringPermissions = permsFor(roleNames);
simpleAuthorizationInfo.setStringPermissions(stringPermissions);
return simpleAuthorizationInfo;
}
示例8: doGetAuthorizationInfo
import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
/**
* 授權
*/
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
String username = (String) principals.getPrimaryPrincipal();
CmsUser user = cmsUserMng.findByUsername(username);
CmsSite site=CmsThreadVariable.getSite();
SimpleAuthorizationInfo auth = new SimpleAuthorizationInfo();
if (user != null) {
Set<String>viewPermissionSet=new HashSet<String>();
Set<String> perms = user.getPerms(site.getId(),viewPermissionSet);
if (!CollectionUtils.isEmpty(perms)) {
// 權限加入AuthorizationInfo認證對象
auth.setStringPermissions(perms);
}
}
return auth;
}
示例9: getAuthorizationInfo
import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
public AuthorizationInfo getAuthorizationInfo(final String login) {
final SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
final UserEntity userEntity = userRepository.findByLogin(login);
if(userEntity == null) {
throw new UnknownAccountException("Account does not exist");
}
final Set<String> permissionNames = new LinkedHashSet<>();
final Set<PermissionEntity> permissions = this.getUserPermissions(userEntity);
for (PermissionEntity permission : permissions) {
permissionNames.add(permission.getValue());
}
info.setStringPermissions(permissionNames);
return info;
}
示例10: doGetAuthorizationInfo
import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
@Override
protected AuthorizationInfo doGetAuthorizationInfo(
final PrincipalCollection principals) {
// retrieve role names and permission names
final String email = (String) principals.getPrimaryPrincipal();
final User user = userRepository.findByEmailAndActive(email, true);
if (user == null) {
throw new UnknownAccountException("Account does not exist");
}
final int totalRoles = user.getRoles().size();
final Set<String> roleNames = new LinkedHashSet<>(totalRoles);
final Set<String> permissionNames = new LinkedHashSet<>();
if (totalRoles > 0) {
for (Role role : user.getRoles()) {
roleNames.add(role.getName());
for (Permission permission : role.getPermissions()) {
permissionNames.add(permission.getName());
}
}
}
final SimpleAuthorizationInfo info = new SimpleAuthorizationInfo(roleNames);
info.setStringPermissions(permissionNames);
return info;
}
示例11: doGetAuthorizationInfo
import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
LOGGER.debug("StatelessRealm doGetAuthenticationInfo");
String accessToken = (String) getAvailablePrincipal(principalCollection);
StatelessUser user = authService.getUser(accessToken);
Set<String> roleNames = new LinkedHashSet<String>();
for (SysRole sysRole : user.getRoles()) {
roleNames.add(sysRole.getRoleName());
}
Set<String> permissions = authService.getPermissions(user.getUserId());
SimpleAuthorizationInfo info = new SimpleAuthorizationInfo(roleNames);
info.setStringPermissions(permissions);
return info;
}
示例12: doGetAuthorizationInfo
import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
User user = (User)principals.getPrimaryPrincipal();
user = userService.get(user.getId());
SimpleAuthorizationInfo authorizationInfo = new SimpleAuthorizationInfo();
Set<String> stringPermissions = new HashSet<>();
if (user.getRoles() != null && user.getRoles().size() > 0) {
List<Role> roles = user.getRoles();
for (Role role : roles) {
if (role.getResources() != null && role.getResources().size() > 0) {
for (Resource resource : role.getResources()) {
if (resource.getValid() == EnableDisableStatus.ENABLE && !StringUtils.isEmpty(resource.getIdentifier())) {
stringPermissions.add(resource.getIdentifier());
}
}
}
}
}
authorizationInfo.setStringPermissions(stringPermissions);
return authorizationInfo;
}
示例13: doGetAuthorizationInfo
import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
@Override
protected AuthorizationInfo doGetAuthorizationInfo(final PrincipalCollection principals) {
LOG.debug("Checking doGetAuthorizationInfo for {}", principals);
// null usernames are invalid
if (principals == null) {
throw new AuthorizationException("PrincipalCollection method argument cannot be null.");
}
final SimpleAuthorizationInfo info = new SimpleAuthorizationInfo(UserRole.ALL_ROLES);
final String email = (String) getAvailablePrincipal(principals);
final User user = userDao.findByEmail(email);
if (user == null) {
throw new UnknownAccountException("No user found with email: " + email);
}
final Set<String> userRoles = UserRole.getRolesFor(user);
info.setStringPermissions(userRoles);
LOG.debug("User {} was assigned permissions: {}", email, userRoles);
return info;
}
示例14: doGetAuthorizationInfo
import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
/**
* 對用戶權限進行判定
*
* @param principals
* @return
*/
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
String username = (String) principals.getPrimaryPrincipal();
SimpleAuthorizationInfo authorizationInfo = new SimpleAuthorizationInfo();
authorizationInfo.setRoles(adminService.findRoles(username));
authorizationInfo.setStringPermissions(adminService.findPermissions(username));
return authorizationInfo;
}
示例15: doGetAuthorizationInfo
import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
/**
* 授權(驗證權限時調用)
*/
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
SysUserEntity user = (SysUserEntity)principals.getPrimaryPrincipal();
Long userId = user.getUserId();
//用戶權限列表
Set<String> permsSet = shiroService.getUserPermissions(userId);
SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
info.setStringPermissions(permsSet);
return info;
}