use of org.motechproject.security.domain.MotechUserProfile in project motech by motech.
the class MotechUserServiceTest method shouldChangePasswordWhenWhenOldHasBeenExpired.
@Test
public void shouldChangePasswordWhenWhenOldHasBeenExpired() {
MotechUser motechUser = new MotechUser();
motechUser.setUserStatus(UserStatus.MUST_CHANGE_PASSWORD);
motechUser.setPassword(PASSWORD);
motechUser.setUserName(USER);
motechUser.setFailureLoginCounter(1);
when(motechUsersDao.findByUserName(USER)).thenReturn(motechUser);
when(motechPasswordEncoder.isPasswordValid(PASSWORD, PASSWORD)).thenReturn(true);
when(motechPasswordEncoder.isPasswordValid(PASSWORD, NEW_PASSWORD)).thenReturn(false);
when(motechPasswordEncoder.encodePassword(NEW_PASSWORD)).thenReturn(NEW_PASSWORD + "_encoded");
when(settingService.getFailureLoginLimit()).thenReturn(2);
MotechUserProfile profile = motechUserService.changeExpiredPassword(USER, PASSWORD, NEW_PASSWORD);
verify(motechUsersDao).update(userCaptor.capture());
verify(motechPasswordEncoder).encodePassword(NEW_PASSWORD);
MotechUser capturedUser = userCaptor.getValue();
assertEquals(USER, capturedUser.getUserName());
assertEquals(NEW_PASSWORD + "_encoded", capturedUser.getPassword());
assertNotNull(profile);
assertEquals(USER, profile.getUserName());
}
use of org.motechproject.security.domain.MotechUserProfile 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.MotechUserProfile 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.MotechUserProfile 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.MotechUserProfile in project motech by motech.
the class MotechUserServiceBundleIT method shouldNotActivateUserWhenPasswordsAreTheSame.
@Test
public void shouldNotActivateUserWhenPasswordsAreTheSame() {
motechUserService.register("expired", "password", "1234", "", asList("IT_ADMIN"), Locale.ENGLISH, UserStatus.MUST_CHANGE_PASSWORD, "");
MotechUserProfile profile = motechUserService.changeExpiredPassword("expired", "password", "password");
assertNull(profile);
UserDto userDto = motechUserService.getUser("expired");
assertEquals(UserStatus.MUST_CHANGE_PASSWORD, userDto.getUserStatus());
}
Aggregations