Index: topia/src/java/org/codelutin/topia/security/TopiaLoginModule.java diff -u topia/src/java/org/codelutin/topia/security/TopiaLoginModule.java:1.3 topia/src/java/org/codelutin/topia/security/TopiaLoginModule.java:1.4 --- topia/src/java/org/codelutin/topia/security/TopiaLoginModule.java:1.3 Fri May 20 17:51:10 2005 +++ topia/src/java/org/codelutin/topia/security/TopiaLoginModule.java Tue Jul 19 13:15:13 2005 @@ -1,31 +1,31 @@ /* *##% - * Copyright (C) 2002, 2003, 2004, 2005 Code Lutin, - * Cédric Pineau, Benjamin Poussin, - * - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - *##%*/ +* Copyright (C) 2002, 2003, 2004, 2005 Code Lutin, +* Cédric Pineau, Benjamin Poussin, +* +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version 2 +* of the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*##%*/ /* * - * TopiaLoginModule.java - * - * Created: 29 avr. 2005 - * - * @author Arnaud Thimel - * @version $Revision: 1.3 $ - */ +* TopiaLoginModule.java +* +* Created: 29 avr. 2005 +* +* @author Arnaud Thimel +* @version $Revision: 1.4 $ +*/ package org.codelutin.topia.security; @@ -46,106 +46,106 @@ import org.codelutin.topia.TopiaContextFactory; import org.codelutin.topia.TopiaException; /** - * LoginModule compatible avec Topia - */ +* LoginModule compatible avec Topia +*/ public class TopiaLoginModule implements LoginModule { - private Subject subject; - private CallbackHandler callbackHandler; - private boolean loginSuccess; - private List principals; - private String appContextFile; + private Subject subject; + private CallbackHandler callbackHandler; + private boolean loginSuccess; + private List principals; + private String appContextFile; - /* (non-Javadoc) + /* (non-Javadoc) * @see javax.security.auth.spi.LoginModule#initialize(javax.security.auth.Subject, javax.security.auth.callback.CallbackHandler, java.util.Map, java.util.Map) */ - public void initialize(Subject subject, CallbackHandler callbackHandler, - Map sharedState, Map options) { - this.subject = subject; - this.callbackHandler = callbackHandler; - this.principals = null; - this.appContextFile = (String)options.get("topia.app.context"); - } + public void initialize(Subject subject, CallbackHandler callbackHandler, + Map sharedState, Map options) { + this.subject = subject; + this.callbackHandler = callbackHandler; + this.principals = null; + this.appContextFile = (String)options.get("topia.app.context"); + } - /* (non-Javadoc) + /* (non-Javadoc) * @see javax.security.auth.spi.LoginModule#login() */ - public boolean login() throws LoginException { - - if (callbackHandler == null) - throw new LoginException("CallbackHandler cannot be null"); - if (appContextFile == null) - throw new LoginException("\"topia.app.context\" property must be set"); - - String login, password = null; - - loginSuccess = false; - - NameCallback nc = new NameCallback("login"); - PasswordCallback pc = new PasswordCallback("password", false); - - Callback[] callbacks = new Callback[2]; - - callbacks[0] = nc; - callbacks[1] = pc; - - try { - //Récupération du login et mot de passe - callbackHandler.handle(callbacks); - } catch (IOException e2) { - e2.printStackTrace(); - } catch (UnsupportedCallbackException e2) { - e2.printStackTrace(); - } - 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(); - } - - //Véricfication du login/pass et récupération des Principal - try { - principals = context.authenticate(login, password); - } catch (TopiaSecurityException e) { - System.err.println("Login failed : " + e.getMessage()); - return false; - } - - loginSuccess = true; - return true; - } + public boolean login() throws LoginException { - /* (non-Javadoc) + if (callbackHandler == null) + throw new LoginException("CallbackHandler cannot be null"); + if (appContextFile == null) + throw new LoginException("\"topia.app.context\" property must be set"); + + String login, password = null; + + loginSuccess = false; + + NameCallback nc = new NameCallback("login"); + PasswordCallback pc = new PasswordCallback("password", false); + + Callback[] callbacks = new Callback[2]; + + callbacks[0] = nc; + callbacks[1] = pc; + + try { + //Récupération du login et mot de passe + callbackHandler.handle(callbacks); + } catch (IOException e2) { + e2.printStackTrace(); + } catch (UnsupportedCallbackException e2) { + e2.printStackTrace(); + } + 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(); + } + + //Véricfication du login/pass et récupération des Principal + try { + principals = context.authenticate(login, password); + } catch (TopiaSecurityException e) { + System.err.println("Login failed : " + e.getMessage()); + return false; + } + + loginSuccess = true; + return true; + } + + /* (non-Javadoc) * @see javax.security.auth.spi.LoginModule#commit() */ - public boolean commit() throws LoginException { - if (loginSuccess) { - subject.getPrincipals().addAll(principals); - return true; - } - return false; - } + public boolean commit() throws LoginException { + if (loginSuccess) { + subject.getPrincipals().addAll(principals); + return true; + } + return false; + } - /* (non-Javadoc) + /* (non-Javadoc) * @see javax.security.auth.spi.LoginModule#abort() */ - public boolean abort() throws LoginException { - return false; - } + public boolean abort() throws LoginException { + return false; + } - /* (non-Javadoc) + /* (non-Javadoc) * @see javax.security.auth.spi.LoginModule#logout() */ - public boolean logout() throws LoginException { - subject = null; - principals = null; - callbackHandler = null; - return true; - } + public boolean logout() throws LoginException { + subject = null; + principals = null; + callbackHandler = null; + return true; + } }