use of org.finra.herd.model.jpa.UserNamespaceAuthorizationEntity in project herd by FINRAOS.
the class UserNamespaceAuthorizationHelperTest method testBuildNamespaceAuthorizationsAssertAuthLookupByUserId.
@Test
public void testBuildNamespaceAuthorizationsAssertAuthLookupByUserId() {
ApplicationUser applicationUser = new ApplicationUser(getClass());
String userId = "userId";
applicationUser.setUserId(userId);
when(configurationHelper.getBooleanProperty(any())).thenReturn(true);
List<UserNamespaceAuthorizationEntity> userNamespaceAuthorizationEntities = new ArrayList<>();
UserNamespaceAuthorizationEntity userNamespaceAuthorizationEntity = new UserNamespaceAuthorizationEntity();
userNamespaceAuthorizationEntity.setUserId("userNamespaceAuthorizationEntityUserId");
NamespaceEntity namespaceEntity = new NamespaceEntity();
namespaceEntity.setCode("namespace");
userNamespaceAuthorizationEntity.setNamespace(namespaceEntity);
userNamespaceAuthorizationEntities.add(userNamespaceAuthorizationEntity);
when(userNamespaceAuthorizationDao.getUserNamespaceAuthorizationsByUserId(any())).thenReturn(userNamespaceAuthorizationEntities);
userNamespaceAuthorizationHelper.buildNamespaceAuthorizations(applicationUser);
assertEquals(1, applicationUser.getNamespaceAuthorizations().size());
NamespaceAuthorization namespaceAuthorization = IterableUtils.get(applicationUser.getNamespaceAuthorizations(), 0);
assertEquals(namespaceEntity.getCode(), namespaceAuthorization.getNamespace());
verify(userNamespaceAuthorizationDao).getUserNamespaceAuthorizationsByUserId(eq(userId));
verify(userNamespaceAuthorizationDao).getUserNamespaceAuthorizationsByUserIdStartsWith(eq(WildcardHelper.WILDCARD_TOKEN));
verifyNoMoreInteractions(userNamespaceAuthorizationDao, wildcardHelper);
}
use of org.finra.herd.model.jpa.UserNamespaceAuthorizationEntity in project herd by FINRAOS.
the class UserNamespaceAuthorizationHelperTest method testBuildNamespaceAuthorizationsAssertWildcardEntityNotAddedIfMatchFails.
@Test
public void testBuildNamespaceAuthorizationsAssertWildcardEntityNotAddedIfMatchFails() {
ApplicationUser applicationUser = new ApplicationUser(getClass());
String userId = "userId";
applicationUser.setUserId(userId);
when(configurationHelper.getBooleanProperty(any())).thenReturn(true);
List<UserNamespaceAuthorizationEntity> wildcardEntities = new ArrayList<>();
UserNamespaceAuthorizationEntity wildcardEntity = new UserNamespaceAuthorizationEntity();
wildcardEntity.setUserId("wildcardEntityUserId");
NamespaceEntity namespaceEntity = new NamespaceEntity();
namespaceEntity.setCode("namespace");
wildcardEntity.setNamespace(namespaceEntity);
wildcardEntities.add(wildcardEntity);
when(userNamespaceAuthorizationDao.getUserNamespaceAuthorizationsByUserIdStartsWith(any())).thenReturn(wildcardEntities);
when(wildcardHelper.matches(any(), any())).thenReturn(false);
userNamespaceAuthorizationHelper.buildNamespaceAuthorizations(applicationUser);
assertEquals(0, applicationUser.getNamespaceAuthorizations().size());
verify(userNamespaceAuthorizationDao).getUserNamespaceAuthorizationsByUserId(eq(userId));
verify(userNamespaceAuthorizationDao).getUserNamespaceAuthorizationsByUserIdStartsWith(eq(WildcardHelper.WILDCARD_TOKEN));
verify(wildcardHelper).matches(eq(userId.toUpperCase()), eq(wildcardEntity.getUserId().toUpperCase()));
verifyNoMoreInteractions(userNamespaceAuthorizationDao, wildcardHelper);
}
use of org.finra.herd.model.jpa.UserNamespaceAuthorizationEntity in project herd by FINRAOS.
the class UserNamespaceAuthorizationDaoTest method testGetUserNamespaceAuthorizationsByUserId.
@Test
public void testGetUserNamespaceAuthorizationsByUserId() {
// Create user namespace authorization keys. The keys are listed out of order to validate the order by logic.
List<UserNamespaceAuthorizationKey> keys = Arrays.asList(new UserNamespaceAuthorizationKey(USER_ID_2, NAMESPACE_2), new UserNamespaceAuthorizationKey(USER_ID_2, NAMESPACE), new UserNamespaceAuthorizationKey(USER_ID, NAMESPACE_2), new UserNamespaceAuthorizationKey(USER_ID, NAMESPACE));
// Create and persist the relative database entities.
List<UserNamespaceAuthorizationEntity> userNamespaceAuthorizationEntities = new ArrayList<>();
for (UserNamespaceAuthorizationKey key : keys) {
userNamespaceAuthorizationEntities.add(userNamespaceAuthorizationDaoTestHelper.createUserNamespaceAuthorizationEntity(key, SUPPORTED_NAMESPACE_PERMISSIONS));
}
// Get user namespace authorizations by user id.
assertEquals(Arrays.asList(userNamespaceAuthorizationEntities.get(3), userNamespaceAuthorizationEntities.get(2)), userNamespaceAuthorizationDao.getUserNamespaceAuthorizationsByUserId(USER_ID));
// Test case insensitivity of the user id input parameter.
assertEquals(Arrays.asList(userNamespaceAuthorizationEntities.get(3), userNamespaceAuthorizationEntities.get(2)), userNamespaceAuthorizationDao.getUserNamespaceAuthorizationsByUserId(USER_ID.toUpperCase()));
assertEquals(Arrays.asList(userNamespaceAuthorizationEntities.get(3), userNamespaceAuthorizationEntities.get(2)), userNamespaceAuthorizationDao.getUserNamespaceAuthorizationsByUserId(USER_ID.toLowerCase()));
// Try to retrieve user namespace authorization using a non-existing user id.
assertEquals(new ArrayList<>(), userNamespaceAuthorizationDao.getUserNamespaceAuthorizationsByUserId(USER_ID_3));
}
use of org.finra.herd.model.jpa.UserNamespaceAuthorizationEntity in project herd by FINRAOS.
the class UserNamespaceAuthorizationDaoTestHelper method createUserNamespaceAuthorizationEntity.
/**
* Creates and persists a new user namespace authorization entity.
*
* @param userId the user id
* @param namespaceEntity the namespace entity
* @param namespacePermissions the list of namespace permissions
*
* @return the newly created user namespace authorization entity
*/
public UserNamespaceAuthorizationEntity createUserNamespaceAuthorizationEntity(String userId, NamespaceEntity namespaceEntity, List<NamespacePermissionEnum> namespacePermissions) {
UserNamespaceAuthorizationEntity userNamespaceAuthorizationEntity = new UserNamespaceAuthorizationEntity();
userNamespaceAuthorizationEntity.setUserId(userId);
userNamespaceAuthorizationEntity.setNamespace(namespaceEntity);
userNamespaceAuthorizationEntity.setReadPermission(namespacePermissions.contains(NamespacePermissionEnum.READ));
userNamespaceAuthorizationEntity.setWritePermission(namespacePermissions.contains(NamespacePermissionEnum.WRITE));
userNamespaceAuthorizationEntity.setExecutePermission(namespacePermissions.contains(NamespacePermissionEnum.EXECUTE));
userNamespaceAuthorizationEntity.setGrantPermission(namespacePermissions.contains(NamespacePermissionEnum.GRANT));
userNamespaceAuthorizationEntity.setWriteDescriptiveContentPermission(namespacePermissions.contains(NamespacePermissionEnum.WRITE_DESCRIPTIVE_CONTENT));
return userNamespaceAuthorizationDao.saveAndRefresh(userNamespaceAuthorizationEntity);
}
use of org.finra.herd.model.jpa.UserNamespaceAuthorizationEntity in project herd by FINRAOS.
the class UserNamespaceAuthorizationServiceImpl method getUserNamespaceAuthorization.
@NamespacePermission(fields = "#key?.namespace", permissions = NamespacePermissionEnum.READ)
@Override
public UserNamespaceAuthorization getUserNamespaceAuthorization(UserNamespaceAuthorizationKey key) {
// Validate and trim the key.
validateUserNamespaceAuthorizationKey(key);
// Retrieve and ensure that a user namespace authorization exists with the specified key.
UserNamespaceAuthorizationEntity userNamespaceAuthorizationEntity = getUserNamespaceAuthorizationEntity(key);
// Create and return the user namespace authorization object from the persisted entity.
return createUserNamespaceAuthorizationFromEntity(userNamespaceAuthorizationEntity);
}
Aggregations