com.sap.cds.repackaged.audit.client.impl.ServiceCredentialParser Maven / Gradle / Ivy
package com.sap.cds.repackaged.audit.client.impl;
import java.io.IOException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.sap.cds.repackaged.audit.api.exception.ClientInitializationException;
import com.sap.xs.env.Credentials;
public class ServiceCredentialParser {
private static final Logger LOGGER = LoggerFactory.getLogger(ServiceCredentialParser.class);
private static final String UAA_PARAMETER_NAME = "uaa";
private static final String NO_UAA_PARAMETER_DETECTED =
"No \"uaa\" parameter detected in the service configuration, this should be the standard plan scenario";
private static final String PARSING_CREDENTIALS_ERROR = "Problem occurred while trying to parse XSUAA credentials";
private static final ObjectMapper MAPPER = new ObjectMapper();
private Credentials serviceCredentials;
public ServiceCredentialParser(Credentials serviceCredentials) {
this.serviceCredentials = serviceCredentials;
}
public OAuthCredentials parseCredentials() {
final Object uaaObj = serviceCredentials.any()
.get(UAA_PARAMETER_NAME);
if (uaaObj == null) {
LOGGER.info(NO_UAA_PARAMETER_DETECTED);
return null;
}
try {
String jsonInString = MAPPER.writeValueAsString(uaaObj);
OAuthCredentials oauthCredentials = MAPPER.readValue(jsonInString, OAuthCredentials.class);
return oauthCredentials;
} catch (IOException e) {
throw new ClientInitializationException(PARSING_CREDENTIALS_ERROR, e);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy