Search in sources :

Example 1 with Condition

use of org.simbasecurity.core.domain.Condition in project simba-os by cegeka.

the class ConditionDTOAssemblerTest method testAssembleSingleCondition_Failure.

@Test(expected = IllegalArgumentException.class)
public void testAssembleSingleCondition_Failure() {
    @SuppressWarnings("serial") Condition condition = new ConditionEntity() {

        @Override
        protected boolean conditionApplies(AuthorizationRequestContext context) {
            return false;
        }
    };
    ConditionDTOAssembler.assemble(condition);
}
Also used : Condition(org.simbasecurity.core.domain.Condition) TimeCondition(org.simbasecurity.core.domain.condition.TimeCondition) AuthorizationRequestContext(org.simbasecurity.core.service.AuthorizationRequestContext) ConditionEntity(org.simbasecurity.core.domain.ConditionEntity) Test(org.junit.Test)

Example 2 with Condition

use of org.simbasecurity.core.domain.Condition in project simba-os by cegeka.

the class ConditionDTOAssemblerTest method testAssembleMultipleConditionsData.

@Test
public void testAssembleMultipleConditionsData() {
    Condition condition = createTimeCondition();
    Collection<ConditionDTO> policyDataList = ConditionDTOAssembler.assemble(Arrays.asList(condition));
    assertNotNull(policyDataList);
    assertEquals(1, policyDataList.size());
}
Also used : Condition(org.simbasecurity.core.domain.Condition) TimeCondition(org.simbasecurity.core.domain.condition.TimeCondition) ConditionDTO(org.simbasecurity.core.service.manager.dto.ConditionDTO) TimeConditionDTO(org.simbasecurity.core.service.manager.dto.TimeConditionDTO) Test(org.junit.Test)

Example 3 with Condition

use of org.simbasecurity.core.domain.Condition in project simba-os by cegeka.

the class ConditionManagerService method addOrUpdate.

@RequestMapping("addOrUpdate")
@ResponseBody
public ConditionDTO addOrUpdate(@RequestBody ConditionWithPoliciesAndExcludedUsersDTO conditionWithPoliciesAndExcludedUsersDTO) {
    final Condition attachedCondition = findOrCreate(conditionWithPoliciesAndExcludedUsersDTO.getCondition());
    final Collection<User> attachedUsers = userRepository.refreshWithOptimisticLocking(conditionWithPoliciesAndExcludedUsersDTO.getExcludedUsers());
    attachedCondition.setExemptedUsers(new HashSet<>(attachedUsers));
    final Collection<Policy> attachedPolicies = policyRepository.refreshWithOptimisticLocking(conditionWithPoliciesAndExcludedUsersDTO.getPolicies());
    conditionRepository.updatePolicies(attachedCondition, attachedPolicies);
    conditionRepository.flush();
    return assemble(attachedCondition);
}
Also used : Condition(org.simbasecurity.core.domain.Condition) Policy(org.simbasecurity.core.domain.Policy) User(org.simbasecurity.core.domain.User) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 4 with Condition

use of org.simbasecurity.core.domain.Condition in project simba-os by cegeka.

the class ConditionManagerService method remove.

@RequestMapping("remove")
@ResponseBody
public void remove(@RequestBody ConditionDTO condition) {
    final Condition conditionEntity = conditionRepository.refreshWithOptimisticLocking(condition);
    conditionRepository.updatePolicies(conditionEntity, Collections.<Policy>emptySet());
    conditionRepository.remove(conditionEntity);
}
Also used : Condition(org.simbasecurity.core.domain.Condition) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 5 with Condition

use of org.simbasecurity.core.domain.Condition in project simba-os by cegeka.

the class ConditionManagerService method findOrCreate.

private Condition findOrCreate(@RequestBody ConditionDTO condition) {
    final Condition attachedCondition;
    if (condition.getId() == 0L) {
        attachedCondition = conditionRepository.persist(assemble(condition));
    } else {
        attachedCondition = conditionRepository.refreshWithOptimisticLocking(condition);
        BeanUtils.copyProperties(condition, attachedCondition);
    }
    return attachedCondition;
}
Also used : Condition(org.simbasecurity.core.domain.Condition)

Aggregations

Condition (org.simbasecurity.core.domain.Condition)6 TimeCondition (org.simbasecurity.core.domain.condition.TimeCondition)3 Test (org.junit.Test)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2 ConditionEntity (org.simbasecurity.core.domain.ConditionEntity)1 Policy (org.simbasecurity.core.domain.Policy)1 User (org.simbasecurity.core.domain.User)1 AuthorizationRequestContext (org.simbasecurity.core.service.AuthorizationRequestContext)1 ConditionDTO (org.simbasecurity.core.service.manager.dto.ConditionDTO)1 TimeConditionDTO (org.simbasecurity.core.service.manager.dto.TimeConditionDTO)1