Example usage for org.eclipse.jgit.transport ReceivePack getPushCertificate

List of usage examples for org.eclipse.jgit.transport ReceivePack getPushCertificate

Introduction

In this page you can find the example usage for org.eclipse.jgit.transport ReceivePack getPushCertificate.

Prototype

public PushCertificate getPushCertificate() 

Source Link

Document

Get the push certificate used to verify the pusher's identity.

Usage

From source file:com.google.gerrit.gpg.SignedPushPreReceiveHook.java

License:Apache License

@Override
public void onPreReceive(ReceivePack rp, Collection<ReceiveCommand> commands) {
    PushCertificate cert = rp.getPushCertificate();
    if (cert == null) {
        return;/*from  w w w  .j a v a2s. c om*/
    }
    PushCertificateChecker checker = new PushCertificateChecker(keyChecker) {
        @Override
        protected Repository getRepository() throws IOException {
            return repoManager.openRepository(allUsers);
        }

        @Override
        protected boolean shouldClose(Repository repo) {
            return true;
        }
    };
    CheckResult result = checker.check(cert);
    if (!result.isOk()) {
        for (String problem : result.getProblems()) {
            rp.sendMessage(problem);
        }
        reject(commands, "invalid push cert");
    }
}

From source file:com.google.gerrit.server.git.gpg.SignedPushPreReceiveHook.java

License:Apache License

@Override
public void onPreReceive(ReceivePack rp, Collection<ReceiveCommand> commands) {
    try {/*from   www .  j a  v a  2s .c  o  m*/
        PushCertificate cert = rp.getPushCertificate();
        if (cert == null) {
            return;
        }
        PushCertificateChecker checker = new PushCertificateChecker(new PublicKeyChecker()) {
            @Override
            protected Repository getRepository() throws IOException {
                return repoManager.openRepository(allUsers);
            }

            @Override
            protected boolean shouldClose(Repository repo) {
                return true;
            }
        };
        CheckResult result = checker.check(cert);
        if (!result.isOk()) {
            for (String problem : result.getProblems()) {
                rp.sendMessage(problem);
            }
            reject(commands, "invalid push cert");
        }
    } catch (PGPException | IOException e) {
        log.error("Error checking push certificate", e);
        reject(commands, "push cert error");
    }
}