![JAR search and dependency download from the Maven repository](/logo.png)
com.sap.cloud.sdk.cloudplatform.metering.OAuthService Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of metering-scp-neo Show documentation
Show all versions of metering-scp-neo Show documentation
Implementation of the Cloud platform abstraction for API metering functionality
on the SAP Cloud Platform (Neo).
/*
* Copyright (c) 2018 SAP SE or an SAP affiliate company. All rights reserved.
*/
package com.sap.cloud.sdk.cloudplatform.metering;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.slf4j.Logger;
import com.netflix.hystrix.exception.HystrixRuntimeException;
import com.sap.cloud.sdk.cloudplatform.logging.CloudLoggerFactory;
import com.sap.cloud.sdk.cloudplatform.security.Role;
import com.sap.cloud.sdk.cloudplatform.tenant.ScpNeoTenant;
import com.sap.cloud.sdk.cloudplatform.tenant.TenantAccessor;
class OAuthService
{
private static final Logger logger = CloudLoggerFactory.getLogger(OAuthService.class);
// Caution: although not public, this method is used directly by Financial Statement Insights!
static OAuthToken getAccessToken()
{
try {
return new OAuthTokenCommand().execute();
}
catch( final HystrixRuntimeException e ) {
logger.warn("Failed to retrieve OAuth token.", e);
return null;
}
}
static List getUsersForRole( @Nonnull final Role role, @Nullable final OAuthToken token )
{
if( token == null ) {
logger.warn("Failed to retrieve users for role \"" + role + "\": no OAuth token available.");
return new ArrayList<>();
}
try {
final ScpNeoTenant currentTenant = (ScpNeoTenant) TenantAccessor.getCurrentTenant();
return new UsersForRoleCommand(
currentTenant.getTenantContext().getTenant().getAccount().getId(),
role,
token).execute();
}
catch( final HystrixRuntimeException e ) {
logger.warn("Failed to retrieve users for role \"" + role + "\".", e);
return new ArrayList<>();
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy