ConceptCollectionRestAuthorization implements IAuthorization { @Override public boolean chkAuthorization(String userName, Object conceptCollectionObj, String[] userRoles) throws QuadrigaStorageException, QuadrigaAccessException { IConceptCollection collection; if (conceptCollectionObj instanceof String) { String conceptCollectionId = (String) conceptCollectionObj; collection = conceptCollectionManager.getConceptCollection(conceptCollectionId); } else { try { collection = (IConceptCollection) conceptCollectionObj; } catch (ClassCastException cce) { throw new IllegalObjectException(cce); } } String conceptCollectionOwner = collection.getOwner().getUserName(); if (userName.equals(conceptCollectionOwner)) { return true; } if (userRoles.length == 0) { return false; } List<String> roles = Arrays.asList(userRoles); List<IConceptCollectionCollaborator> ccCollaboratorList = conceptCollectionManager .showCollaboratingUsers(collection.getConceptCollectionId()); if (ccCollaboratorList == null || ccCollaboratorList.isEmpty()) { return false; } for (IConceptCollectionCollaborator ccCollaborator : ccCollaboratorList) { String collaboratorName = ccCollaborator.getCollaborator().getUserObj().getUserName(); if (userName != null) { if (userName.equals(collaboratorName)) { List<IQuadrigaRole> collaboratorRoles = ccCollaborator.getCollaborator().getCollaboratorRoles(); if (collaboratorRoles != null) { for (IQuadrigaRole collabRole : collaboratorRoles) { String collaboratorRoleId = collabRole.getId(); if (roles != null) { if (roles.contains(collaboratorRoleId)) { return true; } } } } } } } return false; }  @Override boolean chkAuthorization(String userName, Object conceptCollectionObj, String[] userRoles); @Override boolean chkAuthorizationByRole(String userName, String[] userRoles); @Override boolean chkAuthorization(String userName, List<String> accessObjectId, String[] userRoles);  }
@Test public void testChkAuthorizationIsOwner() throws QuadrigaStorageException, QuadrigaAccessException { boolean authorized = authorization.chkAuthorization("testuser", "collectionid", new String[] { "" }); assertTrue(authorized); }
@Test public void testChkAuthorizationHasValidRole() throws QuadrigaStorageException, QuadrigaAccessException { boolean authorized = authorization.chkAuthorization("collabuser", "collectionid", new String[] { "role1" }); assertTrue(authorized); }
@Test public void testChkAuthorizationHasNoValidRole() throws QuadrigaStorageException, QuadrigaAccessException { boolean authorized = authorization.chkAuthorization("collabuser", "collectionid", new String[] { "role2" }); assertFalse(authorized); }
@Test public void testChkAuthorizationIsNotCollaborator() throws QuadrigaStorageException, QuadrigaAccessException { boolean authorized = authorization.chkAuthorization("testuser2", "collectionid", new String[] { "role1" }); assertFalse(authorized); }