Author: jverhaeg(a)redhat.com
Date: 2008-08-06 15:23:19 -0400 (Wed, 06 Aug 2008)
New Revision: 392
Modified:
trunk/dna-spi/src/main/java/org/jboss/dna/spi/ExecutionContext.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/ExecutionContextFactory.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/ExecutionContexts.java
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/connection/BasicExecutionContext.java
trunk/pom.xml
Log:
DNA-193: Added methods to ExecutionContext, ExecutionContextFactory, and implementations
to support JAAS login and access control contexts.
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/ExecutionContext.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/ExecutionContext.java 2008-08-06
19:06:37 UTC (rev 391)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/ExecutionContext.java 2008-08-06
19:23:19 UTC (rev 392)
@@ -21,7 +21,9 @@
*/
package org.jboss.dna.spi;
+import java.security.AccessControlContext;
import javax.security.auth.Subject;
+import javax.security.auth.login.LoginContext;
import org.jboss.dna.spi.graph.NamespaceRegistry;
import org.jboss.dna.spi.graph.Property;
import org.jboss.dna.spi.graph.PropertyFactory;
@@ -29,10 +31,21 @@
/**
* @author Randall Hauch
+ * @author John Verhaeg
*/
public interface ExecutionContext {
/**
+ * @return the access control context; may be <code>null</code>
+ */
+ AccessControlContext getAccessControlContext();
+
+ /**
+ * @return the login context; may be <code>null</code>
+ */
+ LoginContext getLoginContext();
+
+ /**
* Get the factories that should be used to create values for {@link Property
properties}.
*
* @return the property value factory; never null
@@ -59,5 +72,4 @@
* @return the subject; never null
*/
Subject getSubject();
-
}
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/ExecutionContextFactory.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/ExecutionContextFactory.java 2008-08-06
19:06:37 UTC (rev 391)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/ExecutionContextFactory.java 2008-08-06
19:23:19 UTC (rev 392)
@@ -21,6 +21,8 @@
*/
package org.jboss.dna.spi;
+import java.security.AccessControlContext;
+import java.security.AccessController;
import javax.security.auth.Subject;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.login.LoginContext;
@@ -28,14 +30,33 @@
import javax.security.auth.spi.LoginModule;
/**
- * A factory for creating {@link ExecutionContext} instances. Each execution context is
affiliated with a JAAS
- * {@link Subject}, and thus the factory methods take the same parameters that the JAAS
{@link LoginContext} take.
+ * A factory for creating {@link ExecutionContext} instances. Each execution context is
affiliated with a JAAS {@link Subject},
+ * and thus the factory methods take the same parameters that the JAAS {@link
LoginContext} take.
*
* @author Randall Hauch
+ * @author John Verhaeg
*/
public interface ExecutionContextFactory {
/**
+ * Creates an {@link ExecutionContext} using a snapshot of the {@link
AccessControlContext access control context} obtained
+ * from the current calling context.
+ *
+ * @return the execution context; never <code>null</code>.
+ * @see AccessController#getContext()
+ */
+ ExecutionContext create();
+
+ /**
+ * Creates an {@link ExecutionContext} using the supplied {@link AccessControlContext
access control context}.
+ *
+ * @param accessControlContext An access control context.
+ * @return the execution context; never <code>null</code>.
+ * @throws IllegalArgumentException if <code>accessControlContext</code>
is <code>null</code>.
+ */
+ ExecutionContext create( AccessControlContext accessControlContext );
+
+ /**
* Create an {@link ExecutionContext} for the supplied {@link LoginContext}.
*
* @param loginContext the JAAS login context
@@ -62,7 +83,7 @@
* unknown
*/
ExecutionContext create( String name,
- Subject subject ) throws LoginException;
+ Subject subject ) throws LoginException;
/**
* @param name the name of the JAAS login context
@@ -72,7 +93,7 @@
* <code>callbackHandler</code> is null
*/
ExecutionContext create( String name,
- CallbackHandler callbackHandler ) throws
LoginException;
+ CallbackHandler callbackHandler ) throws LoginException;
/**
* @param name the name of the JAAS login context
@@ -84,7 +105,7 @@
* or if the <code>callbackHandler</code> is null
*/
ExecutionContext create( String name,
- Subject subject,
- CallbackHandler callbackHandler ) throws
LoginException;
+ Subject subject,
+ CallbackHandler callbackHandler ) throws LoginException;
}
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/ExecutionContexts.java
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/ExecutionContexts.java 2008-08-06
19:06:37 UTC (rev 391)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/ExecutionContexts.java 2008-08-06
19:23:19 UTC (rev 392)
@@ -21,7 +21,9 @@
*/
package org.jboss.dna.spi;
+import java.security.AccessControlContext;
import javax.security.auth.Subject;
+import javax.security.auth.login.LoginContext;
import org.jboss.dna.common.util.ArgCheck;
import org.jboss.dna.spi.graph.NameFactory;
import org.jboss.dna.spi.graph.NamespaceRegistry;
@@ -34,6 +36,7 @@
* Utility methods for creating various execution contexts with replacement factories or
components.
*
* @author Randall Hauch
+ * @author John Verhaeg
*/
public class ExecutionContexts {
@@ -146,6 +149,24 @@
/**
* {@inheritDoc}
*
+ * @see org.jboss.dna.spi.ExecutionContext#getAccessControlContext()
+ */
+ public AccessControlContext getAccessControlContext() {
+ return delegate.getAccessControlContext();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.ExecutionContext#getLoginContext()
+ */
+ public LoginContext getLoginContext() {
+ return delegate.getLoginContext();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
* @see org.jboss.dna.spi.ExecutionContext#getNamespaceRegistry()
*/
public NamespaceRegistry getNamespaceRegistry() {
@@ -188,6 +209,5 @@
protected ExecutionContext getDelegate() {
return delegate;
}
-
}
}
Modified:
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/connection/BasicExecutionContext.java
===================================================================
---
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/connection/BasicExecutionContext.java 2008-08-06
19:06:37 UTC (rev 391)
+++
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/connection/BasicExecutionContext.java 2008-08-06
19:23:19 UTC (rev 392)
@@ -21,7 +21,10 @@
*/
package org.jboss.dna.spi.graph.connection;
+import java.security.AccessControlContext;
+import java.security.AccessController;
import javax.security.auth.Subject;
+import javax.security.auth.login.LoginContext;
import org.jboss.dna.common.util.ArgCheck;
import org.jboss.dna.spi.ExecutionContext;
import org.jboss.dna.spi.graph.NamespaceRegistry;
@@ -33,44 +36,76 @@
/**
* @author Randall Hauch
+ * @author John Verhaeg
*/
public class BasicExecutionContext implements ExecutionContext {
+ private final LoginContext loginContext;
+ private final AccessControlContext accessControlContext;
private final Subject subject;
private final PropertyFactory propertyFactory;
private final ValueFactories valueFactories;
private final NamespaceRegistry namespaceRegistry;
public BasicExecutionContext() {
- this(new Subject(), new BasicNamespaceRegistry());
+ this(new BasicNamespaceRegistry());
}
public BasicExecutionContext( NamespaceRegistry namespaceRegistry ) {
- this(new Subject(), namespaceRegistry, null, null);
+ this(namespaceRegistry, null, null);
}
- public BasicExecutionContext( NamespaceRegistry namespaceRegistry,
- ValueFactories valueFactories,
- PropertyFactory propertyFactory ) {
- this(new Subject(), namespaceRegistry, valueFactories, propertyFactory);
+ public BasicExecutionContext( LoginContext loginContext ) {
+ this(loginContext, new BasicNamespaceRegistry());
}
- public BasicExecutionContext( Subject subject ) {
- this(subject, new BasicNamespaceRegistry());
+ public BasicExecutionContext( AccessControlContext accessControlContext ) {
+ this(accessControlContext, new BasicNamespaceRegistry());
}
- public BasicExecutionContext( Subject subject,
+ public BasicExecutionContext( LoginContext loginContext,
NamespaceRegistry namespaceRegistry ) {
- this(subject, namespaceRegistry, null, null);
+ this(loginContext, namespaceRegistry, null, null);
}
- public BasicExecutionContext( Subject subject,
+ public BasicExecutionContext( AccessControlContext accessControlContext,
+ NamespaceRegistry namespaceRegistry ) {
+ this(accessControlContext, namespaceRegistry, null, null);
+ }
+
+ public BasicExecutionContext( NamespaceRegistry namespaceRegistry,
+ ValueFactories valueFactories,
+ PropertyFactory propertyFactory ) {
+ this(null, null, namespaceRegistry, valueFactories, propertyFactory);
+ }
+
+ public BasicExecutionContext( LoginContext loginContext,
NamespaceRegistry namespaceRegistry,
ValueFactories valueFactories,
PropertyFactory propertyFactory ) {
- ArgCheck.isNotNull(subject, "subject");
- ArgCheck.isNotNull(namespaceRegistry, "namespace registry");
- this.subject = subject;
+ this(loginContext, null, namespaceRegistry, valueFactories, propertyFactory);
+ }
+
+ public BasicExecutionContext( AccessControlContext accessControlContext,
+ NamespaceRegistry namespaceRegistry,
+ ValueFactories valueFactories,
+ PropertyFactory propertyFactory ) {
+ this(null, accessControlContext, namespaceRegistry, valueFactories,
propertyFactory);
+ }
+
+ private BasicExecutionContext( LoginContext loginContext,
+ AccessControlContext accessControlContext,
+ NamespaceRegistry namespaceRegistry,
+ ValueFactories valueFactories,
+ PropertyFactory propertyFactory ) {
+ ArgCheck.isNotNull(namespaceRegistry, "namespaceRegistry");
+ this.loginContext = loginContext;
+ this.accessControlContext = accessControlContext;
+ if (loginContext == null) {
+ this.subject = Subject.getSubject(accessControlContext == null ?
AccessController.getContext() : accessControlContext);
+ } else {
+ this.subject = loginContext.getSubject();
+ }
this.namespaceRegistry = namespaceRegistry;
this.valueFactories = valueFactories != null ? valueFactories : new
StandardValueFactories(this.namespaceRegistry);
this.propertyFactory = propertyFactory != null ? propertyFactory : new
BasicPropertyFactory(this.valueFactories);
@@ -78,23 +113,34 @@
/**
* {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.ExecutionContext#getAccessControlContext()
*/
- public NamespaceRegistry getNamespaceRegistry() {
- return this.namespaceRegistry;
+ public AccessControlContext getAccessControlContext() {
+ return accessControlContext;
}
/**
* {@inheritDoc}
+ *
+ * @see org.jboss.dna.spi.ExecutionContext#getLoginContext()
*/
- public ValueFactories getValueFactories() {
- return this.valueFactories;
+ public LoginContext getLoginContext() {
+ return loginContext;
}
/**
* {@inheritDoc}
*/
+ public NamespaceRegistry getNamespaceRegistry() {
+ return namespaceRegistry;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public PropertyFactory getPropertyFactory() {
- return this.propertyFactory;
+ return propertyFactory;
}
/**
@@ -103,6 +149,13 @@
* @see org.jboss.dna.spi.ExecutionContext#getSubject()
*/
public Subject getSubject() {
- return this.subject;
+ return subject;
}
+
+ /**
+ * {@inheritDoc}
+ */
+ public ValueFactories getValueFactories() {
+ return valueFactories;
+ }
}
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2008-08-06 19:06:37 UTC (rev 391)
+++ trunk/pom.xml 2008-08-06 19:23:19 UTC (rev 392)
@@ -343,6 +343,11 @@
<artifactId>dna-repository</artifactId>
<version>${dna-version}</version>
</dependency>
+ <dependency>
+ <groupId>org.jboss.dna</groupId>
+ <artifactId>dna-jcr</artifactId>
+ <version>${dna-version}</version>
+ </dependency>
<dependency>
<groupId>org.jboss.dna</groupId>
<artifactId>dna-connector-federation</artifactId>