use of org.finra.herd.model.api.xml.NamespaceAuthorization 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.api.xml.NamespaceAuthorization in project herd by FINRAOS.
the class UserNamespaceAuthorizationHelper method getAllNamespaceAuthorizations.
/**
* Returns a list of namespace authorizations for all namespaces registered in the system and with all permissions enabled.
*
* @return namespacePermissions the list of namespace authorizations
*/
public Set<NamespaceAuthorization> getAllNamespaceAuthorizations() {
Set<NamespaceAuthorization> namespaceAuthorizations = new LinkedHashSet<>();
List<NamespaceKey> namespaceKeys = namespaceDao.getNamespaces();
for (NamespaceKey namespaceKey : namespaceKeys) {
NamespaceAuthorization namespaceAuthorization = new NamespaceAuthorization();
namespaceAuthorizations.add(namespaceAuthorization);
namespaceAuthorization.setNamespace(namespaceKey.getNamespaceCode());
namespaceAuthorization.setNamespacePermissions(getAllNamespacePermissions());
}
return namespaceAuthorizations;
}
use of org.finra.herd.model.api.xml.NamespaceAuthorization in project herd by FINRAOS.
the class UserNamespaceAuthorizationHelper method toNamespaceAuthorization.
/**
* Converts the given UserNamespaceAuthorizationEntity to NamespaceAuthorization.
*
* @param userNamespaceAuthorizationEntity The UserNamespaceAuthorizationEntity
*
* @return The NamespaceAuthorization
*/
private NamespaceAuthorization toNamespaceAuthorization(UserNamespaceAuthorizationEntity userNamespaceAuthorizationEntity) {
NamespaceAuthorization namespaceAuthorization = new NamespaceAuthorization();
namespaceAuthorization.setNamespace(userNamespaceAuthorizationEntity.getNamespace().getCode());
namespaceAuthorization.setNamespacePermissions(getNamespacePermissions(userNamespaceAuthorizationEntity));
return namespaceAuthorization;
}
use of org.finra.herd.model.api.xml.NamespaceAuthorization in project herd by FINRAOS.
the class HttpHeaderAuthenticationFilterTest method testHttpHeaderAuthenticationFilterAdminUser.
@Test
public void testHttpHeaderAuthenticationFilterAdminUser() throws Exception {
// Create and persist the relative database entities.
userDaoTestHelper.createUserEntity(USER_ID, true);
namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE);
namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE_2);
// Create an ordered set of expected namespace authorizations.
Set<NamespaceAuthorization> expectedNamespaceAuthorizations = new HashSet<>();
expectedNamespaceAuthorizations.add(new NamespaceAuthorization(NAMESPACE, SUPPORTED_NAMESPACE_PERMISSIONS));
expectedNamespaceAuthorizations.add(new NamespaceAuthorization(NAMESPACE_2, SUPPORTED_NAMESPACE_PERMISSIONS));
setupTestFunctions("testRole");
modifyPropertySourceInEnvironment(getDefaultSecurityEnvironmentVariables());
try {
MockHttpServletRequest request = getRequestWithHeaders(USER_ID, "testFirstName", "testLastName", "testEmail", "testRole", "Wed, 11 Mar 2015 10:24:09");
// Invalidate user session if exists.
invalidateApplicationUser(request);
httpHeaderAuthenticationFilter.init(new MockFilterConfig());
httpHeaderAuthenticationFilter.doFilter(request, new MockHttpServletResponse(), new MockFilterChain());
validateHttpHeaderApplicationUser(USER_ID, "testFirstName", "testLastName", "testEmail", "testRole", "Wed, 11 Mar 2015 10:24:09", TEST_FUNCTIONS, expectedNamespaceAuthorizations);
// retry with same request.
httpHeaderAuthenticationFilter.doFilter(request, new MockHttpServletResponse(), new MockFilterChain());
validateHttpHeaderApplicationUser(USER_ID, "testFirstName", "testLastName", "testEmail", "testRole", "Wed, 11 Mar 2015 10:24:09", TEST_FUNCTIONS, expectedNamespaceAuthorizations);
} finally {
restorePropertySourceInEnvironment();
}
}
use of org.finra.herd.model.api.xml.NamespaceAuthorization in project herd by FINRAOS.
the class HttpHeaderAuthenticationFilterTest method testHttpHeaderAuthenticationFilterUserAuthorizationInvalidConfigurationValue.
@Test
public void testHttpHeaderAuthenticationFilterUserAuthorizationInvalidConfigurationValue() throws Exception {
// Create and persist the relative database entities.
userDaoTestHelper.createUserEntity(USER_ID, true);
namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE);
namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE_2);
// Create an ordered set of expected namespace authorizations.
Set<NamespaceAuthorization> expectedNamespaceAuthorizations = new HashSet<>();
expectedNamespaceAuthorizations.add(new NamespaceAuthorization(NAMESPACE, SUPPORTED_NAMESPACE_PERMISSIONS));
expectedNamespaceAuthorizations.add(new NamespaceAuthorization(NAMESPACE_2, SUPPORTED_NAMESPACE_PERMISSIONS));
setupTestFunctions("testRole");
Map<String, Object> overrideMap = getDefaultSecurityEnvironmentVariables();
overrideMap.put(ConfigurationValue.USER_NAMESPACE_AUTHORIZATION_ENABLED.getKey(), "NOT_A_BOOLEAN");
modifyPropertySourceInEnvironment(overrideMap);
try {
MockHttpServletRequest request = getRequestWithHeaders(USER_ID, "testFirstName", "testLastName", "testEmail", "testRole", "Wed, 11 Mar 2015 10:24:09");
// Invalidate user session if exists.
invalidateApplicationUser(request);
httpHeaderAuthenticationFilter.init(new MockFilterConfig());
httpHeaderAuthenticationFilter.doFilter(request, new MockHttpServletResponse(), new MockFilterChain());
// Validate that there is no authentication.
assertNull(SecurityContextHolder.getContext().getAuthentication());
} finally {
restorePropertySourceInEnvironment();
}
}
Aggregations