Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagexml
linenumberstrue
<route id="get-service-template">
        <from uri="direct:get-service-template"/>
        <doTry>
            <log loggingLevel="INFO"
                 message="Getting the tosca service template"/>
            <to
                    uri="bean:org.onap.policy.clamp.flow.log.FlowLogOperation?method=invokeLog('AutomationComposition', 'Getting the tosca service template')"/>
            <setHeader name="CamelHttpMethod">
                <constant>GET</constant>
            </setHeader>
            <setHeader name="Content-Type">
                <constant>application/json</constant>
            </setHeader>
            <setProperty name="name">
                <simple>${header.name}</simple>
            </setProperty>
            <setProperty name="version">
                <simple>${header.version}</simple>
            </setProperty>
            <setProperty name="instanceName">
                <simple>${header.instanceName}</simple>
            </setProperty>
            <log loggingLevel="INFO"
                 message="Endpoint to get Tosca Service Template: {{clamp.config.acm.runtime.url}}/onap/policy/clamp/acm/v2/commission/toscaservicetemplate"></log>
            <toD uri="{{clamp.config.acm.runtime.url}}/onap/policy/clamp/acm/v2/commission/toscaservicetemplate?name=${exchangeProperty[name]}&version=${exchangeProperty[version]}&instanceName=${exchangeProperty[instanceName]}&bridgeEndpoint=true&useSystemProperties=true&throwExceptionOnFailure=${exchangeProperty[raiseHttpExceptionFlag]}&authMethod=Basic&authUsername={{clamp.config.acm.runtime.userName}}&authPassword={{clamp.config.acm.runtime.password}}&authenticationPreemptive=true&connectionClose=true"/>
            <convertBodyTo type="java.lang.String"/>
            <doFinally>
                <to uri="direct:reset-raise-http-exception-flag"/>
                <to
                        uri="bean:org.onap.policy.clamp.flow.log.FlowLogOperation?method=invokeReturnLog()"/>
            </doFinally>
        </doTry>
    </route>


The Solution

Create a new REST endpoint controller by applying the same principals as the ACM Endpoints by encompassing all the clamp url and by upgrading the version to V3 which implies that all client connection has to create a new contract with the server side.  This new Rest controller can be utilized in conjunction with Open Api related task.  By having a new Rest Controller where the Camel URL would redirect to a service class, the Rest Controller can replace all of the Camel Configuration XML files.

Code Block
languagejava
linenumberstrue
/*
 * ============LICENSE_START=======================================================
 *  Copyright (C) 2022 Nordix Foundation.
 *  ================================================================================
 *  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
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *  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.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 *  SPDX-License-Identifier: Apache-2.0
 *  ============LICENSE_END=========================================================
 */

package org.onap.policy.clamp.authorization.rest;

import javax.ws.rs.core.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * Abstract Rest Controller for runtime clamp to inherit from.
 */
@RequestMapping(value = "/onap/policy/clamp/clds/v3", produces = {MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON})
public abstract class AbstractRestController {
}


Code Block
languagejava
linenumberstrue
/*
 * ============LICENSE_START=======================================================
 *  Copyright (C) 2022 Nordix Foundation.
 *  ================================================================================
 *  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
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *  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.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 *  SPDX-License-Identifier: Apache-2.0
 *  ============LICENSE_END=========================================================
 */

package org.onap.policy.clamp.authorization.rest;

import org.onap.policy.clamp.authorization.AuthorizationController;
import org.onap.policy.clamp.clds.model.ClampInformation;
import org.onap.policy.clamp.clds.model.CldsHealthCheck;
import org.onap.policy.clamp.clds.service.CldsHealthcheckService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.ws.rs.core.MediaType;

/**
 * Rest clamp controller.
 */
@RestController
public class ClampController extends AbstractRestController {

    private AuthorizationController authorizationController;

    private CldsHealthcheckService healthcheckService;


    /**
     * Constructor for ClampController with autowires other bean classes.
     *
     * @param authorizationController controller for security purposes
     * @param healthcheckService service for healthcheck on all rest endpoints
     */
    @Autowired
    public ClampController(
            AuthorizationController authorizationController,
            CldsHealthcheckService healthcheckService) {

        this.authorizationController = authorizationController;
        this.healthcheckService = healthcheckService;
    }

    @GetMapping(value = "/clampInformation", produces = MediaType.APPLICATION_JSON)
    public ClampInformation getClampInfo() {
        return this.authorizationController.getClampInformation();
    }

    @GetMapping(value = "/user/getUser", produces = MediaType.TEXT_PLAIN)
    public String getUser() {
        return AuthorizationController.getPrincipalName(SecurityContextHolder.getContext());
    }

    @GetMapping(value = "/healthcheck", produces = MediaType.APPLICATION_JSON)
    public CldsHealthCheck getHealthCheck() {
        return this.healthcheckService.gethealthcheck();
    }
}

Issues still need to be addressed

  • The GUI login popup is sent via the headers
  • Spring Security isn't centralized in one location
  • CORS Issue with ACM
  • Preflight Issue with ACM