]> git.argeo.org Git - lgpl/argeo-commons.git/blobdiff - org.argeo.cms/src/org/argeo/cms/internal/kernel/KernelUtils.java
Introduce aggregating node user admin
[lgpl/argeo-commons.git] / org.argeo.cms / src / org / argeo / cms / internal / kernel / KernelUtils.java
index ba2a352a74dd334f14bd55edc1b22bb0fcfbc95b..0a9e6c53e44a2c24d7b438b526ce15ddda5f8214 100644 (file)
@@ -13,17 +13,18 @@ import javax.servlet.http.HttpServletRequest;
 
 import org.apache.commons.logging.Log;
 import org.argeo.cms.CmsException;
-import org.osgi.framework.BundleContext;
+import org.argeo.cms.KernelHeader;
+import org.argeo.cms.internal.auth.GrantedAuthorityPrincipal;
 import org.springframework.security.authentication.AnonymousAuthenticationToken;
 import org.springframework.security.authentication.AuthenticationManager;
 import org.springframework.security.core.Authentication;
-import org.springframework.security.core.authority.SimpleGrantedAuthority;
 import org.springframework.security.core.context.SecurityContextHolder;
 import org.springframework.security.core.userdetails.User;
 import org.springframework.security.core.userdetails.UserDetails;
 
+/** Package utilities */
 class KernelUtils implements KernelConstants {
-       final static String OSGI_INSTANCE_AREA = "osgi.instance.area";
+       private final static String OSGI_INSTANCE_AREA = "osgi.instance.area";
 
        static Dictionary<String, ?> asDictionary(Properties props) {
                Hashtable<String, Object> hashtable = new Hashtable<String, Object>();
@@ -44,18 +45,31 @@ class KernelUtils implements KernelConstants {
                return asDictionary(props);
        }
 
-       static File getOsgiInstanceDir(BundleContext bundleContext) {
-               return new File(bundleContext.getProperty(OSGI_INSTANCE_AREA)
-                               .substring("file:".length())).getAbsoluteFile();
+       static File getOsgiInstanceDir() {
+               return new File(Activator.getBundleContext()
+                               .getProperty(OSGI_INSTANCE_AREA).substring("file:".length()))
+                               .getAbsoluteFile();
+       }
+
+       static String getFrameworkProp(String key, String def) {
+               String value = Activator.getBundleContext().getProperty(key);
+               if (value == null)
+                       return def;
+               return value;
+       }
+
+       static String getFrameworkProp(String key) {
+               return getFrameworkProp(key, null);
        }
 
        // Security
        static void anonymousLogin(AuthenticationManager authenticationManager) {
                try {
-                       List<SimpleGrantedAuthority> anonAuthorities = Collections
-                                       .singletonList(new SimpleGrantedAuthority(ROLE_ANONYMOUS));
-                       UserDetails anonUser = new User(ANONYMOUS_USER, "", true, true,
-                                       true, true, anonAuthorities);
+                       List<GrantedAuthorityPrincipal> anonAuthorities = Collections
+                                       .singletonList(new GrantedAuthorityPrincipal(
+                                                       KernelHeader.ROLE_ANONYMOUS));
+                       UserDetails anonUser = new User(KernelHeader.USERNAME_ANONYMOUS,
+                                       "", true, true, true, true, anonAuthorities);
                        AnonymousAuthenticationToken anonToken = new AnonymousAuthenticationToken(
                                        DEFAULT_SECURITY_KEY, anonUser, anonAuthorities);
                        Authentication authentication = authenticationManager