Java集合容器优化

来源:互联网 发布:容迟网络 编辑:程序博客网 时间:2024/06/01 08:40
public static boolean hasRoleAuth(String roleName) {   Authentication auth = SecurityContextHolder.getContext().getAuthentication();      GrantedAuthority[] ga=auth.getAuthorities();      for (int i = 0; i < ga.length; i++) {   GrantedAuthority authority = ga[i];   if(authority.getAuthority().equals(roleName))      return true;}      return false;  }public static boolean hasRoleAuth(String roleName) {    Authentication auth = SecurityContextHolder.getContext().getAuthentication();    for (GrantedAuthority ga : auth.getAuthorities()) {        if (ga.getAuthority().equals(roleName)) {            return true;        }    }    return false;}---------------------------------------------------------------------------------------  public static Role getRole(){   Authentication auth = SecurityContextHolder.getContext().getAuthentication();      GrantedAuthority[] ga=auth.getAuthorities();      if(ga.length>0){       Role role=roleManager.getRoleByName(ga[0].getAuthority());       return role;      }      return null;  }public static Role getRole() {    Authentication auth = SecurityContextHolder.getContext().getAuthentication();    Collection<? extends GrantedAuthority> ga = auth.getAuthorities();    if (ga.iterator().hasNext()) {        Role role = roleManager.getRoleByName(ga.iterator().next().getAuthority());        return role;    }    return null;}--------------------------------------------------------------------------------------- public static String[] getRoleNames(){   Authentication auth = SecurityContextHolder.getContext().getAuthentication();      GrantedAuthority[] ga=auth.getAuthorities();      String[] roleNames=new String[ga.length];      for (int i = 0; i < ga.length; i++) {   GrantedAuthority authority = ga[i];   roleNames[i]=authority.getAuthority();}      return roleNames;  }public static String[] getRoleNames() {    Authentication auth = SecurityContextHolder.getContext().getAuthentication();    Collection<? extends GrantedAuthority> collection = auth.getAuthorities();    String[] roleNames = new String[collection.size()];    int i = 0;    for (GrantedAuthority g : collection) {        roleNames[i++] = g.getAuthority();    }    return roleNames;}
0 0
原创粉丝点击