VIVO-761 Clean up some logic, remove some obsolete classes.
This commit is contained in:
parent
78fe1bbb41
commit
20ba75d1d2
11 changed files with 134 additions and 339 deletions
|
@ -8,7 +8,7 @@ import org.apache.commons.logging.Log;
|
|||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.policy.bean.PropertyRestrictionPolicyHelper;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.RequestedAction;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ifaces.RequestedAction;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.publish.PublishDataProperty;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.publish.PublishDataPropertyStatement;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.publish.PublishObjectProperty;
|
||||
|
|
|
@ -116,7 +116,6 @@ public class SimplePermission extends Permission {
|
|||
}
|
||||
|
||||
//private final String localName;
|
||||
private final String uri;
|
||||
public final RequestedAction ACTION;
|
||||
|
||||
public SimplePermission(String uri) {
|
||||
|
@ -126,8 +125,6 @@ public class SimplePermission extends Permission {
|
|||
throw new NullPointerException("uri may not be null.");
|
||||
}
|
||||
|
||||
//this.localName = localName;
|
||||
this.uri = uri;
|
||||
this.ACTION = new SimpleRequestedAction(uri);
|
||||
|
||||
if (allInstances.containsKey(this.uri)) {
|
||||
|
|
|
@ -4,8 +4,6 @@ package edu.cornell.mannlib.vitro.webapp.auth.policy;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
@ -14,8 +12,6 @@ import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle;
|
|||
import edu.cornell.mannlib.vitro.webapp.auth.policy.ifaces.Authorization;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.policy.ifaces.PolicyDecision;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.policy.ifaces.PolicyIface;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.AllRequestedAction;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.AnyRequestedAction;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.RequestedAction;
|
||||
|
||||
/**
|
||||
|
@ -42,66 +38,6 @@ public class PolicyList extends ArrayList<PolicyIface> implements PolicyIface{
|
|||
|
||||
@Override
|
||||
public PolicyDecision isAuthorized(IdentifierBundle whoToAuth, RequestedAction whatToAuth) {
|
||||
|
||||
if( whatToAuth instanceof AllRequestedAction ){
|
||||
return doAllAction( whoToAuth, ((AllRequestedAction)whatToAuth));
|
||||
}else if ( whatToAuth instanceof AnyRequestedAction ){
|
||||
return doAnyAction(whoToAuth, ((AnyRequestedAction)whatToAuth));
|
||||
}else{
|
||||
return checkAgainstPolicys( whoToAuth , whatToAuth);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks that at least one of the subRequestedActions are authorized.
|
||||
*/
|
||||
private PolicyDecision doAnyAction(IdentifierBundle whoToAuth,
|
||||
AnyRequestedAction whatToAuth) {
|
||||
boolean anyAuth = false;
|
||||
List<PolicyDecision> subPd = new LinkedList<PolicyDecision>();
|
||||
for( RequestedAction subAct : whatToAuth.getRequestedActions()){
|
||||
PolicyDecision pd = isAuthorized(whoToAuth,subAct);
|
||||
subPd.add(pd);
|
||||
if( pd.getAuthorized() == Authorization.AUTHORIZED){
|
||||
anyAuth = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if( anyAuth )
|
||||
return new CompositPolicyDecision( Authorization.AUTHORIZED,
|
||||
"Some sub-RequestedAction authorized", subPd);
|
||||
else
|
||||
return new CompositPolicyDecision( Authorization.UNAUTHORIZED,
|
||||
"None of the sub-RequestedAction were authorized", subPd);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks that all the subRequestedActions are authorized.
|
||||
*/
|
||||
private PolicyDecision doAllAction(IdentifierBundle whoToAuth, AllRequestedAction whatToAuth) {
|
||||
boolean allAuth = true;
|
||||
|
||||
List<PolicyDecision> subPd = new LinkedList<PolicyDecision>();
|
||||
for( RequestedAction subAct : whatToAuth.getRequestedActions()){
|
||||
PolicyDecision pd = isAuthorized( whoToAuth, subAct) ;
|
||||
subPd.add( pd );
|
||||
if( pd.getAuthorized() != Authorization.AUTHORIZED ){
|
||||
allAuth = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if( allAuth )
|
||||
return new CompositPolicyDecision(
|
||||
Authorization.AUTHORIZED,
|
||||
"All sub-RequestedActions authorized.", subPd );
|
||||
else
|
||||
return new CompositPolicyDecision(
|
||||
Authorization.UNAUTHORIZED,
|
||||
"Not all sub-RequestedActions authorized.", subPd );
|
||||
}
|
||||
|
||||
protected PolicyDecision checkAgainstPolicys( IdentifierBundle whoToAuth, RequestedAction whatToAuth){
|
||||
PolicyDecision pd = null;
|
||||
PolicyDecisionLogger logger = new PolicyDecisionLogger(whoToAuth, whatToAuth);
|
||||
for(PolicyIface policy : this){
|
||||
|
|
|
@ -1,36 +0,0 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.auth.policy.ifaces;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.policy.BasicPolicyDecision;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.RequestedAction;
|
||||
|
||||
/**
|
||||
* A policy where every type of action is authorized as INCONCLUSIVE by default.
|
||||
*
|
||||
* @author bdc34
|
||||
*/
|
||||
public class DefaultInconclusivePolicy implements PolicyIface {
|
||||
protected static PolicyDecision INCONCLUSIVE_DECISION = new BasicPolicyDecision(
|
||||
Authorization.INCONCLUSIVE,
|
||||
"This is the default decision defined in DefaultInconclusivePolicy");
|
||||
|
||||
@Override
|
||||
public PolicyDecision isAuthorized(IdentifierBundle whoToAuth,
|
||||
RequestedAction whatToAuth) {
|
||||
if (whoToAuth == null)
|
||||
return new BasicPolicyDecision(Authorization.INCONCLUSIVE,
|
||||
"null was passed as whoToAuth");
|
||||
if (whatToAuth == null)
|
||||
return new BasicPolicyDecision(Authorization.INCONCLUSIVE,
|
||||
"null was passed as whatToAuth");
|
||||
return INCONCLUSIVE_DECISION;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.getClass().getSimpleName() + " - " + hashCode();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.auth.policy.ifaces;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.policy.BasicPolicyDecision;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.RequestedAction;
|
||||
|
||||
/**
|
||||
*a policy where every type of action is authorized as UNAUTHORIZED
|
||||
* by default. This can be useful for a unauthenticated session or
|
||||
* as the last policy on a PolicyList to force INCONCLUSIVE decisions
|
||||
* to UNAUTHORIZED.
|
||||
*/
|
||||
public class DefaultUnauthorizedPolicy implements PolicyIface{
|
||||
protected static PolicyDecision UNAUTHORIZED_DECISION = new BasicPolicyDecision(
|
||||
Authorization.UNAUTHORIZED,
|
||||
"This is the default decision defined in DefaultUnauthorizedPolicy");
|
||||
|
||||
public PolicyDecision isAuthorized(IdentifierBundle whoToAuth,
|
||||
RequestedAction whatToAuth) {
|
||||
if (whoToAuth == null)
|
||||
return new BasicPolicyDecision(Authorization.UNAUTHORIZED,
|
||||
"null was passed as whoToAuth");
|
||||
if (whatToAuth == null)
|
||||
return new BasicPolicyDecision(Authorization.UNAUTHORIZED,
|
||||
"null was passed as whatToAuth");
|
||||
return UNAUTHORIZED_DECISION;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DefaultInconclusivePolicy";
|
||||
}
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.auth.requestedAction;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
* This action should be authorized if all of its subActions are authorized.
|
||||
* @author bdc34
|
||||
*/
|
||||
public class AllRequestedAction extends RequestedAction{
|
||||
private final Collection<RequestedAction> subActions ;
|
||||
|
||||
public AllRequestedAction(RequestedAction... actions ){
|
||||
this( Arrays.asList( actions ));
|
||||
}
|
||||
public AllRequestedAction(Collection <RequestedAction> subActions){
|
||||
this.subActions = Collections.unmodifiableCollection( subActions );
|
||||
}
|
||||
|
||||
public Collection<RequestedAction> getRequestedActions(){
|
||||
return subActions;
|
||||
}
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.auth.requestedAction;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
public class AnyRequestedAction extends RequestedAction {
|
||||
private final Collection<RequestedAction> subActions ;
|
||||
|
||||
public AnyRequestedAction(RequestedAction... acts){
|
||||
this( Arrays.asList( acts) );
|
||||
}
|
||||
|
||||
public AnyRequestedAction(Collection<RequestedAction> subActions){
|
||||
this.subActions = Collections.unmodifiableCollection( subActions );
|
||||
}
|
||||
|
||||
public Collection<RequestedAction> getRequestedActions(){
|
||||
return subActions;
|
||||
}
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.auth.requestedAction;
|
||||
|
||||
|
||||
/**
|
||||
* Action that should always be authorized. Mainly for testing.
|
||||
* @author bdc34
|
||||
*/
|
||||
public class AuthorizedAction extends RequestedAction{
|
||||
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.auth.requestedAction;
|
||||
|
||||
|
||||
/**
|
||||
* Action that is always unauthorized. Mainly for testing.
|
||||
* @author bdc34
|
||||
*/
|
||||
public class UnauthorizedAction extends RequestedAction{
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue