Search in sources :

Example 1 with SecurityConfigDto

use of org.motechproject.security.model.SecurityConfigDto in project motech by motech.

the class MotechURLSecurityServiceBundleIT method testUpdateSecurity.

@Test
public void testUpdateSecurity() {
    motechUserService.register("admin", "admin", "admin@mail.com", "", asList(SECURITY_MANAGE_ADMIN), Locale.ENGLISH);
    UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken("admin", "admin");
    Authentication auth = authenticationManager.authenticate(authRequest);
    SecurityContext context = SecurityContextHolder.getContext();
    context.setAuthentication(auth);
    List<SecurityRuleDto> rules = new ArrayList<>();
    addRules(rules);
    SecurityConfigDto configuration = new SecurityConfigDto();
    configuration.setSecurityRules(rules);
    securityService.updateSecurityConfiguration(configuration);
    // Shouldn't return rule marked as deleted.
    assertEquals(3, securityService.findAllSecurityRules().size());
}
Also used : Authentication(org.springframework.security.core.Authentication) SecurityContext(org.springframework.security.core.context.SecurityContext) ArrayList(java.util.ArrayList) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) SecurityRuleDto(org.motechproject.security.model.SecurityRuleDto) SecurityConfigDto(org.motechproject.security.model.SecurityConfigDto) Test(org.junit.Test)

Example 2 with SecurityConfigDto

use of org.motechproject.security.model.SecurityConfigDto in project motech by motech.

the class SecurityRulesController method getSecurityRules.

/**
 * Returns security config
 *
 * @return security config
 */
@RequestMapping(value = "/web-api/securityRules", method = RequestMethod.GET)
@ResponseBody
public SecurityConfigDto getSecurityRules() {
    SecurityConfigDto security = new SecurityConfigDto();
    List<SecurityRuleDto> rules = urlSecurityService.findAllSecurityRules();
    security.setSecurityRules(rules);
    return security;
}
Also used : SecurityRuleDto(org.motechproject.security.model.SecurityRuleDto) SecurityConfigDto(org.motechproject.security.model.SecurityConfigDto) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

SecurityConfigDto (org.motechproject.security.model.SecurityConfigDto)2 SecurityRuleDto (org.motechproject.security.model.SecurityRuleDto)2 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)1 Authentication (org.springframework.security.core.Authentication)1 SecurityContext (org.springframework.security.core.context.SecurityContext)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1