make [roles] optional in shiro.ini

This commit is contained in:
Prabhjyot Singh 2016-06-11 10:35:52 +05:30
parent 966a96cb27
commit 310a81d39a

View file

@ -85,7 +85,7 @@ public class SecurityUtils {
public static HashSet<String> getRoles() {
Subject subject = org.apache.shiro.SecurityUtils.getSubject();
HashSet<String> roles = new HashSet<>();
Map allRoles = new HashMap();
Map allRoles = null;
if (subject.isAuthenticated()) {
Collection realmsList = SecurityUtils.getRealmsList();
@ -93,20 +93,20 @@ public class SecurityUtils {
Realm realm = iterator.next();
String name = realm.getName();
if (name.equals("iniRealm")) {
IniRealm r = (IniRealm) realm;
allRoles = r.getIni().get("roles");
allRoles = ((IniRealm) realm).getIni().get("roles");
break;
}
}
Iterator it = allRoles.entrySet().iterator();
while (it.hasNext()) {
Map.Entry pair = (Map.Entry) it.next();
if (subject.hasRole((String) pair.getKey())) {
roles.add((String) pair.getKey());
if (allRoles != null) {
Iterator it = allRoles.entrySet().iterator();
while (it.hasNext()) {
Map.Entry pair = (Map.Entry) it.next();
if (subject.hasRole((String) pair.getKey())) {
roles.add((String) pair.getKey());
}
}
}
}
return roles;
}