Search in sources :

Example 1 with OAuthAccessTokenParams

use of io.pivotal.cla.service.github.OAuthAccessTokenParams in project pivotal-cla by pivotalsoftware.

the class AuthenticationTests method authenticateAdmin.

@Test
public void authenticateAdmin() throws Exception {
    User user = WithAdminUserFactory.create();
    when(mockGitHub.getCurrentUser(any(CurrentUserRequest.class))).thenReturn(user);
    AdminLinkClaPage admin = AdminLinkClaPage.to(driver);
    admin.assertAt();
    ArgumentCaptor<CurrentUserRequest> userCaptor = ArgumentCaptor.forClass(CurrentUserRequest.class);
    verify(mockGitHub).getCurrentUser(userCaptor.capture());
    CurrentUserRequest userRequest = userCaptor.getValue();
    OAuthAccessTokenParams oauthParams = userRequest.getOauthParams();
    assertThat(userRequest.isRequestAdminAccess()).isTrue();
    assertThat(oauthParams.getCallbackUrl()).isEqualTo("https://localhost/login/oauth2/github");
    assertThat(oauthParams.getCode()).isEqualTo("abc");
}
Also used : WithSigningUser(io.pivotal.cla.security.WithSigningUser) User(io.pivotal.cla.data.User) CurrentUserRequest(io.pivotal.cla.service.github.CurrentUserRequest) AdminLinkClaPage(io.pivotal.cla.webdriver.pages.admin.AdminLinkClaPage) OAuthAccessTokenParams(io.pivotal.cla.service.github.OAuthAccessTokenParams) Test(org.junit.Test)

Example 2 with OAuthAccessTokenParams

use of io.pivotal.cla.service.github.OAuthAccessTokenParams in project pivotal-cla by pivotalsoftware.

the class AuthenticationTests method authenticateUser.

@Test
public void authenticateUser() throws Exception {
    User user = WithSigningUserFactory.create();
    when(mockClaRepository.findByNameAndPrimaryTrue(cla.getName())).thenReturn(cla);
    when(mockGitHub.getCurrentUser(any(CurrentUserRequest.class))).thenReturn(user);
    SignClaPage claPage = SignClaPage.go(driver, cla.getName());
    claPage.assertAt();
    ArgumentCaptor<CurrentUserRequest> userCaptor = ArgumentCaptor.forClass(CurrentUserRequest.class);
    verify(mockGitHub).getCurrentUser(userCaptor.capture());
    CurrentUserRequest userRequest = userCaptor.getValue();
    OAuthAccessTokenParams oauthParams = userRequest.getOauthParams();
    assertThat(userRequest.isRequestAdminAccess()).isFalse();
    assertThat(oauthParams.getCallbackUrl()).isEqualTo("https://localhost/login/oauth2/github");
    assertThat(oauthParams.getCode()).isEqualTo("abc");
}
Also used : SignClaPage(io.pivotal.cla.webdriver.pages.SignClaPage) WithSigningUser(io.pivotal.cla.security.WithSigningUser) User(io.pivotal.cla.data.User) CurrentUserRequest(io.pivotal.cla.service.github.CurrentUserRequest) OAuthAccessTokenParams(io.pivotal.cla.service.github.OAuthAccessTokenParams) Test(org.junit.Test)

Example 3 with OAuthAccessTokenParams

use of io.pivotal.cla.service.github.OAuthAccessTokenParams in project pivotal-cla by pivotalsoftware.

the class OAuthController method oauth.

@RequestMapping("/login/oauth2/github")
public void oauth(ImportedSignaturesSessionAttr importedSignaturesAttr, HttpServletRequest request, HttpServletResponse response, @RequestParam String code, @RequestParam String state) throws Exception {
    String actualState = (String) request.getSession().getAttribute("state");
    if (actualState == null || !actualState.equals(state)) {
        throw new InvalidSecretState();
    }
    boolean admin = GitHubAuthenticationEntryPoint.isAdmin(state);
    OAuthAccessTokenParams params = new OAuthAccessTokenParams();
    params.setCallbackUrl(UrlBuilder.fromRequest(request).callbackUrl());
    params.setCode(code);
    params.setState(actualState);
    CurrentUserRequest userRequest = new CurrentUserRequest();
    userRequest.setOauthParams(params);
    userRequest.setRequestAdminAccess(admin);
    User user = gitHub.getCurrentUser(userRequest);
    User existingUser = users.findOne(user.getGitHubLogin());
    boolean isNewUser = existingUser == null;
    users.save(user);
    Authentication authentication = Login.loginAs(user);
    if (isNewUser) {
        List<IndividualSignature> individualSignatures = individual.findSignaturesFor(new PageRequest(0, 1), user);
        boolean signed = !individualSignatures.isEmpty();
        if (!signed) {
            List<String> organizations = gitHub.getOrganizations(user.getGitHubLogin());
            signed = !corporate.findSignatures(new PageRequest(0, 1), organizations, user.getEmails()).isEmpty();
        }
        if (signed) {
            importedSignaturesAttr.setValue(true);
        }
    }
    success.onAuthenticationSuccess(request, response, authentication);
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) User(io.pivotal.cla.data.User) Authentication(org.springframework.security.core.Authentication) CurrentUserRequest(io.pivotal.cla.service.github.CurrentUserRequest) OAuthAccessTokenParams(io.pivotal.cla.service.github.OAuthAccessTokenParams) IndividualSignature(io.pivotal.cla.data.IndividualSignature) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

User (io.pivotal.cla.data.User)3 CurrentUserRequest (io.pivotal.cla.service.github.CurrentUserRequest)3 OAuthAccessTokenParams (io.pivotal.cla.service.github.OAuthAccessTokenParams)3 WithSigningUser (io.pivotal.cla.security.WithSigningUser)2 Test (org.junit.Test)2 IndividualSignature (io.pivotal.cla.data.IndividualSignature)1 SignClaPage (io.pivotal.cla.webdriver.pages.SignClaPage)1 AdminLinkClaPage (io.pivotal.cla.webdriver.pages.admin.AdminLinkClaPage)1 PageRequest (org.springframework.data.domain.PageRequest)1 Authentication (org.springframework.security.core.Authentication)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1