Search in sources :

Example 1 with Role

use of com.epam.pipeline.entity.user.Role in project cloud-pipeline by epam.

the class RoleManager method update.

@Transactional(propagation = Propagation.REQUIRED)
public Role update(final Long roleId, final RoleVO roleVO) {
    Role role = loadRole(roleId);
    role.setName(getValidName(roleVO.getName()));
    role.setUserDefault(roleVO.isUserDefault());
    role.setDefaultStorageId(roleVO.getDefaultStorageId());
    storageValidator.validate(role);
    roleDao.updateRole(role);
    return role;
}
Also used : ExtendedRole(com.epam.pipeline.entity.user.ExtendedRole) Role(com.epam.pipeline.entity.user.Role) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with Role

use of com.epam.pipeline.entity.user.Role in project cloud-pipeline by epam.

the class UserDaoTest method testDefaultAdmin.

@Test
public void testDefaultAdmin() {
    PipelineUser admin = userDao.loadUserByName(defaultAdmin);
    Assert.assertNotNull(admin);
    Assert.assertEquals(defaultAdmin, admin.getUserName());
    Assert.assertTrue(admin.getId().equals(1L));
    Assert.assertEquals(1, admin.getRoles().size());
    Assert.assertTrue(isRolePresent(DefaultRoles.ROLE_ADMIN.getRole(), admin.getRoles()));
    Collection<Role> allRoles = roleDao.loadAllRoles(false);
    Assert.assertEquals(EXPECTED_DEFAULT_ROLES_NUMBER, allRoles.size());
    Assert.assertTrue(isRolePresent(DefaultRoles.ROLE_ADMIN.getRole(), allRoles));
    Assert.assertTrue(isRolePresent(DefaultRoles.ROLE_USER.getRole(), allRoles));
}
Also used : Role(com.epam.pipeline.entity.user.Role) PipelineUser(com.epam.pipeline.entity.user.PipelineUser) Test(org.junit.Test) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest)

Example 3 with Role

use of com.epam.pipeline.entity.user.Role in project cloud-pipeline by epam.

the class RoleContextualPreferenceHandlerTest method isValidShouldReturnTrueIfRoleExists.

@Test
public void isValidShouldReturnTrueIfRoleExists() {
    final ContextualPreference preference = new ContextualPreference(NAME, VALUE, role1Resource);
    when(roleDao.loadRole(eq(Long.valueOf(role1Resource.getResourceId())))).thenReturn(Optional.of(new Role()));
    assertTrue(handler().isValid(preference));
}
Also used : Role(com.epam.pipeline.entity.user.Role) ContextualPreference(com.epam.pipeline.entity.contextual.ContextualPreference) Test(org.junit.Test)

Example 4 with Role

use of com.epam.pipeline.entity.user.Role in project cloud-pipeline by epam.

the class RoleDao method createRole.

@Transactional(propagation = Propagation.MANDATORY)
public Role createRole(String name, boolean predefined, boolean userDefault, Long storageId) {
    Role role = new Role();
    role.setName(name);
    role.setId(daoHelper.createId(roleSequence));
    role.setUserDefault(userDefault);
    role.setPredefined(predefined);
    role.setDefaultStorageId(storageId);
    getNamedParameterJdbcTemplate().update(createRoleQuery, RoleParameters.getParameters(role));
    return role;
}
Also used : ExtendedRole(com.epam.pipeline.entity.user.ExtendedRole) Role(com.epam.pipeline.entity.user.Role) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with Role

use of com.epam.pipeline.entity.user.Role in project cloud-pipeline by epam.

the class RoleManager method deleteRole.

@Transactional(propagation = Propagation.REQUIRED)
public Role deleteRole(Long id) {
    Role role = loadRole(id);
    Assert.isTrue(!role.isPredefined(), "Predefined system roles cannot be deleted");
    permissionManager.deleteGrantedAuthority(role.getName());
    roleDao.deleteRoleReferences(id);
    roleDao.deleteRole(id);
    return role;
}
Also used : ExtendedRole(com.epam.pipeline.entity.user.ExtendedRole) Role(com.epam.pipeline.entity.user.Role) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Role (com.epam.pipeline.entity.user.Role)8 ExtendedRole (com.epam.pipeline.entity.user.ExtendedRole)6 Test (org.junit.Test)5 Transactional (org.springframework.transaction.annotation.Transactional)5 AbstractSpringTest (com.epam.pipeline.AbstractSpringTest)4 S3bucketDataStorage (com.epam.pipeline.entity.datastorage.aws.S3bucketDataStorage)3 DataStorageDao (com.epam.pipeline.dao.datastorage.DataStorageDao)2 DefaultRoles (com.epam.pipeline.entity.user.DefaultRoles)2 ObjectCreatorUtils (com.epam.pipeline.manager.ObjectCreatorUtils)2 Arrays (java.util.Arrays)2 Collection (java.util.Collection)2 List (java.util.List)2 Optional (java.util.Optional)2 CollectionUtils (org.apache.commons.collections4.CollectionUtils)2 CoreMatchers.equalTo (org.hamcrest.CoreMatchers.equalTo)2 IsCollectionWithSize.hasSize (org.hamcrest.collection.IsCollectionWithSize.hasSize)2 Assert (org.junit.Assert)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 ContextualPreference (com.epam.pipeline.entity.contextual.ContextualPreference)1 PipelineUser (com.epam.pipeline.entity.user.PipelineUser)1