From 5301a4b0b49eb568d05d59fd20d7b5724b47b8ac Mon Sep 17 00:00:00 2001 From: Jim Hahn Date: Thu, 6 May 2021 14:57:24 -0400 Subject: Fix sonars in xacml-pdp Fixed: - use "var" instead of actual type Issue-ID: POLICY-3285 Change-Id: Id17142d1f2e3e5f9dfbffcb96aff7fe76321a56b Signed-off-by: Jim Hahn --- .../policy/tutorial/policyenforcement/App.java | 17 +++++++-------- .../policy/tutorial/tutorial/TutorialRequest.java | 4 ++-- .../tutorial/tutorial/TutorialTranslator.java | 25 +++++++++++----------- 3 files changed, 22 insertions(+), 24 deletions(-) (limited to 'tutorials') diff --git a/tutorials/tutorial-enforcement/src/main/java/org/onap/policy/tutorial/policyenforcement/App.java b/tutorials/tutorial-enforcement/src/main/java/org/onap/policy/tutorial/policyenforcement/App.java index 764b3bdf..6b291c6a 100644 --- a/tutorials/tutorial-enforcement/src/main/java/org/onap/policy/tutorial/policyenforcement/App.java +++ b/tutorials/tutorial-enforcement/src/main/java/org/onap/policy/tutorial/policyenforcement/App.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,7 +26,6 @@ import java.util.Map.Entry; import java.util.Scanner; import javax.ws.rs.client.Entity; import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure; import org.onap.policy.common.endpoints.event.comm.TopicEndpointManager; import org.onap.policy.common.endpoints.event.comm.TopicListener; @@ -63,13 +62,13 @@ public class App extends Thread implements TopicListener { xacmlPdpHost = args[0]; xacmlPdpPort = args[1]; - TopicParameters params = new TopicParameters(); + var params = new TopicParameters(); params.setTopicCommInfrastructure("dmaap"); params.setFetchLimit(1); params.setFetchTimeout(5000); params.setTopic("POLICY-NOTIFICATION"); params.setServers(Arrays.asList(args[2] + ":" + args[3])); - TopicParameterGroup topicParams = new TopicParameterGroup(); + var topicParams = new TopicParameterGroup(); topicParams.setTopicSources(Arrays.asList(params)); TopicEndpointManager.getManager().addTopics(topicParams); @@ -117,7 +116,7 @@ public class App extends Thread implements TopicListener { TopicEndpointManager.getManager().start(); @SuppressWarnings("resource") // never close System.in - Scanner input = new Scanner(System.in); + var input = new Scanner(System.in); while (!Thread.currentThread().isInterrupted()) { String quit = input.nextLine(); if ("q".equalsIgnoreCase(quit)) { @@ -155,7 +154,7 @@ public class App extends Thread implements TopicListener { * @return true if MY_POLICYTYPEID is in the message */ private boolean scanForPolicyType(String msg) { - StandardCoder gson = new StandardCoder(); + var gson = new StandardCoder(); try { PolicyNotification notification = gson.decode(msg, PolicyNotification.class); for (PolicyStatus added : notification.getAdded()) { @@ -189,7 +188,7 @@ public class App extends Thread implements TopicListener { Entity entityRequest = Entity.entity(decisionRequest, MediaType.APPLICATION_JSON); - Response response = client.post("/decision", entityRequest, Collections.emptyMap()); + var response = client.post("/decision", entityRequest, Collections.emptyMap()); if (response.getStatus() != 200) { logger.error( @@ -197,7 +196,7 @@ public class App extends Thread implements TopicListener { return Collections.emptyMap(); } - DecisionResponse decisionResponse = HttpClient.getBody(response, DecisionResponse.class); + var decisionResponse = HttpClient.getBody(response, DecisionResponse.class); return decisionResponse.getPolicies(); } @@ -210,7 +209,7 @@ public class App extends Thread implements TopicListener { public static void main(String[] args) { logger.info("Hello Welcome to ONAP Enforcement Tutorial!"); - App app = new App(args); + var app = new App(args); app.start(); diff --git a/tutorials/tutorial-xacml-application/src/main/java/org/onap/policy/tutorial/tutorial/TutorialRequest.java b/tutorials/tutorial-xacml-application/src/main/java/org/onap/policy/tutorial/tutorial/TutorialRequest.java index 4bb94cd7..00d4fe70 100644 --- a/tutorials/tutorial-xacml-application/src/main/java/org/onap/policy/tutorial/tutorial/TutorialRequest.java +++ b/tutorials/tutorial-xacml-application/src/main/java/org/onap/policy/tutorial/tutorial/TutorialRequest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -65,7 +65,7 @@ public class TutorialRequest { // // Create our object // - TutorialRequest request = new TutorialRequest(); + var request = new TutorialRequest(); // // Add the subject attributes // diff --git a/tutorials/tutorial-xacml-application/src/main/java/org/onap/policy/tutorial/tutorial/TutorialTranslator.java b/tutorials/tutorial-xacml-application/src/main/java/org/onap/policy/tutorial/tutorial/TutorialTranslator.java index 7a6b5d8a..3d9effe5 100644 --- a/tutorials/tutorial-xacml-application/src/main/java/org/onap/policy/tutorial/tutorial/TutorialTranslator.java +++ b/tutorials/tutorial-xacml-application/src/main/java/org/onap/policy/tutorial/tutorial/TutorialTranslator.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,7 +31,6 @@ import java.util.List; import java.util.Map; import oasis.names.tc.xacml._3_0.core.schema.wd_17.AnyOfType; import oasis.names.tc.xacml._3_0.core.schema.wd_17.EffectType; -import oasis.names.tc.xacml._3_0.core.schema.wd_17.MatchType; import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType; import oasis.names.tc.xacml._3_0.core.schema.wd_17.RuleType; import oasis.names.tc.xacml._3_0.core.schema.wd_17.TargetType; @@ -59,7 +58,7 @@ public class TutorialTranslator implements ToscaPolicyTranslator { // // Here is our policy with a version and default combining algo // - PolicyType newPolicyType = new PolicyType(); + var newPolicyType = new PolicyType(); newPolicyType.setPolicyId(toscaPolicy.getMetadata().get("policy-id")); newPolicyType.setVersion(toscaPolicy.getMetadata().get("policy-version")); // @@ -77,33 +76,33 @@ public class TutorialTranslator implements ToscaPolicyTranslator { // // For simplicity, let's just match on the action "authorize" and the user // - MatchType matchAction = ToscaPolicyTranslatorUtils.buildMatchTypeDesignator( + var matchAction = ToscaPolicyTranslatorUtils.buildMatchTypeDesignator( XACML3.ID_FUNCTION_STRING_EQUAL, "authorize", XACML3.ID_DATATYPE_STRING, XACML3.ID_ACTION_ACTION_ID, XACML3.ID_ATTRIBUTE_CATEGORY_ACTION); Map props = toscaPolicy.getProperties(); - String user = props.get("user").toString(); - MatchType matchUser = ToscaPolicyTranslatorUtils.buildMatchTypeDesignator(XACML3.ID_FUNCTION_STRING_EQUAL, user, + var user = props.get("user").toString(); + var matchUser = ToscaPolicyTranslatorUtils.buildMatchTypeDesignator(XACML3.ID_FUNCTION_STRING_EQUAL, user, XACML3.ID_DATATYPE_STRING, ID_TUTORIAL_USER, XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE); - AnyOfType anyOf = new AnyOfType(); + var anyOf = new AnyOfType(); // // Create AllOf (AND) of just Policy Id // anyOf.getAllOf().add(ToscaPolicyTranslatorUtils.buildAllOf(matchAction, matchUser)); - TargetType target = new TargetType(); + var target = new TargetType(); target.getAnyOf().add(anyOf); newPolicyType.setTarget(target); // // Now add the rule for each permission // - int ruleNumber = 0; + var ruleNumber = 0; List permissions = (List) props.get("permissions"); for (Object permission : permissions) { - MatchType matchEntity = ToscaPolicyTranslatorUtils.buildMatchTypeDesignator(XACML3.ID_FUNCTION_STRING_EQUAL, + var matchEntity = ToscaPolicyTranslatorUtils.buildMatchTypeDesignator(XACML3.ID_FUNCTION_STRING_EQUAL, ((Map) permission).get("entity"), XACML3.ID_DATATYPE_STRING, ID_TUTORIAL_ENTITY, XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE); - MatchType matchPermission = ToscaPolicyTranslatorUtils.buildMatchTypeDesignator( + var matchPermission = ToscaPolicyTranslatorUtils.buildMatchTypeDesignator( XACML3.ID_FUNCTION_STRING_EQUAL, ((Map) permission).get("permission"), XACML3.ID_DATATYPE_STRING, ID_TUTORIAL_PERM, XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE); anyOf = new AnyOfType(); @@ -111,7 +110,7 @@ public class TutorialTranslator implements ToscaPolicyTranslator { target = new TargetType(); target.getAnyOf().add(anyOf); - RuleType rule = new RuleType(); + var rule = new RuleType(); rule.setDescription("Default is to PERMIT if the policy matches."); rule.setRuleId(newPolicyType.getPolicyId() + ":rule" + ruleNumber); @@ -141,7 +140,7 @@ public class TutorialTranslator implements ToscaPolicyTranslator { * Convert XACML Response to ONAP DecisionResponse. */ public DecisionResponse convertResponse(Response xacmlResponse) { - DecisionResponse decisionResponse = new DecisionResponse(); + var decisionResponse = new DecisionResponse(); // // Iterate through all the results // -- cgit 1.2.3-korg