Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
  • 3 commits
  • 4 files changed
  • 0 commit comments
  • 2 contributors
View
7 fcrepo-auth-roles-common/src/main/java/org/fcrepo/auth/roles/common/AccessRoles.java
@@ -137,11 +137,7 @@ public Response post(@PathParam("path")
try {
validatePOST(data);
- } catch (final IllegalArgumentException e) {
- throw new WebApplicationException(e, Response.status(Status.BAD_REQUEST).build());
- }
- try {
final FedoraResource resource =
nodeService.getObject(session, path);
this.getAccessRolesProvider().postRoles(resource.getNode(), data);
@@ -150,6 +146,9 @@ public Response post(@PathParam("path")
response =
Response.created(getUriInfo().getBaseUriBuilder()
.path(path).path("fcr:accessroles").build());
+
+ } catch (final IllegalArgumentException e) {
+ throw new WebApplicationException(e, Response.status(Status.BAD_REQUEST).build());
} finally {
session.logout();
}
View
57 fcrepo-auth-roles-common/src/main/java/org/fcrepo/auth/roles/common/AccessRolesTypes.java
@@ -42,11 +42,7 @@
.getLogger(AccessRolesTypes.class);
@Autowired
- private SessionFactory sessionFactory = null;
-
- private static boolean registered = false;
-
- private static final Object mutex = new Object();
+ private final SessionFactory sessionFactory = null;
/**
* Initialize, register role assignment node types.
@@ -57,38 +53,31 @@
@PostConstruct
public void setUpRepositoryConfiguration() throws RepositoryException,
IOException {
- if (!registered) {
- registerNodeTypes(sessionFactory);
- }
+ registerNodeTypes(sessionFactory);
}
- private static void registerNodeTypes(final SessionFactory sessions)
+ private void registerNodeTypes(final SessionFactory sessions)
throws RepositoryException, IOException {
- synchronized (mutex) {
- if (!registered) {
- Session session = null;
- try {
- session = sessions.getInternalSession();
- final NodeTypeManager mgr =
- (NodeTypeManager) session.getWorkspace()
- .getNodeTypeManager();
- final URL cnd =
- AccessRoles.class
- .getResource("/cnd/access-control.cnd");
- final NodeTypeIterator nti =
- mgr.registerNodeTypes(cnd, true);
- while (nti.hasNext()) {
- final NodeType nt = nti.nextNodeType();
- LOGGER.debug("registered node type: {}", nt.getName());
- }
- session.save();
- registered = true;
- LOGGER.debug("Registered access role node types");
- } finally {
- if (session != null) {
- session.logout();
- }
- }
+ Session session = null;
+ try {
+ session = sessions.getInternalSession();
+ final NodeTypeManager mgr =
+ (NodeTypeManager) session.getWorkspace()
+ .getNodeTypeManager();
+ final URL cnd =
+ AccessRoles.class
+ .getResource("/cnd/access-control.cnd");
+ final NodeTypeIterator nti =
+ mgr.registerNodeTypes(cnd, true);
+ while (nti.hasNext()) {
+ final NodeType nt = nti.nextNodeType();
+ LOGGER.debug("registered node type: {}", nt.getName());
+ }
+ session.save();
+ LOGGER.debug("Registered access role node types");
+ } finally {
+ if (session != null) {
+ session.logout();
}
}
}
View
3  fcrepo-auth-roles-common/src/test/java/org/fcrepo/auth/roles/common/AccessRolesTest.java
@@ -227,8 +227,7 @@ private void invalidPost(final Map<String, Set<String>> data)
Matchers.<Map<String, Set<String>>> any());
// Verify no changes saved
verify(session, never()).save();
- // Logout does not currently happen when the post is invalid
- verify(session, never()).logout();
+ verify(session).logout();
}
}
View
31 ...po-auth-roles-common/src/test/java/org/fcrepo/auth/roles/common/AccessRolesTypesTest.java
@@ -20,13 +20,11 @@
import static org.mockito.Matchers.anyBoolean;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;
import java.io.IOException;
-import java.lang.reflect.Field;
import java.net.URL;
import javax.jcr.RepositoryException;
@@ -90,18 +88,6 @@ public void setUp() throws RepositoryException, NoSuchFieldException,
setField(accessRolesTypes, "sessionFactory", sessionFactory);
when(sessionFactory.getInternalSession()).thenReturn(session);
-
- // Ugly zone, reset private static flag between tests
- final Field registeredField =
- AccessRolesTypes.class.getDeclaredField("registered");
- registeredField.setAccessible(true);
- try {
- registeredField.setBoolean(registeredField, false);
- } catch (final IllegalArgumentException e) {
- LOGGER.error("Reflection error", e);
- } catch (final IllegalAccessException e) {
- LOGGER.error("Reflection error", e);
- }
}
@Test(expected = RepositoryException.class)
@@ -145,21 +131,4 @@ public void testSetupRepoConfig() throws RepositoryException, IOException {
verify(session).save();
verify(session).logout();
}
-
- @Test
- public void testSetupRepoConfigAlreadyRegistered()
- throws RepositoryException, IOException {
- accessRolesTypes.setUpRepositoryConfiguration();
-
- // Clear verify counts
- reset(nodeTypeManager);
- reset(session);
-
- accessRolesTypes.setUpRepositoryConfiguration();
-
- verify(nodeTypeManager, never()).registerNodeTypes(any(URL.class),
- anyBoolean());
- verify(session, never()).save();
- verify(session, never()).logout();
- }
}

No commit comments for this range

Something went wrong with that request. Please try again.