tvaultapi/src/main/java/com/tmobile/cso/vault/api/service/SSLCertificateService.java
public boolean hasDownloadPermission(String certificateName, UserDetails userDetails, String certType) {
		String certPrefix=(certType.equalsIgnoreCase(SSLCertificateConstants.INTERNAL))?
                SSLCertificateConstants.INTERNAL_POLICY_NAME :SSLCertificateConstants.EXTERNAL_POLICY_NAME;	
        String readPolicy = SSLCertificateConstants.READ_CERT_POLICY_PREFIX +certPrefix+"_" + certificateName;
        String sudoPolicy = SSLCertificateConstants.SUDO_CERT_POLICY_PREFIX +certPrefix+"_" + certificateName;
        String renewRevokePolicy = SSLCertificateConstants.WRITE_CERT_POLICY_PREFIX +certPrefix+"_" + certificateName;
        if (userDetails.isAdmin() || userDetails.isCertAdmin()) {
            return true;
        }
        VaultTokenLookupDetails  vaultTokenLookupDetails = null;
        try {
            vaultTokenLookupDetails = tokenValidator.getVaultTokenLookupDetails(userDetails.getClientToken());
        } catch (TVaultValidationException e) {
            log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder().
                    put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)).
                    put(LogMessage.ACTION, "hasDownloadPermission").
                    put(LogMessage.MESSAGE, String.format ("Failed to get lookup details for user  [%s]", userDetails.getUsername())).
                    put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).
                    build()));
            return false;
        }
        String[] policies = vaultTokenLookupDetails.getPolicies();
        if (ArrayUtils.isNotEmpty(policies) && (Arrays.asList(policies).contains(readPolicy) || Arrays.asList(policies).contains(sudoPolicy) || Arrays.asList(policies).contains(renewRevokePolicy))) {
            return true;
        }
        return false;
    }
/**
     * Check if user has download permission.
     * @param certificateName
     * @param userDetails
     * @return
     */
Check if user has download permission.
@param certificateName
@param userDetails
@return
Check if user has download permission . @param certificateName @param userDetails @return
public boolean hasDownloadPermission(String certificateName, UserDetails userDetails, String certType) {
		String certPrefix=(certType.equalsIgnoreCase(SSLCertificateConstants.INTERNAL))?
                SSLCertificateConstants.INTERNAL_POLICY_NAME :SSLCertificateConstants.EXTERNAL_POLICY_NAME;	
        String readPolicy = SSLCertificateConstants.READ_CERT_POLICY_PREFIX +certPrefix+"_" + certificateName;
        String sudoPolicy = SSLCertificateConstants.SUDO_CERT_POLICY_PREFIX +certPrefix+"_" + certificateName;
        String renewRevokePolicy = SSLCertificateConstants.WRITE_CERT_POLICY_PREFIX +certPrefix+"_" + certificateName;
        if (userDetails.isAdmin() || userDetails.isCertAdmin()) {
            return true;
        }
        VaultTokenLookupDetails  vaultTokenLookupDetails = null;
        try {
            vaultTokenLookupDetails = tokenValidator.getVaultTokenLookupDetails(userDetails.getClientToken());
        } catch (TVaultValidationException e) {
            log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder().
                    put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)).
                    put(LogMessage.ACTION, "hasDownloadPermission").
                    put(LogMessage.MESSAGE, String.format ("Failed to get lookup details for user  [%s]", userDetails.getUsername())).
                    put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).
                    build()));
            return false;
        }
        String[] policies = vaultTokenLookupDetails.getPolicies();
        if (ArrayUtils.isNotEmpty(policies) && (Arrays.asList(policies).contains(readPolicy) || Arrays.asList(policies).contains(sudoPolicy) || Arrays.asList(policies).contains(renewRevokePolicy))) {
            return true;
        }
        return false;
    }
public boolean hasDownloadPermission ( String certificateName , UserDetails userDetails , String certType ) { String certPrefix = ( certType . equalsIgnoreCase ( SSLCertificateConstants . INTERNAL ) ) ? SSLCertificateConstants . INTERNAL_POLICY_NAME : SSLCertificateConstants . EXTERNAL_POLICY_NAME ; String readPolicy = SSLCertificateConstants . READ_CERT_POLICY_PREFIX + certPrefix + "_" + certificateName ; String sudoPolicy = SSLCertificateConstants . SUDO_CERT_POLICY_PREFIX + certPrefix + "_" + certificateName ; String renewRevokePolicy = SSLCertificateConstants . WRITE_CERT_POLICY_PREFIX + certPrefix + "_" + certificateName ; if ( userDetails . isAdmin ( ) || userDetails . isCertAdmin ( ) ) { return true ; } VaultTokenLookupDetails vaultTokenLookupDetails = null ; try { vaultTokenLookupDetails = tokenValidator . getVaultTokenLookupDetails ( userDetails . getClientToken ( ) ) ; } catch ( TVaultValidationException e ) { log . debug ( JSONUtil . getJSON ( ImmutableMap . < String , String > builder ( ) . put ( LogMessage . USER , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . USER ) ) . put ( LogMessage . ACTION , "hasDownloadPermission" ) . put ( LogMessage . MESSAGE , String . format ( "Failed to get lookup details for user  [%s]" , userDetails . getUsername ( ) ) ) . put ( LogMessage . APIURL , ThreadLocalContext . getCurrentMap ( ) . get ( LogMessage . APIURL ) ) . build ( ) ) ) ; return false ; } String [ ] policies = vaultTokenLookupDetails . getPolicies ( ) ; if ( ArrayUtils . isNotEmpty ( policies ) && ( Arrays . asList ( policies ) . contains ( readPolicy ) || Arrays . asList ( policies ) . contains ( sudoPolicy ) || Arrays . asList ( policies ) . contains ( renewRevokePolicy ) ) ) { return true ; } return false ; }
Check if user has download permission.
Check if user has download permission .