diff options
Diffstat (limited to 'java/sca/modules/policy-security/src')
5 files changed, 36 insertions, 37 deletions
diff --git a/java/sca/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/authentication/basic/BasicAuthenticationPolicyProcessor.java b/java/sca/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/authentication/basic/BasicAuthenticationPolicyProcessor.java index 99a8508ba4..3df06c1e00 100644 --- a/java/sca/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/authentication/basic/BasicAuthenticationPolicyProcessor.java +++ b/java/sca/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/authentication/basic/BasicAuthenticationPolicyProcessor.java @@ -29,10 +29,10 @@ import javax.xml.stream.XMLStreamWriter; import org.apache.tuscany.sca.contribution.processor.ContributionReadException; import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; import org.apache.tuscany.sca.contribution.processor.ContributionWriteException; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; import org.apache.tuscany.sca.core.FactoryExtensionPoint; -import org.apache.tuscany.sca.monitor.Monitor; /** * @@ -45,11 +45,11 @@ public class BasicAuthenticationPolicyProcessor implements StAXArtifactProcessor return BasicAuthenticationPolicy.BASIC_AUTHENTICATION_POLICY_QNAME; } - public BasicAuthenticationPolicyProcessor(FactoryExtensionPoint modelFactories, Monitor monitor) { + public BasicAuthenticationPolicyProcessor(FactoryExtensionPoint modelFactories) { } - public BasicAuthenticationPolicy read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + public BasicAuthenticationPolicy read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException { BasicAuthenticationPolicy policy = new BasicAuthenticationPolicy(); int event = reader.getEventType(); QName name = null; @@ -85,7 +85,7 @@ public class BasicAuthenticationPolicyProcessor implements StAXArtifactProcessor return policy; } - public void write(BasicAuthenticationPolicy policy, XMLStreamWriter writer) + public void write(BasicAuthenticationPolicy policy, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, XMLStreamException { String prefix = "tuscany"; writer.writeStartElement(prefix, @@ -116,7 +116,7 @@ public class BasicAuthenticationPolicyProcessor implements StAXArtifactProcessor return BasicAuthenticationPolicy.class; } - public void resolve(BasicAuthenticationPolicy arg0, ModelResolver arg1) throws ContributionResolveException { + public void resolve(BasicAuthenticationPolicy arg0, ModelResolver arg1, ProcessorContext context) throws ContributionResolveException { } diff --git a/java/sca/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/authorization/AuthorizationPolicyProcessor.java b/java/sca/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/authorization/AuthorizationPolicyProcessor.java index d78c0fc2e3..8a65a10560 100644 --- a/java/sca/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/authorization/AuthorizationPolicyProcessor.java +++ b/java/sca/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/authorization/AuthorizationPolicyProcessor.java @@ -31,6 +31,7 @@ import javax.xml.stream.XMLStreamWriter; import org.apache.tuscany.sca.contribution.processor.ContributionReadException; import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; import org.apache.tuscany.sca.contribution.processor.ContributionWriteException; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; import org.apache.tuscany.sca.core.FactoryExtensionPoint; @@ -44,14 +45,12 @@ import org.apache.tuscany.sca.monitor.Problem.Severity; */ public class AuthorizationPolicyProcessor implements StAXArtifactProcessor<AuthorizationPolicy> { private static final String ROLES = "roles"; - private Monitor monitor; public QName getArtifactType() { return AuthorizationPolicy.NAME; } - public AuthorizationPolicyProcessor(FactoryExtensionPoint modelFactories, Monitor monitor) { - this.monitor = monitor; + public AuthorizationPolicyProcessor(FactoryExtensionPoint modelFactories) { } /** @@ -61,14 +60,14 @@ public class AuthorizationPolicyProcessor implements StAXArtifactProcessor<Autho * @param message * @param model */ - private void error(String message, Object model, Object... messageParameters) { + private void error(Monitor monitor, String message, Object model, Object... messageParameters) { if (monitor != null) { Problem problem = monitor.createProblem(this.getClass().getName(), "policy-security-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters); monitor.problem(problem); } } - public AuthorizationPolicy read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + public AuthorizationPolicy read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException { AuthorizationPolicy policy = new AuthorizationPolicy(); int event = reader.getEventType(); QName start = reader.getName(); @@ -80,7 +79,7 @@ public class AuthorizationPolicyProcessor implements StAXArtifactProcessor<Autho policy.setAccessControl(AuthorizationPolicy.AcessControl.allow); String roleNames = reader.getAttributeValue(null, ROLES); if (roleNames == null) { - error("RequiredAttributeRolesMissing", reader); + error(context.getMonitor(), "RequiredAttributeRolesMissing", reader); //throw new IllegalArgumentException("Required attribute 'roles' is missing."); } else { StringTokenizer st = new StringTokenizer(roleNames); @@ -111,7 +110,7 @@ public class AuthorizationPolicyProcessor implements StAXArtifactProcessor<Autho } } - public void write(AuthorizationPolicy policy, XMLStreamWriter writer) throws ContributionWriteException, + public void write(AuthorizationPolicy policy, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, XMLStreamException { writer.writeStartElement(AuthorizationPolicy.NAME.getLocalPart()); @@ -136,7 +135,7 @@ public class AuthorizationPolicyProcessor implements StAXArtifactProcessor<Autho return AuthorizationPolicy.class; } - public void resolve(AuthorizationPolicy policy, ModelResolver resolver) throws ContributionResolveException { + public void resolve(AuthorizationPolicy policy, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { if ((policy.getAccessControl() == AuthorizationPolicy.AcessControl.allow) && (policy.getRoleNames().isEmpty())){ diff --git a/java/sca/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/identity/SecurityIdentityPolicyProcessor.java b/java/sca/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/identity/SecurityIdentityPolicyProcessor.java index 0ccda91364..3c91b9fbcf 100644 --- a/java/sca/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/identity/SecurityIdentityPolicyProcessor.java +++ b/java/sca/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/identity/SecurityIdentityPolicyProcessor.java @@ -29,6 +29,7 @@ import javax.xml.stream.XMLStreamWriter; import org.apache.tuscany.sca.contribution.processor.ContributionReadException; import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; import org.apache.tuscany.sca.contribution.processor.ContributionWriteException; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; import org.apache.tuscany.sca.core.FactoryExtensionPoint; @@ -42,14 +43,12 @@ import org.apache.tuscany.sca.monitor.Problem.Severity; */ public class SecurityIdentityPolicyProcessor implements StAXArtifactProcessor<SecurityIdentityPolicy> { private static final String ROLE = "role"; - private Monitor monitor; public QName getArtifactType() { return SecurityIdentityPolicy.NAME; } - public SecurityIdentityPolicyProcessor(FactoryExtensionPoint modelFactories, Monitor monitor) { - this.monitor = monitor; + public SecurityIdentityPolicyProcessor(FactoryExtensionPoint modelFactories) { } /** @@ -59,14 +58,14 @@ public class SecurityIdentityPolicyProcessor implements StAXArtifactProcessor<Se * @param message * @param model */ - private void error(String message, Object model, Object... messageParameters) { + private void error(Monitor monitor, String message, Object model, Object... messageParameters) { if (monitor != null) { Problem problem = monitor.createProblem(this.getClass().getName(), "policy-security-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters); monitor.problem(problem); } } - public SecurityIdentityPolicy read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + public SecurityIdentityPolicy read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException { SecurityIdentityPolicy policy = new SecurityIdentityPolicy(); int event = reader.getEventType(); QName start = reader.getName(); @@ -77,7 +76,7 @@ public class SecurityIdentityPolicyProcessor implements StAXArtifactProcessor<Se if ("runAs".equals(ac)) { String roleName = reader.getAttributeValue(null, ROLE); if (roleName == null) { - error("RequiredAttributeRolesMissing", reader); + error(context.getMonitor(), "RequiredAttributeRolesMissing", reader); //throw new IllegalArgumentException("Required attribute 'roles' is missing."); } else { policy.setRunAsRole(roleName); @@ -103,7 +102,7 @@ public class SecurityIdentityPolicyProcessor implements StAXArtifactProcessor<Se } } - public void write(SecurityIdentityPolicy policy, XMLStreamWriter writer) throws ContributionWriteException, + public void write(SecurityIdentityPolicy policy, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, XMLStreamException { writer.writeStartElement(SecurityIdentityPolicy.NAME.getLocalPart()); @@ -122,7 +121,7 @@ public class SecurityIdentityPolicyProcessor implements StAXArtifactProcessor<Se return SecurityIdentityPolicy.class; } - public void resolve(SecurityIdentityPolicy policy, ModelResolver resolver) throws ContributionResolveException { + public void resolve(SecurityIdentityPolicy policy, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { if (policy.getRunAsRole() != null) //right now nothing to resolve diff --git a/java/sca/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/security/jaas/JaasAuthenticationPolicyProcessor.java b/java/sca/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/security/jaas/JaasAuthenticationPolicyProcessor.java index 615e8bf5a3..b9ab68aa2f 100644 --- a/java/sca/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/security/jaas/JaasAuthenticationPolicyProcessor.java +++ b/java/sca/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/security/jaas/JaasAuthenticationPolicyProcessor.java @@ -29,6 +29,7 @@ import javax.xml.stream.XMLStreamWriter; import org.apache.tuscany.sca.contribution.processor.ContributionReadException; import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; import org.apache.tuscany.sca.contribution.processor.ContributionWriteException; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; import org.apache.tuscany.sca.contribution.resolver.ClassReference; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; @@ -47,14 +48,13 @@ public class JaasAuthenticationPolicyProcessor implements StAXArtifactProcessor< private static final String SCA10_TUSCANY_NS = "http://tuscany.apache.org/xmlns/sca/1.1"; public static final QName CALLBACK_HANDLER_QNAME = new QName(SCA10_TUSCANY_NS, callbackHandler); public static final QName CONFIGURATION_QNAME = new QName(SCA10_TUSCANY_NS, "configurationName"); - private Monitor monitor; + public QName getArtifactType() { return JAAS_AUTHENTICATION_POLICY_QNAME; } - public JaasAuthenticationPolicyProcessor(FactoryExtensionPoint modelFactories, Monitor monitor) { - this.monitor = monitor; + public JaasAuthenticationPolicyProcessor(FactoryExtensionPoint modelFactories) { } /** @@ -64,14 +64,14 @@ public class JaasAuthenticationPolicyProcessor implements StAXArtifactProcessor< * @param message * @param model */ - private void error(String message, Object model, Object... messageParameters) { + private void error(Monitor monitor, String message, Object model, Object... messageParameters) { if (monitor != null) { Problem problem = monitor.createProblem(this.getClass().getName(), "policy-security-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters); monitor.problem(problem); } } - public JaasAuthenticationPolicy read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + public JaasAuthenticationPolicy read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException { JaasAuthenticationPolicy policy = new JaasAuthenticationPolicy(); int event = reader.getEventType(); QName name = null; @@ -113,7 +113,7 @@ public class JaasAuthenticationPolicyProcessor implements StAXArtifactProcessor< return policy; } - public void write(JaasAuthenticationPolicy policy, XMLStreamWriter writer) throws ContributionWriteException, + public void write(JaasAuthenticationPolicy policy, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, XMLStreamException { String prefix = "tuscany"; writer.writeStartElement(prefix, @@ -129,14 +129,14 @@ public class JaasAuthenticationPolicyProcessor implements StAXArtifactProcessor< return JaasAuthenticationPolicy.class; } - public void resolve(JaasAuthenticationPolicy policy, ModelResolver resolver) throws ContributionResolveException { + public void resolve(JaasAuthenticationPolicy policy, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { if (policy.getCallbackHandlerClassName() != null) { ClassReference classReference = new ClassReference(policy.getCallbackHandlerClassName()); - classReference = resolver.resolveModel(ClassReference.class, classReference); + classReference = resolver.resolveModel(ClassReference.class, classReference, context); Class<?> callbackClass = classReference.getJavaClass(); if (callbackClass == null) { - error("ClassNotFoundException", resolver, policy.getCallbackHandlerClassName()); + error(context.getMonitor(), "ClassNotFoundException", resolver, policy.getCallbackHandlerClassName()); //throw new ContributionResolveException(new ClassNotFoundException(policy.getCallbackHandlerClassName())); } else { policy.setCallbackHandlerClass(callbackClass); diff --git a/java/sca/modules/policy-security/src/test/java/org/apache/tuscany/sca/policy/security/PolicyProcessorTestCase.java b/java/sca/modules/policy-security/src/test/java/org/apache/tuscany/sca/policy/security/PolicyProcessorTestCase.java index a1b790dbb4..0d8a5d5a9c 100644 --- a/java/sca/modules/policy-security/src/test/java/org/apache/tuscany/sca/policy/security/PolicyProcessorTestCase.java +++ b/java/sca/modules/policy-security/src/test/java/org/apache/tuscany/sca/policy/security/PolicyProcessorTestCase.java @@ -31,6 +31,7 @@ import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamConstants; import javax.xml.stream.XMLStreamReader; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; import org.apache.tuscany.sca.policy.authorization.AuthorizationPolicy; import org.apache.tuscany.sca.policy.authorization.AuthorizationPolicyProcessor; @@ -59,12 +60,12 @@ public class PolicyProcessorTestCase { public void testRead() throws Exception { List<String> results = new ArrayList<String>(); Map<QName, StAXArtifactProcessor> processors = new HashMap<QName, StAXArtifactProcessor>(); - processors.put(AuthorizationPolicy.NAME, new AuthorizationPolicyProcessor(null,null)); - processors.put(SecurityIdentityPolicy.NAME, new SecurityIdentityPolicyProcessor(null,null)); - processors.put(new QName(SCA11_NS, "allow"), new AuthorizationPolicyProcessor(null,null)); - processors.put(new QName(SCA11_NS, "permitAll"), new AuthorizationPolicyProcessor(null,null)); - processors.put(new QName(SCA11_NS, "denyAll"), new AuthorizationPolicyProcessor(null,null)); - processors.put(new QName(SCA11_NS, "runAs"), new SecurityIdentityPolicyProcessor(null,null)); + processors.put(AuthorizationPolicy.NAME, new AuthorizationPolicyProcessor(null)); + processors.put(SecurityIdentityPolicy.NAME, new SecurityIdentityPolicyProcessor(null)); + processors.put(new QName(SCA11_NS, "allow"), new AuthorizationPolicyProcessor(null)); + processors.put(new QName(SCA11_NS, "permitAll"), new AuthorizationPolicyProcessor(null)); + processors.put(new QName(SCA11_NS, "denyAll"), new AuthorizationPolicyProcessor(null)); + processors.put(new QName(SCA11_NS, "runAs"), new SecurityIdentityPolicyProcessor(null)); InputStream is = getClass().getResourceAsStream("mock_policy_definitions.xml"); XMLInputFactory factory = XMLInputFactory.newInstance(); XMLStreamReader reader = factory.createXMLStreamReader(is); @@ -73,7 +74,7 @@ public class PolicyProcessorTestCase { if (event == XMLStreamConstants.START_ELEMENT) { if ("policySet".equals(reader.getName().getLocalPart())) { reader.nextTag(); - results.add(processors.get(reader.getName()).read(reader).toString()); + results.add(processors.get(reader.getName()).read(reader, new ProcessorContext()).toString()); } } if (reader.hasNext()) { |