This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository wikitty. See http://git.nuiton.org/wikitty.git commit 737bb1bea44e78676ab71cea9906f755de5ec84e Author: Benjamin POUSSIN <poussin@codelutin.com> Date: Sun Aug 2 03:22:07 2015 +0200 create new WikittyServiceAuthorisation to return null is user can't read Wikitty --- .../services/WikittyServiceAuthorisation.java | 20 ++++-- .../WikittyServiceAuthorisationReadNullify.java | 72 ++++++++++++++++++++++ 2 files changed, 86 insertions(+), 6 deletions(-) diff --git a/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyServiceAuthorisation.java b/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyServiceAuthorisation.java index f6c5ef9..6292fb8 100644 --- a/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyServiceAuthorisation.java +++ b/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyServiceAuthorisation.java @@ -25,6 +25,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; +import java.util.ListIterator; import java.util.Map; import java.util.Set; import org.apache.commons.collections.CollectionUtils; @@ -191,9 +192,11 @@ public class WikittyServiceAuthorisation extends WikittyServiceDelegator { List<Wikitty> wikitties = getDelegate().restore(securityToken, ids); long start = TimeLog.getTime(); - for (Wikitty wikitty : wikitties) { - if (wikitty != null) { - refuseUnauthorizedRead(securityToken, userId, wikitty); + for (ListIterator<Wikitty> i=wikitties.listIterator(); i.hasNext();) { + Wikitty wikitty = i.next(); + Wikitty filtered = refuseUnauthorizedRead(securityToken, userId, wikitty); + if (filtered != wikitty) { + i.set(filtered); } } timeLog.log(start, "restore"); @@ -368,8 +371,12 @@ public class WikittyServiceAuthorisation extends WikittyServiceDelegator { } } - /** throw an exception if read is not allowed */ - protected void refuseUnauthorizedRead( String securityToken, + /** + * default implementation throw an exception if read is not allowed + * you can create sub class that return null, or other to replace + * unreadable Wikitty. + */ + protected Wikitty refuseUnauthorizedRead( String securityToken, String userId, Wikitty wikitty) { if (wikitty != null) { @@ -382,6 +389,7 @@ public class WikittyServiceAuthorisation extends WikittyServiceDelegator { } } } + return wikitty; } protected boolean canRead(String securityToken, String userId, @@ -610,7 +618,7 @@ public class WikittyServiceAuthorisation extends WikittyServiceDelegator { Wikitty wikitty = getDelegate().restoreVersion(securityToken, wikittyId, version); long start = TimeLog.getTime(); String userId = getUserId(securityToken); - refuseUnauthorizedRead(securityToken, userId, wikitty); + wikitty = refuseUnauthorizedRead(securityToken, userId, wikitty); timeLog.log(start, "restoreVersion"); return wikitty; } diff --git a/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyServiceAuthorisationReadNullify.java b/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyServiceAuthorisationReadNullify.java new file mode 100644 index 0000000..efd2073 --- /dev/null +++ b/wikitty-api/src/main/java/org/nuiton/wikitty/services/WikittyServiceAuthorisationReadNullify.java @@ -0,0 +1,72 @@ +/* + * #%L + * Wikitty :: api + * %% + * Copyright (C) 2009 - 2015 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ +package org.nuiton.wikitty.services; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.config.ApplicationConfig; +import org.nuiton.wikitty.WikittyService; +import org.nuiton.wikitty.entities.Wikitty; + +/** + * Cette classe au lieu de lever une exception si l'utilisateur n'a pas le droit + * de lire un object, le remplace par null. + * + * @author poussin + * @version $Revision$ + * + * Last update: $Date$ + * by : $Author$ + */ +public class WikittyServiceAuthorisationReadNullify extends WikittyServiceAuthorisation { + + /** to use log facility, just put in your code: log.info(\"...\"); */ + final static private Log log = LogFactory.getLog(WikittyServiceAuthorisationReadNullify.class); + + /** + * + * @param config + * @param ws + */ + public WikittyServiceAuthorisationReadNullify(ApplicationConfig config, WikittyService ws) { + super(config, ws); + } + + /** + * default implementation throw an exception if read is not allowed + * you can create sub class that return null, or other to replace + * unreadable Wikitty. + */ + protected Wikitty refuseUnauthorizedRead( String securityToken, + String userId, + Wikitty wikitty) { + if (wikitty != null) { + for (String extensionName : wikitty.getExtensionNames()) { + if ( ! canRead(securityToken, userId, extensionName, wikitty)) { + return null; + } + } + } + return wikitty; + } + +} -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.