Search in sources :

Example 1 with UserEntity

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

the class RoleManagerServiceTest method setup.

@Before
public void setup() {
    GlobalContext.initialize(locator);
    when(locator.locate(UserValidator.class)).thenReturn(userValidator);
    when(locator.locate(PasswordValidator.class)).thenReturn(passwordValidator);
    when(locator.locate(ConfigurationServiceImpl.class)).thenReturn(configurationService);
    UserEntity userEntity1 = new UserEntity("user-1");
    UserEntity userEntity2 = new UserEntity("user-2");
    ReflectionUtil.setField(entityFilterService, "filters", filterServices);
    roleEntity1.addPolicy(policyEntity1);
    roleEntity2.addPolicy(policyEntity2);
    roleEntity3.addPolicy(policyEntity1);
    roleEntity3.addPolicy(policyEntity2);
    roleEntity1.addUser(userEntity1);
    roleEntity2.addUser(userEntity2);
    roleEntity3.addUser(userEntity1);
    roleEntity3.addUser(userEntity2);
    Collection<Role> roles = asList(roleEntity1, roleEntity2, roleEntity3);
    when(roleRepository.findAll()).thenReturn(roles);
    when(roleRepository.lookUp(roleDTO1)).thenReturn(roleEntity1);
    when(roleRepository.lookUp(roleDTO2)).thenReturn(roleEntity2);
    when(roleRepository.lookUp(roleDTO3)).thenReturn(roleEntity3);
    when(policyRepository.findNotLinked(roleEntity1)).thenReturn(singletonList(policyEntity2));
    when(policyRepository.findNotLinked(roleEntity2)).thenReturn(singletonList(policyEntity1));
    when(policyRepository.findNotLinked(roleEntity3)).thenReturn(emptyList());
    when(policyRepository.findForRole(roleEntity1)).thenReturn(singletonList(policyEntity1));
    when(policyRepository.findForRole(roleEntity2)).thenReturn(singletonList(policyEntity2));
    when(policyRepository.findForRole(roleEntity3)).thenReturn(asList(policyEntity1, policyEntity2));
    when(userRepository.findNotLinked(roleEntity1)).thenReturn(singletonList(userEntity2));
    when(userRepository.findNotLinked(roleEntity2)).thenReturn(singletonList(userEntity1));
    when(userRepository.findNotLinked(roleEntity3)).thenReturn(emptyList());
    when(userRepository.findForRole(roleEntity1)).thenReturn(singletonList(userEntity1));
    when(userRepository.findForRole(roleEntity2)).thenReturn(singletonList(userEntity2));
    when(userRepository.findForRole(roleEntity3)).thenReturn(asList(userEntity1, userEntity2));
}
Also used : Role(org.simbasecurity.core.domain.Role) UserEntity(org.simbasecurity.core.domain.UserEntity) Before(org.junit.Before)

Example 2 with UserEntity

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

the class UserDTOAssemblerTest method createUser.

private User createUser() {
    User user = new UserEntity("username");
    user.setFirstName("first name");
    user.setName("name");
    user.setStatus(Status.ACTIVE);
    user.setSuccessURL("success url");
    user.setLanguage(Language.en_US);
    user.setChangePasswordOnNextLogon(true);
    return user;
}
Also used : User(org.simbasecurity.core.domain.User) UserEntity(org.simbasecurity.core.domain.UserEntity)

Example 3 with UserEntity

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

the class CreateEIDUserCommand method execute.

@Override
public State execute(ChainContext context) throws Exception {
    SAMLUser samlUser = context.getSAMLUser();
    User user = userService.findByName(samlUser.getInsz());
    if (user == null) {
        List<String> roles = configurationService.getValue(SimbaConfigurationParameter.DEFAULT_USER_ROLE);
        user = new UserEntity(samlUser.getInsz());
        user.setName(samlUser.getLastname());
        user.setFirstName(samlUser.getFirstname());
        user.setLanguage(getLanguageIfUnknownUseNL(samlUser));
        user.setPasswordChangeRequired(false);
        user.setChangePasswordOnNextLogon(false);
        userService.create(user, roles);
        audit.log(auditLogFactory.createEventForEIDSAMLResponse(context, "New user for eid created with username [" + user.getUserName() + "]"));
    } else {
        user.setName(samlUser.getLastname());
        user.setFirstName(samlUser.getFirstname());
        user.setLanguage(getLanguageIfUnknownUseNL(samlUser));
        audit.log(auditLogFactory.createEventForEIDSAMLResponse(context, "Updated user with username [" + user.getUserName() + "] with new FAS data"));
    }
    context.setUserPrincipal(user.getUserName());
    return State.CONTINUE;
}
Also used : User(org.simbasecurity.core.domain.User) UserEntity(org.simbasecurity.core.domain.UserEntity)

Example 4 with UserEntity

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

the class RuleDatabaseRepositoryTest method setupWithGroups.

private ResourceRule setupWithGroups() {
    User user = new UserEntity(USER_VIA_GROUP);
    Role role = new RoleEntity("role2");
    Group group = new GroupEntity("groupName", "cn");
    Policy policy = new PolicyEntity("policy2");
    ResourceRule resourceRuleEntity = new ResourceRuleEntity("resrule2");
    resourceRuleEntity.setResourceName("resname2");
    urlRuleEntityViaGroup = new URLRuleEntity("urlrule2");
    persistAndRefresh(user, role, policy, resourceRuleEntity, urlRuleEntityViaGroup);
    persistAndRefresh(user, group, role, policy, resourceRuleEntity, urlRuleEntityViaGroup);
    policy.addRule(resourceRuleEntity);
    policy.addRule(urlRuleEntityViaGroup);
    role.addPolicy(policy);
    group.addRole(role);
    user.addGroup(group);
    return resourceRuleEntity;
}
Also used : Role(org.simbasecurity.core.domain.Role) RoleEntity(org.simbasecurity.core.domain.RoleEntity) Policy(org.simbasecurity.core.domain.Policy) Group(org.simbasecurity.core.domain.Group) User(org.simbasecurity.core.domain.User) GroupEntity(org.simbasecurity.core.domain.GroupEntity) PolicyEntity(org.simbasecurity.core.domain.PolicyEntity) ResourceRule(org.simbasecurity.core.domain.ResourceRule) ResourceRuleEntity(org.simbasecurity.core.domain.ResourceRuleEntity) UserEntity(org.simbasecurity.core.domain.UserEntity) URLRuleEntity(org.simbasecurity.core.domain.URLRuleEntity)

Example 5 with UserEntity

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

the class SessionDatabaseRepositoryTest method canFindBySSOToken.

@Test
public void canFindBySSOToken() throws Exception {
    User user = new UserEntity("jos");
    SSOToken ssoToken = new SSOToken("eenSsoTokentje");
    SessionEntity session = new SessionEntity(user, ssoToken, "127.0.0.1", "192.168.1.1");
    persistAndRefresh(user, session);
    assertEquals(session, sessionDatabaseRepository.findBySSOToken(ssoToken));
}
Also used : User(org.simbasecurity.core.domain.User) SSOToken(org.simbasecurity.api.service.thrift.SSOToken) SessionEntity(org.simbasecurity.core.domain.SessionEntity) UserEntity(org.simbasecurity.core.domain.UserEntity) Test(org.junit.Test)

Aggregations

UserEntity (org.simbasecurity.core.domain.UserEntity)8 User (org.simbasecurity.core.domain.User)5 Test (org.junit.Test)3 Before (org.junit.Before)2 Group (org.simbasecurity.core.domain.Group)2 PolicyEntity (org.simbasecurity.core.domain.PolicyEntity)2 ResourceRuleEntity (org.simbasecurity.core.domain.ResourceRuleEntity)2 Role (org.simbasecurity.core.domain.Role)2 RoleEntity (org.simbasecurity.core.domain.RoleEntity)2 URLRuleEntity (org.simbasecurity.core.domain.URLRuleEntity)2 SSOToken (org.simbasecurity.api.service.thrift.SSOToken)1 State (org.simbasecurity.core.chain.Command.State)1 GroupEntity (org.simbasecurity.core.domain.GroupEntity)1 Policy (org.simbasecurity.core.domain.Policy)1 ResourceRule (org.simbasecurity.core.domain.ResourceRule)1 SessionEntity (org.simbasecurity.core.domain.SessionEntity)1