Introduce OSAuthentication
[lgpl/argeo-commons.git] / security / plugins / org.argeo.security.ui / src / main / java / org / argeo / security / ui / internal / CurrentUser.java
index 638eb03a59e14c3b209f8f4a7ce257f6f7c5c761..ed50d1e3ccd521d864d5e1ac77a8ee5b4a6bdc82 100644 (file)
@@ -23,12 +23,16 @@ public class CurrentUser {
        }
 
        public final static Set<String> roles() {
-               Principal principal = getSubject().getPrincipals(Authentication.class)
-                               .iterator().next();
-               Authentication authentication = (Authentication) principal;
                Set<String> roles = Collections.synchronizedSet(new HashSet<String>());
-               for (GrantedAuthority ga : authentication.getAuthorities()) {
-                       roles.add(ga.getAuthority());
+
+               Set<Authentication> authens = getSubject().getPrincipals(
+                               Authentication.class);
+               if (authens != null && !authens.isEmpty()) {
+                       Principal principal = authens.iterator().next();
+                       Authentication authentication = (Authentication) principal;
+                       for (GrantedAuthority ga : authentication.getAuthorities()) {
+                               roles.add(ga.getAuthority());
+                       }
                }
                return Collections.unmodifiableSet(roles);
        }