Search in sources :

Example 1 with OauthRegistrationForm

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

the class OauthRegistrationController method getRegister.

@RequestMapping(value = "/oauth/custom/register/empty.json", method = RequestMethod.GET)
@ResponseBody
public OauthRegistrationForm getRegister(HttpServletRequest request, HttpServletResponse response) {
    // Remove the session hash if needed
    if (request.getSession().getAttribute(RegistrationController.GRECAPTCHA_SESSION_ATTRIBUTE_NAME) != null) {
        request.getSession().removeAttribute(RegistrationController.GRECAPTCHA_SESSION_ATTRIBUTE_NAME);
    }
    OauthRegistrationForm empty = new OauthRegistrationForm(registrationController.getRegister(request, response));
    // Creation type in oauth will always be member referred
    empty.setCreationType(Text.valueOf(CreationMethod.MEMBER_REFERRED.value()));
    Text emptyText = Text.valueOf(StringUtils.EMPTY);
    empty.setPassword(emptyText);
    return empty;
}
Also used : OauthRegistrationForm(org.orcid.pojo.ajaxForm.OauthRegistrationForm) Text(org.orcid.pojo.ajaxForm.Text) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 2 with OauthRegistrationForm

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

the class OauthRegistrationControllerTest method testStripHtmlFromNames.

@SuppressWarnings("unchecked")
@Test
public void testStripHtmlFromNames() throws UnsupportedEncodingException {
    HttpSession session = mock(HttpSession.class);
    RequestInfoForm rf = new RequestInfoForm();
    RedirectView mv = new RedirectView();
    when(servletRequest.getSession()).thenReturn(session);
    when(servletRequest.getSession().getAttribute("requestInfoForm")).thenReturn(rf);
    when(authorizationEndpoint.approveOrDeny(Matchers.anyMap(), Matchers.anyMap(), Matchers.any(SessionStatus.class), Matchers.any(Principal.class))).thenReturn(mv);
    when(authenticationManager.authenticate(Matchers.any(Authentication.class))).thenAnswer(new Answer<Authentication>() {

        @Override
        public Authentication answer(InvocationOnMock invocation) throws Throwable {
            OrcidOAuth2Authentication mockedAuthentication = mock(OrcidOAuth2Authentication.class);
            return mockedAuthentication;
        }
    });
    Text email = Text.valueOf(System.currentTimeMillis() + "@test.orcid.org");
    OauthRegistrationForm reg = new OauthRegistrationForm();
    org.orcid.pojo.ajaxForm.Visibility fv = new org.orcid.pojo.ajaxForm.Visibility();
    fv.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.PUBLIC);
    reg.setActivitiesVisibilityDefault(fv);
    reg.setEmail(email);
    reg.setEmailConfirm(email);
    reg.setFamilyNames(Text.valueOf("<button onclick=\"alert('hello')\">Family Name</button>"));
    reg.setGivenNames(Text.valueOf("<button onclick=\"alert('hello')\">Given Names</button>"));
    reg.setPassword(Text.valueOf("1234abcd"));
    reg.setPasswordConfirm(Text.valueOf("1234abcd"));
    reg.setValNumClient(2L);
    reg.setValNumServer(4L);
    reg.setApproved(true);
    Checkbox c = new Checkbox();
    c.setValue(true);
    reg.setTermsOfUse(c);
    reg.setCreationType(Text.valueOf(CreationMethod.DIRECT.value()));
    reg.setPersistentTokenEnabled(true);
    oauthRegistrationController.registerAndAuthorize(servletRequest, servletResponse, reg);
    ArgumentCaptor<HttpServletRequest> argument1 = ArgumentCaptor.forClass(HttpServletRequest.class);
    ArgumentCaptor<Registration> argument2 = ArgumentCaptor.forClass(Registration.class);
    ArgumentCaptor<Boolean> argument3 = ArgumentCaptor.forClass(Boolean.class);
    ArgumentCaptor<Locale> argument4 = ArgumentCaptor.forClass(Locale.class);
    ArgumentCaptor<String> argument5 = ArgumentCaptor.forClass(String.class);
    verify(registrationController).createMinimalRegistration(argument1.capture(), argument2.capture(), argument3.capture(), argument4.capture(), argument5.capture());
    assertNotNull(argument2.getValue());
    Registration registration = argument2.getValue();
    assertEquals(email.getValue(), registration.getEmail().getValue());
    assertEquals("Given Names", registration.getGivenNames().getValue());
    assertEquals("Family Name", registration.getFamilyNames().getValue());
}
Also used : Locale(java.util.Locale) HttpServletRequest(javax.servlet.http.HttpServletRequest) OauthRegistrationForm(org.orcid.pojo.ajaxForm.OauthRegistrationForm) Checkbox(org.orcid.pojo.ajaxForm.Checkbox) Registration(org.orcid.pojo.ajaxForm.Registration) SessionStatus(org.springframework.web.bind.support.SessionStatus) RequestInfoForm(org.orcid.pojo.ajaxForm.RequestInfoForm) HttpSession(javax.servlet.http.HttpSession) Text(org.orcid.pojo.ajaxForm.Text) OrcidOAuth2Authentication(org.orcid.core.oauth.OrcidOAuth2Authentication) OrcidOAuth2Authentication(org.orcid.core.oauth.OrcidOAuth2Authentication) Authentication(org.springframework.security.core.Authentication) InvocationOnMock(org.mockito.invocation.InvocationOnMock) RedirectView(org.springframework.web.servlet.view.RedirectView) Principal(java.security.Principal) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Aggregations

OauthRegistrationForm (org.orcid.pojo.ajaxForm.OauthRegistrationForm)2 Text (org.orcid.pojo.ajaxForm.Text)2 Principal (java.security.Principal)1 Locale (java.util.Locale)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpSession (javax.servlet.http.HttpSession)1 Test (org.junit.Test)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 OrcidOAuth2Authentication (org.orcid.core.oauth.OrcidOAuth2Authentication)1 Checkbox (org.orcid.pojo.ajaxForm.Checkbox)1 Registration (org.orcid.pojo.ajaxForm.Registration)1 RequestInfoForm (org.orcid.pojo.ajaxForm.RequestInfoForm)1 DBUnitTest (org.orcid.test.DBUnitTest)1 Authentication (org.springframework.security.core.Authentication)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1 SessionStatus (org.springframework.web.bind.support.SessionStatus)1 RedirectView (org.springframework.web.servlet.view.RedirectView)1