Improve user profile
[lgpl/argeo-commons.git] / security / plugins / org.argeo.security.ui / src / main / java / org / argeo / security / ui / internal / CurrentUser.java
index b26df1018965d797b9beca95a5e28124a2280f56..7b5287b7b0f572d57f444255e38eda4f4f482d4e 100644 (file)
@@ -28,17 +28,22 @@ public class CurrentUser {
 
        public final static Set<String> roles() {
                Set<String> roles = Collections.synchronizedSet(new HashSet<String>());
+               Authentication authentication = getAuthentication();
+               for (GrantedAuthority ga : authentication.getAuthorities()) {
+                       roles.add(ga.getAuthority());
+               }
+               return Collections.unmodifiableSet(roles);
+       }
 
+       public final static Authentication getAuthentication() {
                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 authentication;
                }
-               return Collections.unmodifiableSet(roles);
+               throw new ArgeoException("No authentication found");
        }
 
        public final static Subject getSubject() {