use of org.platformlayer.auth.v1.CertificateChainInfo in project platformlayer by platformlayer.
the class CertificateChains method toModel.
public static CertificateChainInfo toModel(X509Certificate[] chain) {
CertificateChainInfo chainInfo = new CertificateChainInfo();
List<CertificateInfo> certificates = chainInfo.getCertificates();
for (X509Certificate cert : chain) {
CertificateInfo certificateInfo = new CertificateInfo();
certificateInfo.setSubjectDN(Certificates.getSubject(cert));
Md5Hash hash = OpenSshUtils.getSignature(cert.getPublicKey());
certificateInfo.setPublicKeyHash(hash.toHex());
byte[] data = cert.getPublicKey().getEncoded();
certificateInfo.setPublicKey(Hex.toHex(data));
certificates.add(certificateInfo);
}
return chainInfo;
}
use of org.platformlayer.auth.v1.CertificateChainInfo in project platformlayer by platformlayer.
the class PlatformLayerAuthAdminClient method checkServiceAccess.
public String checkServiceAccess(CertificateChainInfo chain) {
String url = "services/check";
CheckServiceAccessRequest request = new CheckServiceAccessRequest();
request.setChain(chain);
try {
CheckServiceAccessResponse response = doSimpleXmlRequest(HttpMethod.POST, url, request, CheckServiceAccessResponse.class);
return response.getServiceAccount();
} catch (RestClientException e) {
throw new IllegalArgumentException("Error while checking service access", e);
}
}
use of org.platformlayer.auth.v1.CertificateChainInfo in project platformlayer by platformlayer.
the class PlatformLayerAuthAdminClient method validateChain.
@Override
public ProjectAuthorization validateChain(X509Certificate[] chain, String projectKey) {
// v2.0/keychain[?project={projectKey}]
String url = "v2.0/keychain";
url += "?project=" + UrlUtils.urlEncode(projectKey);
CertificateChainInfo chainInfo = CertificateChains.toModel(chain);
try {
ValidateTokenResponse response = doSimpleXmlRequest(HttpMethod.POST, url, chainInfo, ValidateTokenResponse.class);
ValidateAccess access = response.getAccess();
if (access == null) {
return null;
}
UserValidation userInfo = access.getUser();
if (userInfo == null) {
return null;
}
ProjectValidation projectInfo = access.getProject();
if (projectInfo == null) {
return null;
}
String userKey = userInfo.getName();
PlatformlayerUserAuthentication user = new PlatformlayerUserAuthentication(null, userKey);
PlatformlayerProjectAuthorization project = buildPlatformlayerProjectAuthorization(user, projectInfo);
return project;
} catch (RestClientException e) {
if (e.getHttpResponseCode() != null && e.getHttpResponseCode() == 404) {
// Not found => invalid token
return null;
}
log.warn("Error while validating credentials", e);
throw new IllegalArgumentException("Error while validating credentials", e);
}
}
Aggregations