]> git.argeo.org Git - lgpl/argeo-commons.git/blobdiff - security/runtime/org.argeo.security.core/src/main/java/org/argeo/security/core/OsAuthenticationProvider.java
Add remember me capabilities to RAP
[lgpl/argeo-commons.git] / security / runtime / org.argeo.security.core / src / main / java / org / argeo / security / core / OsAuthenticationProvider.java
index e9c83839f2e35c6d3ca836aa578a1913da517e89..3360b1eeae2c2cf5b1fd7bfb908448cc2fc67fe2 100644 (file)
@@ -10,7 +10,12 @@ import org.springframework.security.GrantedAuthority;
 import org.springframework.security.GrantedAuthorityImpl;
 import org.springframework.security.providers.AuthenticationProvider;
 
-/** Validates an OS authentication. */
+/**
+ * Validates an OS authentication. The id is that it will always be
+ * authenticated since we are always runnign within an OS, but the fact that the
+ * {@link Authentication} works properly depends on the proper OS login module
+ * having been called as well.
+ */
 public class OsAuthenticationProvider implements AuthenticationProvider {
        private String osUserRole = "ROLE_OS_USER";
        private String userRole = "ROLE_USER";
@@ -20,16 +25,16 @@ public class OsAuthenticationProvider implements AuthenticationProvider {
 
        public Authentication authenticate(Authentication authentication)
                        throws AuthenticationException {
-               if (authentication instanceof OsAuthenticationToken) {
-                       List<GrantedAuthority> auths = new ArrayList<GrantedAuthority>();
-                       auths.add(new GrantedAuthorityImpl(osUserRole));
-                       auths.add(new GrantedAuthorityImpl(userRole));
-                       if (isAdmin)
-                               auths.add(new GrantedAuthorityImpl(adminRole));
-                       return new OsAuthenticationToken(
-                                       auths.toArray(new GrantedAuthority[auths.size()]));
-               }
-               return null;
+               return new OsAuthenticationToken(getBaseAuthorities());
+       }
+
+       protected GrantedAuthority[] getBaseAuthorities() {
+               List<GrantedAuthority> auths = new ArrayList<GrantedAuthority>();
+               auths.add(new GrantedAuthorityImpl(osUserRole));
+               auths.add(new GrantedAuthorityImpl(userRole));
+               if (isAdmin)
+                       auths.add(new GrantedAuthorityImpl(adminRole));
+               return auths.toArray(new GrantedAuthority[auths.size()]);
        }
 
        @SuppressWarnings("rawtypes")
@@ -41,6 +46,10 @@ public class OsAuthenticationProvider implements AuthenticationProvider {
                this.osUserRole = osUserRole;
        }
 
+       public void setUserRole(String userRole) {
+               this.userRole = userRole;
+       }
+
        public void setAdminRole(String adminRole) {
                this.adminRole = adminRole;
        }