The goal of this document is to investigate about removal of deprecated code such as Camel


Instruction

To be able to remove the legacy deprecated code the first rule is to isolate it, and after the successfull isolation is to go to the chopping board and do the hard code removal.

Distributed Services

Diagram 1 - Using Gui Server

Diagram 2 - Using Legacy Clamp

Diagram 3 - No Middle Server

Login UI

Known Issues

Multiple Logins for different applications.

Suggestions


Creating new Rest Endpoints - Either on Legacy Clamp or Gui-Server

Create new rest endpoint to let the gui or postman connect to the different services, which this will request the AAF which permissions the specific user has.

/*
 * ============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 {
}

/*
 * ============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 implements ClampApi {

    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();
    }
}

CORS and Preflight

To solve the CORS and Preflight issue if the gui will connect directly with ACM Runtime.

Server side configuration

/*
 * ============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.acm.runtime.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.CorsConfigurationSource;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;

import java.util.Arrays;
import java.util.List;

@Configuration
public class CorsWebConfiguration {

    @Bean
    public CorsConfigurationSource corsConfigurationSource() {
        CorsConfiguration configuration = new CorsConfiguration();
        configuration.setAllowedOrigins(List.of("*"));
        configuration.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONAL"));
        configuration.setAllowCredentials(true);
        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
        source.registerCorsConfiguration("/**", configuration);

        return source;
    }
}  

Client side configuration

const response = await fetch('http://localhost:6969/onap/policy/clamp/acm/v2/instantiation',  {
      method: 'GET',
      mode: 'no-cors',
      credentials: "include",
      headers: {
        "Content-Type": "application/json",
        Authorization: "Basic " + btoa('runtimeUser:zb!XztG34')
      }
    });

    return response
  • No labels