assertEquals(0, getFailedLogins(userService4, userId));
}
@Test
public void checkUserSuspension() {
UserTO userTO = UserTestITCase.getUniqueSampleTO("checkSuspension@syncope.apache.org");
MembershipTO membershipTO = new MembershipTO();
membershipTO.setRoleId(7L);
AttributeTO testAttributeTO = new AttributeTO();
testAttributeTO.setSchema("testAttribute");
testAttributeTO.addValue("a value");
membershipTO.addAttribute(testAttributeTO);
userTO.addMembership(membershipTO);
userTO = createUser(userTO);
long userId = userTO.getId();
assertNotNull(userTO);
UserService userService2 = setupCredentials(userService, UserService.class,
userTO.getUsername(), "password123");
assertEquals(0, getFailedLogins(userService2, userId));
// authentications failed ...
UserService userService3 = setupCredentials(userService, UserService.class,
userTO.getUsername(), "wrongpwd1");
assertReadFails(userService3, userId);
assertReadFails(userService3, userId);
assertReadFails(userService3, userId);
// reset admin credentials for restTemplate
super.resetRestTemplate();
assertEquals(3, getFailedLogins(userService, userId));
// last authentication before suspension
// TODO remove after CXF migration is complete
userService3 = setupCredentials(userService, UserService.class, userTO.getUsername(), "wrongpwd1");
assertReadFails(userService3, userId);
// reset admin credentials for restTemplate
super.resetRestTemplate();
userTO = userService.read(userTO.getId());
assertNotNull(userTO);
assertNotNull(userTO.getFailedLogins());
assertEquals(Integer.valueOf(3), userTO.getFailedLogins());
assertEquals("suspended", userTO.getStatus());
// Access with correct credentials should fail as user is suspended
// TODO remove after CXF migration is complete
userService2 = setupCredentials(userService, UserService.class, userTO.getUsername(), "password123");
assertReadFails(userService2, userId);
// reset admin credentials for restTemplate
super.resetRestTemplate();
userTO = userService.reactivate(userTO.getId());
assertNotNull(userTO);
assertEquals("active", userTO.getStatus());
// TODO remove after CXF migration is complete
userService2 = setupCredentials(userService, UserService.class, userTO.getUsername(), "password123");
assertEquals(0, getFailedLogins(userService2, userId));
}