summaryrefslogtreecommitdiffstats
path: root/branches/sca-java-1.x/modules/binding-jms-policy/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/JMSTokenAuthenticationServicePolicyInterceptor.java
diff options
context:
space:
mode:
authorslaws <slaws@13f79535-47bb-0310-9956-ffa450edef68>2008-11-30 13:46:51 +0000
committerslaws <slaws@13f79535-47bb-0310-9956-ffa450edef68>2008-11-30 13:46:51 +0000
commitc8f58fe2afa3f2f3bdf86846a48cb5a6dd7d503b (patch)
treeb96a10cd0bf623da0612ceff196be9315c7da2e8 /branches/sca-java-1.x/modules/binding-jms-policy/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/JMSTokenAuthenticationServicePolicyInterceptor.java
parentb30b676df944c0444a7a6ec8df26f8208a01e896 (diff)
Tidy jms policy implementations to remove code from the binding and put it into binding wire interceptors. The implication is that the JMS runtime no longer depends on the JMS policy package. Also get rid of split packages in wire format and operation selector packages. Add a binding context to the Tuscany message so that you don't have to keep finding it in the message header.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@721811 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
-rw-r--r--branches/sca-java-1.x/modules/binding-jms-policy/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/JMSTokenAuthenticationServicePolicyInterceptor.java49
1 files changed, 30 insertions, 19 deletions
diff --git a/branches/sca-java-1.x/modules/binding-jms-policy/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/JMSTokenAuthenticationServicePolicyInterceptor.java b/branches/sca-java-1.x/modules/binding-jms-policy/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/JMSTokenAuthenticationServicePolicyInterceptor.java
index ec3be6e165..c8d28ad5db 100644
--- a/branches/sca-java-1.x/modules/binding-jms-policy/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/JMSTokenAuthenticationServicePolicyInterceptor.java
+++ b/branches/sca-java-1.x/modules/binding-jms-policy/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/JMSTokenAuthenticationServicePolicyInterceptor.java
@@ -19,13 +19,13 @@
package org.apache.tuscany.sca.binding.jms.policy.authentication.token;
-import java.security.Principal;
+import javax.jms.JMSException;
import javax.security.auth.Subject;
-import javax.xml.namespace.QName;
-import org.apache.tuscany.sca.assembly.xml.Constants;
-import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.binding.jms.context.JMSBindingContext;
+import org.apache.tuscany.sca.binding.jms.impl.JMSBindingConstants;
+import org.apache.tuscany.sca.binding.jms.impl.JMSBindingException;
import org.apache.tuscany.sca.invocation.Interceptor;
import org.apache.tuscany.sca.invocation.Invoker;
import org.apache.tuscany.sca.invocation.Message;
@@ -34,21 +34,19 @@ import org.apache.tuscany.sca.policy.SecurityUtil;
import org.apache.tuscany.sca.policy.authentication.token.TokenPrincipal;
/**
- * Policy handler to handle PolicySet related to Logging with the QName
+ * Policy handler to handle token based authentication
* {http://tuscany.apache.org/xmlns/sca/1.0/impl/java}LoggingPolicy
*
* @version $Rev$ $Date$
*/
public class JMSTokenAuthenticationServicePolicyInterceptor implements Interceptor {
private Invoker next;
- private Operation operation;
private PolicySet policySet = null;
private String context;
private JMSTokenAuthenticationPolicy policy;
- public JMSTokenAuthenticationServicePolicyInterceptor(String context, Operation operation, PolicySet policySet) {
+ public JMSTokenAuthenticationServicePolicyInterceptor(String context, PolicySet policySet) {
super();
- this.operation = operation;
this.policySet = policySet;
this.context = context;
init();
@@ -66,17 +64,30 @@ public class JMSTokenAuthenticationServicePolicyInterceptor implements Intercept
}
public Message invoke(Message msg) {
- Subject subject = SecurityUtil.getSubject(msg);
- TokenPrincipal principal = SecurityUtil.getPrincipal(subject, TokenPrincipal.class);
-
- if (principal != null) {
- System.out.println("Token: " + principal.getName());
-
- // call out here to some 3rd party system to do whatever you
- // need to authenticate the principal
- }
-
- return getNext().invoke(msg);
+ try{
+ // get the jms context
+ JMSBindingContext context = msg.getBindingContext();
+ javax.jms.Message jmsMsg = context.getJmsMsg();
+
+ String token = jmsMsg.getStringProperty(policy.getTokenName().toString());
+
+ Subject subject = SecurityUtil.getSubject(msg);
+ TokenPrincipal principal = SecurityUtil.getPrincipal(subject, TokenPrincipal.class);
+
+ if (principal == null){
+ principal = new TokenPrincipal(token);
+ subject.getPrincipals().add(principal);
+ }
+
+ System.out.println("JMS service received token: " + principal.getName());
+
+ // call out here to some 3rd party system to do whatever you
+ // need to authenticate the principal
+
+ return getNext().invoke(msg);
+ } catch (JMSException e) {
+ throw new JMSBindingException(e);
+ }
}
public Invoker getNext() {