diff options
author | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2009-07-24 07:45:36 +0000 |
---|---|---|
committer | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2009-07-24 07:45:36 +0000 |
commit | d7899fb9299b55db23ac654aa7d6b6530f190ded (patch) | |
tree | 24cf544bb81059e47599c6c8a5f94b3b91207d31 /branches | |
parent | 99924a5a8d7c02c535aa0dc998a86c4be7b320c2 (diff) |
Adding support for explicitly configuring policySets
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@797356 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'branches')
2 files changed, 176 insertions, 73 deletions
diff --git a/branches/sca-java-1.x/modules/policy-security-http/src/main/java/org/apache/tuscany/sca/policy/security/http/LDAPRealmAuthenticationImplementationPolicyProvider.java b/branches/sca-java-1.x/modules/policy-security-http/src/main/java/org/apache/tuscany/sca/policy/security/http/LDAPRealmAuthenticationImplementationPolicyProvider.java index 88f153c064..ad217d69ff 100644 --- a/branches/sca-java-1.x/modules/policy-security-http/src/main/java/org/apache/tuscany/sca/policy/security/http/LDAPRealmAuthenticationImplementationPolicyProvider.java +++ b/branches/sca-java-1.x/modules/policy-security-http/src/main/java/org/apache/tuscany/sca/policy/security/http/LDAPRealmAuthenticationImplementationPolicyProvider.java @@ -68,57 +68,111 @@ public class LDAPRealmAuthenticationImplementationPolicyProvider implements Poli */ private List<LDAPRealmAuthenticationPolicy> findAuthenticationPolicies(Operation op) { List<LDAPRealmAuthenticationPolicy> polices = new ArrayList<LDAPRealmAuthenticationPolicy>(); - if (implementation instanceof OperationsConfigurator) { - OperationsConfigurator operationsConfigurator = (OperationsConfigurator)implementation; - for (ConfiguredOperation cop : operationsConfigurator.getConfiguredOperations()) { - if (cop != null && cop.getName() != null && cop.getName().equals(op.getName())) { - for (PolicySet ps : cop.getPolicySets()) { - for (Object p : ps.getPolicies()) { - if (LDAPRealmAuthenticationPolicy.class.isInstance(p)) { - polices.add((LDAPRealmAuthenticationPolicy)p); - } - } + + + // check explicity added policies first + ConfiguredOperation configuredOperation = findOperation(op); + if (configuredOperation!= null && configuredOperation.getPolicySets().size() > 0) { + for ( PolicySet ps : configuredOperation.getPolicySets()) { + for (Object p : ps.getPolicies()) { + if (p instanceof LDAPRealmAuthenticationPolicy) { + polices.add((LDAPRealmAuthenticationPolicy)p); } } } } - List<PolicySet> policySets = component.getPolicySets(); - for (PolicySet ps : policySets) { - for (Object p : ps.getPolicies()) { - if (LDAPRealmAuthenticationPolicy.class.isInstance(p)) { - polices.add((LDAPRealmAuthenticationPolicy)p); + // otherwise find applicable policySets + if ( polices.size() == 0) { + + if (implementation instanceof OperationsConfigurator) { + OperationsConfigurator operationsConfigurator = (OperationsConfigurator)implementation; + for (ConfiguredOperation cop : operationsConfigurator.getConfiguredOperations()) { + if (cop != null && cop.getName() != null && cop.getName().equals(op.getName())) { + for (PolicySet ps : cop.getPolicySets()) { + for (Object p : ps.getPolicies()) { + if (LDAPRealmAuthenticationPolicy.class.isInstance(p)) { + polices.add((LDAPRealmAuthenticationPolicy)p); + } + } + } + } } } + + List<PolicySet> policySets = component.getPolicySets(); + for (PolicySet ps : policySets) { + for (Object p : ps.getPolicies()) { + if (LDAPRealmAuthenticationPolicy.class.isInstance(p)) { + polices.add((LDAPRealmAuthenticationPolicy)p); + } + } + } } + return polices; } private List<AuthorizationPolicy> findAuthorizationPolicies(Operation op) { List<AuthorizationPolicy> polices = new ArrayList<AuthorizationPolicy>(); - if (implementation instanceof OperationsConfigurator) { - OperationsConfigurator operationsConfigurator = (OperationsConfigurator)implementation; - for (ConfiguredOperation cop : operationsConfigurator.getConfiguredOperations()) { - if (cop != null && cop.getName() != null && cop.getName().equals(op.getName())) { - for (PolicySet ps : cop.getPolicySets()) { - for (Object p : ps.getPolicies()) { - if (AuthorizationPolicy.class.isInstance(p)) { - polices.add((AuthorizationPolicy)p); - } - } + + + // check explicity added policies first + ConfiguredOperation configuredOperation = findOperation(op); + if (configuredOperation!= null && configuredOperation.getPolicySets().size() > 0) { + for ( PolicySet ps : configuredOperation.getPolicySets()) { + for (Object p : ps.getPolicies()) { + if (p instanceof AuthorizationPolicy) { + polices.add((AuthorizationPolicy)p); } } } } - List<PolicySet> policySets = component.getPolicySets(); - for (PolicySet ps : policySets) { - for (Object p : ps.getPolicies()) { - if (AuthorizationPolicy.class.isInstance(p)) { - polices.add((AuthorizationPolicy)p); + // otherwise find applicable policySets + if ( polices.size() == 0) { + + if (implementation instanceof OperationsConfigurator) { + OperationsConfigurator operationsConfigurator = (OperationsConfigurator)implementation; + for (ConfiguredOperation cop : operationsConfigurator.getConfiguredOperations()) { + if (cop != null && cop.getName() != null && cop.getName().equals(op.getName())) { + for (PolicySet ps : cop.getPolicySets()) { + for (Object p : ps.getPolicies()) { + if (AuthorizationPolicy.class.isInstance(p)) { + polices.add((AuthorizationPolicy)p); + } + } + } + } + } + } + + List<PolicySet> policySets = component.getPolicySets(); + for (PolicySet ps : policySets) { + for (Object p : ps.getPolicies()) { + if (AuthorizationPolicy.class.isInstance(p)) { + polices.add((AuthorizationPolicy)p); + } } } + } + return polices; } + + + private ConfiguredOperation findOperation(Operation operation) { + ConfiguredOperation configuredOperation = null; + + for (ConfiguredOperation cOperation : ((OperationsConfigurator)component).getConfiguredOperations()) { + if(cOperation.getName().equals(operation.getName())) { + configuredOperation = cOperation; + break; + } + } + + return configuredOperation; + } + } diff --git a/branches/sca-java-1.x/modules/policy-security-http/src/main/java/org/apache/tuscany/sca/policy/security/http/LDAPRealmAuthenticationServicePolicyProvider.java b/branches/sca-java-1.x/modules/policy-security-http/src/main/java/org/apache/tuscany/sca/policy/security/http/LDAPRealmAuthenticationServicePolicyProvider.java index 6189de5a5a..69520081b3 100644 --- a/branches/sca-java-1.x/modules/policy-security-http/src/main/java/org/apache/tuscany/sca/policy/security/http/LDAPRealmAuthenticationServicePolicyProvider.java +++ b/branches/sca-java-1.x/modules/policy-security-http/src/main/java/org/apache/tuscany/sca/policy/security/http/LDAPRealmAuthenticationServicePolicyProvider.java @@ -81,45 +81,64 @@ public class LDAPRealmAuthenticationServicePolicyProvider implements PolicyProvi */ /** - * + * Find applicable authorization policySets + * It first check if any explicitly policySet was identified + * Otherwise it look into the list of applicablePolicySets * @param op * @return */ private List<LDAPRealmAuthenticationPolicy> findAuthenticationPolicies(Operation op) { List<LDAPRealmAuthenticationPolicy> polices = new ArrayList<LDAPRealmAuthenticationPolicy>(); - // FIXME: How do we get a list of effective policySets for a given operation? - for(Operation operation : operations) { - if (operation!= null && operation.getName() != null && operation.getName().equals(op.getName())) { - for (PolicySet ps : operation.getPolicySets()) { - for (Object p : ps.getPolicies()) { - if (LDAPRealmAuthenticationPolicy.class.isInstance(p)) { - polices.add((LDAPRealmAuthenticationPolicy)p); - } + + // check explicity added policies first + ConfiguredOperation configuredOperation = findOperation(op); + if (configuredOperation!= null && configuredOperation.getPolicySets().size() > 0) { + for ( PolicySet ps : configuredOperation.getPolicySets()) { + for (Object p : ps.getPolicies()) { + if (p instanceof LDAPRealmAuthenticationPolicy) { + polices.add((LDAPRealmAuthenticationPolicy)p); } } } } - if (service instanceof OperationsConfigurator) { - OperationsConfigurator operationsConfigurator = (OperationsConfigurator)service; - for (ConfiguredOperation cop : operationsConfigurator.getConfiguredOperations()) { - if (cop!= null && cop.getName() != null && cop.getName().equals(op.getName())) { - for (PolicySet ps : cop.getApplicablePolicySets()) { + + // otherwise find applicable policySets + if ( polices.size() == 0) { + // FIXME: How do we get a list of effective policySets for a given operation? + for(Operation operation : operations) { + if (operation!= null && operation.getName() != null && operation.getName().equals(op.getName())) { + for (PolicySet ps : operation.getPolicySets()) { for (Object p : ps.getPolicies()) { - if (LDAPRealmAuthenticationPolicy.class.isInstance(p)) { + if (p instanceof LDAPRealmAuthenticationPolicy) { polices.add((LDAPRealmAuthenticationPolicy)p); } } } } } - } - List<PolicySet> policySets = service.getPolicySets(); - for (PolicySet ps : policySets) { - for (Object p : ps.getPolicies()) { - if (LDAPRealmAuthenticationPolicy.class.isInstance(p)) { - polices.add((LDAPRealmAuthenticationPolicy)p); + if (service instanceof OperationsConfigurator) { + OperationsConfigurator operationsConfigurator = (OperationsConfigurator)service; + for (ConfiguredOperation cop : operationsConfigurator.getConfiguredOperations()) { + if (cop!= null && cop.getName() != null && cop.getName().equals(op.getName())) { + for (PolicySet ps : cop.getApplicablePolicySets()) { + for (Object p : ps.getPolicies()) { + if (p instanceof LDAPRealmAuthenticationPolicy) { + polices.add((LDAPRealmAuthenticationPolicy)p); + } + } + } + } + } + } + + List<PolicySet> policySets = service.getPolicySets(); + for (PolicySet ps : policySets) { + for (Object p : ps.getPolicies()) { + if (p instanceof LDAPRealmAuthenticationPolicy) { + polices.add((LDAPRealmAuthenticationPolicy)p); + } } } } @@ -128,50 +147,80 @@ public class LDAPRealmAuthenticationServicePolicyProvider implements PolicyProvi } /** - * + * Find applicable authorization policySets + * It first check if any explicitly policySet was identified + * Otherwise it look into the list of applicablePolicySets * @param op * @return */ private List<AuthorizationPolicy> findAuthorizationPolicies(Operation op) { List<AuthorizationPolicy> polices = new ArrayList<AuthorizationPolicy>(); - // FIXME: How do we get a list of effective policySets for a given operation? - for(Operation operation : operations) { - if (operation!= null && operation.getName() != null && operation.getName().equals(op.getName())) { - for (PolicySet ps : operation.getPolicySets()) { - for (Object p : ps.getPolicies()) { - if (AuthorizationPolicy.class.isInstance(p)) { - polices.add((AuthorizationPolicy)p); - } + + // check explicity added policies first + ConfiguredOperation configuredOperation = findOperation(op); + if (configuredOperation!= null && configuredOperation.getPolicySets().size() > 0) { + for ( PolicySet ps : configuredOperation.getPolicySets()) { + for (Object p : ps.getPolicies()) { + if (p instanceof AuthorizationPolicy) { + polices.add((AuthorizationPolicy)p); } } } } - - if (service instanceof OperationsConfigurator) { - OperationsConfigurator operationsConfigurator = (OperationsConfigurator)service; - for (ConfiguredOperation cop : operationsConfigurator.getConfiguredOperations()) { - if (cop != null && cop.getName() != null && cop.getName().equals(op.getName())) { - for (PolicySet ps : cop.getApplicablePolicySets()) { + + // otherwise find applicable policySets + if ( polices.size() == 0) { + // FIXME: How do we get a list of effective policySets for a given operation? + for(Operation operation : operations) { + if (operation!= null && operation.getName() != null && operation.getName().equals(op.getName())) { + for (PolicySet ps : operation.getPolicySets()) { for (Object p : ps.getPolicies()) { - if (AuthorizationPolicy.class.isInstance(p)) { + if (p instanceof AuthorizationPolicy) { polices.add((AuthorizationPolicy)p); } } } } } - } - List<PolicySet> policySets = service.getPolicySets(); - for (PolicySet ps : policySets) { - for (Object p : ps.getPolicies()) { - if (AuthorizationPolicy.class.isInstance(p)) { - polices.add((AuthorizationPolicy)p); + if (service instanceof OperationsConfigurator) { + OperationsConfigurator operationsConfigurator = (OperationsConfigurator)service; + for (ConfiguredOperation cop : operationsConfigurator.getConfiguredOperations()) { + if (cop != null && cop.getName() != null && cop.getName().equals(op.getName())) { + for (PolicySet ps : cop.getApplicablePolicySets()) { + for (Object p : ps.getPolicies()) { + if (p instanceof AuthorizationPolicy) { + polices.add((AuthorizationPolicy)p); + } + } + } + } } } + + List<PolicySet> policySets = service.getPolicySets(); + for (PolicySet ps : policySets) { + for (Object p : ps.getPolicies()) { + if (p instanceof AuthorizationPolicy) { + polices.add((AuthorizationPolicy)p); + } + } + } } return polices; } + private ConfiguredOperation findOperation(Operation operation) { + ConfiguredOperation configuredOperation = null; + + for (ConfiguredOperation cOperation : ((OperationsConfigurator)component).getConfiguredOperations()) { + if(cOperation.getName().equals(operation.getName())) { + configuredOperation = cOperation; + break; + } + } + + return configuredOperation; + } } |