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