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);
}
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());
}
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);
}
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);
}
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;
}
Aggregations