本文整理匯總了Java中org.apache.shiro.authz.SimpleAuthorizationInfo.addStringPermissions方法的典型用法代碼示例。如果您正苦於以下問題:Java SimpleAuthorizationInfo.addStringPermissions方法的具體用法?Java SimpleAuthorizationInfo.addStringPermissions怎麽用?Java SimpleAuthorizationInfo.addStringPermissions使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.shiro.authz.SimpleAuthorizationInfo
的用法示例。
在下文中一共展示了SimpleAuthorizationInfo.addStringPermissions方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: doGetAuthorizationInfo
import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
/**
* 完成授權
*/
@Override
protected AuthorizationInfo doGetAuthorizationInfo(
PrincipalCollection principals) {
//得到認證成功之後憑證的身份信息
String username=((User) principals.getPrimaryPrincipal()).getUsername();
//查詢數據庫得到所有的權限列表
List<String> permissionList=new ArrayList<String>();
UserCustom userCustom = customMapper.findUserCustomByUsername(username);
Set<RoleCustom> roles=userCustom.getRoleSet();
for(RoleCustom role:roles){
Set<Permission> permissionSet = role.getPermissionSet();
for (Permission permission:permissionSet) {
permissionList.add(permission.getPname());
}
}
SimpleAuthorizationInfo authorizationInfo=new SimpleAuthorizationInfo();
authorizationInfo.addStringPermissions(permissionList);
return authorizationInfo;
}
示例2: doGetAuthorizationInfo
import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
/**
* 完成授權
*/
@Override
protected AuthorizationInfo doGetAuthorizationInfo(
PrincipalCollection principals) {
//得到認證成功之後憑證的身份信息
String username=(String) principals.getPrimaryPrincipal();
//查詢數據庫得到所有的權限列表
List<String> permissionList=new ArrayList<String>();
UserCustomMapper mapper=getUserCustomMapper();
UserCustom userCustom = mapper.findUserCustomByUsername(username);
Set<RoleCustom> roles=userCustom.getRoleSet();
for(RoleCustom role:roles){
Set<Permission> permissionSet = role.getPermissionSet();
for (Permission permission:permissionSet) {
permissionList.add(permission.getPname());
}
}
SimpleAuthorizationInfo authorizationInfo=new SimpleAuthorizationInfo();
authorizationInfo.addStringPermissions(permissionList);
return authorizationInfo;
}
示例3: doGetAuthorizationInfo
import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
/**
* 此方法調用 hasRole,hasPermission的時候才會進行回調.
*
* 權限信息.(授權):
* 1、如果用戶正常退出,緩存自動清空;
* 2、如果用戶非正常退出,緩存自動清空;
* 3、如果我們修改了用戶的權限,而用戶不退出係統,修改的權限無法立即生效。
* (需要手動編程進行實現;放在service進行調用)
* 在權限修改後調用realm中的方法,realm已經由spring管理,所以從spring中獲取realm實例,
* 調用clearCached方法;
* :Authorization 是授權訪問控製,用於對用戶進行的操作授權,證明該用戶是否允許進行當前操作,如訪問某個鏈接,某個資源文件等。
* @param principals
* @return
*/
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) throws AuthenticationException{
/*
* 當沒有使用緩存的時候,不斷刷新頁麵的話,這個代碼會不斷執行,
* 當其實沒有必要每次都重新設置權限信息,所以我們需要放到緩存中進行管理;
* 當放到緩存中時,這樣的話,doGetAuthorizationInfo就隻會執行一次了,
* 緩存過期之後會再次執行。
*/
SimpleAuthorizationInfo authorizationInfo = new SimpleAuthorizationInfo();
AdminDO userInfo = (AdminDO)principals.getPrimaryPrincipal();
Set<String> set = new HashSet<String>();
set.add(userInfo.getRole().getRoleId());
authorizationInfo.setRoles(set);
Set<String> menus = roleMenuService.getMenuCodesByRoleId(userInfo.getRole().getRoleId());
authorizationInfo.addStringPermissions(menus);
return authorizationInfo;
}
示例4: doGetAuthorizationInfo
import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
// 配置用戶權限
Principal principal = (Principal) principals.fromRealm(getName()).iterator().next();
if (principal != null) {
// 推薦將權限標識加入緩存,然後從緩存獲取權限標識集合,並添加給SimpleAuthorizationInfo,避免頻繁訪問數據庫獲取資源
// 如:List<String> permissions = redisService.findUserPermissions(userId);
// 權限標識與applicationContext-shiro.xml配置的filterChainDefinitionsperms中類似["admin:userModule"]
// 以下示例
List<String> permissions = new ArrayList<String>();
permissions.add("admin:userModule");// 賦予這個標識才有權限訪問/user/findPage.html
SimpleAuthorizationInfo authorizationInfo = new SimpleAuthorizationInfo();
authorizationInfo.addStringPermissions(permissions);
return authorizationInfo;
}
return null;
}
示例5: doGetAuthorizationInfo
import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
/**
* 完成授權
*/
@Override
protected AuthorizationInfo doGetAuthorizationInfo(
PrincipalCollection principals) {
//得到認證成功之後憑證的身份信息
String username=((User) principals.getPrimaryPrincipal()).getUsername();
//查詢數據庫得到所有的權限列表
List<String> permissionList=new ArrayList<String>();
List<String> roleList=new ArrayList<>();
UserCustom userCustom = customMapper.findUserCustomByUsername(username);
Set<RoleCustom> roles=userCustom.getRoleSet();
for(RoleCustom role:roles){
roleList.add(role.getRname());
Set<Permission> permissionSet = role.getPermissionSet();
for (Permission permission:permissionSet) {
permissionList.add(permission.getPname());
}
}
SimpleAuthorizationInfo authorizationInfo=new SimpleAuthorizationInfo();
authorizationInfo.addStringPermissions(permissionList);
authorizationInfo.addRoles(roleList);
return authorizationInfo;
}
示例6: doGetAuthorizationInfo
import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
Preconditions.checkNotNull(principalCollection, "You can't have a null collection of principals. No really, how did you do that");
String userEmail = (String) getAvailablePrincipal(principalCollection);
if (userEmail == null) {
throw new NullPointerException("Can't find a principal in the collection");
}
LOGGER.debug("Finding authorization info for " + userEmail + " in DB");
final User user = userRepository.findByEmailAndActive(userEmail, true);
LOGGER.debug("Found " + userEmail + " in DB");
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());
}
}
}
SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
info.addRoles(roleNames);
info.addStringPermissions(permissionNames);
return info;
}
示例7: doGetAuthorizationInfo
import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
/**
* 獲取授權信息
*
* @param principals
* principals
* @return 授權信息
*/
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
Principal principal = (Principal) principals.fromRealm(getName()).iterator().next();
if (principal != null) {
List<String> authorities = adminService.findAuthorities(principal.getId());
if (authorities != null) {
SimpleAuthorizationInfo authorizationInfo = new SimpleAuthorizationInfo();
authorizationInfo.addStringPermissions(authorities);
return authorizationInfo;
}
}
return null;
}
示例8: doGetAuthorizationInfo
import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
checkNotNull(principals.getPrimaryPrincipal());
checkArgument(principals.getPrimaryPrincipal() instanceof ToAccount);
ToAccount toAccount = (ToAccount) principals.getPrimaryPrincipal();
List<ToRole> toRoles = fetchRoles(toAccount.getId());
List<ToPermission> toPermissions = fetchPermissions(toAccount.getId());
SimpleAuthorizationInfo authorizationInfo = new SimpleAuthorizationInfo();
authorizationInfo.addRoles(
toRoles.stream()
.map(ToRole::getId)
.collect(Collectors.toList())
);
authorizationInfo.addStringPermissions(
toPermissions.parallelStream()
.map(ToPermission::getId)
.collect(Collectors.toList())
);
return authorizationInfo;
}
示例9: doGetAuthorizationInfo
import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
protected AuthorizationInfo doGetAuthorizationInfo(
PrincipalCollection principals) {
Principal principal = (Principal) getAvailablePrincipal(principals);
if (principal.getName() != null) {
UserService userService = BGDispatch.userService;
Collection<Role> myRoles = userService.getRoles(principal.getName(),principal.getPassword());
if (myRoles != null) {
SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
for (Role each : myRoles) {
info.addRole(each.getStr(Role.NAME));
Set<String> pers = new HashSet<String>();
for (Permission permission : each.getPermissions()) {
if(StringUtils.isNotBlank(permission.getStr("permission"))){
pers.add(permission.getStr("permission"));
}
}
info.addStringPermissions(pers);
}
return info;
}
}
return null;
}
示例10: doGetAuthorizationInfo
import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
/**
* AuthorizationInfo(Subject's roles and permissions)
*/
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
String username = (String) principalCollection.fromRealm(getName()).iterator().next();
User loginUser = userService.findByUsername(username);
if (loginUser != null) {
SimpleAuthorizationInfo authInfo = new SimpleAuthorizationInfo();
for (Role role : loginUser.getRoles()) {
String roleName = String.valueOf(role.getId());
authInfo.addRole(roleName);
authInfo.addStringPermissions(role.getStringPermissions());
}
return authInfo;
}
return null;
}
示例11: doGetAuthorizationInfo
import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals)
{
String username = principals.getPrimaryPrincipal().toString();
User user = this.jpaRealmRepository.findUserByName(username);
if (null != user)
{
SimpleAuthorizationInfo authorization = new SimpleAuthorizationInfo();
for (Role role : user.getRoles())
{
authorization.addStringPermissions(role.getPermissions());
}
return authorization;
}
return null;
}
示例12: doGetAuthorizationInfo
import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
/**
* 當用戶進行訪問鏈接時的授權方法
*/
@Override
protected AuthorizationInfo doGetAuthorizationInfo(
PrincipalCollection principals) {
/*
* if (principals == null) {
throw new AuthorizationException("Principal對象不能為空");
}
User user = (User) principals.fromRealm(getName()).iterator().next();
* */
Principal principal = (Principal) getAvailablePrincipal(principals);
User user = null;//userService.getByUserName(principal.getName());
// 獲取用戶響應的permission
List<String> permissions = Collections3.extractToList(user.getRoleList(), "permission");
SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
info.addStringPermissions(permissions);
return info;
}
示例13: doGetAuthorizationInfo
import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
UserSession session = SessionHelper.get();
if (session==null) {
return null;
}
SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
info.addRole(String.valueOf(session.getRole()));
info.addStringPermissions(session.getPermission());
return info;
}
示例14: doGetAuthorizationInfo
import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
/**
* 授權查詢回調函數, 進行鑒權但緩存中無用戶的授權信息時調用.
*/
/* (non-Javadoc)
* @see org.apache.shiro.realm.AuthorizingRealm#doGetAuthorizationInfo(org.apache.shiro.subject.PrincipalCollection)
*/
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
System.out.println("開始授權查詢");
User curUser = userService.findByAccount(principals.getPrimaryPrincipal().toString());
int userId = curUser.getId();
SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
List<Role> rolesList = roleService.selectRolesByUser(userId);
List<Integer> roleIds = Lists.newArrayList();
Set<String> roleCodes = Sets.newHashSet();
if (null != rolesList && rolesList.size() > 0) {
for (Role role : rolesList) {
if (!Strings.isNullOrEmpty(role.getCode())) {
roleIds.add(role.getId());
roleCodes.add(role.getCode());
}
}
info.addRoles(roleCodes);
}
// 權限
Set<String> permissions = Sets.newHashSet();
if (roleIds.size() > 0) {
for (Integer roleId: roleIds) {
List<String> dataList = permissionService.findPermissionsByRoleId(roleId);
if(null != dataList && dataList.size() > 0) {
permissions.addAll(dataList);
}
}
}
permissions.remove("");
info.addStringPermissions(permissions);
return info;
}
示例15: doGetAuthorizationInfo
import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
/**
* 授權
*/
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
String userName = (String) principals.getPrimaryPrincipal();
User user = userService.findUserByName(userName);
SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
Set<Role> roleSet = user.getRoles();
Set<String> permissionSet = new HashSet<String>();
for (Role role : roleSet) {
if(StringUtils.isNotBlank(role.getRoleName())){
info.addRole(role.getRoleName());
Set<Resource> resources = role.getResources();
if(resources!=null && !resources.isEmpty()){
for(Resource r : resources){
if(StringUtils.isNotBlank(r.getUrl())){
permissionSet.add(r.getUrl());
}
}
}
}
}
info.addStringPermissions(permissionSet);
return info;
}