You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by sv...@apache.org on 2008/03/26 09:26:33 UTC

svn commit: r641200 - in /incubator/tuscany/branches/sca-java-1.2/demos/bigbank-account/src/main: java/bigbank/account/security/ resources/META-INF/services/

Author: svkrish
Date: Wed Mar 26 01:26:32 2008
New Revision: 641200

URL: http://svn.apache.org/viewvc?rev=641200&view=rev
Log:
adding support for custom authorization using the PolicyProvider SPI mechanism

Added:
    incubator/tuscany/branches/sca-java-1.2/demos/bigbank-account/src/main/java/bigbank/account/security/CheckingsDeptAuthImplementationPolicyProvider.java   (with props)
    incubator/tuscany/branches/sca-java-1.2/demos/bigbank-account/src/main/java/bigbank/account/security/CheckingsDeptAuthPolicyInterceptor.java   (with props)
    incubator/tuscany/branches/sca-java-1.2/demos/bigbank-account/src/main/java/bigbank/account/security/CheckingsDeptAuthPolicyProviderFactory.java   (with props)
    incubator/tuscany/branches/sca-java-1.2/demos/bigbank-account/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.PolicyProviderFactory
Modified:
    incubator/tuscany/branches/sca-java-1.2/demos/bigbank-account/src/main/java/bigbank/account/security/CheckingsDeptAuthPolicy.java

Added: incubator/tuscany/branches/sca-java-1.2/demos/bigbank-account/src/main/java/bigbank/account/security/CheckingsDeptAuthImplementationPolicyProvider.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-1.2/demos/bigbank-account/src/main/java/bigbank/account/security/CheckingsDeptAuthImplementationPolicyProvider.java?rev=641200&view=auto
==============================================================================
--- incubator/tuscany/branches/sca-java-1.2/demos/bigbank-account/src/main/java/bigbank/account/security/CheckingsDeptAuthImplementationPolicyProvider.java (added)
+++ incubator/tuscany/branches/sca-java-1.2/demos/bigbank-account/src/main/java/bigbank/account/security/CheckingsDeptAuthImplementationPolicyProvider.java Wed Mar 26 01:26:32 2008
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+
+package bigbank.account.security;
+
+import org.apache.tuscany.sca.assembly.ConfiguredOperation;
+import org.apache.tuscany.sca.assembly.Implementation;
+import org.apache.tuscany.sca.assembly.OperationsConfigurator;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.invocation.Interceptor;
+import org.apache.tuscany.sca.invocation.Phase;
+import org.apache.tuscany.sca.policy.PolicySet;
+import org.apache.tuscany.sca.provider.PolicyProvider;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class CheckingsDeptAuthImplementationPolicyProvider implements PolicyProvider {
+    private RuntimeComponent component;
+    private Implementation implementation;
+
+    public CheckingsDeptAuthImplementationPolicyProvider(RuntimeComponent component, Implementation implementation) {
+        super();
+        this.component = component;
+        this.implementation = implementation;
+    }
+
+    private String getContext() {
+        return "component.implementation: " + component.getURI() + "(" + implementation.getClass().getName() + ")";
+    }
+
+    private PolicySet findPolicySet(Operation operation) {
+    	for (PolicySet ps : component.getPolicySets()) {
+            for (Object p : ps.getPolicies()) {
+                if (CheckingsDeptAuthPolicy.class.isInstance(p)) {
+                    return ps;
+                }
+            }
+        }
+        
+        if ( component instanceof OperationsConfigurator ) {
+        	for ( ConfiguredOperation confOp : ((OperationsConfigurator)component).getConfiguredOperations() ) {
+        		if ( confOp.getName().equals(operation.getName())) {
+        			for (PolicySet ps : confOp.getPolicySets()) {
+        	            for (Object p : ps.getPolicies()) {
+        	                if (CheckingsDeptAuthPolicy.class.isInstance(p)) {
+        	                    return ps;
+        	                }
+        	            }
+        	        }
+        		}
+        	}
+        }
+        
+        return null;
+    }
+
+    /**
+     * @see org.apache.tuscany.sca.provider.PolicyProvider#createInterceptor(org.apache.tuscany.sca.interfacedef.Operation)
+     */
+    public Interceptor createInterceptor(Operation operation) {
+        PolicySet ps = findPolicySet(operation);
+        return ps == null ? null : new CheckingsDeptAuthPolicyInterceptor(getContext(), operation, ps);
+    }
+
+    /**
+     * @see org.apache.tuscany.sca.provider.PolicyProvider#getPhase()
+     */
+    public String getPhase() {
+        return Phase.IMPLEMENTATION_POLICY;
+    }
+
+}

Propchange: incubator/tuscany/branches/sca-java-1.2/demos/bigbank-account/src/main/java/bigbank/account/security/CheckingsDeptAuthImplementationPolicyProvider.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/branches/sca-java-1.2/demos/bigbank-account/src/main/java/bigbank/account/security/CheckingsDeptAuthImplementationPolicyProvider.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/tuscany/branches/sca-java-1.2/demos/bigbank-account/src/main/java/bigbank/account/security/CheckingsDeptAuthPolicy.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-1.2/demos/bigbank-account/src/main/java/bigbank/account/security/CheckingsDeptAuthPolicy.java?rev=641200&r1=641199&r2=641200&view=diff
==============================================================================
--- incubator/tuscany/branches/sca-java-1.2/demos/bigbank-account/src/main/java/bigbank/account/security/CheckingsDeptAuthPolicy.java (original)
+++ incubator/tuscany/branches/sca-java-1.2/demos/bigbank-account/src/main/java/bigbank/account/security/CheckingsDeptAuthPolicy.java Wed Mar 26 01:26:32 2008
@@ -19,9 +19,28 @@
 
 package bigbank.account.security;
 
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.policy.Policy;
+
 /**
  * @version $Rev$ $Date$
  */
-public class CheckingsDeptAuthPolicy {
+public class CheckingsDeptAuthPolicy implements Policy {
+
+	public QName getSchemaName() {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+	public boolean isUnresolved() {
+		// TODO Auto-generated method stub
+		return false;
+	}
+
+	public void setUnresolved(boolean unresolved) {
+		// TODO Auto-generated method stub
+		
+	}
 
 }

Added: incubator/tuscany/branches/sca-java-1.2/demos/bigbank-account/src/main/java/bigbank/account/security/CheckingsDeptAuthPolicyInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-1.2/demos/bigbank-account/src/main/java/bigbank/account/security/CheckingsDeptAuthPolicyInterceptor.java?rev=641200&view=auto
==============================================================================
--- incubator/tuscany/branches/sca-java-1.2/demos/bigbank-account/src/main/java/bigbank/account/security/CheckingsDeptAuthPolicyInterceptor.java (added)
+++ incubator/tuscany/branches/sca-java-1.2/demos/bigbank-account/src/main/java/bigbank/account/security/CheckingsDeptAuthPolicyInterceptor.java Wed Mar 26 01:26:32 2008
@@ -0,0 +1,77 @@
+package bigbank.account.security;
+
+import java.security.Principal;
+import java.util.logging.ConsoleHandler;
+import java.util.logging.Handler;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.xml.namespace.QName;
+
+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.PolicySet;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+
+/**
+ * Policy handler to handle PolicySet related to Logging with the QName
+ * {http://tuscany.apache.org/xmlns/sca/1.0/impl/java}LoggingPolicy
+ */
+public class CheckingsDeptAuthPolicyInterceptor implements Interceptor {
+    private Invoker next;
+
+    public CheckingsDeptAuthPolicyInterceptor(String context, Operation operation, PolicySet policySet) {
+        super();
+        init();
+    }
+
+    private final void init() {
+    }
+
+    public Message invoke(Message msg) {
+        Object msgBody = msg.getBody();
+        if (msgBody instanceof Object[]) {
+        	Object args[] = (Object[])msg.getBody();
+            if ( msg.getQoSContext().get(Message.QOS_CTX_SECURITY_PRINCIPAL) != null ) {
+                    BigbankCheckingsAcl.authorize((Principal)msg.getQoSContext().get(Message.QOS_CTX_SECURITY_PRINCIPAL),
+                                                  (String)args[0]);
+            }
+        } 
+        
+        Message responseMsg = null;
+        try {
+            responseMsg = getNext().invoke(msg);
+            return responseMsg;
+        } catch (RuntimeException e) {
+            throw e;
+        } 
+    }
+
+    public Invoker getNext() {
+        return next;
+    }
+
+    public void setNext(Invoker next) {
+        this.next = next;
+    }
+}

Propchange: incubator/tuscany/branches/sca-java-1.2/demos/bigbank-account/src/main/java/bigbank/account/security/CheckingsDeptAuthPolicyInterceptor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/branches/sca-java-1.2/demos/bigbank-account/src/main/java/bigbank/account/security/CheckingsDeptAuthPolicyInterceptor.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/branches/sca-java-1.2/demos/bigbank-account/src/main/java/bigbank/account/security/CheckingsDeptAuthPolicyProviderFactory.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-1.2/demos/bigbank-account/src/main/java/bigbank/account/security/CheckingsDeptAuthPolicyProviderFactory.java?rev=641200&view=auto
==============================================================================
--- incubator/tuscany/branches/sca-java-1.2/demos/bigbank-account/src/main/java/bigbank/account/security/CheckingsDeptAuthPolicyProviderFactory.java (added)
+++ incubator/tuscany/branches/sca-java-1.2/demos/bigbank-account/src/main/java/bigbank/account/security/CheckingsDeptAuthPolicyProviderFactory.java Wed Mar 26 01:26:32 2008
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+
+package bigbank.account.security;
+
+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.provider.PolicyProvider;
+import org.apache.tuscany.sca.provider.PolicyProviderFactory;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.runtime.RuntimeComponentReference;
+import org.apache.tuscany.sca.runtime.RuntimeComponentService;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class CheckingsDeptAuthPolicyProviderFactory implements PolicyProviderFactory<CheckingsDeptAuthPolicy> {
+    private ExtensionPointRegistry registry;
+    
+    public CheckingsDeptAuthPolicyProviderFactory(ExtensionPointRegistry registry) {
+        super();
+        this.registry = registry;
+    }
+
+    /**
+     * @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 new CheckingsDeptAuthImplementationPolicyProvider(component, implementation);
+    }
+
+    /**
+     * @see org.apache.tuscany.sca.provider.PolicyProviderFactory#createReferencePolicyProvider(org.apache.tuscany.sca.runtime.RuntimeComponent, org.apache.tuscany.sca.runtime.RuntimeComponentReference, org.apache.tuscany.sca.assembly.Binding)
+     */
+    public PolicyProvider createReferencePolicyProvider(RuntimeComponent component,
+                                                        RuntimeComponentReference reference,
+                                                        Binding binding) {
+        return null;
+    }
+
+    /**
+     * @see org.apache.tuscany.sca.provider.PolicyProviderFactory#createServicePolicyProvider(org.apache.tuscany.sca.runtime.RuntimeComponent, org.apache.tuscany.sca.runtime.RuntimeComponentService, org.apache.tuscany.sca.assembly.Binding)
+     */
+    public PolicyProvider createServicePolicyProvider(RuntimeComponent component,
+                                                      RuntimeComponentService service,
+                                                      Binding binding) {
+        return null;
+    }
+
+    /**
+     * @see org.apache.tuscany.sca.provider.ProviderFactory#getModelType()
+     */
+    public Class getModelType() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+}

Propchange: incubator/tuscany/branches/sca-java-1.2/demos/bigbank-account/src/main/java/bigbank/account/security/CheckingsDeptAuthPolicyProviderFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/branches/sca-java-1.2/demos/bigbank-account/src/main/java/bigbank/account/security/CheckingsDeptAuthPolicyProviderFactory.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/branches/sca-java-1.2/demos/bigbank-account/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.PolicyProviderFactory
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-1.2/demos/bigbank-account/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.PolicyProviderFactory?rev=641200&view=auto
==============================================================================
--- incubator/tuscany/branches/sca-java-1.2/demos/bigbank-account/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.PolicyProviderFactory (added)
+++ incubator/tuscany/branches/sca-java-1.2/demos/bigbank-account/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.PolicyProviderFactory Wed Mar 26 01:26:32 2008
@@ -0,0 +1,19 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License. 
+
+# Implementation class for the policy extension
+bigbank.account.security.CheckingsDeptAuthPolicyProviderFactory;model=bigbank.account.security.CheckingsDeptAuthPolicy
\ No newline at end of file



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org