use of org.finra.herd.model.jpa.UserNamespaceAuthorizationEntity in project herd by FINRAOS.
the class UserNamespaceAuthorizationServiceImpl method deleteUserNamespaceAuthorization.
@NamespacePermission(fields = "#key?.namespace", permissions = NamespacePermissionEnum.GRANT)
@Override
public UserNamespaceAuthorization deleteUserNamespaceAuthorization(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);
// Delete the business object definition.
userNamespaceAuthorizationDao.delete(userNamespaceAuthorizationEntity);
// Create and return the user namespace authorization object from the deleted entity.
return createUserNamespaceAuthorizationFromEntity(userNamespaceAuthorizationEntity);
}
use of org.finra.herd.model.jpa.UserNamespaceAuthorizationEntity in project herd by FINRAOS.
the class UserNamespaceAuthorizationServiceImpl method createUserNamespaceAuthorization.
@NamespacePermission(fields = "#request?.userNamespaceAuthorizationKey?.namespace", permissions = NamespacePermissionEnum.GRANT)
@Override
public UserNamespaceAuthorization createUserNamespaceAuthorization(UserNamespaceAuthorizationCreateRequest request) {
// Validate and trim the request parameters.
validateUserNamespaceAuthorizationCreateRequest(request);
// Get the user namespace authorization key.
UserNamespaceAuthorizationKey key = request.getUserNamespaceAuthorizationKey();
// Ensure a user namespace authorization with the specified name doesn't already exist for the specified namespace.
UserNamespaceAuthorizationEntity userNamespaceAuthorizationEntity = userNamespaceAuthorizationDao.getUserNamespaceAuthorizationByKey(key);
if (userNamespaceAuthorizationEntity != null) {
throw new AlreadyExistsException(String.format("Unable to create user namespace authorization with user id \"%s\" and namespace \"%s\" because it already exists.", key.getUserId(), key.getNamespace()));
}
// Retrieve and ensure that namespace exists with the specified user namespace authorization namespace code.
NamespaceEntity namespaceEntity = namespaceDaoHelper.getNamespaceEntity(key.getNamespace());
// Create and persist a new user namespace authorization entity from the request information.
userNamespaceAuthorizationEntity = createUserNamespaceAuthorizationEntity(key.getUserId(), namespaceEntity, request.getNamespacePermissions());
// Create and return the user namespace authorization object from the persisted entity.
return createUserNamespaceAuthorizationFromEntity(userNamespaceAuthorizationEntity);
}
use of org.finra.herd.model.jpa.UserNamespaceAuthorizationEntity in project herd by FINRAOS.
the class UserNamespaceAuthorizationHelperTest method testBuildNamespaceAuthorizationsAssertWildcardQueryExecuted.
@Test
public void testBuildNamespaceAuthorizationsAssertWildcardQueryExecuted() {
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(true);
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));
verify(wildcardHelper).matches(eq(userId.toUpperCase()), eq(wildcardEntity.getUserId().toUpperCase()));
verifyNoMoreInteractions(userNamespaceAuthorizationDao, wildcardHelper);
}
Aggregations