Index: topia/src/java/org/codelutin/topia/security/TopiaLoginModule.java diff -u topia/src/java/org/codelutin/topia/security/TopiaLoginModule.java:1.5 topia/src/java/org/codelutin/topia/security/TopiaLoginModule.java:1.6 --- topia/src/java/org/codelutin/topia/security/TopiaLoginModule.java:1.5 Wed Jul 20 12:49:53 2005 +++ topia/src/java/org/codelutin/topia/security/TopiaLoginModule.java Thu Jul 21 17:10:38 2005 @@ -24,7 +24,7 @@ * Created: 29 avr. 2005 * * @author Arnaud Thimel -* @version $Revision: 1.5 $ +* @version $Revision: 1.6 $ */ package org.codelutin.topia.security; @@ -40,10 +40,7 @@ import javax.security.auth.login.LoginException; import javax.security.auth.spi.LoginModule; import javax.security.auth.Subject; -import org.codelutin.topia.TopiaContext; -import org.codelutin.topia.TopiaContextFactory; -import org.codelutin.topia.TopiaException; -import org.codelutin.topia.TopiaNotFoundException; + /** * LoginModule compatible avec Topia */ @@ -53,7 +50,7 @@ private CallbackHandler callbackHandler; private boolean loginSuccess; private List principals; - private String appContextFile; + private TopiaSecurityHelper securityHelper; /* (non-Javadoc) * @see javax.security.auth.spi.LoginModule#initialize(javax.security.auth.Subject, javax.security.auth.callback.CallbackHandler, java.util.Map, java.util.Map) @@ -63,7 +60,7 @@ this.subject = subject; this.callbackHandler = callbackHandler; this.principals = null; - this.appContextFile = (String)options.get("topia.app.context"); + this.securityHelper = (TopiaSecurityHelper)options.get("topia.app.context"); } /* (non-Javadoc) @@ -73,7 +70,7 @@ if (callbackHandler == null) throw new LoginException("CallbackHandler cannot be null"); - if (appContextFile == null) + if (securityHelper == null) throw new LoginException("\"topia.app.context\" property must be set"); String login, password = null; @@ -98,24 +95,24 @@ } login = nc.getName(); password = new String(pc.getPassword()); - - //Récupération du TopiaContext - TopiaContext context = null; - try { - context = TopiaContextFactory.getContext(appContextFile); - } catch (TopiaException e1) { - e1.printStackTrace(); - } +// +// //Récupération du TopiaContext +// TopiaContext context = null; +// try { +// context = TopiaContextFactory.getContext(securityHelper); +// } catch (TopiaException e1) { +// e1.printStackTrace(); +// } //Véricfication du login/pass et récupération des Principal try { - principals = context.getSecurityHelper().authenticate(login, password); + principals = securityHelper.authenticate(login, password); } catch (TopiaSecurityException e) { System.err.println("Login failed : " + e.getMessage()); return false; - } catch (TopiaNotFoundException e) { - System.err.println("Login failed : " + e.getMessage()); - return false; +// } catch (TopiaNotFoundException e) { +// System.err.println("Login failed : " + e.getMessage()); +// return false; } loginSuccess = true; Index: topia/src/java/org/codelutin/topia/security/TopiaSecurityHelper.java diff -u topia/src/java/org/codelutin/topia/security/TopiaSecurityHelper.java:1.3 topia/src/java/org/codelutin/topia/security/TopiaSecurityHelper.java:1.4 --- topia/src/java/org/codelutin/topia/security/TopiaSecurityHelper.java:1.3 Thu Jul 21 16:51:39 2005 +++ topia/src/java/org/codelutin/topia/security/TopiaSecurityHelper.java Thu Jul 21 17:10:38 2005 @@ -23,10 +23,10 @@ * Created: 15 juillet 2005 17:39:35 CEST * * @author Benjamin POUSSIN - * @version $Revision: 1.3 $ + * @version $Revision: 1.4 $ * - * Last update: $Date: 2005/07/21 16:51:39 $ - * by : $Author: bpoussin $ + * Last update: $Date: 2005/07/21 17:10:38 $ + * by : $Author: thimel $ */ package org.codelutin.topia.security; @@ -45,7 +45,14 @@ import java.util.Properties; import java.util.StringTokenizer; import java.util.Vector; + +import javax.security.auth.callback.CallbackHandler; +import javax.security.auth.login.Configuration; +import javax.security.auth.login.LoginContext; +import javax.security.auth.login.LoginException; + import org.codelutin.topia.TopiaContext; +import org.codelutin.topia.TopiaNotFoundException; import org.codelutin.util.HashMapMultiKey; import org.codelutin.util.ListenerSet; @@ -67,6 +74,17 @@ public TopiaSecurityHelper(TopiaContext context, Properties properties){ this.context = context; this.properties = properties; + initSecurity(); + } + + private void initSecurity() { + String appEntryName = properties.getProperty("topia.auth.loginEntry"); + Configuration conf = new TopiaConfiguration(appEntryName, this); + Configuration.setConfiguration(conf); + TopiaPolicy policy = new TopiaPolicy(); + policy.installPolicy(); + addPermissionListener(policy); + loadPermissions(); } /** @@ -372,5 +390,16 @@ } } -} // TopiaSecurityHelper + public LoginContext login(String login, String password) throws LoginException { + LoginContext ctx = new LoginContext(properties.getProperty("topia.auth.loginEntry"), new TopiaSimpleCallbackHandler(login, password)); + ctx.login(); + return ctx; + } + + public LoginContext login(CallbackHandler callbackHandler) throws LoginException { + LoginContext ctx = new LoginContext(properties.getProperty("topia.auth.loginEntry"), callbackHandler); + ctx.login(); + return ctx; + } +} // TopiaSecurityHelper Index: topia/src/java/org/codelutin/topia/security/TopiaConfiguration.java diff -u topia/src/java/org/codelutin/topia/security/TopiaConfiguration.java:1.1 topia/src/java/org/codelutin/topia/security/TopiaConfiguration.java:1.2 --- topia/src/java/org/codelutin/topia/security/TopiaConfiguration.java:1.1 Fri May 20 17:51:10 2005 +++ topia/src/java/org/codelutin/topia/security/TopiaConfiguration.java Thu Jul 21 17:10:38 2005 @@ -24,7 +24,7 @@ * Created: 10 mai 2005 * * @author Arnaud Thimel - * @version $Revision: 1.1 $ + * @version $Revision: 1.2 $ */ package org.codelutin.topia.security; @@ -52,19 +52,19 @@ * @param name le nom de la configurationEntry * @param contextPropertiesName le nom du fichier de propriétés */ - public TopiaConfiguration(String name, String contextPropertiesName) { + public TopiaConfiguration(String name, TopiaSecurityHelper securityHelper) { super(); appConfEntries = new HashMap(); - addEntry(name, contextPropertiesName); + addEntry(name, securityHelper); } /** * Ajoute une ConfigurationEntry avec le nom de fichier de propriétés * associé * @param name le nom de la configurationEntry - * @param contextPropertiesName le nom du fichier de propriétés + * @param securityHelper le nom du fichier de propriétés */ - private void addEntry(String name, String contextPropertiesName) { + private void addEntry(String name, TopiaSecurityHelper securityHelper) { AppConfigurationEntry[] confEntries = getAppConfigurationEntry(name); if (confEntries != null) { int i = 0; @@ -76,7 +76,7 @@ confEntries = new AppConfigurationEntry[confEntries.length + 1]; for (int j = 0; j < confEntries.length; j++) confEntries[j] = tmpConfEntries[j]; - confEntries[confEntries.length - 1] = createEntry(contextPropertiesName); + confEntries[confEntries.length - 1] = createEntry(securityHelper); } else { if ( /*Mauvais FLAG*/ !AppConfigurationEntry.LoginModuleControlFlag.REQUIRED.equals(confEntries[i].getControlFlag()) @@ -85,37 +85,37 @@ "topia.app.context") /*Propriété mal initialisée*/ || !confEntries[i].getOptions().get("topia.app.context").equals( - contextPropertiesName)) - confEntries[i] = createEntry(contextPropertiesName, + securityHelper)) + confEntries[i] = createEntry(securityHelper, confEntries[i].getOptions()); } } else { confEntries = new AppConfigurationEntry[1]; - confEntries[0] = createEntry(contextPropertiesName); + confEntries[0] = createEntry(securityHelper); } appConfEntries.put(name, confEntries); } /** * Créé une entry avec des options vides - * @param contextPropertiesName le nom du fichier de propriétés + * @param securityHelper le SecurityHelper * @return l'entry créée */ - private AppConfigurationEntry createEntry(String contextPropertiesName) { - return createEntry(contextPropertiesName, null); + private AppConfigurationEntry createEntry(TopiaSecurityHelper securityHelper) { + return createEntry(securityHelper, null); } /** * Créé une entry en rajoutant les options nécessaires à l'attribut options - * @param contextPropertiesName le nom du fichier de propriétés + * @param securityHelper le nom du fichier de propriétés * @param options l'objet contenant les options précédentes * @return l'entry créée */ - private AppConfigurationEntry createEntry(String contextPropertiesName, + private AppConfigurationEntry createEntry(TopiaSecurityHelper securityHelper, Map options) { if (options == null) options = new HashMap(); - options.put("topia.app.context", contextPropertiesName); + options.put("topia.app.context", securityHelper); return new AppConfigurationEntry(TOPIA_LOGIN_MODULE, AppConfigurationEntry.LoginModuleControlFlag.REQUIRED, options); }