All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.sap.cds.repackaged.audit.client.impl.TokenFactory Maven / Gradle / Ivy

There is a newer version: 3.2.0
Show newest version
package com.sap.cds.repackaged.audit.client.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.sap.cloud.security.xsuaa.client.OAuth2TokenResponse;
import com.sap.cloud.security.xsuaa.tokenflows.TokenFlowException;
import com.sap.cloud.security.xsuaa.tokenflows.XsuaaTokenFlows;

public class TokenFactory {
    private static final Logger LOGGER = LoggerFactory.getLogger(TokenFactory.class);

    private final XsuaaTokenFlows xsuaaTokenFlows;

    public TokenFactory(XsuaaTokenFlows xsuaaTokenFlows) {
        this.xsuaaTokenFlows = xsuaaTokenFlows;
    }

    public String getClientCredentialsGrantAccessToken()
            throws IllegalArgumentException, TokenFlowException {
        final OAuth2TokenResponse response = xsuaaTokenFlows.clientCredentialsTokenFlow()
                .disableCache(false)
                .execute();
        LOGGER.info("Got client credentials grant JWT token");
        return response.getAccessToken();
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy