]> git.argeo.org Git - lgpl/argeo-commons.git/blobdiff - security/plugins/org.argeo.security.equinox/src/main/java/org/argeo/security/equinox/SpringLoginModule.java
First working remote node
[lgpl/argeo-commons.git] / security / plugins / org.argeo.security.equinox / src / main / java / org / argeo / security / equinox / SpringLoginModule.java
index 03f5f35ed960d2c8d529337f4c0f8cef7838cb2c..dada3440525caf6c95b3e0172c25c33201223713 100644 (file)
@@ -20,6 +20,8 @@ import org.springframework.security.providers.jaas.SecurityContextLoginModule;
 
 /** Login module which caches one subject per thread. */
 public class SpringLoginModule extends SecurityContextLoginModule {
+       final static String NODE_REPO_URI = "argeo.node.repo.uri";
+
        private final static Log log = LogFactory.getLog(SpringLoginModule.class);
 
        private AuthenticationManager authenticationManager;
@@ -30,6 +32,8 @@ public class SpringLoginModule extends SecurityContextLoginModule {
 
        private Long waitBetweenFailedLoginAttempts = 5 * 1000l;
 
+       private Boolean remote = false;
+
        public SpringLoginModule() {
 
        }
@@ -64,12 +68,16 @@ public class SpringLoginModule extends SecurityContextLoginModule {
                        PasswordCallback passwordCallback = new PasswordCallback(
                                        "Password", false);
 
-                       // NameCallback urlCallback = new NameCallback("Site URL");
+                       NameCallback urlCallback = new NameCallback("Site URL");
 
                        if (callbackHandler == null)
                                throw new LoginException("No call back handler available");
-                       callbackHandler.handle(new Callback[] { nameCallback,
-                                       passwordCallback });
+                       if (remote)
+                               callbackHandler.handle(new Callback[] { nameCallback,
+                                               passwordCallback, urlCallback });
+                       else
+                               callbackHandler.handle(new Callback[] { nameCallback,
+                                               passwordCallback });
 
                        // Set user name and password
                        String username = nameCallback.getName();
@@ -80,12 +88,16 @@ public class SpringLoginModule extends SecurityContextLoginModule {
                        if (passwordCallback.getPassword() != null)
                                password = String.valueOf(passwordCallback.getPassword());
 
-                       // String url = urlCallback.getName();
+                       String url = remote ? urlCallback.getName() : null;
+                       if (remote && (url == null || url.trim().equals("")))
+                               // for convenience, may be removed in the future
+                               url = System.getProperty(NODE_REPO_URI);
+
                        // TODO: set it via system properties
                        String workspace = null;
 
                        SiteAuthenticationToken credentials = new SiteAuthenticationToken(
-                                       username, password, null, workspace);
+                                       username, password, url, workspace);
 
                        Authentication authentication;
                        try {
@@ -135,4 +147,8 @@ public class SpringLoginModule extends SecurityContextLoginModule {
                        AuthenticationManager authenticationManager) {
                this.authenticationManager = authenticationManager;
        }
+
+       public void setRemote(Boolean remote) {
+               this.remote = remote;
+       }
 }