Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Auth roles common validation and initialization cleanup #259

Merged
merged 2 commits into from

2 participants

@bbpennel
Collaborator

No description provided.

@gregjan gregjan merged commit d887b21 into fcrepo4:master

1 check passed

Details default The Travis CI build passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
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();
- }
}
Something went wrong with that request. Please try again.