Index: topia-service/src/java/org/codelutin/topia/taas/jaas/TaasCallbackHandler.java diff -u /dev/null topia-service/src/java/org/codelutin/topia/taas/jaas/TaasCallbackHandler.java:1.1 --- /dev/null Fri Dec 7 16:24:42 2007 +++ topia-service/src/java/org/codelutin/topia/taas/jaas/TaasCallbackHandler.java Fri Dec 7 16:24:37 2007 @@ -0,0 +1,83 @@ +/* *##% + * 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. + *##%*/ + +/* * + * TopiaCallbackHandler.java + * + * Created: 20 févr. 2006 + * + * @author Arnaud Thimel + * @version $Revision: 1.1 $ + * + * Mise a jour: $Date: 2007-12-07 16:24:37 $ + * par : $Author: ruchaud $ + */ + +package org.codelutin.topia.taas.jaas; + +import java.io.IOException; + +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.UnsupportedCallbackException; + +/** + * Classe permettant l'interfaçage entre l'application et la sécurité. + * @author ruchaud + */ +public class TaasCallbackHandler implements CallbackHandler { + + private String username; + + private String password; + + /** + * Contructeur + * @param username login de l'utilisateur + * @param password mot de passe de l'utilisateur + */ + public TaasCallbackHandler(String username, String password) { + super(); + this.username = username; + this.password = password; + } + + /* + * (non-Javadoc) + * + * @see javax.security.auth.callback.CallbackHandler#handle(javax.security.auth.callback.Callback[]) + */ + public void handle(Callback[] callbacks) throws IOException, + UnsupportedCallbackException { + for (int i = 0; i < callbacks.length; i++) { + if (callbacks[i] instanceof NameCallback) { + NameCallback nc = (NameCallback) callbacks[i]; + nc.setName(username); + } else if (callbacks[i] instanceof PasswordCallback) { + PasswordCallback pc = (PasswordCallback) callbacks[i]; + pc.setPassword(password.toCharArray()); + } else + throw new UnsupportedCallbackException(callbacks[i]); + } + } + +}