Search in sources :

Example 1 with CertificateChainInfo

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;
}
Also used : CertificateChainInfo(org.platformlayer.auth.v1.CertificateChainInfo) CertificateInfo(org.platformlayer.auth.v1.CertificateInfo) Md5Hash(com.fathomdb.hash.Md5Hash) X509Certificate(java.security.cert.X509Certificate)

Example 2 with CertificateChainInfo

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);
    }
}
Also used : CheckServiceAccessRequest(org.platformlayer.auth.v1.CheckServiceAccessRequest) RestClientException(org.platformlayer.rest.RestClientException) CheckServiceAccessResponse(org.platformlayer.auth.v1.CheckServiceAccessResponse)

Example 3 with CertificateChainInfo

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);
    }
}
Also used : ValidateTokenResponse(org.platformlayer.auth.v1.ValidateTokenResponse) UserValidation(org.platformlayer.auth.v1.UserValidation) ProjectValidation(org.platformlayer.auth.v1.ProjectValidation) ValidateAccess(org.platformlayer.auth.v1.ValidateAccess) CertificateChainInfo(org.platformlayer.auth.v1.CertificateChainInfo) RestClientException(org.platformlayer.rest.RestClientException)

Aggregations

CertificateChainInfo (org.platformlayer.auth.v1.CertificateChainInfo)2 RestClientException (org.platformlayer.rest.RestClientException)2 Md5Hash (com.fathomdb.hash.Md5Hash)1 X509Certificate (java.security.cert.X509Certificate)1 CertificateInfo (org.platformlayer.auth.v1.CertificateInfo)1 CheckServiceAccessRequest (org.platformlayer.auth.v1.CheckServiceAccessRequest)1 CheckServiceAccessResponse (org.platformlayer.auth.v1.CheckServiceAccessResponse)1 ProjectValidation (org.platformlayer.auth.v1.ProjectValidation)1 UserValidation (org.platformlayer.auth.v1.UserValidation)1 ValidateAccess (org.platformlayer.auth.v1.ValidateAccess)1 ValidateTokenResponse (org.platformlayer.auth.v1.ValidateTokenResponse)1