Index: topia-service/src/java/org/codelutin/topia/taas/entities/TaasAuthorizationImpl.java diff -u /dev/null topia-service/src/java/org/codelutin/topia/taas/entities/TaasAuthorizationImpl.java:1.1 --- /dev/null Thu Nov 29 16:08:34 2007 +++ topia-service/src/java/org/codelutin/topia/taas/entities/TaasAuthorizationImpl.java Thu Nov 29 16:08:29 2007 @@ -0,0 +1,90 @@ +/* *##% +* 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. +*##%*/ + +package org.codelutin.topia.taas.entities; + +import static org.codelutin.topia.taas.TaasUtil.CREATE; +import static org.codelutin.topia.taas.TaasUtil.LOAD; +import static org.codelutin.topia.taas.TaasUtil.UPDATE; +import static org.codelutin.topia.taas.TaasUtil.DELETE; + +import org.codelutin.topia.taas.TaasAuthorization; +import org.codelutin.topia.taas.TaasAuthorizationAbstract; + +/** + * Classe permettant la comparaison des autorisations. + * @author ruchaud + */ +public class TaasAuthorizationImpl extends TaasAuthorizationAbstract implements + TaasAuthorization { + + public TaasAuthorizationImpl(String expression, int actions) { + this.expression = expression; + this.actions = actions; + } + + /** + * Compare deux autorisations entres elles. + * @param other une autre autorisation + * @return vrai si l'autorisation implique l'autre + */ + public boolean implies(TaasAuthorization other) { + return impliesExpression(getExpression(), other.getExpression()) && + impliesActions(getActions(), other.getActions()); + } + + /** + * Comparare deux identifiants entres eux. + * thisId => thatId = ? + * @param thisExpression un identifiant + * @param thatExpression un autre identifiant + * @return vrai si thisId implique thatId + */ + public boolean impliesExpression(String thisExpression, String thatExpression) { + return (thisExpression.equals(thatExpression) || + "*".equals(thisExpression) || + (thatExpression.startsWith(thisExpression.substring(0, thisExpression.length()-1)) + && thisExpression.endsWith("*"))); + } + + /** + * Compare deux actions entre elles. + * thisActions => thatActions = ? + * @param thisActions une action + * @param thatActions une autre action + * @return vrai si thisActions implique thatActions + */ + public 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; + } + }