diff options
author | slaws <slaws@13f79535-47bb-0310-9956-ffa450edef68> | 2010-02-12 16:25:54 +0000 |
---|---|---|
committer | slaws <slaws@13f79535-47bb-0310-9956-ffa450edef68> | 2010-02-12 16:25:54 +0000 |
commit | 8eb19f847acca5895a37db8abf9ae4570cf9d8a6 (patch) | |
tree | fb3813dcca7f334aa2249a34a4eca6b2a85d714c /sca-java-2.x/trunk/modules | |
parent | f23d76120aa71b7d9cd0c45ad04c4bb01270342a (diff) |
Fix up the basic auth policy provider
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@909490 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk/modules')
3 files changed, 26 insertions, 17 deletions
diff --git a/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/basic/BasicAuthenticationReferencePolicyInterceptor.java b/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/basic/BasicAuthenticationReferencePolicyInterceptor.java index bbbba81fb7..04b46485d8 100644 --- a/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/basic/BasicAuthenticationReferencePolicyInterceptor.java +++ b/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/basic/BasicAuthenticationReferencePolicyInterceptor.java @@ -25,15 +25,14 @@ import javax.security.auth.Subject; import javax.xml.namespace.QName; import org.apache.axis2.client.OperationClient; -import org.apache.axis2.context.MessageContext; import org.apache.axis2.transport.http.HTTPConstants; import org.apache.axis2.transport.http.HttpTransportProperties; import org.apache.axis2.transport.http.HttpTransportProperties.Authenticator; -import org.apache.tuscany.sca.interfacedef.Operation; import org.apache.tuscany.sca.invocation.Invoker; import org.apache.tuscany.sca.invocation.Message; import org.apache.tuscany.sca.invocation.Phase; import org.apache.tuscany.sca.invocation.PhasedInterceptor; +import org.apache.tuscany.sca.policy.PolicyExpression; import org.apache.tuscany.sca.policy.PolicySet; import org.apache.tuscany.sca.policy.authentication.basic.BasicAuthenticationPolicy; import org.apache.tuscany.sca.policy.authentication.basic.BasicAuthenticationPrincipal; @@ -49,24 +48,24 @@ public class BasicAuthenticationReferencePolicyInterceptor implements PhasedInte public static final QName policySetQName = new QName(SCA10_TUSCANY_NS, "wsBasicAuthentication"); private Invoker next; - private Operation operation; private PolicySet policySet = null; private String context; private BasicAuthenticationPolicy policy; - public BasicAuthenticationReferencePolicyInterceptor(String context, Operation operation, PolicySet policySet) { + public BasicAuthenticationReferencePolicyInterceptor(String context, PolicySet policySet) { super(); - this.operation = operation; this.policySet = policySet; this.context = context; init(); } private void init() { + // TODO - how to get the appropriate expression out of the + // policy set. Need WS Policy help here if (policySet != null) { - for (Object policyObject : policySet.getPolicies()){ - if (policyObject instanceof BasicAuthenticationPolicy){ - policy = (BasicAuthenticationPolicy)policyObject; + for (PolicyExpression policyExpression : policySet.getPolicies()){ + if (policyExpression.getPolicy() instanceof BasicAuthenticationPolicy){ + policy = (BasicAuthenticationPolicy)policyExpression.getPolicy(); break; } } @@ -89,10 +88,17 @@ public class BasicAuthenticationReferencePolicyInterceptor implements PhasedInte if ( principal != null ) { username = ((BasicAuthenticationPrincipal)principal).getName(); password = ((BasicAuthenticationPrincipal)principal).getPassword(); - } + } else if (policy != null ){ + username = policy.getUserName(); + password = policy.getPassword(); + + principal = new BasicAuthenticationPrincipal(username, + password); + subject.getPrincipals().add(principal); + } if (username == null || password == null ){ - throw new ServiceRuntimeException("Basic authentication username or password is null"); + throw new ServiceRuntimeException("Basic authentication username and/or password is null"); } HttpTransportProperties.Authenticator authenticator = new HttpTransportProperties.Authenticator(); @@ -118,6 +124,6 @@ public class BasicAuthenticationReferencePolicyInterceptor implements PhasedInte } public String getPhase() { - return Phase.REFERENCE_POLICY; + return Phase.REFERENCE_BINDING_POLICY; } } diff --git a/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/basic/BasicAuthenticationReferencePolicyProvider.java b/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/basic/BasicAuthenticationReferencePolicyProvider.java index d51f2b5562..a59f7e5791 100644 --- a/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/basic/BasicAuthenticationReferencePolicyProvider.java +++ b/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/basic/BasicAuthenticationReferencePolicyProvider.java @@ -35,9 +35,9 @@ public class BasicAuthenticationReferencePolicyProvider extends BasePolicyProvid super(BasicAuthenticationPolicy.class, endpointReference); } - public PhasedInterceptor createInterceptor(Operation operation) { + public PhasedInterceptor createBindingInterceptor() { PolicySet ps = findPolicySet(); - return ps == null ? null : new BasicAuthenticationReferencePolicyInterceptor(getContext(), operation, ps); + return ps == null ? null : new BasicAuthenticationReferencePolicyInterceptor(getContext(), ps); } public void start() { diff --git a/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/basic/BasicAuthenticationServicePolicyInterceptor.java b/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/basic/BasicAuthenticationServicePolicyInterceptor.java index 6cfe8e1a84..3d73410ae9 100644 --- a/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/basic/BasicAuthenticationServicePolicyInterceptor.java +++ b/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/basic/BasicAuthenticationServicePolicyInterceptor.java @@ -30,6 +30,7 @@ import org.apache.tuscany.sca.invocation.Invoker; import org.apache.tuscany.sca.invocation.Message; import org.apache.tuscany.sca.invocation.Phase; import org.apache.tuscany.sca.invocation.PhasedInterceptor; +import org.apache.tuscany.sca.policy.PolicyExpression; import org.apache.tuscany.sca.policy.PolicySet; import org.apache.tuscany.sca.policy.authentication.basic.BasicAuthenticationPolicy; import org.apache.tuscany.sca.policy.authentication.basic.BasicAuthenticationPrincipal; @@ -59,10 +60,12 @@ public class BasicAuthenticationServicePolicyInterceptor implements PhasedInterc } private void init() { + // TODO - how to get the appropriate expression out of the + // policy set. Need WS Policy help here if (policySet != null) { - for (Object policyObject : policySet.getPolicies()){ - if (policyObject instanceof BasicAuthenticationPolicy){ - policy = (BasicAuthenticationPolicy)policyObject; + for (PolicyExpression policyExpression : policySet.getPolicies()){ + if (policyExpression.getPolicy() instanceof BasicAuthenticationPolicy){ + policy = (BasicAuthenticationPolicy)policyExpression.getPolicy(); break; } } @@ -114,7 +117,7 @@ public class BasicAuthenticationServicePolicyInterceptor implements PhasedInterc } public String getPhase() { - return Phase.SERVICE_POLICY; + return Phase.SERVICE_BINDING_POLICY; } } |