Search in sources :

Example 1 with SecurityQuestion

use of org.orcid.pojo.SecurityQuestion in project ORCID-Source by ORCID.

the class ManageProfileControllerTest method testSetSecurityQuestionWithEmptyAnswer.

@Test
public void testSetSecurityQuestionWithEmptyAnswer() {
    SecurityQuestion s = new SecurityQuestion();
    s.setPassword("password");
    s.setSecurityAnswer("");
    s.setSecurityQuestionId(1L);
    controller.setSecurityQuestion(s);
    assertEquals(1, s.getErrors().size());
    assertEquals("manage.pleaseProvideAnAnswer", s.getErrors().get(0));
    verify(mockProfileEntityManager, times(0)).updateSecurityQuestion(Mockito.anyString(), Mockito.any(), Mockito.any());
}
Also used : SecurityQuestion(org.orcid.pojo.SecurityQuestion) Test(org.junit.Test)

Example 2 with SecurityQuestion

use of org.orcid.pojo.SecurityQuestion in project ORCID-Source by ORCID.

the class ManageProfileController method getSecurityQuestion.

@RequestMapping(value = "/security-question.json", method = RequestMethod.GET)
@ResponseBody
public SecurityQuestion getSecurityQuestion() {
    ProfileEntity profile = profileEntityCacheManager.retrieve(getCurrentUserOrcid());
    SecurityQuestion securityQuestion = new SecurityQuestion();
    if (profile.getSecurityQuestion() != null) {
        Long id = Long.valueOf(profile.getSecurityQuestion().getId());
        String encryptedAnswer = profile.getEncryptedSecurityAnswer();
        if (!PojoUtil.isEmpty(encryptedAnswer)) {
            securityQuestion.setSecurityAnswer(encryptionManager.decryptForInternalUse(encryptedAnswer));
        }
        securityQuestion.setSecurityQuestionId(id);
    }
    return securityQuestion;
}
Also used : ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) SecurityQuestion(org.orcid.pojo.SecurityQuestion) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 3 with SecurityQuestion

use of org.orcid.pojo.SecurityQuestion in project ORCID-Source by ORCID.

the class ManageProfileControllerTest method testSetSecurityQuestionWithIvalidPassword.

@Test
public void testSetSecurityQuestionWithIvalidPassword() {
    SecurityQuestion s = new SecurityQuestion();
    s.setPassword("invalid password");
    s.setSecurityAnswer("answer");
    s.setSecurityQuestionId(1L);
    controller.setSecurityQuestion(s);
    assertEquals(1, s.getErrors().size());
    assertEquals("check_password_modal.incorrect_password", s.getErrors().get(0));
    verify(mockProfileEntityManager, times(0)).updateSecurityQuestion(Mockito.anyString(), Mockito.any(), Mockito.any());
}
Also used : SecurityQuestion(org.orcid.pojo.SecurityQuestion) Test(org.junit.Test)

Example 4 with SecurityQuestion

use of org.orcid.pojo.SecurityQuestion in project ORCID-Source by ORCID.

the class ManageProfileControllerTest method testSetSecurityQuestion.

@Test
public void testSetSecurityQuestion() {
    SecurityContextHolder.getContext().setAuthentication(getAuthentication(USER_ORCID));
    SecurityQuestion s = new SecurityQuestion();
    s.setPassword("password");
    s.setSecurityAnswer("answer");
    s.setSecurityQuestionId(1L);
    controller.setSecurityQuestion(s);
    assertEquals(1, s.getErrors().size());
    assertEquals("manage.securityQuestionUpdated", s.getErrors().get(0));
    verify(mockProfileEntityManager, times(1)).updateSecurityQuestion(Mockito.eq(USER_ORCID), Mockito.eq(Integer.valueOf(1)), Mockito.eq("answer"));
}
Also used : SecurityQuestion(org.orcid.pojo.SecurityQuestion) Test(org.junit.Test)

Aggregations

SecurityQuestion (org.orcid.pojo.SecurityQuestion)4 Test (org.junit.Test)3 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1