use of org.motechproject.security.domain.MotechRole in project motech by motech.
the class MotechURLSecurityServiceBundleIT method setUp.
@Before
@Override
public void setUp() throws Exception {
super.setUp();
securityService = getFromContext(MotechURLSecurityService.class, "motechURLSecurityService");
authenticationManager = getFromContext(AuthenticationManager.class, "authenticationManager");
motechUserService.registerMotechAdmin("motech", "motech", "aaa@admin.com", Locale.ENGLISH);
setUpSecurityContext("motech", "motech", getPermissions());
getSecurityRuleDataService().deleteAll();
usersDataService.deleteAll();
rolesDataService.deleteAll();
rolesDataService.create(new MotechRole(SECURITY_MANAGE_ADMIN, asList(PermissionNames.MANAGE_URL_PERMISSION), false));
}
use of org.motechproject.security.domain.MotechRole in project motech by motech.
the class MotechAuthenticationProviderTest method shouldRetrieveUserFromDatabase.
@Test
public void shouldRetrieveUserFromDatabase() {
MotechUser motechUser = new MotechUser("bob", "encodedPassword", "entity_1", "", asList("some_role"), "", Locale.ENGLISH);
MotechRole motechRole = new MotechRole("some_role", asList("some_permission"), false);
when(motechUsersDao.findByUserName("bob")).thenReturn(motechUser);
// when(allMotechRoles.findByRoleName("some_role")).thenReturn(motechRole);
UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken("bob", "password");
UserDetails userDetails = authenticationProvider.retrieveUser("bob", authentication);
assertEquals("encodedPassword", userDetails.getPassword());
assertEquals(motechUser.getUserName(), ((MotechUserProfile) authentication.getDetails()).getUserName());
assertEquals(motechUser.getUserName(), userDetails.getUsername());
}
use of org.motechproject.security.domain.MotechRole in project motech by motech.
the class MotechRoleServiceTest method shouldRefreshUserContextWhenRoleIsDeleted.
@Test
public void shouldRefreshUserContextWhenRoleIsDeleted() {
RoleDto role = new RoleDto("role1", asList("permission1"));
MotechRole motechRole = mock(MotechRole.class);
when(motechRole.isDeletable()).thenReturn(true);
when(rolesDataService.findByRoleName("role1")).thenReturn(motechRole);
motechRoleService.deleteRole(role);
verify(userContextsService).refreshAllUsersContextIfActive();
}
use of org.motechproject.security.domain.MotechRole in project motech by motech.
the class MotechRoleServiceTest method shouldRefreshUserContextWhenRoleIsUpdated.
@Test
public void shouldRefreshUserContextWhenRoleIsUpdated() {
RoleDto role = new RoleDto("role1", asList("permission1"));
MotechRole motechRole = mock(MotechRole.class);
when(rolesDataService.findByRoleName("role1")).thenReturn(motechRole);
motechRoleService.updateRole(role);
verify(userContextsService).refreshAllUsersContextIfActive();
}
use of org.motechproject.security.domain.MotechRole in project motech by motech.
the class MotechRoleServiceBundleIT method shouldNotCreateNewRoleIfRoleOfTheSameNameAlreadyExists.
@Test
public void shouldNotCreateNewRoleIfRoleOfTheSameNameAlreadyExists() {
String roleName = "sameRole";
motechRoleService.createRole(new RoleDto(roleName, asList("per1", "per2"), false));
motechRoleService.createRole(new RoleDto(roleName, asList("per3", "per4"), false));
MotechRole motechRole = rolesDataService.findByRoleName(roleName);
List<MotechRole> allRoles = rolesDataService.retrieveAll();
int numberOfRoles = 0;
for (MotechRole role : allRoles) {
if (roleName.equalsIgnoreCase(role.getRoleName())) {
++numberOfRoles;
}
}
assertEquals(1, numberOfRoles);
assertEquals("per1", motechRole.getPermissionNames().get(0));
assertEquals("per2", motechRole.getPermissionNames().get(1));
}
Aggregations