Index: topia2/src/java/org/codelutin/topia/security/entities/TopiaPermissionManager.java diff -u /dev/null topia2/src/java/org/codelutin/topia/security/entities/TopiaPermissionManager.java:1.1 --- /dev/null Fri Feb 24 00:48:20 2006 +++ topia2/src/java/org/codelutin/topia/security/entities/TopiaPermissionManager.java Fri Feb 24 00:48:15 2006 @@ -0,0 +1,64 @@ +/* *##% +* 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. +*##%*/ + +/* * +* TopiaPermissionManager.java +* +* Created: 13 févr. 2006 +* +* @author Arnaud Thimel +* @version $Revision$ +* +* Mise a jour: $Date$ +* par : $Author$ +*/ + +package org.codelutin.topia.security.entities; + +import java.security.Principal; +import java.util.Collection; +import java.util.Set; + +import org.codelutin.topia.TopiaException; + +public interface TopiaPermissionManager { + + /** + * Renvoie toutes les permissions de l'application + * @return une Collection de TopiaPermisssion + */ + public Collection getAllPermissions() throws TopiaException; + + /** + * Créé une nouvelle permission avec les paramètres indiqués + */ + public TopiaPermission create(String id, int actions, Set principals) throws TopiaException; + + /** + * Créé une nouvelle permission avec les paramètres indiqués + */ + public void update(TopiaPermission perm) throws TopiaException; + + /** + * Créé une nouvelle permission avec les paramètres indiqués + */ + public void delete(TopiaPermission perm) throws TopiaException; + +} Index: topia2/src/java/org/codelutin/topia/security/entities/TopiaEntityPermissionImpl.java diff -u /dev/null topia2/src/java/org/codelutin/topia/security/entities/TopiaEntityPermissionImpl.java:1.1 --- /dev/null Fri Feb 24 00:48:20 2006 +++ topia2/src/java/org/codelutin/topia/security/entities/TopiaEntityPermissionImpl.java Fri Feb 24 00:48:15 2006 @@ -0,0 +1,450 @@ +/* *##% + * 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. + *##%*/ + +/* * + * TopiaPermission.java + * + * Created: 13 févr. 2006 + * + * @author Arnaud Thimel + * @version $Revision$ + * + * Mise a jour: $Date$ + * par : $Author$ + */ + +package org.codelutin.topia.security.entities; + +import static org.codelutin.topia.security.TopiaSecurityUtil.CREATE; +import static org.codelutin.topia.security.TopiaSecurityUtil.CREATE_TEXT; +import static org.codelutin.topia.security.TopiaSecurityUtil.DELETE; +import static org.codelutin.topia.security.TopiaSecurityUtil.DELETE_TEXT; +import static org.codelutin.topia.security.TopiaSecurityUtil.LOAD; +import static org.codelutin.topia.security.TopiaSecurityUtil.LOAD_TEXT; +import static org.codelutin.topia.security.TopiaSecurityUtil.UPDATE; +import static org.codelutin.topia.security.TopiaSecurityUtil.UPDATE_TEXT; + +import java.security.Principal; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.StringTokenizer; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.codelutin.topia.persistence.TopiaEntityAbstract; + +public class TopiaEntityPermissionImpl extends TopiaEntityAbstract + implements TopiaEntityPermission { + + /** to use log facility, just put in your code: log.info("..."); */ + static private Log log = LogFactory.getLog(TopiaEntityPermissionImpl.class); + + protected String id = null; + + protected String principalsAsString = null; + + protected Map> principals = null; + + /** les actions autorisees pour cette permission */ + protected int actions = 0x0; + + /** Représente l'attribut actions sous forme de chaine */ + protected String actionsAsString = null; + + /* (non-Javadoc) + * @see org.codelutin.topia.framework.security.TopiaEntityPermission#getId() + */ + public String getId() { + return id; + } + + /** + * Pour chaque entrée de cette map, la clé est un nom de classe + * qui implémente l'interface Principal, la valeur est un Set qui + * contient tous les noms sur les quels porte cette permission. + * + * @return Map + */ + public Map> getPrincipals() { + return principals; + } + + /** + * Transforme actionsAsString en un entier. + * + * @param actionsAsString - + * combinaison de mots cles "load" "update" "create" et "delete" + * separes par des virgules. Ex : "load,update" + * @return 0 si aucune permission. Une combinaison des permissions + */ + protected static int actionsAsStringToInt(String actionsAsString) { + int result = 0x0; + StringTokenizer tokens = new StringTokenizer(actionsAsString, ","); + while (tokens.hasMoreTokens()) { + String action = tokens.nextToken().trim(); + if (LOAD_TEXT.equalsIgnoreCase(action)) { + result |= LOAD; + } else if (CREATE_TEXT.equalsIgnoreCase(action)) { + result |= CREATE; + } else if (UPDATE_TEXT.equalsIgnoreCase(action)) { + result |= UPDATE; + } else if (DELETE_TEXT.equalsIgnoreCase(action)) { + result |= DELETE; + } else { + throw new IllegalArgumentException("action not supported: " + + action); + } + } + return result; + } + + /* Constructeurs */ + + public TopiaEntityPermissionImpl() { + principals = new HashMap>(); + } + + /** + * Permet de construire une Permission avec un id, un set de principals et + * des actions + * + * @param id + * l'id de l'objet cible + * @param principals + * la liste des principals disponible dans le subject + * @param actionsAsString + * les actions possibles sur l'objet sous forme de chaine. Voir + * actionsAsStringToInt. + * @see #actionsAsStringToInt(String) + */ + public TopiaEntityPermissionImpl(String id, Set principals, + String actionsAsString) { + this(id, principals, actionsAsStringToInt(actionsAsString)); + } + + /** + * Permet de construire une Permission avec un id, un set de principals et + * des actions + * + * @param id + * l'id de l'objet cible + * @param principals + * la liste des principals disponible dans le subject + * @param actions + * les actions possibles sur l'objet + */ + public TopiaEntityPermissionImpl(String id, Set principals, + int actions) { + init(id, principals, actions); + } + + public void init(String id, Set principals, + int actions) { + this.id = id; + this.actions = actions; + this.principals = new HashMap>(); + for (Principal p : principals) { + addPrincipal(p.getClass().getName(), p.getName()); + } + } + + /** + * Permet de construire une Permission. L'id et les principaux sont lu + * depuis la chaine 's' (voir init). Les actions autorises sont LOAD. + * + * @param s + * l'id, suivi de n fois (la classe du principal suivi du nom du + * principal). Voir {@link #init}. + * @see #init(String, int) + */ + public TopiaEntityPermissionImpl(String s) { + this(s, LOAD_TEXT); + } + + /** + * Permet de construire une Permission. L'id et les principaux sont lu + * depuis la chaine 's' (voir init). + * + * @param s + * la liste des principals disponible dans le subject + * @param actionsAsString + * les actions possibles sur l'objet, sous forme de chaine. Voir + * actionsAsStringToInt. + * @see #actionsAsStringToInt(String) + */ + public TopiaEntityPermissionImpl(String s, String actionsAsString) { + this(s, actionsAsStringToInt(actionsAsString)); + } + + /** + * Permet de construire une Permission. L'id et les principaux sont lu + * depuis la chaine 's' (voir init). + * + * @param s + * la liste des principals disponible dans le subject + * @param actionsAsInt + * les actions possibles sur l'objet, sous forme d'entier + * (combinaison de TopiaPermission.LOAD CREATE UPDATE et DELETE). + * @see #init(String, int) + */ + public TopiaEntityPermissionImpl(String s, int actionsAsInt) { + init(s, actionsAsInt); + } + + /** + * Parse la chaine s pour en deduire l'id ainsi que le nom de la classe + * principal et le nom du principal. Le nom de la classe principal et le nom + * du principal peuvent etre repete n fois. Appelle + * {@link #addPrincipal(String, String)} pour ajouter chaque principal. + * + * @param s + * format : id espace (principalClass espace principalName)* + * @param actionsAsInt + * action1,action2 ... + */ + protected void init(String s, int actionsAsInt) { + // log.info(this.getClass().getName()+" name="+name+" + // actions="+actionsAsInt); + + actions = actionsAsInt; + s = s.replaceAll(" +", " ");// Un seul espace quand il y en a plusieurs + StringTokenizer tok = new StringTokenizer(s, " ", false); + if (tok.hasMoreTokens()) { + id = tok.nextToken(); + // log.info("id="+id); + } + + principals = new HashMap>(); + // Ajout de la possibilité d'écrire "Principal [abc,def, ghi]" faite !!! + boolean inBrackets = false; + String principalClass = null; + while (tok.hasMoreTokens()) { + if (!inBrackets) + principalClass = tok.nextToken(); + String principalName = null; + if (tok.hasMoreTokens()) { + principalName = tok.nextToken(); + } else { + throw new IllegalArgumentException( + "Principal must be followed by name"); + } + if (principalName.startsWith("[")) { + inBrackets = true; + principalName = principalName.substring(1); + } + if (!inBrackets) { + addPrincipal(principalClass, principalName); + } else { + if (principalName.endsWith("]")) { + inBrackets = false; + principalName = principalName.substring(0, principalName + .length() - 1); + } + if (principalName.trim().equals("")) + continue; + StringTokenizer sTK = new StringTokenizer(principalName, ","); + while (sTK.hasMoreTokens()) { + principalName = sTK.nextToken().trim(); + addPrincipal(principalClass, principalName); + } + } + } + } + + /** + * principals est une Map. A chaque clé (principalClass) est associé une + * HashSet contenant la liste des principalName. Si la clé n'existe pas, + * elle est créée. + * + * @param principalClass + * Le nom de la sous-classe de Principal + * @param principalName + * Le nom a associe a principalClass + */ + protected void addPrincipal(String principalClass, String principalName) { + Set names = principals.get(principalClass); + if (names == null) { + principals.put(principalClass, names = new HashSet()); + } + if (principalName.trim().startsWith("[") && principalName.endsWith("]")) + principalName = principalName.substring(1, principalName + .lastIndexOf("]")); + names.add(principalName); + // log.info("principal added : "+principalClass+" "+principalName); + } + + /* (non-Javadoc) + * @see org.codelutin.topia.framework.security.TopiaEntityPermission#getActions() + */ + public String getActionsAsString() { + StringBuffer result = new StringBuffer(); + if (actionsAsString == null) { + if ((actions & LOAD) == LOAD) { + result.append(LOAD_TEXT); + result.append(","); + } + if ((actions & CREATE) == CREATE) { + result.append(CREATE_TEXT); + result.append(","); + } + if ((actions & UPDATE) == UPDATE) { + result.append(UPDATE_TEXT); + result.append(","); + } + if ((actions & DELETE) == DELETE) { + result.append(DELETE_TEXT); + result.append(","); + } + if (result.length() > 0) { + actionsAsString = result.substring(0, result.length() - 1); + } else { + actionsAsString = ""; + } + } + return actionsAsString; + } + + /** @return le hashCode de l'id */ + public int hashCode() { +// return id.hashCode(); + return super.hashCode(); + } + + /* (non-Javadoc) + * @see org.codelutin.topia.framework.security.TopiaEntityPermission# + * implies(org.codelutin.topia.framework.security.TopiaEntityPermissionImpl) + */ + public boolean implies(TopiaEntityPermission other) { + if (!impliesId(getId(), other.getId())) + return false; + if (!impliesActions(actions, other.getActions())) + return false; + return impliesPrincipal(this.principals, other.getPrincipals()); + } + + /** + * @param thisId + * un id + * @param thatId + * un autre Id + * @return vrai si les ids sont egaux + */ + private boolean impliesId(String thisId, String thatId) { + return (thisId.equals(thatId) || + "*".equals(thisId) || + (thatId.startsWith(thisId.substring(0, thisId.length()-1)) + && thisId.endsWith("#*"))); + } + + /** + * @param thisActions + * @param thatActions + * @return vrai si thisActions implique thatActions. C'est à dire que pour + * chaque action de that, this la contient également + */ + private boolean impliesActions(int thisActions, int thatActions) { + boolean result = true; + if ((thatActions & LOAD) == LOAD) { + result &= ((thisActions & LOAD) == LOAD); + } + if ((thatActions & CREATE) == CREATE) { + result &= ((thisActions & CREATE) == CREATE); + } + if ((thatActions & UPDATE) == UPDATE) { + result &= ((thisActions & UPDATE) == UPDATE); + } + if ((thatActions & DELETE) == DELETE) { + result &= ((thisActions & DELETE) == DELETE); + } + return result; + } + + /** + * @param thisPrincipals + * @param thatPrincipals + * @return vrai si thisPrincipals implique thatPrincipals. + */ + private boolean impliesPrincipal(Map> thisPrincipals, + Map> thatPrincipals) { + // this should never happen + if (thisPrincipals == null || thatPrincipals == null) + return false; + + if (thisPrincipals.size() == 0 || thatPrincipals.size() == 0) { + return true; + } + + boolean result = true; + for (String thisPrincipalClass : thisPrincipals.keySet()) { + if ("*".equals(thisPrincipalClass)) { + continue; + } + + Set thisPrincipalNames = thisPrincipals + .get(thisPrincipalClass); + Set thatPrincipalNames = thatPrincipals + .get(thisPrincipalClass); + + if (thatPrincipalNames != null // that contient bien le principal + // nécessaire ! + && (thisPrincipalNames.contains("*") || thatPrincipalNames + .containsAll(thisPrincipalNames))) { + // (this contient une étoile (accepte tous)) ou (that contient + // tout ce que contient this) + continue; + } + + result = false; + } + return result; + } + + /** + * Returns a string that displays and identifies this object's properties + * + * @return a String representation of this object + */ + public String toString() { + return "(TopiaEntityPermission" + " id=\"" + + id + "\" principals=" + principals + " actions=\"" + + getActionsAsString() + "\")"; + } + + public String principalsToString() { + String output = ""; + for (String className : principals.keySet()) { + output += className + " " + principals.get(className) + " "; + } + return output; + } + + public int getActions() { + return actions; + } + + public void setId(String id) { + if (this.id == null) { + this.id = id; + } + } + +} // TopiaEntityPermission Index: topia2/src/java/org/codelutin/topia/security/entities/TopiaUser.java diff -u /dev/null topia2/src/java/org/codelutin/topia/security/entities/TopiaUser.java:1.1 --- /dev/null Fri Feb 24 00:48:20 2006 +++ topia2/src/java/org/codelutin/topia/security/entities/TopiaUser.java Fri Feb 24 00:48:15 2006 @@ -0,0 +1,72 @@ +/* *##% + * 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. + *##%*/ + +/* * + * TopiaUser.java + * + * Created: 10 févr. 2006 + * + * @author Arnaud Thimel + * @version $Revision$ + * + * Mise a jour: $Date$ + * par : $Author$ + */ + +package org.codelutin.topia.security.entities; + +import org.codelutin.topia.persistence.TopiaEntity; + +public interface TopiaUser extends TopiaEntity { + + /** + * Retourne l'email + */ + public String getEmail(); + + /** + * Change l'email + */ + public void setEmail(String email); + + /** + * Retourne le login + */ + public String getLogin(); + + /** + * Change le login + */ + public void setLogin(String login); + + /** + * Modifie le mot de passe si l'ancien spécifié est correct. + * @param oldPassword Le mot de passe actuel + * @param newPassword Le nouveau mot de passe + */ + public void setPassword(String oldPassword, String newPassword); + + /** + * Indique si le mot de passe en paramètre est correct + * @param password le mot de passe à tester + */ + public boolean isCorrectPassord(String password); + +} \ No newline at end of file Index: topia2/src/java/org/codelutin/topia/security/entities/TopiaPermission.java diff -u /dev/null topia2/src/java/org/codelutin/topia/security/entities/TopiaPermission.java:1.1 --- /dev/null Fri Feb 24 00:48:20 2006 +++ topia2/src/java/org/codelutin/topia/security/entities/TopiaPermission.java Fri Feb 24 00:48:15 2006 @@ -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. +*##%*/ + +/* * +* TopiaPermission.java +* +* Created: 16 févr. 2006 +* +* @author Arnaud Thimel +* @version $Revision$ +* +* Mise a jour: $Date$ +* par : $Author$ +*/ + + +package org.codelutin.topia.security.entities; + +import java.security.Permission; + + +public class TopiaPermission extends Permission { + + private TopiaEntityPermission entityPermission; + + public TopiaPermission(TopiaEntityPermission entityPermission) { + super(entityPermission.getId()); + this.entityPermission = entityPermission; + } + + @Override + public boolean implies(Permission permission) { + if (permission == null) + return false; + if (!(permission instanceof TopiaPermission)) + return false; + TopiaPermission other = (TopiaPermission)permission; + return entityPermission.implies(other.getEntityPermission()); + } + + @Override + public boolean equals(Object obj) { + if (obj == null) + return false; + if (obj == this) + return true; + if (!(obj instanceof TopiaPermission)) + return false; + TopiaPermission that = (TopiaPermission)obj; + return (this.implies(that) && that.implies(this)); + } + + @Override + public int hashCode() { + return entityPermission.hashCode(); + } + + @Override + public String getActions() { + return entityPermission.getActionsAsString(); + } + + public TopiaEntityPermission getEntityPermission() { + return entityPermission; + } +} Index: topia2/src/java/org/codelutin/topia/security/entities/TopiaEntityPermission.java diff -u /dev/null topia2/src/java/org/codelutin/topia/security/entities/TopiaEntityPermission.java:1.1 --- /dev/null Fri Feb 24 00:48:20 2006 +++ topia2/src/java/org/codelutin/topia/security/entities/TopiaEntityPermission.java Fri Feb 24 00:48:15 2006 @@ -0,0 +1,72 @@ +/* *##% + * 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. + *##%*/ + +/* * + * TopiaEntityPermission.java + * + * Created: 20 févr. 2006 + * + * @author Arnaud Thimel + * @version $Revision$ + * + * Mise a jour: $Date$ + * par : $Author$ + */ + +package org.codelutin.topia.security.entities; + +import java.util.Map; +import java.util.Set; + +import org.codelutin.topia.persistence.TopiaEntity; + +public interface TopiaEntityPermission extends TopiaEntity { + + /** + * identifiant de l'objet sur le quel porte cette permission. + * + * @return String + */ + public String getId(); + + /** + * @return une chaine représentant le contenu de la variable d'instance + * actions sous forme de chaine. + */ + public String getActionsAsString(); + + /** + * @return la variable actions représentant les actions possibles avec cette + * permission + */ + public int getActions(); + + /** + * @param p + * une permission + * @return Vrai si la permission p est incluse dans this + */ + public boolean implies(TopiaEntityPermission other); + + public Map> getPrincipals(); + + public void setId(String id); + +} //TopiaEntityPermission \ No newline at end of file Index: topia2/src/java/org/codelutin/topia/security/entities/TopiaUserManager.java diff -u /dev/null topia2/src/java/org/codelutin/topia/security/entities/TopiaUserManager.java:1.1 --- /dev/null Fri Feb 24 00:48:20 2006 +++ topia2/src/java/org/codelutin/topia/security/entities/TopiaUserManager.java Fri Feb 24 00:48:15 2006 @@ -0,0 +1,98 @@ +/* *##% +* 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. +*##%*/ + +/* * +* UserManager.java +* +* Created: 10 févr. 2006 +* +* @author Arnaud Thimel +* @version $Revision$ +* +* Mise a jour: $Date$ +* par : $Author$ +*/ + +package org.codelutin.topia.security.entities; + +import java.security.Principal; +import java.util.List; +import java.util.Set; + +import org.codelutin.topia.TopiaException; + +/** + * Interface des gestionnaires d'utilisateurs pour ToPIA. + */ +public interface TopiaUserManager { + + /** + * Créé un nouvel utilisateur + * @param login l'identifiant de l'utilisateur + * @param email son email + * @param password le mot de passe de l'utilisateur + */ + public TopiaUser create(String login, String email, String password) throws TopiaException; + + /** + * Mets à jour l'utilisateur spécifié + * @param login l'identifiant de l'utilisateur + * @param email son email + * @param password le mot de passe de l'utilisateur + */ + public void update(TopiaUser user) throws TopiaException; + + /** + * Supprime un utilisateur + * @param login l'identifiant de l'utilisateur + */ + public void delete(TopiaUser user) throws TopiaException; + + /** + * Vérifie la validité du mot de passe de l'utilisateur + * @param login l'identifiant de l'utilisateur + * @param password le mot de passe de l'utilisateur + */ + public boolean checkPassword(TopiaUser user, String password) throws TopiaException; + + /** + * Cherche et renvoie le TopiaUser dont le login correspond à celui passé en + * paramètres + * @param login le login à chercher + */ + public TopiaUser findUserByLogin(String login) throws TopiaException; + + /** + * Renvoie la liste des TopiaUser dont l'email correspond au paramètre. + * @param email l'email à chercher + */ + public List findUserByEmail(String email) throws TopiaException; + + /** + * Effectue une tentative d'authentification à partir du couple login pass + * spécifié + * @param login le login à tester + * @param password le mot de passe à tester + * @return l'ensemble des Principal de l'utilisateur + * @throws TopiaException Dans les cas où l'authentification a échoué + */ + public Set authenticate(String login, String password) throws TopiaException; + +} //TopiaUserManager Index: topia2/src/java/org/codelutin/topia/security/entities/TopiaUser.hbm.xml diff -u /dev/null topia2/src/java/org/codelutin/topia/security/entities/TopiaUser.hbm.xml:1.1 --- /dev/null Fri Feb 24 00:48:20 2006 +++ topia2/src/java/org/codelutin/topia/security/entities/TopiaUser.hbm.xml Fri Feb 24 00:48:15 2006 @@ -0,0 +1,15 @@ + + + + + + + + + + + + + Index: topia2/src/java/org/codelutin/topia/security/entities/TopiaUserImpl.java diff -u /dev/null topia2/src/java/org/codelutin/topia/security/entities/TopiaUserImpl.java:1.1 --- /dev/null Fri Feb 24 00:48:20 2006 +++ topia2/src/java/org/codelutin/topia/security/entities/TopiaUserImpl.java Fri Feb 24 00:48:15 2006 @@ -0,0 +1,108 @@ +/* *##% +* 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. +*##%*/ + +/* * +* TopiaUserAbstract.java +* +* Created: 10 févr. 2006 +* +* @author Arnaud Thimel +* @version $Revision$ +* +* Mise a jour: $Date$ +* par : $Author$ +*/ + + +/** + * + */ +package org.codelutin.topia.security.entities; + +import org.codelutin.topia.persistence.TopiaEntityAbstract; + +import static org.codelutin.topia.security.TopiaSecurityUtil.hash; + +/** + * Représente un utilisateur ToPIA + */ +public class TopiaUserImpl extends TopiaEntityAbstract implements TopiaUser { + + private String login; + private String email; + private String password; + + /* (non-Javadoc) + * @see org.codelutin.topia.framework.security.TopiaUser#getEmail() + */ + public String getEmail() { + return email; + } + + /* (non-Javadoc) + * @see org.codelutin.topia.framework.security.TopiaUser#setEmail(java.lang.String) + */ + public void setEmail(String email) { + this.email = email; + } + + /* (non-Javadoc) + * @see org.codelutin.topia.framework.security.TopiaUser#getLogin() + */ + public String getLogin() { + return login; + } + + /* (non-Javadoc) + * @see org.codelutin.topia.framework.security.TopiaUser#setLogin(java.lang.String) + */ + public void setLogin(String login) { + this.login = login; + } + + /* (non-Javadoc) + * @see org.codelutin.topia.framework.security.TopiaUser#setPassword(java.lang.String, java.lang.String) + */ + public void setPassword(String oldPassword, String newPassword) { + if (!isCorrectPassord(oldPassword)) { + return; + } + password = hash(newPassword); + } + + /* (non-Javadoc) + * @see org.codelutin.topia.framework.security.TopiaUser#isCorrectPassord(java.lang.String) + */ + public boolean isCorrectPassord(String password) { + if (this.password == null) { + if (password != null) { + return false; + } + } else if (!this.password.equals(hash(password))) { + return false; + } + return true; + } + + public String toString() { + return "User[login:\"" + login + "\",email:\"" + email + "\",password:\""+password + "\"]"; + } + +} //TopiaUserAbstract Index: topia2/src/java/org/codelutin/topia/security/entities/TopiaEntityPermission.hbm.xml diff -u /dev/null topia2/src/java/org/codelutin/topia/security/entities/TopiaEntityPermission.hbm.xml:1.1 --- /dev/null Fri Feb 24 00:48:20 2006 +++ topia2/src/java/org/codelutin/topia/security/entities/TopiaEntityPermission.hbm.xml Fri Feb 24 00:48:15 2006 @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + Index: topia2/src/java/org/codelutin/topia/security/entities/TopiaPrincipal.java diff -u /dev/null topia2/src/java/org/codelutin/topia/security/entities/TopiaPrincipal.java:1.1 --- /dev/null Fri Feb 24 00:48:20 2006 +++ topia2/src/java/org/codelutin/topia/security/entities/TopiaPrincipal.java Fri Feb 24 00:48:15 2006 @@ -0,0 +1,71 @@ +/* *##% +* 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. +*##%*/ + +/* * +* TopiaPrincipal.java +* +* Created: 15 févr. 2006 +* +* @author Arnaud Thimel +* @version $Revision$ +* +* Mise a jour: $Date$ +* par : $Author$ +*/ + +package org.codelutin.topia.security.entities; + +import java.security.Principal; + +public class TopiaPrincipal implements Principal { + + protected String name; + + public TopiaPrincipal(String name) { + this.name = name; + } + + /* (non-Javadoc) + * @see java.security.Principal#getName() + */ + public String getName() { + return name; + } + + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + public String toString() { + return this.getClass().getName() + " : " + name; + } + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + public boolean equals(Object o) { + if (!(o instanceof TopiaPrincipal)) + return false; + if (name == null) { + return (((Principal)o).getName() == null); + } + return name.equals(((TopiaPrincipal)o).getName()); + } + +} //TopiaPrincipal