Author: jverhaeg(a)redhat.com
Date: 2008-09-16 16:26:44 -0400 (Tue, 16 Sep 2008)
New Revision: 522
Modified:
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRepository.java
trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java
trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrRepositoryTest.java
Log:
Fixed problem in repository that assumed a login context was available from the execution
context. This allows for skipping authentication if JAAS hasn't been configured.
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRepository.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRepository.java 2008-09-16 19:03:58
UTC (rev 521)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRepository.java 2008-09-16 20:26:44
UTC (rev 522)
@@ -245,13 +245,15 @@
throw new RepositoryException(error);
}
}
- // Authenticate
- try {
- assert execContext != null;
- assert execContext.getLoginContext() != null;
- execContext.getLoginContext().login();
- } catch (javax.security.auth.login.LoginException error) {
- throw new LoginException(error);
+ // Authenticate if possible
+ assert execContext != null;
+ LoginContext loginContext = execContext.getLoginContext();
+ if (loginContext != null) {
+ try {
+ loginContext.login();
+ } catch (javax.security.auth.login.LoginException error) {
+ throw new LoginException(error);
+ }
}
// Ensure valid workspace name
if (workspaceName == null) workspaceName = JcrI18n.defaultWorkspaceName.text();
Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java 2008-09-16 19:03:58 UTC
(rev 521)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrSession.java 2008-09-16 20:26:44 UTC
(rev 522)
@@ -45,6 +45,7 @@
import javax.jcr.ValueFactory;
import javax.jcr.Workspace;
import javax.security.auth.Subject;
+import javax.security.auth.login.LoginContext;
import javax.security.auth.login.LoginException;
import net.jcip.annotations.NotThreadSafe;
import org.jboss.dna.common.util.ArgCheck;
@@ -487,17 +488,20 @@
if (!isLive()) {
return;
}
- try {
- if (connection != null) {
- connection.close();
- connection = null;
+ if (connection != null) {
+ connection.close();
+ connection = null;
+ }
+ LoginContext loginContext = executionContext.getLoginContext();
+ if (loginContext != null) {
+ try {
+ loginContext.logout();
+ } catch (LoginException error) {
+ // TODO: Change to DnaException once DNA-180 is addressed
+ throw new RuntimeException(error);
}
- assert executionContext.getLoginContext() != null;
- executionContext.getLoginContext().logout();
- isLive = false;
- } catch (LoginException error) {
- // TODO; Log error
}
+ isLive = false;
}
/**
Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrRepositoryTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrRepositoryTest.java 2008-09-16
19:03:58 UTC (rev 521)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrRepositoryTest.java 2008-09-16
20:26:44 UTC (rev 522)
@@ -77,7 +77,6 @@
@Before
public void before() throws Exception {
MockitoAnnotations.initMocks(this);
- stub(executionContext.getLoginContext()).toReturn(loginContext);
stub(executionContextFactory.create()).toReturn(executionContext);
stub(executionContextFactory.create(accessControlContext)).toReturn(executionContext);
stub(connectionFactory.createConnection(JcrI18n.defaultWorkspaceName.text())).toReturn(connection);
Show replies by date