當前位置: 首頁>>代碼示例>>Java>>正文


Java SimpleAuthorizationInfo.setRoles方法代碼示例

本文整理匯總了Java中org.apache.shiro.authz.SimpleAuthorizationInfo.setRoles方法的典型用法代碼示例。如果您正苦於以下問題:Java SimpleAuthorizationInfo.setRoles方法的具體用法?Java SimpleAuthorizationInfo.setRoles怎麽用?Java SimpleAuthorizationInfo.setRoles使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.shiro.authz.SimpleAuthorizationInfo的用法示例。


在下文中一共展示了SimpleAuthorizationInfo.setRoles方法的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;
}
 
開發者ID:phoenix-varus,項目名稱:jeeWe,代碼行數:24,代碼來源:UserRealm.java

示例2: 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;
}
 
開發者ID:wu05281,項目名稱:admin-shiro,代碼行數:34,代碼來源:AdminShiroRealm.java

示例3: 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;  
  }
 
開發者ID:miracle857,項目名稱:weibo,代碼行數:19,代碼來源:SampleRealm.java

示例4: 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;
}
 
開發者ID:peterchenhdu,項目名稱:spring-shiro-demo,代碼行數:21,代碼來源:UserRealm.java

示例5: 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;
}
 
開發者ID:howiefh,項目名稱:jee-restful-web,代碼行數:18,代碼來源:StatelessRealm.java

示例6: 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;
}
 
開發者ID:melonlee,項目名稱:LazyAdmin,代碼行數:15,代碼來源:UserRealm.java

示例7: doGetAuthorizationInfo

import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
/**
 * 授權:驗證權限時調用
 * @param principalCollection
 * @return
 */
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
    String username = (String) principalCollection.getPrimaryPrincipal();
    UpmsUser upmsUser = upmsApiService.selectUpmsUserByUsername(username);

    // 當前用戶所有角色
    List<UpmsRole> upmsRoles = upmsApiService.selectUpmsRoleByUpmsUserId(upmsUser.getUserId());
    Set<String> roles = new HashSet<>();
    for (UpmsRole upmsRole : upmsRoles) {
        if (StringUtils.isNotBlank(upmsRole.getName())) {
            roles.add(upmsRole.getName());
        }
    }

    // 當前用戶所有權限
    List<UpmsPermission> upmsPermissions = upmsApiService.selectUpmsPermissionByUpmsUserId(upmsUser.getUserId());
    Set<String> permissions = new HashSet<>();
    for (UpmsPermission upmsPermission : upmsPermissions) {
        if (StringUtils.isNotBlank(upmsPermission.getPermissionValue())) {
            permissions.add(upmsPermission.getPermissionValue());
        }
    }

    SimpleAuthorizationInfo simpleAuthorizationInfo = new SimpleAuthorizationInfo();
    simpleAuthorizationInfo.setStringPermissions(permissions);
    simpleAuthorizationInfo.setRoles(roles);
    return simpleAuthorizationInfo;
}
 
開發者ID:youngMen1,項目名稱:-Spring-SpringMVC-Mybatis-,代碼行數:34,代碼來源:UpmsRealm.java

示例8: doGetAuthorizationInfo

import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) throws AuthenticationException {
 String email = (String)principals.getPrimaryPrincipal();
    SimpleAuthorizationInfo authorizationInfo = new SimpleAuthorizationInfo();
    authorizationInfo.setRoles(UserRoleDAO.getRoles(email));
    authorizationInfo.setStringPermissions(RolePermissionDAO.getPermission(email));
    return authorizationInfo;
}
 
開發者ID:ETspielberg,項目名稱:bibliometrics,代碼行數:9,代碼來源:BibliometricsRealm.java

示例9: doGetAuthorizationInfo

import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
/**
 * Shiro權限認證
 */
@Override
protected AuthorizationInfo doGetAuthorizationInfo(
        PrincipalCollection principals) {
    ShiroUser shiroUser = (ShiroUser) principals.getPrimaryPrincipal();
    
    SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
    info.setRoles(shiroUser.getRoles());
    info.addStringPermissions(shiroUser.getUrlSet());
    
    return info;
}
 
開發者ID:TomChen001,項目名稱:xmanager,代碼行數:15,代碼來源:ShiroDbRealm.java

示例10: doGetAuthorizationInfo

import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
/**
 * 返回權限信息
 * @param principal
 * @return
 */
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principal) {

    //獲取用戶名
    String username=principal.getPrimaryPrincipal().toString();
    SimpleAuthorizationInfo authorizationInfo=new SimpleAuthorizationInfo();
    //獲得授權角色
    authorizationInfo.setRoles(userService.getRoles(username));
    //獲得授權權限
    authorizationInfo.setStringPermissions(userService.getPermissions(username));
    return authorizationInfo;
}
 
開發者ID:Exrick,項目名稱:xmall,代碼行數:18,代碼來源:MyRealm.java

示例11: doGetAuthorizationInfo

import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
    String username = (String) principalCollection.getPrimaryPrincipal();
    SimpleAuthorizationInfo simpleAuthorizationInfo = new SimpleAuthorizationInfo();
    Set<String> roles = new HashSet<String>();
    roles.add("leader");
    Set<String> permissions = new HashSet<String>();
    permissions.add("user:view");
    simpleAuthorizationInfo.setRoles(roles);
    simpleAuthorizationInfo.setStringPermissions(permissions);
    return simpleAuthorizationInfo;
}
 
開發者ID:gittozji,項目名稱:home,代碼行數:12,代碼來源:SimpleRealm.java

示例12: 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(userService.findRoles(username));
    authorizationInfo.setStringPermissions(userService.findPermissions(username));
    return authorizationInfo;
}
 
開發者ID:melonlee,項目名稱:PowerApi,代碼行數:15,代碼來源:UserRealm.java

示例13: doGetAuthorizationInfo

import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
/**
 * 權限認證
 *
 * @param principals
 * @return AuthorizationInfo
 */
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
  String principal_username = principals.getPrimaryPrincipal().toString();
  SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
  Set<String> roleNames = userMService.findRoleNames(principal_username);
  Set<String> permissionNames = userMService.findPermissionNames(roleNames);
  info.setRoles(roleNames);

  //基於權限的授權相比基於角色的授權更好,更靈活,更符合實際情況
  info.setStringPermissions(permissionNames);
  return info;
}
 
開發者ID:MiniPa,項目名稱:cjs_ssms,代碼行數:19,代碼來源:UUserRealm.java

示例14: doGetAuthorizationInfo

import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
/**
 * 權限認證
 *
 * @param principals
 * @return AuthorizationInfo
 */
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
  String principal_username = principals.getPrimaryPrincipal().toString();
  SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
  Set<String> roleNames = userFService.findRoleNames(principal_username);
  Set<String> permissionNames = userFService.findPermissionNames(roleNames);
  info.setRoles(roleNames);

  //基於權限的授權相比基於角色的授權更好,更靈活,更符合實際情況
  info.setStringPermissions(permissionNames);
  return info;
}
 
開發者ID:MiniPa,項目名稱:cjs_ssms,代碼行數:19,代碼來源:UserRealm.java

示例15: doGetAuthorizationInfo

import org.apache.shiro.authz.SimpleAuthorizationInfo; //導入方法依賴的package包/類
/**
 * 主要用於鑒權
 * @param principals
 * @return
 */
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
    String username = (String)principals.getPrimaryPrincipal();
    SimpleAuthorizationInfo authorizationInfo = new SimpleAuthorizationInfo();
    authorizationInfo.setRoles(userService.findRoles(username));
    authorizationInfo.setStringPermissions(userService.findPermissions(username));

    return authorizationInfo;
}
 
開發者ID:l81893521,項目名稱:shiro-demo,代碼行數:14,代碼來源:UserRealm.java


注:本文中的org.apache.shiro.authz.SimpleAuthorizationInfo.setRoles方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。