use of org.motechproject.security.domain.MotechUser in project motech by motech.
the class MotechAccessVoterTest method shouldVoteAffirmativeIfUserHasAccess.
@Test
public void shouldVoteAffirmativeIfUserHasAccess() {
List<ConfigAttribute> attributes = new ArrayList<ConfigAttribute>();
attributes.add(new SecurityConfig("access_testuser"));
attributes.add(new SecurityConfig("access_motechUser"));
MotechUserProfile userProfile = new MotechUserProfile(new MotechUser("TestUser", "p@ssw0rd", "", "", null, "", Locale.ENGLISH));
UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken("TestUser", "p@ssw0rd");
authentication.setDetails(userProfile);
MotechAccessVoter voter = new MotechAccessVoter();
assertEquals(1, voter.vote(authentication, null, attributes));
}
use of org.motechproject.security.domain.MotechUser in project motech by motech.
the class MotechAccessVoterTest method shouldAbstrainIfNoAccessAttributes.
public void shouldAbstrainIfNoAccessAttributes() {
List<ConfigAttribute> attributes = new ArrayList<ConfigAttribute>();
MotechUserProfile userProfile = new MotechUserProfile(new MotechUser("TestUser", "p@ssw0rd", "", "", null, "", Locale.ENGLISH));
UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken("TestUser", "p@ssw0rd");
authentication.setDetails(userProfile);
MotechAccessVoter voter = new MotechAccessVoter();
assertEquals(0, voter.vote(authentication, null, attributes));
}
use of org.motechproject.security.domain.MotechUser in project motech by motech.
the class MotechAccessVoterTest method shouldVoteNegativeIfUserDoesNotHaveAccess.
public void shouldVoteNegativeIfUserDoesNotHaveAccess() {
List<ConfigAttribute> attributes = new ArrayList<ConfigAttribute>();
attributes.add(new SecurityConfig("access_otheruser"));
attributes.add(new SecurityConfig("access_motechUser"));
MotechUserProfile userProfile = new MotechUserProfile(new MotechUser("TestUser", "p@ssw0rd", "", "", null, "", Locale.ENGLISH));
UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken("TestUser", "p@ssw0rd");
authentication.setDetails(userProfile);
MotechAccessVoter voter = new MotechAccessVoter();
assertEquals(-1, voter.vote(authentication, null, attributes));
}
use of org.motechproject.security.domain.MotechUser in project motech by motech.
the class MotechRoleServiceBundleIT method shouldNotDeleteRoleWithUsers.
@Test(expected = RoleHasUserException.class)
public void shouldNotDeleteRoleWithUsers() {
motechRoleService.createRole(new RoleDto("Role-With-User", asList("permissionA, permissionB"), true));
RoleDto role = motechRoleService.getRole("Role-With-User");
assertNotNull(role);
motechUserService.register("duke", "password", "email", "1234", asList("Role-With-User"), Locale.ENGLISH);
MotechUser motechUser = usersDataService.findByUserName("duke");
assertNotNull(motechUser);
assertTrue(motechUser.hasRole("Role-With-User"));
motechRoleService.deleteRole(role);
}
use of org.motechproject.security.domain.MotechUser in project motech by motech.
the class MotechUserServiceBundleIT method shouldNotActivateInvalidUser.
@Test
public void shouldNotActivateInvalidUser() {
motechUserService.register("userName", "password", "1234", "", asList("IT_ADMIN", "DB_ADMIN"), Locale.ENGLISH, UserStatus.BLOCKED, null);
motechUserService.activateUser("userName1");
MotechUser motechUser = usersDataService.findByUserName("userName");
assertFalse(motechUser.isActive());
}
Aggregations