]> 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 ad6390d367a13333fc9f459a0199b7cc78bd121e..dada3440525caf6c95b3e0172c25c33201223713 100644 (file)
@@ -7,7 +7,6 @@ import javax.security.auth.callback.Callback;
 import javax.security.auth.callback.CallbackHandler;
 import javax.security.auth.callback.NameCallback;
 import javax.security.auth.callback.PasswordCallback;
-import javax.security.auth.callback.TextOutputCallback;
 import javax.security.auth.login.LoginException;
 
 import org.apache.commons.logging.Log;
@@ -21,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;
@@ -28,8 +29,10 @@ public class SpringLoginModule extends SecurityContextLoginModule {
        private CallbackHandler callbackHandler;
 
        private Subject subject;
-       
-       private Long waitBetweenFailedLoginAttempts = 5*1000l;
+
+       private Long waitBetweenFailedLoginAttempts = 5 * 1000l;
+
+       private Boolean remote = false;
 
        public SpringLoginModule() {
 
@@ -61,18 +64,20 @@ public class SpringLoginModule extends SecurityContextLoginModule {
                                subject.getPublicCredentials().clear();
 
                        // ask for username and password
-                       Callback label = new TextOutputCallback(
-                                       TextOutputCallback.INFORMATION, "Required login");
                        NameCallback nameCallback = new NameCallback("User");
                        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[] { label, 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();
@@ -83,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 {
@@ -138,4 +147,8 @@ public class SpringLoginModule extends SecurityContextLoginModule {
                        AuthenticationManager authenticationManager) {
                this.authenticationManager = authenticationManager;
        }
+
+       public void setRemote(Boolean remote) {
+               this.remote = remote;
+       }
 }