use of com.evolveum.midpoint.xml.ns._public.common.common_3.SecurityQuestionsCredentialsType in project midpoint by Evolveum.
the class SecurityQuestionsPolicyEvaluator method validateCredentialContainerValues.
@Override
protected void validateCredentialContainerValues(PrismContainerValue<SecurityQuestionsCredentialsType> cVal) throws PolicyViolationException, SchemaException, ObjectNotFoundException, ExpressionEvaluationException {
SecurityQuestionsCredentialsType securityQuestions = cVal.asContainerable();
if (securityQuestions != null) {
List<SecurityQuestionAnswerType> questionAnswers = securityQuestions.getQuestionAnswer();
for (SecurityQuestionAnswerType questionAnswer : questionAnswers) {
ProtectedStringType answer = questionAnswer.getQuestionAnswer();
validateProtectedStringValue(answer);
}
}
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.SecurityQuestionsCredentialsType in project midpoint by Evolveum.
the class PageSecurityQuestions method createUsersSecurityQuestionsList.
public List<SecurityQuestionAnswerDTO> createUsersSecurityQuestionsList(PrismObject<UserType> user) {
SecurityQuestionsCredentialsType credentialsPolicyType = user.asObjectable().getCredentials().getSecurityQuestions();
if (credentialsPolicyType == null) {
return null;
}
List<SecurityQuestionAnswerType> secQuestAnsList = credentialsPolicyType.getQuestionAnswer();
if (secQuestAnsList != null) {
List<SecurityQuestionAnswerDTO> secQuestAnswListDTO = new ArrayList<SecurityQuestionAnswerDTO>();
for (Iterator iterator = secQuestAnsList.iterator(); iterator.hasNext(); ) {
SecurityQuestionAnswerType securityQuestionAnswerType = (SecurityQuestionAnswerType) iterator.next();
Protector protector = getPrismContext().getDefaultProtector();
String decoded = "";
if (securityQuestionAnswerType.getQuestionAnswer().getEncryptedDataType() != null) {
try {
decoded = protector.decryptString(securityQuestionAnswerType.getQuestionAnswer());
} catch (EncryptionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
secQuestAnswListDTO.add(new SecurityQuestionAnswerDTO(securityQuestionAnswerType.getQuestionIdentifier(), decoded));
}
return secQuestAnswListDTO;
} else {
return null;
}
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.SecurityQuestionsCredentialsType in project midpoint by Evolveum.
the class TestAbstractRestService method test600modifySecurityQuestionAnswer.
@Test
public void test600modifySecurityQuestionAnswer() throws Exception {
final String TEST_NAME = "test600modifySecurityQuestionAnswer";
displayTestTile(this, TEST_NAME);
WebClient client = prepareClient();
client.path("/users/" + USER_DARTHADDER_OID);
getDummyAuditService().clear();
TestUtil.displayWhen(TEST_NAME);
Response response = client.post(getRequestFile(MODIFICATION_REPLACE_ANSWER));
TestUtil.displayThen(TEST_NAME);
displayResponse(response);
traceResponse(response);
assertEquals("Expected 204 but got " + response.getStatus(), 204, response.getStatus());
IntegrationTestTools.display("Audit", getDummyAuditService());
getDummyAuditService().assertRecords(4);
getDummyAuditService().assertLoginLogout(SchemaConstants.CHANNEL_REST_URI);
getDummyAuditService().assertHasDelta(1, ChangeType.MODIFY, UserType.class);
TestUtil.displayWhen(TEST_NAME);
response = client.get();
TestUtil.displayThen(TEST_NAME);
displayResponse(response);
assertEquals("Expected 200 but got " + response.getStatus(), 200, response.getStatus());
UserType userDarthadder = response.readEntity(UserType.class);
CredentialsType credentials = userDarthadder.getCredentials();
assertNotNull("No credentials in user. Something is wrong.", credentials);
SecurityQuestionsCredentialsType securityQuestions = credentials.getSecurityQuestions();
assertNotNull("No security questions defined for user. Something is wrong.", securityQuestions);
List<SecurityQuestionAnswerType> secQuestionAnswers = securityQuestions.getQuestionAnswer();
assertEquals("Expected just one question-answer couple, but found " + secQuestionAnswers.size(), 1, secQuestionAnswers.size());
SecurityQuestionAnswerType secQuestionAnswer = secQuestionAnswers.iterator().next();
String decrypted = getPrismContext().getDefaultProtector().decryptString(secQuestionAnswer.getQuestionAnswer());
assertEquals("Unexpected answer " + decrypted + ". Expected 'newAnswer'.", "newAnswer", decrypted);
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.SecurityQuestionsCredentialsType in project midpoint by Evolveum.
the class SecurityQuestionAuthneticationEvaluatorImpl method passwordMatches.
@Override
protected boolean passwordMatches(ConnectionEnvironment connEnv, MidPointPrincipal principal, SecurityQuestionsCredentialsType passwordType, SecurityQuestionsAuthenticationContext authCtx) {
SecurityQuestionsCredentialsPolicyType policy = authCtx.getPolicy();
Integer iNumberOfQuestions = policy.getQuestionNumber();
int numberOfQuestions = 0;
if (iNumberOfQuestions != null) {
numberOfQuestions = iNumberOfQuestions.intValue();
}
Map<String, String> enteredQuestionsAnswers = authCtx.getQuestionAnswerMap();
if (numberOfQuestions > enteredQuestionsAnswers.size()) {
return false;
}
List<SecurityQuestionAnswerType> quetionsAnswers = passwordType.getQuestionAnswer();
int matched = 0;
for (SecurityQuestionAnswerType questionAnswer : quetionsAnswers) {
String enteredAnswer = enteredQuestionsAnswers.get(questionAnswer.getQuestionIdentifier());
if (StringUtils.isNotBlank(enteredAnswer)) {
if (decryptAndMatch(connEnv, principal, questionAnswer.getQuestionAnswer(), enteredAnswer)) {
matched++;
}
}
}
return matched > 0 && matched >= numberOfQuestions;
}
Aggregations