* ============LICENSE_START=======================================================
* ONAP-PDP-REST
* ================================================================================
* ============LICENSE_START=======================================================
* ONAP-PDP-REST
* ================================================================================
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* limitations under the License.
* ============LICENSE_END=========================================================
*/
* limitations under the License.
* ============LICENSE_END=========================================================
*/
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import org.onap.policy.api.PolicyEngineException;
import org.onap.policy.common.logging.eelf.MessageCodes;
import org.onap.policy.common.logging.flexlogger.FlexLogger;
import org.onap.policy.api.PolicyEngineException;
import org.onap.policy.common.logging.eelf.MessageCodes;
import org.onap.policy.common.logging.flexlogger.FlexLogger;
import org.onap.policy.rest.XACMLRestProperties;
import org.onap.policy.utils.AAFPolicyClient;
import org.onap.policy.utils.AAFPolicyException;
import org.onap.policy.rest.XACMLRestProperties;
import org.onap.policy.utils.AAFPolicyClient;
import org.onap.policy.utils.AAFPolicyException;
public class PDPApiAuth {
private static final Logger LOGGER = FlexLogger.getLogger(PDPApiAuth.class);
private static String environment = null;
private static Path clientPath = null;
public class PDPApiAuth {
private static final Logger LOGGER = FlexLogger.getLogger(PDPApiAuth.class);
private static String environment = null;
private static Path clientPath = null;
public static void setProperty() {
environment = XACMLProperties.getProperty("ENVIRONMENT", "DEVL");
String clientFile = XACMLProperties.getProperty(XACMLRestProperties.PROP_PEP_IDFILE);
public static void setProperty() {
environment = XACMLProperties.getProperty("ENVIRONMENT", "DEVL");
String clientFile = XACMLProperties.getProperty(XACMLRestProperties.PROP_PEP_IDFILE);
String usernameAndPassword = null;
byte[] decodedBytes = Base64.getDecoder().decode(clientEncoding);
usernameAndPassword = new String(decodedBytes, "UTF-8");
StringTokenizer tokenizer = new StringTokenizer(usernameAndPassword, ":");
String username = tokenizer.nextToken();
String password = tokenizer.nextToken();
String usernameAndPassword = null;
byte[] decodedBytes = Base64.getDecoder().decode(clientEncoding);
usernameAndPassword = new String(decodedBytes, "UTF-8");
StringTokenizer tokenizer = new StringTokenizer(usernameAndPassword, ":");
String username = tokenizer.nextToken();
String password = tokenizer.nextToken();
- * If AAF is NOT enabled in the properties we will allow the user to
- * continue to use the client.properties file to authenticate.
- * Note: Disabling AAF is for testing purposes and not intended for production.
+ * If AAF is NOT enabled in the properties we will allow the user to continue to use the
+ * client.properties file to authenticate. Note: Disabling AAF is for testing purposes and not intended
+ * for production.
String aafPolicyNameSpace = XACMLProperties.getProperty("policy.aaf.namespace");
String aafResource = XACMLProperties.getProperty("policy.aaf.root.permission");
String type = null;
String aafPolicyNameSpace = XACMLProperties.getProperty("policy.aaf.namespace");
String aafResource = XACMLProperties.getProperty("policy.aaf.root.permission");
String type = null;
result = aafClient.checkAuthPerm(userNamePass[0], userNamePass[1], type, environment, "*");
}
return result;
result = aafClient.checkAuthPerm(userNamePass[0], userNamePass[1], type, environment, "*");
}
return result;
private static String reverseNamespace(String namespace) {
final List<String> components = Arrays.asList(namespace.split("\\."));
private static String reverseNamespace(String namespace) {
final List<String> components = Arrays.asList(namespace.split("\\."));
- private static Map<String, ArrayList<String>> readProps(Path clientPath) throws PolicyEngineException{
- if(oldModified!=null){
+ private static Map<String, ArrayList<String>> readProps(Path clientPath) throws PolicyEngineException {
+ if (oldModified != null) {
- LOGGER.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR , e);
- throw new PolicyEngineException(XACMLErrorConstants.ERROR_SYSTEM_ERROR +"Cannot Load the Properties file", e);
+ LOGGER.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR, e);
+ throw new PolicyEngineException(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Cannot Load the Properties file",
+ e);
String clientValue = clientProp.getProperty(clientID);
if (clientValue != null && clientValue.contains(",")) {
ArrayList<String> clientValues = new ArrayList<>(Arrays.asList(clientValue.split("\\s*,\\s*")));
String clientValue = clientProp.getProperty(clientID);
if (clientValue != null && clientValue.contains(",")) {
ArrayList<String> clientValues = new ArrayList<>(Arrays.asList(clientValue.split("\\s*,\\s*")));
- if(clientValues.get(0)!=null || clientValues.get(1)!=null || clientValues.get(0).isEmpty() || clientValues.get(1).isEmpty()){
+ if (clientValues.get(0) != null || clientValues.get(1) != null || clientValues.get(0).isEmpty()
+ || clientValues.get(1).isEmpty()) {
+ clientValues.set(0, PeCryptoUtils.decrypt(clientValues.get(0)));
clientMap.put(clientID, clientValues);
}
}
}
if (clientMap.isEmpty()) {
clientMap.put(clientID, clientValues);
}
}
}
if (clientMap.isEmpty()) {
- LOGGER.debug(XACMLErrorConstants.ERROR_PERMISSIONS + "No Clients ID , Client Key and Scopes are available. Cannot serve any Clients !!");
+ LOGGER.debug(XACMLErrorConstants.ERROR_PERMISSIONS
+ + "No Clients ID , Client Key and Scopes are available. Cannot serve any Clients !!");
throw new PolicyEngineException("Empty Client file");
}
oldModified = clientPath.toFile().lastModified();
return clientMap;
}
throw new PolicyEngineException("Empty Client file");
}
oldModified = clientPath.toFile().lastModified();
return clientMap;
}