summaryrefslogtreecommitdiffstats
path: root/vespa-athenz/src/main/java/com/yahoo/vespa/athenz/zpe/DefaultZpe.java
blob: 29044111adad8813f07913b7c042c39bce7dff6d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.athenz.zpe;

import com.yahoo.athenz.zpe.AuthZpeClient;
import com.yahoo.vespa.athenz.api.AthenzResourceName;
import com.yahoo.vespa.athenz.api.ZToken;

import java.security.cert.X509Certificate;

/**
 * The default implementation of {@link Zpe}.
 * This implementation is currently based on the official Athenz ZPE library.
 *
 * @author bjorncs
 */
public class DefaultZpe implements Zpe {

    public DefaultZpe() {
        AuthZpeClient.init();
    }

    @Override
    public AuthorizationResult checkAccessAllowed(ZToken roleToken, AthenzResourceName resourceName, String action) {
        return AuthorizationResult.fromAccessCheckStatus(
                AuthZpeClient.allowAccess(roleToken.getRawToken(), resourceName.toResourceNameString(), action));
    }

    @Override
    public AuthorizationResult checkAccessAllowed(X509Certificate roleCertificate, AthenzResourceName resourceName, String action) {
        return AuthorizationResult.fromAccessCheckStatus(
                AuthZpeClient.allowAccess(roleCertificate, resourceName.toResourceNameString(), action));
    }

}