Search in sources :

Example 31 with NamespaceAuthorization

use of org.finra.herd.model.api.xml.NamespaceAuthorization in project herd by FINRAOS.

the class NamespaceSecurityHelperTest method getAuthorizedNamespacesWhenUserHasPermissionAssertReturnNamespace.

@Test
public void getAuthorizedNamespacesWhenUserHasPermissionAssertReturnNamespace() {
    ApplicationUser applicationUser = new ApplicationUser(getClass());
    applicationUser.setNamespaceAuthorizations(new HashSet<>(Arrays.asList(new NamespaceAuthorization("namespace", Arrays.asList(NamespacePermissionEnum.READ)))));
    SecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken(new SecurityUserWrapper("username", "", true, true, true, true, Collections.emptyList(), applicationUser), null));
    Set<String> authorizedNamespaces = namespaceSecurityHelper.getAuthorizedNamespaces(NamespacePermissionEnum.READ);
    assertEquals(1, authorizedNamespaces.size());
    assertTrue(authorizedNamespaces.contains("namespace"));
}
Also used : ApplicationUser(org.finra.herd.model.dto.ApplicationUser) SecurityUserWrapper(org.finra.herd.model.dto.SecurityUserWrapper) NamespaceAuthorization(org.finra.herd.model.api.xml.NamespaceAuthorization) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) Test(org.junit.Test)

Example 32 with NamespaceAuthorization

use of org.finra.herd.model.api.xml.NamespaceAuthorization in project herd by FINRAOS.

the class NamespaceSecurityHelperTest method getAuthorizedNamespacesWhenUserHasNoPermissionAssertReturnEmpty.

@Test
public void getAuthorizedNamespacesWhenUserHasNoPermissionAssertReturnEmpty() {
    ApplicationUser applicationUser = new ApplicationUser(getClass());
    applicationUser.setNamespaceAuthorizations(new HashSet<>(Arrays.asList(new NamespaceAuthorization("namespace", Arrays.asList(NamespacePermissionEnum.WRITE)))));
    SecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken(new SecurityUserWrapper("username", "", true, true, true, true, Collections.emptyList(), applicationUser), null));
    Set<String> authorizedNamespaces = namespaceSecurityHelper.getAuthorizedNamespaces(NamespacePermissionEnum.READ);
    assertEquals(0, authorizedNamespaces.size());
}
Also used : ApplicationUser(org.finra.herd.model.dto.ApplicationUser) SecurityUserWrapper(org.finra.herd.model.dto.SecurityUserWrapper) NamespaceAuthorization(org.finra.herd.model.api.xml.NamespaceAuthorization) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) Test(org.junit.Test)

Example 33 with NamespaceAuthorization

use of org.finra.herd.model.api.xml.NamespaceAuthorization 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);
}
Also used : ApplicationUser(org.finra.herd.model.dto.ApplicationUser) NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) ArrayList(java.util.ArrayList) UserNamespaceAuthorizationEntity(org.finra.herd.model.jpa.UserNamespaceAuthorizationEntity) NamespaceAuthorization(org.finra.herd.model.api.xml.NamespaceAuthorization) Test(org.junit.Test)

Aggregations

NamespaceAuthorization (org.finra.herd.model.api.xml.NamespaceAuthorization)33 Test (org.junit.Test)29 ApplicationUser (org.finra.herd.model.dto.ApplicationUser)25 SecurityUserWrapper (org.finra.herd.model.dto.SecurityUserWrapper)22 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)20 AccessDeniedException (org.springframework.security.access.AccessDeniedException)17 Method (java.lang.reflect.Method)14 JoinPoint (org.aspectj.lang.JoinPoint)14 MethodSignature (org.aspectj.lang.reflect.MethodSignature)14 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)14 LinkedHashSet (java.util.LinkedHashSet)7 ArrayList (java.util.ArrayList)5 HashSet (java.util.HashSet)5 AbstractAppTest (org.finra.herd.app.AbstractAppTest)5 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)5 MockFilterChain (org.springframework.mock.web.MockFilterChain)4 MockFilterConfig (org.springframework.mock.web.MockFilterConfig)4 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)4 Job (org.finra.herd.model.api.xml.Job)3 UserAuthorizations (org.finra.herd.model.api.xml.UserAuthorizations)3