]> git.argeo.org Git - lgpl/argeo-commons.git/blobdiff - org.argeo.security.core/src/org/argeo/security/core/AbstractSystemExecution.java
Introduce ROLE_USER_ADMIN and ROLE_GROUP_ADMIN
[lgpl/argeo-commons.git] / org.argeo.security.core / src / org / argeo / security / core / AbstractSystemExecution.java
index b84f3de00e6819139292d613cddc504b0cacdb7b..3acf26c8a1d3097f0336aea0d1c0051556d477dc 100644 (file)
@@ -19,10 +19,10 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.argeo.ArgeoException;
 import org.argeo.security.SystemAuthentication;
-import org.springframework.security.Authentication;
-import org.springframework.security.AuthenticationManager;
-import org.springframework.security.context.SecurityContext;
-import org.springframework.security.context.SecurityContextHolder;
+import org.springframework.security.authentication.AuthenticationManager;
+import org.springframework.security.core.Authentication;
+import org.springframework.security.core.context.SecurityContext;
+import org.springframework.security.core.context.SecurityContextHolder;
 
 /** Provides base method for executing code with system authorization. */
 public abstract class AbstractSystemExecution {
@@ -30,9 +30,10 @@ public abstract class AbstractSystemExecution {
                // Forces Spring Security to use inheritable strategy
                // FIXME find a better place for forcing spring security mode
                // doesn't work for the time being
-//             if (System.getProperty(SecurityContextHolder.SYSTEM_PROPERTY) == null)
-//                     SecurityContextHolder
-//                                     .setStrategyName(SecurityContextHolder.MODE_INHERITABLETHREADLOCAL);
+               // if (System.getProperty(SecurityContextHolder.SYSTEM_PROPERTY) ==
+               // null)
+               // SecurityContextHolder
+               // .setStrategyName(SecurityContextHolder.MODE_INHERITABLETHREADLOCAL);
        }
 
        private final static Log log = LogFactory
@@ -72,13 +73,16 @@ public abstract class AbstractSystemExecution {
 
                String key = systemAuthenticationKey != null ? systemAuthenticationKey
                                : System.getProperty(
-                                               InternalAuthentication.SYSTEM_KEY_PROPERTY,
+                                               SystemAuthentication.SYSTEM_KEY_PROPERTY,
                                                InternalAuthentication.SYSTEM_KEY_DEFAULT);
                if (key == null)
                        throw new ArgeoException("No system key defined");
+               if (authenticationManager == null)
+                       throw new ArgeoException("Authentication manager cannot be null.");
                Authentication auth = authenticationManager
                                .authenticate(new InternalAuthentication(key));
                securityContext.setAuthentication(auth);
+
                authenticatedBySelf.set(true);
                if (log.isTraceEnabled())
                        log.trace("System authenticated");
@@ -112,5 +116,4 @@ public abstract class AbstractSystemExecution {
        public void setSystemAuthenticationKey(String systemAuthenticationKey) {
                this.systemAuthenticationKey = systemAuthenticationKey;
        }
-
 }