diff options
4 files changed, 197 insertions, 79 deletions
diff --git a/branches/sca-java-1.5.1/modules/policy-security-http/src/main/java/org/apache/tuscany/sca/policy/security/http/LDAPRealmAuthenticationCallbackHandler.java b/branches/sca-java-1.5.1/modules/policy-security-http/src/main/java/org/apache/tuscany/sca/policy/security/http/LDAPRealmAuthenticationCallbackHandler.java index 00453a213b..ee094f022d 100644 --- a/branches/sca-java-1.5.1/modules/policy-security-http/src/main/java/org/apache/tuscany/sca/policy/security/http/LDAPRealmAuthenticationCallbackHandler.java +++ b/branches/sca-java-1.5.1/modules/policy-security-http/src/main/java/org/apache/tuscany/sca/policy/security/http/LDAPRealmAuthenticationCallbackHandler.java @@ -46,10 +46,11 @@ public class LDAPRealmAuthenticationCallbackHandler implements CallbackHandler { BasicAuthenticationPrincipal principal = SecurityUtil.getPrincipal(subject, BasicAuthenticationPrincipal.class); if (principal != null){ + /* System.out.println(">>> LDAPRealmAuthenticationCallbackHandler" + " Username: " + principal.getName() + " Password: " + principal.getPassword()); - + */ for (int i = 0; i < callbacks.length; i++) { if (callbacks[i] instanceof NameCallback) { NameCallback nc = (NameCallback)callbacks[i]; diff --git a/branches/sca-java-1.5.1/modules/policy-security-http/src/main/java/org/apache/tuscany/sca/policy/security/http/LDAPRealmAuthenticationImplementationPolicyProvider.java b/branches/sca-java-1.5.1/modules/policy-security-http/src/main/java/org/apache/tuscany/sca/policy/security/http/LDAPRealmAuthenticationImplementationPolicyProvider.java index 88f153c064..dd454f21c7 100644 --- a/branches/sca-java-1.5.1/modules/policy-security-http/src/main/java/org/apache/tuscany/sca/policy/security/http/LDAPRealmAuthenticationImplementationPolicyProvider.java +++ b/branches/sca-java-1.5.1/modules/policy-security-http/src/main/java/org/apache/tuscany/sca/policy/security/http/LDAPRealmAuthenticationImplementationPolicyProvider.java @@ -62,63 +62,129 @@ public class LDAPRealmAuthenticationImplementationPolicyProvider implements Poli */ /** - * + * Find applicable authentication 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>(); - 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; } + /** + * 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>(); - 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; } + + /** + * Find a given configured operation + * @param operation + * @return + */ + 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.5.1/modules/policy-security-http/src/main/java/org/apache/tuscany/sca/policy/security/http/LDAPRealmAuthenticationPolicyProviderFactory.java b/branches/sca-java-1.5.1/modules/policy-security-http/src/main/java/org/apache/tuscany/sca/policy/security/http/LDAPRealmAuthenticationPolicyProviderFactory.java index ec6111a3ef..75176bba9b 100644 --- a/branches/sca-java-1.5.1/modules/policy-security-http/src/main/java/org/apache/tuscany/sca/policy/security/http/LDAPRealmAuthenticationPolicyProviderFactory.java +++ b/branches/sca-java-1.5.1/modules/policy-security-http/src/main/java/org/apache/tuscany/sca/policy/security/http/LDAPRealmAuthenticationPolicyProviderFactory.java @@ -22,9 +22,6 @@ package org.apache.tuscany.sca.policy.security.http; import org.apache.tuscany.sca.assembly.Binding; import org.apache.tuscany.sca.assembly.Implementation; import org.apache.tuscany.sca.core.ExtensionPointRegistry; -import org.apache.tuscany.sca.policy.security.jaas.JaasAuthenticationImplementationPolicyProvider; -import org.apache.tuscany.sca.policy.security.jaas.JaasAuthenticationPolicy; -import org.apache.tuscany.sca.policy.security.jaas.JaasAuthenticationServicePolicyProvider; import org.apache.tuscany.sca.provider.PolicyProvider; import org.apache.tuscany.sca.provider.PolicyProviderFactory; import org.apache.tuscany.sca.runtime.RuntimeComponent; diff --git a/branches/sca-java-1.5.1/modules/policy-security-http/src/main/java/org/apache/tuscany/sca/policy/security/http/LDAPRealmAuthenticationServicePolicyProvider.java b/branches/sca-java-1.5.1/modules/policy-security-http/src/main/java/org/apache/tuscany/sca/policy/security/http/LDAPRealmAuthenticationServicePolicyProvider.java index 6189de5a5a..32fce4eb81 100644 --- a/branches/sca-java-1.5.1/modules/policy-security-http/src/main/java/org/apache/tuscany/sca/policy/security/http/LDAPRealmAuthenticationServicePolicyProvider.java +++ b/branches/sca-java-1.5.1/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,85 @@ 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; } - + + /** + * Find a given configured operation + * @param operation + * @return + */ + 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; + } } |