summaryrefslogtreecommitdiffstats
path: root/java/sca/modules/binding-ws-axis2-policy/src/main
diff options
context:
space:
mode:
authorslaws <slaws@13f79535-47bb-0310-9956-ffa450edef68>2008-09-15 08:07:58 +0000
committerslaws <slaws@13f79535-47bb-0310-9956-ffa450edef68>2008-09-15 08:07:58 +0000
commitfa51018b6c24f598ae8174afa183b0b46436e69b (patch)
treeb6c37b85d26f0755ba95200227ea942bd2135c00 /java/sca/modules/binding-ws-axis2-policy/src/main
parent5c5b60f1525a5865a3c2bc35263224c2cd79c713 (diff)
More work exploring the policy extension model by implementing a token based authentication schema across binding.ws and binding.jm. No authentication is actually performed here. That is left for users to provide their own policy interceptors. However tokens are passed and security Subjects/Principals are created. This exercise has highlighted some awkwardness in the process of building policy implementations. I'll post about this on the mail list.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@695374 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/modules/binding-ws-axis2-policy/src/main')
-rw-r--r--java/sca/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/token/Axis2TokenAuthenticationPolicy.java (renamed from java/sca/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/basic/Axis2BasicAuthenticationPolicy.java)33
-rw-r--r--java/sca/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/token/Axis2TokenAuthenticationPolicyProcessor.java (renamed from java/sca/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/basic/Axis2BasicAuthenticationPolicyProcessor.java)45
-rw-r--r--java/sca/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/token/Axis2TokenAuthenticationPolicyProviderFactory.java (renamed from java/sca/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/basic/Axis2BasicAuthenticationPolicyProviderFactory.java)12
-rw-r--r--java/sca/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/token/Axis2TokenAuthenticationReferencePolicyInterceptor.java (renamed from java/sca/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/basic/Axis2BasicAuthenticationReferencePolicyInterceptor.java)37
-rw-r--r--java/sca/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/token/Axis2TokenAuthenticationReferencePolicyProvider.java (renamed from java/sca/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/basic/Axis2BasicAuthenticationReferencePolicyProvider.java)10
-rw-r--r--java/sca/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/token/Axis2TokenAuthenticationServicePolicyInterceptor.java (renamed from java/sca/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/basic/Axis2BasicAuthenticationServicePolicyInterceptor.java)46
-rw-r--r--java/sca/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/token/Axis2TokenAuthenticationServicePolicyProvider.java (renamed from java/sca/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/basic/Axis2BasicAuthenticationServicePolicyProvider.java)11
-rw-r--r--java/sca/modules/binding-ws-axis2-policy/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor3
-rw-r--r--java/sca/modules/binding-ws-axis2-policy/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.PolicyProviderFactory3
9 files changed, 103 insertions, 97 deletions
diff --git a/java/sca/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/basic/Axis2BasicAuthenticationPolicy.java b/java/sca/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/token/Axis2TokenAuthenticationPolicy.java
index 2b7d753023..8fecb84bb4 100644
--- a/java/sca/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/basic/Axis2BasicAuthenticationPolicy.java
+++ b/java/sca/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/token/Axis2TokenAuthenticationPolicy.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.tuscany.sca.binding.ws.axis2.policy.authentication.basic;
+package org.apache.tuscany.sca.binding.ws.axis2.policy.authentication.token;
import javax.xml.namespace.QName;
@@ -29,33 +29,22 @@ import org.apache.tuscany.sca.policy.Policy;
*
* @version $Rev$ $Date$
*/
-public class Axis2BasicAuthenticationPolicy implements Policy {
- public static final QName AXIS2_BASIC_AUTHENTICATION_POLICY_QNAME = new QName(Constants.SCA10_TUSCANY_NS, "axis2BasicAuthentication");
- public static final String AXIS2_BASIC_AUTHENTICATION_USERNAME = "username";
- public static final String AXIS2_BASIC_AUTHENTICATION_PASSWORD = "password";
- public static final String AXIS2_BASIC_AUTHENTICATION_HTTP_HEADER = "httpheader";
+public class Axis2TokenAuthenticationPolicy implements Policy {
+ public static final QName AXIS2_TOKEN_AUTHENTICATION_POLICY_QNAME = new QName(Constants.SCA10_TUSCANY_NS, "axis2TokenAuthentication");
+ public static final String AXIS2_TOKEN_AUTHENTICATION_TOKEN_NAME = "tokenName";
- private String userName;
- private String password;
-
- public String getUserName() {
- return userName;
- }
-
- public void setUserName(String userName) {
- this.userName = userName;
+ private QName tokenName;
+
+ public QName getTokenName() {
+ return tokenName;
}
- public String getPassword() {
- return password;
+ public void setTokenName(QName tokenName) {
+ this.tokenName = tokenName;
}
- public void setPassword(String password) {
- this.password = password;
- }
-
public QName getSchemaName() {
- return AXIS2_BASIC_AUTHENTICATION_POLICY_QNAME;
+ return AXIS2_TOKEN_AUTHENTICATION_POLICY_QNAME;
}
public boolean isUnresolved() {
diff --git a/java/sca/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/basic/Axis2BasicAuthenticationPolicyProcessor.java b/java/sca/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/token/Axis2TokenAuthenticationPolicyProcessor.java
index 019d59b80b..e8a7872858 100644
--- a/java/sca/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/basic/Axis2BasicAuthenticationPolicyProcessor.java
+++ b/java/sca/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/token/Axis2TokenAuthenticationPolicyProcessor.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.tuscany.sca.binding.ws.axis2.policy.authentication.basic;
+package org.apache.tuscany.sca.binding.ws.axis2.policy.authentication.token;
import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
@@ -28,6 +28,7 @@ import javax.xml.stream.XMLStreamWriter;
import org.apache.tuscany.sca.assembly.xml.Constants;
import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor;
import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
import org.apache.tuscany.sca.contribution.service.ContributionReadException;
@@ -39,18 +40,18 @@ import org.apache.tuscany.sca.monitor.Monitor;
*
* @version $Rev$ $Date$
*/
-public class Axis2BasicAuthenticationPolicyProcessor implements StAXArtifactProcessor<Axis2BasicAuthenticationPolicy> {
+public class Axis2TokenAuthenticationPolicyProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor<Axis2TokenAuthenticationPolicy> {
public QName getArtifactType() {
- return Axis2BasicAuthenticationPolicy.AXIS2_BASIC_AUTHENTICATION_POLICY_QNAME;
+ return Axis2TokenAuthenticationPolicy.AXIS2_TOKEN_AUTHENTICATION_POLICY_QNAME;
}
- public Axis2BasicAuthenticationPolicyProcessor(ModelFactoryExtensionPoint modelFactories, Monitor monitor) {
+ public Axis2TokenAuthenticationPolicyProcessor(ModelFactoryExtensionPoint modelFactories, Monitor monitor) {
}
- public Axis2BasicAuthenticationPolicy read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException {
- Axis2BasicAuthenticationPolicy policy = new Axis2BasicAuthenticationPolicy();
+ public Axis2TokenAuthenticationPolicy read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException {
+ Axis2TokenAuthenticationPolicy policy = new Axis2TokenAuthenticationPolicy();
int event = reader.getEventType();
QName name = null;
@@ -60,12 +61,8 @@ public class Axis2BasicAuthenticationPolicyProcessor implements StAXArtifactProc
case START_ELEMENT : {
name = reader.getName();
if ( name.equals(getArtifactType()) ) {
- // no attributes at the moment
- } else if ( Axis2BasicAuthenticationPolicy.AXIS2_BASIC_AUTHENTICATION_USERNAME.equals(name.getLocalPart()) ) {
- policy.setUserName(reader.getElementText());
- } else if ( Axis2BasicAuthenticationPolicy.AXIS2_BASIC_AUTHENTICATION_PASSWORD.equals(name.getLocalPart()) ) {
- policy.setPassword(reader.getElementText());
- }
+ policy.setTokenName(getQName(reader, Axis2TokenAuthenticationPolicy.AXIS2_TOKEN_AUTHENTICATION_TOKEN_NAME));
+ }
break;
}
}
@@ -85,7 +82,7 @@ public class Axis2BasicAuthenticationPolicyProcessor implements StAXArtifactProc
return policy;
}
- public void write(Axis2BasicAuthenticationPolicy policy, XMLStreamWriter writer)
+ public void write(Axis2TokenAuthenticationPolicy policy, XMLStreamWriter writer)
throws ContributionWriteException, XMLStreamException {
String prefix = "tuscany";
writer.writeStartElement(prefix,
@@ -93,30 +90,22 @@ public class Axis2BasicAuthenticationPolicyProcessor implements StAXArtifactProc
getArtifactType().getNamespaceURI());
writer.writeNamespace("tuscany", Constants.SCA10_TUSCANY_NS);
- if ( policy.getUserName() != null ) {
+ if ( policy.getTokenName() != null ) {
writer.writeStartElement(prefix,
- Axis2BasicAuthenticationPolicy.AXIS2_BASIC_AUTHENTICATION_USERNAME,
+ Axis2TokenAuthenticationPolicy.AXIS2_TOKEN_AUTHENTICATION_TOKEN_NAME,
getArtifactType().getNamespaceURI());
- writer.writeCharacters(policy.getUserName());
+ writer.writeCharacters(policy.getTokenName().toString());
writer.writeEndElement();
- }
-
- if ( policy.getPassword() != null ) {
- writer.writeStartElement(prefix,
- Axis2BasicAuthenticationPolicy.AXIS2_BASIC_AUTHENTICATION_PASSWORD,
- getArtifactType().getNamespaceURI());
- writer.writeCharacters(policy.getPassword());
- writer.writeEndElement();
- }
+ }
writer.writeEndElement();
}
- public Class<Axis2BasicAuthenticationPolicy> getModelType() {
- return Axis2BasicAuthenticationPolicy.class;
+ public Class<Axis2TokenAuthenticationPolicy> getModelType() {
+ return Axis2TokenAuthenticationPolicy.class;
}
- public void resolve(Axis2BasicAuthenticationPolicy arg0, ModelResolver arg1) throws ContributionResolveException {
+ public void resolve(Axis2TokenAuthenticationPolicy arg0, ModelResolver arg1) throws ContributionResolveException {
}
diff --git a/java/sca/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/basic/Axis2BasicAuthenticationPolicyProviderFactory.java b/java/sca/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/token/Axis2TokenAuthenticationPolicyProviderFactory.java
index 5ec4cf9baa..cef881af30 100644
--- a/java/sca/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/basic/Axis2BasicAuthenticationPolicyProviderFactory.java
+++ b/java/sca/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/token/Axis2TokenAuthenticationPolicyProviderFactory.java
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.tuscany.sca.binding.ws.axis2.policy.authentication.basic;
+package org.apache.tuscany.sca.binding.ws.axis2.policy.authentication.token;
import org.apache.tuscany.sca.assembly.Binding;
import org.apache.tuscany.sca.assembly.Implementation;
@@ -31,10 +31,10 @@ import org.apache.tuscany.sca.runtime.RuntimeComponentService;
/**
* @version $Rev$ $Date$
*/
-public class Axis2BasicAuthenticationPolicyProviderFactory implements PolicyProviderFactory<Axis2BasicAuthenticationPolicy> {
+public class Axis2TokenAuthenticationPolicyProviderFactory implements PolicyProviderFactory<Axis2TokenAuthenticationPolicy> {
private ExtensionPointRegistry registry;
- public Axis2BasicAuthenticationPolicyProviderFactory(ExtensionPointRegistry registry) {
+ public Axis2TokenAuthenticationPolicyProviderFactory(ExtensionPointRegistry registry) {
super();
this.registry = registry;
}
@@ -43,7 +43,7 @@ public class Axis2BasicAuthenticationPolicyProviderFactory implements PolicyProv
* @see org.apache.tuscany.sca.provider.PolicyProviderFactory#createImplementationPolicyProvider(org.apache.tuscany.sca.runtime.RuntimeComponent, org.apache.tuscany.sca.assembly.Implementation)
*/
public PolicyProvider createImplementationPolicyProvider(RuntimeComponent component, Implementation implementation) {
- return null;//new WSBasicAuthenticationImplementationPolicyProvider(component, implementation);
+ return null;//new TokenAuthenticationImplementationPolicyProvider(component, implementation);
}
/**
@@ -52,7 +52,7 @@ public class Axis2BasicAuthenticationPolicyProviderFactory implements PolicyProv
public PolicyProvider createReferencePolicyProvider(RuntimeComponent component,
RuntimeComponentReference reference,
Binding binding) {
- return new Axis2BasicAuthenticationReferencePolicyProvider(component, reference, binding);
+ return new Axis2TokenAuthenticationReferencePolicyProvider(component, reference, binding);
}
/**
@@ -61,7 +61,7 @@ public class Axis2BasicAuthenticationPolicyProviderFactory implements PolicyProv
public PolicyProvider createServicePolicyProvider(RuntimeComponent component,
RuntimeComponentService service,
Binding binding) {
- return new Axis2BasicAuthenticationServicePolicyProvider(component, service, binding);
+ return new Axis2TokenAuthenticationServicePolicyProvider(component, service, binding);
}
/**
diff --git a/java/sca/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/basic/Axis2BasicAuthenticationReferencePolicyInterceptor.java b/java/sca/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/token/Axis2TokenAuthenticationReferencePolicyInterceptor.java
index 6bd1eed1bd..1ed80ba4da 100644
--- a/java/sca/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/basic/Axis2BasicAuthenticationReferencePolicyInterceptor.java
+++ b/java/sca/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/token/Axis2TokenAuthenticationReferencePolicyInterceptor.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.tuscany.sca.binding.ws.axis2.policy.authentication.basic;
+package org.apache.tuscany.sca.binding.ws.axis2.policy.authentication.token;
import java.util.logging.ConsoleHandler;
import java.util.logging.Handler;
@@ -25,7 +25,15 @@ import java.util.logging.Logger;
import javax.xml.namespace.QName;
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.om.OMText;
+import org.apache.axiom.om.impl.llom.util.AXIOMUtil;
+import org.apache.axiom.soap.SOAPFactory;
import org.apache.tuscany.sca.assembly.xml.Constants;
+import org.apache.tuscany.sca.binding.ws.axis2.policy.header.Axis2SOAPHeaderString;
import org.apache.tuscany.sca.interfacedef.Operation;
import org.apache.tuscany.sca.invocation.Interceptor;
import org.apache.tuscany.sca.invocation.Invoker;
@@ -39,16 +47,15 @@ import org.apache.tuscany.sca.policy.PolicySet;
*
* @version $Rev$ $Date$
*/
-public class Axis2BasicAuthenticationReferencePolicyInterceptor implements Interceptor {
- public static final QName policySetQName = new QName(Constants.SCA10_TUSCANY_NS, "wsBasicAuthentication");
+public class Axis2TokenAuthenticationReferencePolicyInterceptor implements Interceptor {
private Invoker next;
private Operation operation;
private PolicySet policySet = null;
private String context;
- private Axis2BasicAuthenticationPolicy policy;
+ private Axis2TokenAuthenticationPolicy policy;
- public Axis2BasicAuthenticationReferencePolicyInterceptor(String context, Operation operation, PolicySet policySet) {
+ public Axis2TokenAuthenticationReferencePolicyInterceptor(String context, Operation operation, PolicySet policySet) {
super();
this.operation = operation;
this.policySet = policySet;
@@ -59,8 +66,8 @@ public class Axis2BasicAuthenticationReferencePolicyInterceptor implements Inter
private void init() {
if (policySet != null) {
for (Object policyObject : policySet.getPolicies()){
- if (policyObject instanceof Axis2BasicAuthenticationPolicy){
- policy = (Axis2BasicAuthenticationPolicy)policyObject;
+ if (policyObject instanceof Axis2TokenAuthenticationPolicy){
+ policy = (Axis2TokenAuthenticationPolicy)policyObject;
break;
}
}
@@ -68,9 +75,19 @@ public class Axis2BasicAuthenticationReferencePolicyInterceptor implements Inter
}
public Message invoke(Message msg) {
- // TODO - We might use interceptors to do the Axis2 config
- // if we can change the infrastructure split the
- // invoker up
+ // could call out here to some 3rd party system to get credentials
+
+ if ( policy.getTokenName() != null){
+ // create Axis representation of header
+ Axis2SOAPHeaderString header = new Axis2SOAPHeaderString();
+ header.setHeaderName(policy.getTokenName());
+ header.setHeaderString("SomeWSAuthorizationToken");
+
+ // add header to Tuscany message
+ msg.getHeaders().put(policy.getTokenName().toString(),
+ header);
+ }
+
return getNext().invoke(msg);
}
diff --git a/java/sca/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/basic/Axis2BasicAuthenticationReferencePolicyProvider.java b/java/sca/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/token/Axis2TokenAuthenticationReferencePolicyProvider.java
index 530d99c01e..147fd1f42a 100644
--- a/java/sca/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/basic/Axis2BasicAuthenticationReferencePolicyProvider.java
+++ b/java/sca/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/token/Axis2TokenAuthenticationReferencePolicyProvider.java
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.tuscany.sca.binding.ws.axis2.policy.authentication.basic;
+package org.apache.tuscany.sca.binding.ws.axis2.policy.authentication.token;
import java.util.List;
@@ -35,12 +35,12 @@ import org.apache.tuscany.sca.runtime.RuntimeComponentReference;
/**
* @version $Rev$ $Date$
*/
-public class Axis2BasicAuthenticationReferencePolicyProvider implements PolicyProvider {
+public class Axis2TokenAuthenticationReferencePolicyProvider implements PolicyProvider {
private RuntimeComponent component;
private RuntimeComponentReference reference;
private Binding binding;
- public Axis2BasicAuthenticationReferencePolicyProvider(RuntimeComponent component,
+ public Axis2TokenAuthenticationReferencePolicyProvider(RuntimeComponent component,
RuntimeComponentReference reference,
Binding binding) {
super();
@@ -54,7 +54,7 @@ public class Axis2BasicAuthenticationReferencePolicyProvider implements PolicyPr
List<PolicySet> policySets = ((PolicySetAttachPoint)binding).getApplicablePolicySets();
for (PolicySet ps : policySets) {
for (Object p : ps.getPolicies()) {
- if (Axis2BasicAuthenticationPolicy.class.isInstance(p)) {
+ if (Axis2TokenAuthenticationPolicy.class.isInstance(p)) {
return ps;
}
}
@@ -77,7 +77,7 @@ public class Axis2BasicAuthenticationReferencePolicyProvider implements PolicyPr
*/
public Interceptor createInterceptor(Operation operation) {
PolicySet ps = findPolicySet();
- return ps == null ? null : new Axis2BasicAuthenticationReferencePolicyInterceptor(getContext(), operation, ps);
+ return ps == null ? null : new Axis2TokenAuthenticationReferencePolicyInterceptor(getContext(), operation, ps);
}
/**
diff --git a/java/sca/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/basic/Axis2BasicAuthenticationServicePolicyInterceptor.java b/java/sca/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/token/Axis2TokenAuthenticationServicePolicyInterceptor.java
index f2964650ef..9ff7b82be2 100644
--- a/java/sca/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/basic/Axis2BasicAuthenticationServicePolicyInterceptor.java
+++ b/java/sca/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/token/Axis2TokenAuthenticationServicePolicyInterceptor.java
@@ -16,24 +16,25 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.tuscany.sca.binding.ws.axis2.policy.authentication.basic;
+package org.apache.tuscany.sca.binding.ws.axis2.policy.authentication.token;
-import java.util.Map;
-import java.util.logging.ConsoleHandler;
-import java.util.logging.Handler;
-import java.util.logging.Level;
-import java.util.logging.Logger;
+import java.security.Principal;
+
+import javax.security.auth.Subject;
import javax.xml.namespace.QName;
-import org.apache.axiom.om.util.Base64;
+import org.apache.axiom.om.OMElement;
import org.apache.tuscany.sca.assembly.xml.Constants;
+import org.apache.tuscany.sca.binding.ws.axis2.policy.header.Axis2SOAPHeaderString;
import org.apache.tuscany.sca.interfacedef.Operation;
import org.apache.tuscany.sca.invocation.Interceptor;
import org.apache.tuscany.sca.invocation.Invoker;
import org.apache.tuscany.sca.invocation.Message;
-import org.apache.tuscany.sca.policy.Policy;
import org.apache.tuscany.sca.policy.PolicySet;
+import org.apache.tuscany.sca.policy.SecurityUtil;
+import org.apache.tuscany.sca.policy.authentication.basic.BasicAuthenticationPrincipal;
+import org.apache.tuscany.sca.policy.authentication.token.TokenPrincipal;
/**
* Policy handler to handle PolicySet related to Logging with the QName
@@ -41,16 +42,14 @@ import org.apache.tuscany.sca.policy.PolicySet;
*
* @version $Rev$ $Date$
*/
-public class Axis2BasicAuthenticationServicePolicyInterceptor implements Interceptor {
- public static final QName policySetQName = new QName(Constants.SCA10_TUSCANY_NS, "wsBasicAuthentication");
-
+public class Axis2TokenAuthenticationServicePolicyInterceptor implements Interceptor {
private Invoker next;
private Operation operation;
private PolicySet policySet = null;
private String context;
- private Axis2BasicAuthenticationPolicy policy;
+ private Axis2TokenAuthenticationPolicy policy;
- public Axis2BasicAuthenticationServicePolicyInterceptor(String context, Operation operation, PolicySet policySet) {
+ public Axis2TokenAuthenticationServicePolicyInterceptor(String context, Operation operation, PolicySet policySet) {
super();
this.operation = operation;
this.policySet = policySet;
@@ -61,8 +60,8 @@ public class Axis2BasicAuthenticationServicePolicyInterceptor implements Interce
private void init() {
if (policySet != null) {
for (Object policyObject : policySet.getPolicies()){
- if (policyObject instanceof Axis2BasicAuthenticationPolicy){
- policy = (Axis2BasicAuthenticationPolicy)policyObject;
+ if (policyObject instanceof Axis2TokenAuthenticationPolicy){
+ policy = (Axis2TokenAuthenticationPolicy)policyObject;
break;
}
}
@@ -70,9 +69,20 @@ public class Axis2BasicAuthenticationServicePolicyInterceptor implements Interce
}
public Message invoke(Message msg) {
- // TODO - We might use interceptors to do the Axis2 config
- // if we can change the infrastructure split the
- // invoker up
+
+ Axis2SOAPHeaderString header = (Axis2SOAPHeaderString)msg.getHeaders().get(policy.getTokenName().toString());
+
+ if (header != null) {
+ System.out.println("Token: " + header.getHeaderString());
+
+ // call out here to some 3rd party system to do whatever you
+ // need to turn header credentials into an authenticated principal
+
+ Subject subject = SecurityUtil.getSubject(msg);
+ Principal principal = new TokenPrincipal(header.getHeaderString());
+ subject.getPrincipals().add(principal);
+ }
+
return getNext().invoke(msg);
}
diff --git a/java/sca/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/basic/Axis2BasicAuthenticationServicePolicyProvider.java b/java/sca/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/token/Axis2TokenAuthenticationServicePolicyProvider.java
index 9c1a9704d3..e3e2a4b9a0 100644
--- a/java/sca/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/basic/Axis2BasicAuthenticationServicePolicyProvider.java
+++ b/java/sca/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/token/Axis2TokenAuthenticationServicePolicyProvider.java
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.tuscany.sca.binding.ws.axis2.policy.authentication.basic;
+package org.apache.tuscany.sca.binding.ws.axis2.policy.authentication.token;
import java.util.List;
@@ -35,12 +35,12 @@ import org.apache.tuscany.sca.runtime.RuntimeComponentService;
/**
* @version $Rev$ $Date$
*/
-public class Axis2BasicAuthenticationServicePolicyProvider implements PolicyProvider {
+public class Axis2TokenAuthenticationServicePolicyProvider implements PolicyProvider {
private RuntimeComponent component;
private RuntimeComponentService service;
private Binding binding;
- public Axis2BasicAuthenticationServicePolicyProvider(RuntimeComponent component, RuntimeComponentService service, Binding binding) {
+ public Axis2TokenAuthenticationServicePolicyProvider(RuntimeComponent component, RuntimeComponentService service, Binding binding) {
super();
this.component = component;
this.service = service;
@@ -52,7 +52,7 @@ public class Axis2BasicAuthenticationServicePolicyProvider implements PolicyProv
List<PolicySet> policySets = ((PolicySetAttachPoint)binding).getApplicablePolicySets();
for (PolicySet ps : policySets) {
for (Object p : ps.getPolicies()) {
- if (Axis2BasicAuthenticationPolicy.class.isInstance(p)) {
+ if (Axis2TokenAuthenticationPolicy.class.isInstance(p)) {
return ps;
}
}
@@ -69,14 +69,13 @@ public class Axis2BasicAuthenticationServicePolicyProvider implements PolicyProv
+ binding.getClass().getName()
+ ")";
}
-
/**
* @see org.apache.tuscany.sca.provider.PolicyProvider#createInterceptor(org.apache.tuscany.sca.interfacedef.Operation)
*/
public Interceptor createInterceptor(Operation operation) {
PolicySet ps = findPolicySet();
- return ps == null ? null : new Axis2BasicAuthenticationReferencePolicyInterceptor(getContext(), operation, ps);
+ return ps == null ? null : new Axis2TokenAuthenticationServicePolicyInterceptor(getContext(), operation, ps);
}
/**
diff --git a/java/sca/modules/binding-ws-axis2-policy/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/java/sca/modules/binding-ws-axis2-policy/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor
index 7a223848fa..96782b74bf 100644
--- a/java/sca/modules/binding-ws-axis2-policy/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor
+++ b/java/sca/modules/binding-ws-axis2-policy/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor
@@ -17,4 +17,5 @@
# Implementation class for the artifact processor extension
org.apache.tuscany.sca.binding.ws.axis2.policy.configuration.Axis2ConfigParamPolicyProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.0#wsConfigParam,model=org.apache.tuscany.sca.binding.ws.axis2.policy.configuration.Axis2ConfigParamPolicy
-org.apache.tuscany.sca.binding.ws.axis2.policy.authentication.basic.Axis2BasicAuthenticationPolicyProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.0#axis2BasicAuthentication,model=org.apache.tuscany.sca.binding.ws.axis2.policy.authentication.basic.Axis2BasicAuthenticationPolicy
+org.apache.tuscany.sca.binding.ws.axis2.policy.authentication.token.Axis2TokenAuthenticationPolicyProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.0#axis2TokenAuthentication,model=org.apache.tuscany.sca.binding.ws.axis2.policy.authentication.token.Axis2TokenAuthenticationPolicy
+org.apache.tuscany.sca.binding.ws.axis2.policy.header.Axis2HeaderPolicyProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.0#axis2Header,model=org.apache.tuscany.sca.binding.ws.axis2.policy.header.Axis2HeaderPolicy
diff --git a/java/sca/modules/binding-ws-axis2-policy/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.PolicyProviderFactory b/java/sca/modules/binding-ws-axis2-policy/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.PolicyProviderFactory
index 7d7f4299f4..ced48cf236 100644
--- a/java/sca/modules/binding-ws-axis2-policy/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.PolicyProviderFactory
+++ b/java/sca/modules/binding-ws-axis2-policy/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.PolicyProviderFactory
@@ -16,4 +16,5 @@
# under the License.
# Implementation class for the policy extension
-org.apache.tuscany.sca.binding.ws.axis2.policy.authentication.basic.Axis2BasicAuthenticationPolicyProviderFactory;model=org.apache.tuscany.sca.binding.ws.axis2.policy.authentication.basic.Axis2BasicAuthenticationPolicy \ No newline at end of file
+org.apache.tuscany.sca.binding.ws.axis2.policy.authentication.token.Axis2TokenAuthenticationPolicyProviderFactory;model=org.apache.tuscany.sca.binding.ws.axis2.policy.authentication.token.Axis2TokenAuthenticationPolicy
+org.apache.tuscany.sca.binding.ws.axis2.policy.header.Axis2HeaderPolicyProviderFactory;model=org.apache.tuscany.sca.binding.ws.axis2.policy.header.Axis2HeaderPolicy \ No newline at end of file