Skip to content

Commit

Permalink
Issue #406
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel Stastny committed Dec 13, 2016
1 parent 8d21941 commit b2fd250
Show file tree
Hide file tree
Showing 5 changed files with 182 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*
* Copyright (C) 2016 Pavel Stastny
*
* 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 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 Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package cz.incad.kramerius.security.impl.criteria;

import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

import cz.incad.kramerius.FedoraAccess;
import cz.incad.kramerius.ObjectPidsPath;
import cz.incad.kramerius.security.EvaluatingResult;
import cz.incad.kramerius.security.RightCriterium;
import cz.incad.kramerius.security.RightCriteriumContext;
import cz.incad.kramerius.security.RightCriteriumException;
import cz.incad.kramerius.security.RightCriteriumPriorityHint;
import cz.incad.kramerius.security.SecuredActions;

/**
* @author pavels
*
*/
public class BenevolentModelFilter extends AbstractCriterium implements RightCriterium {

public static final Logger LOGGER = Logger.getLogger(BenevolentModelFilter.class.getName());


/* (non-Javadoc)
* @see cz.incad.kramerius.security.RightCriterium#evalute()
*/
@Override
public EvaluatingResult evalute() throws RightCriteriumException {
return evaluateInternal(getObjects(), getEvaluateContext());
}

/**
* @return
*/
static EvaluatingResult evaluateInternal(Object[] params, RightCriteriumContext ctx) {
try {
FedoraAccess fa = ctx.getFedoraAccess();
ObjectPidsPath[] pathsToRoot = ctx
.getPathsToRoot();
for (ObjectPidsPath pth : pathsToRoot) {
String[] pids = pth.getPathFromLeafToRoot();
for (String pid : pids) {
String modelName = fa.getKrameriusModelName(pid);
if (containsModelName(params,modelName)) return EvaluatingResult.TRUE;
}
}
return EvaluatingResult.NOT_APPLICABLE;
} catch (IOException e) {
LOGGER.log(Level.SEVERE, e.getMessage(), e);
return EvaluatingResult.NOT_APPLICABLE;
}
}

static boolean containsModelName(Object[] objects, String modelName) {
for (Object object : objects) {
if (object.toString().equals(modelName)) return true;
}
return false;
}

/* (non-Javadoc)
* @see cz.incad.kramerius.security.RightCriterium#getApplicableActions()
*/
@Override
public SecuredActions[] getApplicableActions() {
return new SecuredActions[] {
SecuredActions.READ,
SecuredActions.SHOW_CLIENT_PRINT_MENU,
SecuredActions.SHOW_CLIENT_PDF_MENU
};
}

/* (non-Javadoc)
* @see cz.incad.kramerius.security.RightCriterium#getPriorityHint()
*/
@Override
public RightCriteriumPriorityHint getPriorityHint() {
return RightCriteriumPriorityHint.NORMAL;
}

/* (non-Javadoc)
* @see cz.incad.kramerius.security.RightCriterium#isParamsNecessary()
*/
@Override
public boolean isParamsNecessary() {
return true;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright (C) 2016 Pavel Stastny
*
* 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 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 Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package cz.incad.kramerius.security.impl.criteria;

import cz.incad.kramerius.security.EvaluatingResult;
import cz.incad.kramerius.security.RightCriterium;
import cz.incad.kramerius.security.RightCriteriumException;
import cz.incad.kramerius.security.RightCriteriumPriorityHint;
import cz.incad.kramerius.security.SecuredActions;

/**
* @author pavels
*
*/
public class NegativeBenevolentModelFilter extends AbstractCriterium implements RightCriterium {

/* (non-Javadoc)
* @see cz.incad.kramerius.security.RightCriterium#evalute()
*/
@Override
public EvaluatingResult evalute() throws RightCriteriumException {
EvaluatingResult result = BenevolentModelFilter.evaluateInternal(getObjects(), getEvaluateContext());
return result.equals(EvaluatingResult.TRUE) ? EvaluatingResult.NOT_APPLICABLE : EvaluatingResult.TRUE;
}

/* (non-Javadoc)
* @see cz.incad.kramerius.security.RightCriterium#getApplicableActions()
*/
@Override
public SecuredActions[] getApplicableActions() {
return new SecuredActions[] {
SecuredActions.READ,
SecuredActions.SHOW_CLIENT_PRINT_MENU,
SecuredActions.SHOW_CLIENT_PDF_MENU
};
}

/* (non-Javadoc)
* @see cz.incad.kramerius.security.RightCriterium#getPriorityHint()
*/
@Override
public RightCriteriumPriorityHint getPriorityHint() {
return RightCriteriumPriorityHint.NORMAL;
}

/* (non-Javadoc)
* @see cz.incad.kramerius.security.RightCriterium#isParamsNecessary()
*/
@Override
public boolean isParamsNecessary() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ cz.incad.kramerius.security.impl.criteria.StrictIPAddresFilter
cz.incad.kramerius.security.impl.criteria.DefaultIPAddressFilter
cz.incad.kramerius.security.impl.criteria.PolicyFlag
cz.incad.kramerius.security.impl.criteria.DefaultDomainFilter
cz.incad.kramerius.security.impl.criteria.StrictDomainFilter
cz.incad.kramerius.security.impl.criteria.StrictDomainFilter
cz.incad.kramerius.security.impl.criteria.NegativeBenevolentModelFilter
cz.incad.kramerius.security.impl.criteria.BenevolentModelFilter
3 changes: 3 additions & 0 deletions search/src/java/labels.properties
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,9 @@ rights.dialog.editright.title= Change right for action
rights.dialog.showrights.title= Secured action for this object


cz.incad.kramerius.security.impl.criteria.NegativeBenevolentModelFilter=Negative object's model Filter (benevolent)
cz.incad.kramerius.security.impl.criteria.BenevolentModelFilter=Object's model Filter (benevolent)

cz.incad.kramerius.security.impl.criteria.DefaultDomainFilter=Domain Filter (benevolent)
cz.incad.kramerius.security.impl.criteria.StrictDomainFilter=Domain Filter (strict)

Expand Down
3 changes: 3 additions & 0 deletions search/src/java/labels_cs.properties
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,9 @@ rights.dialog.editright.title=Zm\u011Bna pr\u00E1va pro akci
rights.dialog.showrights.title=Pr\u00E1va objektu


cz.incad.kramerius.security.impl.criteria.NegativeBenevolentModelFilter=Filtr modelu - negace (benevolentn\u00ED)
cz.incad.kramerius.security.impl.criteria.BenevolentModelFilter=Filtr modelu (benevolentn\u00ED)

cz.incad.kramerius.security.impl.criteria.DefaultDomainFilter=Dom\u00E9nov\u00FD Filtr (benevolentn\u00ED)
cz.incad.kramerius.security.impl.criteria.StrictDomainFilter=Dom\u00E9nov\u00FD filtr (striktn\u00ED)

Expand Down

0 comments on commit b2fd250

Please sign in to comment.