summaryrefslogtreecommitdiffstats
path: root/branches/sca-java-1.x/modules/policy-security-http/src
diff options
context:
space:
mode:
authorlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2009-02-26 04:41:26 +0000
committerlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2009-02-26 04:41:26 +0000
commit750e2e19dddb236c49d458ff27c2ab50b1848a63 (patch)
tree95acb6f1b3b9d9e0b38c1dbd96227c70a039fd6f /branches/sca-java-1.x/modules/policy-security-http/src
parentccdb9264ce71a776d4bb1cbf66a4e3f5012b48fd (diff)
Adding support for enabling and configuring authentication for embedded http server using policy
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@748014 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'branches/sca-java-1.x/modules/policy-security-http/src')
-rw-r--r--branches/sca-java-1.x/modules/policy-security-http/src/main/java/org/apache/tuscany/sca/policy/authentication/AuthenticationConfigurationPolicy.java45
-rw-r--r--branches/sca-java-1.x/modules/policy-security-http/src/main/java/org/apache/tuscany/sca/policy/authentication/AuthenticationConfigurationPolicyProcessor.java156
-rw-r--r--branches/sca-java-1.x/modules/policy-security-http/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor3
3 files changed, 203 insertions, 1 deletions
diff --git a/branches/sca-java-1.x/modules/policy-security-http/src/main/java/org/apache/tuscany/sca/policy/authentication/AuthenticationConfigurationPolicy.java b/branches/sca-java-1.x/modules/policy-security-http/src/main/java/org/apache/tuscany/sca/policy/authentication/AuthenticationConfigurationPolicy.java
new file mode 100644
index 0000000000..4ab7e582ac
--- /dev/null
+++ b/branches/sca-java-1.x/modules/policy-security-http/src/main/java/org/apache/tuscany/sca/policy/authentication/AuthenticationConfigurationPolicy.java
@@ -0,0 +1,45 @@
+/*
+ * 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 org.apache.tuscany.sca.policy.authentication;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.assembly.xml.Constants;
+import org.apache.tuscany.sca.host.http.UserContext;
+
+/**
+ * This policy configures authentication/authorization
+ * in embedded http servers
+ *
+ * @version $Rev$ $Date$
+ */
+public class AuthenticationConfigurationPolicy {
+ public static final QName NAME = new QName(Constants.SCA10_TUSCANY_NS, "basicAuthenticationConfiguration");
+
+ private List<UserContext> users = new ArrayList<UserContext>();
+
+ public List<UserContext> getUsers() {
+ return this.users;
+ }
+
+}
diff --git a/branches/sca-java-1.x/modules/policy-security-http/src/main/java/org/apache/tuscany/sca/policy/authentication/AuthenticationConfigurationPolicyProcessor.java b/branches/sca-java-1.x/modules/policy-security-http/src/main/java/org/apache/tuscany/sca/policy/authentication/AuthenticationConfigurationPolicyProcessor.java
new file mode 100644
index 0000000000..77d8fa6203
--- /dev/null
+++ b/branches/sca-java-1.x/modules/policy-security-http/src/main/java/org/apache/tuscany/sca/policy/authentication/AuthenticationConfigurationPolicyProcessor.java
@@ -0,0 +1,156 @@
+/*
+ * 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 org.apache.tuscany.sca.policy.authentication;
+
+import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
+import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
+
+import java.util.StringTokenizer;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.tuscany.sca.assembly.builder.impl.ProblemImpl;
+import org.apache.tuscany.sca.assembly.xml.Constants;
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.contribution.service.ContributionReadException;
+import org.apache.tuscany.sca.contribution.service.ContributionResolveException;
+import org.apache.tuscany.sca.contribution.service.ContributionWriteException;
+import org.apache.tuscany.sca.host.http.UserContext;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.monitor.Problem;
+import org.apache.tuscany.sca.monitor.Problem.Severity;
+
+/**
+ * <sca:policySet name="widgetBindingAuthenticationPolicySet"
+ * provides="sca:authentication"
+ * appliesTo="tuscany:binding.http">
+ * <tuscany:authenticationConfiguration>
+ * <tuscany:user username="user1" password="tuscany" roles="admin"/>
+ * <tuscany:user username="user2" password="tuscany" roles="admin, user"/>
+ * <tuscany:user username="user3" password="tuscany" roles="user"/>
+ * </tuscany:authenticationConfiguration>
+ * </sca:policySet>
+ *
+ *
+ * @version $Rev$ $Date$
+ */
+
+public class AuthenticationConfigurationPolicyProcessor implements StAXArtifactProcessor<AuthenticationConfigurationPolicy> {
+ private static final QName AUTHENTICATION_CONFIGURATION_QNAME = new QName(Constants.SCA10_TUSCANY_NS, "authenticationConfiguration");
+ private static final QName USER_QNAME = new QName(Constants.SCA10_TUSCANY_NS, "user");
+
+ private Monitor monitor;
+
+ public AuthenticationConfigurationPolicyProcessor(ModelFactoryExtensionPoint modelFactories, Monitor monitor) {
+ this.monitor = monitor;
+ }
+
+ /**
+ * Report a error.
+ *
+ * @param problems
+ * @param message
+ * @param model
+ */
+ private void error(String message, Object model, Object... messageParameters) {
+ if (monitor != null) {
+ Problem problem = new ProblemImpl(this.getClass().getName(), "policy-security-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters);
+ monitor.problem(problem);
+ }
+ }
+
+ public QName getArtifactType() {
+ return AuthenticationConfigurationPolicy.NAME;
+ }
+
+ public Class<AuthenticationConfigurationPolicy> getModelType() {
+ return AuthenticationConfigurationPolicy.class;
+ }
+
+ public AuthenticationConfigurationPolicy read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException {
+ AuthenticationConfigurationPolicy authenticationConfiguration = new AuthenticationConfigurationPolicy();
+
+ int event = reader.getEventType();
+ QName start = reader.getName();
+ QName name = null;
+ while (true) {
+ switch (event) {
+ case START_ELEMENT:
+ name = reader.getName();
+ if(USER_QNAME.equals(name)) {
+ UserContext user = new UserContext();
+ //<tuscany:user username="user1" password="tuscany" roles="admin, user"/>
+ String username = reader.getAttributeValue(null, "username");
+ if(username == null) {
+ error("RequiredAttributeUsernameMissing", reader);
+ } else {
+ user.setUsername(username);
+ }
+
+ String password = reader.getAttributeValue(null, "password");
+ if(password == null) {
+ error("RequiredAttributePasswordMissing", reader);
+ } else {
+ user.setPassword(password);
+ }
+
+ String roles = reader.getAttributeValue(null, "roles");
+ if(roles == null) {
+ error("RequiredAttributeRolesMissing", reader);
+ } else {
+ for (StringTokenizer tokens = new StringTokenizer(roles, ","); tokens.hasMoreTokens();) {
+ user.getRoles().add(tokens.nextToken());
+ }
+ }
+
+ authenticationConfiguration.getUsers().add(user);
+ }
+ break;
+ case END_ELEMENT:
+ if (start.equals(reader.getName())) {
+ if (reader.hasNext()) {
+ reader.next();
+ }
+ return authenticationConfiguration;
+ }
+
+ }
+ if (reader.hasNext()) {
+ event = reader.next();
+ } else {
+ return authenticationConfiguration;
+ }
+ }
+ }
+
+ public void write(AuthenticationConfigurationPolicy model, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException {
+ // TODO Auto-generated method stub
+ }
+
+ public void resolve(AuthenticationConfigurationPolicy model, ModelResolver resolver) throws ContributionResolveException {
+
+ }
+
+}
diff --git a/branches/sca-java-1.x/modules/policy-security-http/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/branches/sca-java-1.x/modules/policy-security-http/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor
index bd44ec8681..65605d69fe 100644
--- a/branches/sca-java-1.x/modules/policy-security-http/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor
+++ b/branches/sca-java-1.x/modules/policy-security-http/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor
@@ -16,4 +16,5 @@
# under the License.
# Implementation class for the artifact processor extension
-org.apache.tuscany.sca.policy.confidentiality.ConfidentialityPolicyProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.0#confidentiality,model=org.apache.tuscany.sca.policy.confidentiality.ConfidentialityPolicy \ No newline at end of file
+org.apache.tuscany.sca.policy.confidentiality.ConfidentialityPolicyProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.0#confidentiality,model=org.apache.tuscany.sca.policy.confidentiality.ConfidentialityPolicy
+org.apache.tuscany.sca.policy.authentication.AuthenticationConfigurationPolicyProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.0#authenticationConfiguration,model=org.apache.tuscany.sca.policy.authentication.AuthenticationConfigurationPolicy