2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.policy.pypdp;
23 import java.util.UUID;
25 import org.openecomp.policy.api.PolicyConfigException;
26 import org.openecomp.policy.pypdp.model_pojo.PepPushPolicyRequest;
27 import org.openecomp.policy.std.StdPolicyEngine;
29 import org.openecomp.policy.xacml.api.XACMLErrorConstants;
31 import org.openecomp.policy.common.logging.eelf.MessageCodes;
32 import org.openecomp.policy.common.logging.eelf.PolicyLogger;
34 public class PushPolicyRequest {
35 private StdPolicyEngine pe;
36 public PushPolicyRequest(StdPolicyEngine pe){
40 public String run(PepPushPolicyRequest pep, String requestID, String userID, String passcode) {
44 // construct a UUID from the request string
45 UUID requestUUID = null;
46 if (requestID != null && !requestID.isEmpty()) {
48 requestUUID = UUID.fromString(requestID);
50 catch (IllegalArgumentException e) {
51 requestUUID = UUID.randomUUID();
52 PolicyLogger.info("Generated Random UUID: " + requestUUID.toString());
55 requestUUID = UUID.randomUUID();
56 PolicyLogger.error("No Request UUID Given, hence generating one random ID: " + requestUUID.toString());
58 String policyName = pep.getPolicyName();
59 String policyScope = pep.getPolicyScope();
60 if(policyName==null || policyName.isEmpty()){
61 return XACMLErrorConstants.ERROR_DATA_ISSUE + "BAD REQUEST: policyName was null or empty.";
63 if(policyScope== null || policyScope.isEmpty()){
65 policyName = pep.getPolicyName().substring(pep.getPolicyName().lastIndexOf(".")+1, pep.getPolicyName().length());
66 policyScope = pep.getPolicyName().substring(0, pep.getPolicyName().lastIndexOf("."));
67 } catch (Exception e){
68 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "BAD REQUEST: policyScope was null or empty.");
69 return XACMLErrorConstants.ERROR_DATA_ISSUE + "BAD REQUEST: policyScope was null or empty.";
72 PolicyLogger.info("policyName: " + policyName + " policyScope is : " + policyScope);
73 if (pep.getPolicyType() != null && !pep.getPolicyType().isEmpty()) {
74 if (pep.getPdpGroup() != null && !pep.getPdpGroup().isEmpty()) {
76 result = pe.pushPolicy(policyScope ,policyName , pep.getPolicyType(), pep.getPdpGroup(), requestUUID, userID, passcode);
77 } catch (PolicyConfigException e) {
78 result = e.getMessage();
79 } catch (Exception e) {
80 result = e.getMessage();
83 result = XACMLErrorConstants.ERROR_DATA_ISSUE + "BAD REQUEST: policyGroup was null or empty.";
86 result = XACMLErrorConstants.ERROR_DATA_ISSUE + "BAD REQUEST: policyType was null or empty.";