Search in sources :

Example 11 with WebRequest

use of org.springframework.web.context.request.WebRequest in project molgenis by molgenis.

the class PermissionManagerControllerTest method testUpdateUserPackagePermissions.

@Test
public void testUpdateUserPackagePermissions() {
    WebRequest webRequest = mock(WebRequest.class);
    when(webRequest.getParameter("radio-1")).thenReturn("write");
    when(webRequest.getParameter("radio-2")).thenReturn("none");
    when(webRequest.getParameter("radio-3")).thenReturn("read");
    MutableAcl acl1 = mock(MutableAcl.class);
    MutableAcl acl2 = mock(MutableAcl.class);
    MutableAcl acl3 = mock(MutableAcl.class);
    AccessControlEntry ace1 = mock(AccessControlEntry.class);
    AccessControlEntry ace2 = mock(AccessControlEntry.class);
    PrincipalSid sid = new PrincipalSid("Ipsum");
    when(ace1.getSid()).thenReturn(sid);
    when(ace2.getSid()).thenReturn(sid);
    when(acl1.getEntries()).thenReturn(Collections.singletonList(ace1));
    when(acl2.getEntries()).thenReturn(Collections.singletonList(ace2));
    when(acl3.getEntries()).thenReturn(Collections.emptyList());
    when(mutableAclService.readAclById(packageIdentity1, singletonList(sid))).thenReturn(acl1);
    when(mutableAclService.readAclById(packageIdentity2, singletonList(sid))).thenReturn(acl2);
    when(mutableAclService.readAclById(packageIdentity3, singletonList(sid))).thenReturn(acl3);
    permissionManagerController.updateUserPackagePermissions("1", webRequest);
    verify(acl1).deleteAce(0);
    verify(acl1).insertAce(0, cumulativeEntityPermissionWrite, sid, true);
    verify(acl2).deleteAce(0);
    verify(acl3).insertAce(0, cumulativeEntityPermissionRead, sid, true);
    verify(mutableAclService).updateAcl(acl1);
    verify(mutableAclService).updateAcl(acl2);
    verify(mutableAclService).updateAcl(acl3);
}
Also used : WebRequest(org.springframework.web.context.request.WebRequest) PrincipalSid(org.springframework.security.acls.domain.PrincipalSid) Test(org.testng.annotations.Test)

Example 12 with WebRequest

use of org.springframework.web.context.request.WebRequest in project molgenis by molgenis.

the class PermissionManagerControllerTest method testUpdateUserEntityClassPermissions.

@Test
public void testUpdateUserEntityClassPermissions() {
    WebRequest webRequest = mock(WebRequest.class);
    when(webRequest.getParameter("radio-1")).thenReturn("write");
    when(webRequest.getParameter("radio-2")).thenReturn("none");
    when(webRequest.getParameter("radio-3")).thenReturn("read");
    ObjectIdentity objectIdentity1 = new EntityTypeIdentity(entityType1);
    ObjectIdentity objectIdentity2 = new EntityTypeIdentity(entityType2);
    ObjectIdentity objectIdentity3 = new EntityTypeIdentity(entityType3);
    MutableAcl acl1 = mock(MutableAcl.class);
    MutableAcl acl2 = mock(MutableAcl.class);
    MutableAcl acl3 = mock(MutableAcl.class);
    AccessControlEntry ace1 = mock(AccessControlEntry.class);
    AccessControlEntry ace2 = mock(AccessControlEntry.class);
    PrincipalSid sid = new PrincipalSid("Ipsum");
    when(ace1.getSid()).thenReturn(sid);
    when(ace2.getSid()).thenReturn(sid);
    when(acl1.getEntries()).thenReturn(Collections.singletonList(ace1));
    when(acl2.getEntries()).thenReturn(Collections.singletonList(ace2));
    when(acl3.getEntries()).thenReturn(Collections.emptyList());
    when(mutableAclService.readAclById(objectIdentity1, singletonList(sid))).thenReturn(acl1);
    when(mutableAclService.readAclById(objectIdentity2, singletonList(sid))).thenReturn(acl2);
    when(mutableAclService.readAclById(objectIdentity3, singletonList(sid))).thenReturn(acl3);
    permissionManagerController.updateUserEntityClassPermissions("1", webRequest);
    verify(acl1).deleteAce(0);
    verify(acl1).insertAce(0, cumulativeEntityPermissionWrite, sid, true);
    verify(acl2).deleteAce(0);
    verify(acl3).insertAce(0, cumulativeEntityPermissionRead, sid, true);
    verify(mutableAclService).updateAcl(acl1);
    verify(mutableAclService).updateAcl(acl2);
    verify(mutableAclService).updateAcl(acl3);
}
Also used : EntityTypeIdentity(org.molgenis.data.security.EntityTypeIdentity) WebRequest(org.springframework.web.context.request.WebRequest) PrincipalSid(org.springframework.security.acls.domain.PrincipalSid) Test(org.testng.annotations.Test)

Example 13 with WebRequest

use of org.springframework.web.context.request.WebRequest in project molgenis by molgenis.

the class PermissionManagerControllerTest method testUpdateGroupPackagePermissions.

@Test
public void testUpdateGroupPackagePermissions() {
    WebRequest webRequest = mock(WebRequest.class);
    when(webRequest.getParameter("radio-1")).thenReturn("write");
    when(webRequest.getParameter("radio-2")).thenReturn("none");
    when(webRequest.getParameter("radio-3")).thenReturn("read");
    MutableAcl acl1 = mock(MutableAcl.class);
    MutableAcl acl2 = mock(MutableAcl.class);
    MutableAcl acl3 = mock(MutableAcl.class);
    AccessControlEntry ace1 = mock(AccessControlEntry.class);
    AccessControlEntry ace2 = mock(AccessControlEntry.class);
    GrantedAuthoritySid sid = new GrantedAuthoritySid("ROLE_1");
    when(ace1.getSid()).thenReturn(sid);
    when(ace2.getSid()).thenReturn(sid);
    when(acl1.getEntries()).thenReturn(Collections.singletonList(ace1));
    when(acl2.getEntries()).thenReturn(Collections.singletonList(ace2));
    when(acl3.getEntries()).thenReturn(Collections.emptyList());
    when(mutableAclService.readAclById(packageIdentity1, singletonList(sid))).thenReturn(acl1);
    when(mutableAclService.readAclById(packageIdentity2, singletonList(sid))).thenReturn(acl2);
    when(mutableAclService.readAclById(packageIdentity3, singletonList(sid))).thenReturn(acl3);
    permissionManagerController.updateGroupPackagePermissions("1", webRequest);
    verify(acl1).deleteAce(0);
    verify(acl1).insertAce(0, cumulativeEntityPermissionWrite, sid, true);
    verify(acl2).deleteAce(0);
    verify(acl3).insertAce(0, cumulativeEntityPermissionRead, sid, true);
    verify(mutableAclService).updateAcl(acl1);
    verify(mutableAclService).updateAcl(acl2);
    verify(mutableAclService).updateAcl(acl3);
}
Also used : WebRequest(org.springframework.web.context.request.WebRequest) GrantedAuthoritySid(org.springframework.security.acls.domain.GrantedAuthoritySid) Test(org.testng.annotations.Test)

Example 14 with WebRequest

use of org.springframework.web.context.request.WebRequest in project molgenis by molgenis.

the class PermissionManagerControllerTest method testUpdateGroupEntityClassPermissions.

@Test
public void testUpdateGroupEntityClassPermissions() {
    WebRequest webRequest = mock(WebRequest.class);
    when(webRequest.getParameter("radio-1")).thenReturn("write");
    when(webRequest.getParameter("radio-2")).thenReturn("none");
    when(webRequest.getParameter("radio-3")).thenReturn("read");
    MutableAcl acl1 = mock(MutableAcl.class);
    MutableAcl acl2 = mock(MutableAcl.class);
    MutableAcl acl3 = mock(MutableAcl.class);
    AccessControlEntry ace1 = mock(AccessControlEntry.class);
    AccessControlEntry ace2 = mock(AccessControlEntry.class);
    GrantedAuthoritySid sid = new GrantedAuthoritySid("ROLE_1");
    when(ace1.getSid()).thenReturn(sid);
    when(ace2.getSid()).thenReturn(sid);
    when(acl1.getEntries()).thenReturn(Collections.singletonList(ace1));
    when(acl2.getEntries()).thenReturn(Collections.singletonList(ace2));
    when(acl3.getEntries()).thenReturn(Collections.emptyList());
    when(mutableAclService.readAclById(entityIdentity1, singletonList(sid))).thenReturn(acl1);
    when(mutableAclService.readAclById(entityIdentity2, singletonList(sid))).thenReturn(acl2);
    when(mutableAclService.readAclById(entityIdentity3, singletonList(sid))).thenReturn(acl3);
    permissionManagerController.updateGroupEntityClassPermissions("1", webRequest);
    verify(acl1).deleteAce(0);
    verify(acl1).insertAce(0, cumulativeEntityPermissionWrite, sid, true);
    verify(acl2).deleteAce(0);
    verify(acl3).insertAce(0, cumulativeEntityPermissionRead, sid, true);
    verify(mutableAclService).updateAcl(acl1);
    verify(mutableAclService).updateAcl(acl2);
    verify(mutableAclService).updateAcl(acl3);
}
Also used : WebRequest(org.springframework.web.context.request.WebRequest) GrantedAuthoritySid(org.springframework.security.acls.domain.GrantedAuthoritySid) Test(org.testng.annotations.Test)

Example 15 with WebRequest

use of org.springframework.web.context.request.WebRequest in project molgenis by molgenis.

the class PermissionManagerControllerTest method testUpdateUserPluginPermissions.

@Test
public void testUpdateUserPluginPermissions() {
    WebRequest webRequest = mock(WebRequest.class);
    when(webRequest.getParameter("radio-1")).thenReturn("read");
    when(webRequest.getParameter("radio-2")).thenReturn("none");
    ObjectIdentity objectIdentity1 = new PluginIdentity(plugin1);
    ObjectIdentity objectIdentity2 = new PluginIdentity(plugin2);
    MutableAcl acl1 = mock(MutableAcl.class);
    MutableAcl acl2 = mock(MutableAcl.class);
    AccessControlEntry ace1 = mock(AccessControlEntry.class);
    when(ace1.getSid()).thenReturn(userSid);
    when(acl1.getEntries()).thenReturn(Collections.singletonList(ace1));
    when(acl2.getEntries()).thenReturn(Collections.emptyList());
    when(mutableAclService.readAclById(objectIdentity1, singletonList(userSid))).thenReturn(acl1);
    when(mutableAclService.readAclById(objectIdentity2, singletonList(userSid))).thenReturn(acl2);
    permissionManagerController.updateUserPluginPermissions("1", webRequest);
    verify(acl1).insertAce(0, pluginPermissionRead, userSid, true);
    verify(mutableAclService).updateAcl(acl1);
}
Also used : WebRequest(org.springframework.web.context.request.WebRequest) PluginIdentity(org.molgenis.data.plugin.model.PluginIdentity) Test(org.testng.annotations.Test)

Aggregations

WebRequest (org.springframework.web.context.request.WebRequest)20 Test (org.testng.annotations.Test)6 ServletWebRequest (org.springframework.web.context.request.ServletWebRequest)5 List (java.util.List)4 Autowired (org.springframework.beans.factory.annotation.Autowired)4 Locale (java.util.Locale)3 HttpHeaders (org.springframework.http.HttpHeaders)3 HttpStatus (org.springframework.http.HttpStatus)3 ResponseEntity (org.springframework.http.ResponseEntity)3 MethodArgumentNotValidException (org.springframework.web.bind.MethodArgumentNotValidException)3 ControllerAdvice (org.springframework.web.bind.annotation.ControllerAdvice)3 ExceptionHandler (org.springframework.web.bind.annotation.ExceptionHandler)3 ResponseEntityExceptionHandler (org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler)3 Optional (java.util.Optional)2 Collectors (java.util.stream.Collectors)2 Test (org.junit.jupiter.api.Test)2 ErrorAttributeOptions (org.springframework.boot.web.error.ErrorAttributeOptions)2 DefaultErrorAttributes (org.springframework.boot.web.servlet.error.DefaultErrorAttributes)2 ErrorAttributes (org.springframework.boot.web.servlet.error.ErrorAttributes)2 MessageSource (org.springframework.context.MessageSource)2