Search in sources :

Example 1 with ServiceAccount

use of org.platformlayer.auth.ServiceAccount in project platformlayer by platformlayer.

the class RootResource method requireSystemAccess.

protected void requireSystemAccess() throws AuthenticatorException {
    X509Certificate[] certChain = getCertificateChain();
    if (certChain != null && certChain.length != 0) {
        CertificateChainInfo chain = new CertificateChainInfo();
        for (X509Certificate cert : certChain) {
            CertificateInfo info = new CertificateInfo();
            info.publicKey = Hex.toHex(cert.getPublicKey().getEncoded());
            info.subjectDN = Certificates.getSubject(cert);
            // Md5Hash hash = OpenSshUtils.getSignature(cert.getPublicKey());
            // certificateInfo.setPublicKeyHash(hash.toHex());
            chain.certificates.add(info);
        }
        ServiceAccount auth = systemAuthenticator.authenticate(chain);
        if (auth != null) {
            log.debug("Certificate authentication SUCCESS for " + chain);
            return;
        }
        log.debug("Certificate authentication FAIL for " + chain);
    } else {
        log.debug("Certificate authentication FAIL (no certificate presented)");
    }
    throwUnauthorized();
// return myTokenInfo;
}
Also used : ServiceAccount(org.platformlayer.auth.ServiceAccount) CertificateChainInfo(org.platformlayer.auth.model.CertificateChainInfo) CertificateInfo(org.platformlayer.auth.model.CertificateInfo) X509Certificate(java.security.cert.X509Certificate)

Example 2 with ServiceAccount

use of org.platformlayer.auth.ServiceAccount in project platformlayer by platformlayer.

the class CreateServiceAccount method runCommand.

@Override
public Object runCommand() throws Exception {
    Certificate[] certificateChain = getContext().getCertificateChain(keystore, keystoreSecret, keyAlias);
    X509Certificate cert;
    if (certificateChain.length == 1) {
        cert = (X509Certificate) certificateChain[0];
    } else {
        System.out.println("Certificate chain has length " + certificateChain.length + ", assuming entry 2 is CA");
        cert = (X509Certificate) certificateChain[1];
    }
    UserDatabase userRepository = getContext().getUserRepository();
    ServiceAccount account = userRepository.createServiceAccount(cert);
    return account;
}
Also used : ServiceAccount(org.platformlayer.auth.ServiceAccount) UserDatabase(org.platformlayer.auth.UserDatabase) X509Certificate(java.security.cert.X509Certificate) X509Certificate(java.security.cert.X509Certificate) Certificate(java.security.cert.Certificate)

Aggregations

X509Certificate (java.security.cert.X509Certificate)2 ServiceAccount (org.platformlayer.auth.ServiceAccount)2 Certificate (java.security.cert.Certificate)1 UserDatabase (org.platformlayer.auth.UserDatabase)1 CertificateChainInfo (org.platformlayer.auth.model.CertificateChainInfo)1 CertificateInfo (org.platformlayer.auth.model.CertificateInfo)1