Search in sources :

Example 16 with AccessToken

use of io.pivotal.cla.data.AccessToken in project pivotal-cla by pivotalsoftware.

the class GitHubSignatureTests method setup.

@Before
public void setup() {
    gitHubSignature = new GitHubSignature(mockAccessTokens);
    token = new AccessToken();
    token.setToken("bff3b811-ea31-437b-8083-e451c50f0f99");
}
Also used : AccessToken(io.pivotal.cla.data.AccessToken) Before(org.junit.Before)

Example 17 with AccessToken

use of io.pivotal.cla.data.AccessToken in project pivotal-cla by pivotalsoftware.

the class GenerateAccessTokenConfig method afterSingletonsInstantiated.

/* (non-Javadoc)
	 * @see org.springframework.beans.factory.SmartInitializingSingleton#afterSingletonsInstantiated()
	 */
@Override
public void afterSingletonsInstantiated() {
    AccessToken accessToken = accessTokens.findOne(AccessToken.CLA_ACCESS_TOKEN_ID);
    if (accessToken != null) {
        return;
    }
    String token = UUID.randomUUID().toString();
    accessToken = new AccessToken(AccessToken.CLA_ACCESS_TOKEN_ID, token);
    accessTokens.save(accessToken);
}
Also used : AccessToken(io.pivotal.cla.data.AccessToken)

Example 18 with AccessToken

use of io.pivotal.cla.data.AccessToken in project pivotal-cla by pivotalsoftware.

the class GitHubSignature method check.

@SneakyThrows
public boolean check(String gitHubSignature, String body) {
    if (gitHubSignature == null || !gitHubSignature.startsWith(SIGNATURE_PREFIX)) {
        return false;
    }
    AccessToken expectedToken = accessTokens.findOne(AccessToken.CLA_ACCESS_TOKEN_ID);
    if (expectedToken == null) {
        return false;
    }
    String providedHmac = gitHubSignature.substring(SIGNATURE_PREFIX.length());
    byte[] providedHmacBytes = Hex.decode(providedHmac);
    byte[] expectedBytes = sign(body, expectedToken.getToken());
    return MessageDigest.isEqual(providedHmacBytes, expectedBytes);
}
Also used : AccessToken(io.pivotal.cla.data.AccessToken) SneakyThrows(lombok.SneakyThrows)

Example 19 with AccessToken

use of io.pivotal.cla.data.AccessToken in project pivotal-cla by pivotalsoftware.

the class ClaService method savePullRequestStatus.

public void savePullRequestStatus(ClaPullRequestStatusRequest request) {
    String claName = request.getClaName();
    PullRequestStatus commitStatus = request.getCommitStatus();
    String gitHubLogin = commitStatus.getGitHubUsername();
    if (commitStatus.getAccessToken() == null) {
        AccessToken accessToken = accessTokenRepository.findOne(commitStatus.getRepoId());
        if (accessToken == null) {
            return;
        }
        String token = accessToken.getToken();
        commitStatus.setAccessToken(token);
    }
    if (commitStatus.getSha() == null) {
        String sha = gitHub.getShaForPullRequest(commitStatus);
        if (sha == null) {
            return;
        }
        commitStatus.setSha(sha);
    }
    if (commitStatus.getSuccess() == null) {
        boolean hasSigned = hasSigned(gitHubLogin, claName);
        commitStatus.setSuccess(hasSigned);
    }
    gitHub.save(commitStatus);
}
Also used : AccessToken(io.pivotal.cla.data.AccessToken) PullRequestStatus(io.pivotal.cla.service.github.PullRequestStatus)

Aggregations

AccessToken (io.pivotal.cla.data.AccessToken)19 Test (org.junit.Test)13 PullRequestStatus (io.pivotal.cla.service.github.PullRequestStatus)10 User (io.pivotal.cla.data.User)9 WithSigningUser (io.pivotal.cla.security.WithSigningUser)2 ContributingUrlsResponse (io.pivotal.cla.service.github.ContributingUrlsResponse)2 CreatePullRequestHookRequest (io.pivotal.cla.service.github.CreatePullRequestHookRequest)2 Before (org.junit.Before)2 Matchers.anyString (org.mockito.Matchers.anyString)2 PullRequestId (io.pivotal.cla.egit.github.core.PullRequestId)1 UrlBuilder (io.pivotal.cla.mvc.util.UrlBuilder)1 WithAdminUser (io.pivotal.cla.security.WithAdminUser)1 SignCclaPage (io.pivotal.cla.webdriver.pages.SignCclaPage)1 SignClaPage (io.pivotal.cla.webdriver.pages.SignClaPage)1 SignIclaPage (io.pivotal.cla.webdriver.pages.SignIclaPage)1 AdminLinkClaPage (io.pivotal.cla.webdriver.pages.admin.AdminLinkClaPage)1 SneakyThrows (lombok.SneakyThrows)1 WithAnonymousUser (org.springframework.security.test.context.support.WithAnonymousUser)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1