@Test public void removeLdapGroupTest() throws Exception { String directory = "armedia"; AcmGroup group = new AcmGroup(); group.setName("test-group"); group.setDescription("test ldap group"); AcmLdapAuthenticateConfig config = new AcmLdapAuthenticateConfig(); config.setEnableEditingLdapUsers(true); mockBehaviour(group); when(springContextHolder.getAllBeansOfType(AcmLdapAuthenticateConfig.class)) .thenReturn(Collections.singletonMap("armedia_authenticate", config)); MvcResult result = mockMvc .perform(delete("/api/v1/ldap/" + directory + "/groups/" + group.getName()) .accept(MediaType.parseMediaType("application/json;charset=UTF-8")).contentType(MediaType.APPLICATION_JSON)) .andReturn(); LOG.info("Results: {}", result.getResponse().getContentAsString()); assertEquals(HttpStatus.OK.value(), result.getResponse().getStatus()); verify(mockLdapGroupService, times(1)).deleteLdapGroup(anyString(), anyString()); verifyAll(); }
@RequestMapping(value = "/{directory:.+}/groups/{groupName:.+}", method = RequestMethod.DELETE) public ResponseEntity<?> deleteLdapGroup(@PathVariable("directory") String directory, @PathVariable("groupName") String groupName) throws AcmAppErrorJsonMsg { checkIfLdapManagementIsAllowed(directory); try { groupName = new String(Base64.getUrlDecoder().decode(groupName.getBytes())); ldapGroupService.deleteLdapGroup(groupName, directory); return new ResponseEntity<>(HttpStatus.OK); } catch (AcmLdapActionFailedException e) { throw new AcmAppErrorJsonMsg("Deleting LDAP group failed. Cause: " + e.getMessage(), "LDAP_GROUP", e); } catch (AcmObjectNotFoundException e) { throw new AcmAppErrorJsonMsg("Deleting LDAP group failed. Cause: " + e.getCauseMessage(), "LDAP_GROUP", e); } catch (Exception e) { throw new AcmAppErrorJsonMsg("Deleting LDAP group failed", "LDAP_GROUP", e); } }
LdapGroupAPIController extends SecureLdapController { @RequestMapping(value = "/{directory:.+}/groups/{groupName:.+}", method = RequestMethod.DELETE) public ResponseEntity<?> deleteLdapGroup(@PathVariable("directory") String directory, @PathVariable("groupName") String groupName) throws AcmAppErrorJsonMsg { checkIfLdapManagementIsAllowed(directory); try { groupName = new String(Base64.getUrlDecoder().decode(groupName.getBytes())); ldapGroupService.deleteLdapGroup(groupName, directory); return new ResponseEntity<>(HttpStatus.OK); } catch (AcmLdapActionFailedException e) { throw new AcmAppErrorJsonMsg("Deleting LDAP group failed. Cause: " + e.getMessage(), "LDAP_GROUP", e); } catch (AcmObjectNotFoundException e) { throw new AcmAppErrorJsonMsg("Deleting LDAP group failed. Cause: " + e.getCauseMessage(), "LDAP_GROUP", e); } catch (Exception e) { throw new AcmAppErrorJsonMsg("Deleting LDAP group failed", "LDAP_GROUP", e); } } }
LdapGroupAPIController extends SecureLdapController { @RequestMapping(value = "/{directory:.+}/groups/{groupName:.+}", method = RequestMethod.DELETE) public ResponseEntity<?> deleteLdapGroup(@PathVariable("directory") String directory, @PathVariable("groupName") String groupName) throws AcmAppErrorJsonMsg { checkIfLdapManagementIsAllowed(directory); try { groupName = new String(Base64.getUrlDecoder().decode(groupName.getBytes())); ldapGroupService.deleteLdapGroup(groupName, directory); return new ResponseEntity<>(HttpStatus.OK); } catch (AcmLdapActionFailedException e) { throw new AcmAppErrorJsonMsg("Deleting LDAP group failed. Cause: " + e.getMessage(), "LDAP_GROUP", e); } catch (AcmObjectNotFoundException e) { throw new AcmAppErrorJsonMsg("Deleting LDAP group failed. Cause: " + e.getCauseMessage(), "LDAP_GROUP", e); } catch (Exception e) { throw new AcmAppErrorJsonMsg("Deleting LDAP group failed", "LDAP_GROUP", e); } }  }
LdapGroupAPIController extends SecureLdapController { @RequestMapping(value = "/{directory:.+}/groups/{groupName:.+}", method = RequestMethod.DELETE) public ResponseEntity<?> deleteLdapGroup(@PathVariable("directory") String directory, @PathVariable("groupName") String groupName) throws AcmAppErrorJsonMsg { checkIfLdapManagementIsAllowed(directory); try { groupName = new String(Base64.getUrlDecoder().decode(groupName.getBytes())); ldapGroupService.deleteLdapGroup(groupName, directory); return new ResponseEntity<>(HttpStatus.OK); } catch (AcmLdapActionFailedException e) { throw new AcmAppErrorJsonMsg("Deleting LDAP group failed. Cause: " + e.getMessage(), "LDAP_GROUP", e); } catch (AcmObjectNotFoundException e) { throw new AcmAppErrorJsonMsg("Deleting LDAP group failed. Cause: " + e.getCauseMessage(), "LDAP_GROUP", e); } catch (Exception e) { throw new AcmAppErrorJsonMsg("Deleting LDAP group failed", "LDAP_GROUP", e); } }  @RequestMapping(value = "/{directory:.+}/groups", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody AcmGroup createLdapGroup(@RequestBody @Valid AcmGroup group, @PathVariable String directory); @RequestMapping(value = "/{directory:.+}/groups/{parentGroupName:.+}", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody AcmGroup createLdapSubgroup(@RequestBody @Valid AcmGroup group, @PathVariable String directory,
            @PathVariable String parentGroupName); @RequestMapping(value = "/{directory:.+}/groups/{groupName:.+}", method = RequestMethod.DELETE) ResponseEntity<?> deleteLdapGroup(@PathVariable("directory") String directory,
            @PathVariable("groupName") String groupName); @RequestMapping(value = "/{directory:.+}/groups/{groupName:.+}/parent/{parentName:.+}", method = RequestMethod.DELETE) ResponseEntity<?> removeGroupMembership(@PathVariable("directory") String directory,
            @PathVariable("groupName") String groupName,
            @PathVariable("parentName") String parentName); LdapGroupService getLdapGroupService(); void setLdapGroupService(LdapGroupService ldapGroupService); }
LdapGroupAPIController extends SecureLdapController { @RequestMapping(value = "/{directory:.+}/groups/{groupName:.+}", method = RequestMethod.DELETE) public ResponseEntity<?> deleteLdapGroup(@PathVariable("directory") String directory, @PathVariable("groupName") String groupName) throws AcmAppErrorJsonMsg { checkIfLdapManagementIsAllowed(directory); try { groupName = new String(Base64.getUrlDecoder().decode(groupName.getBytes())); ldapGroupService.deleteLdapGroup(groupName, directory); return new ResponseEntity<>(HttpStatus.OK); } catch (AcmLdapActionFailedException e) { throw new AcmAppErrorJsonMsg("Deleting LDAP group failed. Cause: " + e.getMessage(), "LDAP_GROUP", e); } catch (AcmObjectNotFoundException e) { throw new AcmAppErrorJsonMsg("Deleting LDAP group failed. Cause: " + e.getCauseMessage(), "LDAP_GROUP", e); } catch (Exception e) { throw new AcmAppErrorJsonMsg("Deleting LDAP group failed", "LDAP_GROUP", e); } }  @RequestMapping(value = "/{directory:.+}/groups", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody AcmGroup createLdapGroup(@RequestBody @Valid AcmGroup group, @PathVariable String directory); @RequestMapping(value = "/{directory:.+}/groups/{parentGroupName:.+}", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody AcmGroup createLdapSubgroup(@RequestBody @Valid AcmGroup group, @PathVariable String directory,
            @PathVariable String parentGroupName); @RequestMapping(value = "/{directory:.+}/groups/{groupName:.+}", method = RequestMethod.DELETE) ResponseEntity<?> deleteLdapGroup(@PathVariable("directory") String directory,
            @PathVariable("groupName") String groupName); @RequestMapping(value = "/{directory:.+}/groups/{groupName:.+}/parent/{parentName:.+}", method = RequestMethod.DELETE) ResponseEntity<?> removeGroupMembership(@PathVariable("directory") String directory,
            @PathVariable("groupName") String groupName,
            @PathVariable("parentName") String parentName); LdapGroupService getLdapGroupService(); void setLdapGroupService(LdapGroupService ldapGroupService);  }