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");
}
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);
}
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);
}
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);
}
Aggregations