diff options
Diffstat (limited to 'sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/server')
7 files changed, 364 insertions, 0 deletions
diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/server/config/ApplicationConfigurer.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/server/config/ApplicationConfigurer.java new file mode 100644 index 00000000..a5cce460 --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/server/config/ApplicationConfigurer.java @@ -0,0 +1,50 @@ +/* + * Copyright © 2018 European Support Limited + * + * 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. + * ============LICENSE_END========================================================= + * Modifications copyright (c) 2019 Nokia + * ================================================================================ + */ + +package org.onap.sdc.workflow.server.config; + +import java.util.List; +import org.onap.sdc.workflow.server.resolvers.UserIdResolver; +import org.openecomp.sdc.logging.servlet.spring.LoggingInterceptor; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.method.support.HandlerMethodArgumentResolver; +import org.springframework.web.servlet.config.annotation.InterceptorRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +@Configuration +public class ApplicationConfigurer implements WebMvcConfigurer { + + private final LoggingInterceptor loggingInterceptor; + + @Autowired + public ApplicationConfigurer(LoggingInterceptor loggingInterceptor) { + this.loggingInterceptor = loggingInterceptor; + } + + @Override + public void addInterceptors(InterceptorRegistry registry) { + registry.addInterceptor(loggingInterceptor); + } + + @Override + public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) { + argumentResolvers.add(new UserIdResolver()); + } +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/server/config/LoggingInterceptorConfig.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/server/config/LoggingInterceptorConfig.java new file mode 100644 index 00000000..53dbda59 --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/server/config/LoggingInterceptorConfig.java @@ -0,0 +1,39 @@ +/* + * Copyright © 2018 European Support Limited + * + * 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. + */ + +package org.onap.sdc.workflow.server.config; + +import org.openecomp.sdc.logging.servlet.HttpHeader; +import org.openecomp.sdc.logging.servlet.spring.LoggingInterceptor; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class LoggingInterceptorConfig { + + @Value("${onap.logging.requestIdHeader}") + private String[] loggingRequestIdHeaders; + + @Value("${onap.logging.partnerNameHeader}") + private String[] loggingPartnerNameHeader; + + @Bean + public LoggingInterceptor createLoggingInterceptor() { + return new LoggingInterceptor(new HttpHeader(loggingRequestIdHeaders), + new HttpHeader(loggingPartnerNameHeader)); + } +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/server/config/SwaggerConfig.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/server/config/SwaggerConfig.java new file mode 100644 index 00000000..a2eca63a --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/server/config/SwaggerConfig.java @@ -0,0 +1,39 @@ +/* + * Copyright © 2018 European Support Limited + * + * 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. + */ + +package org.onap.sdc.workflow.server.config; + +import static springfox.documentation.builders.PathSelectors.regex; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import springfox.documentation.builders.RequestHandlerSelectors; +import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spring.web.plugins.Docket; +import springfox.documentation.swagger2.annotations.EnableSwagger2; + +@Configuration +@EnableSwagger2 +public class SwaggerConfig { + + @Bean + public Docket api() { + return new Docket(DocumentationType.SWAGGER_2) + .select().apis(RequestHandlerSelectors.basePackage("org.onap.sdc.workflow.api")) + .paths(regex("/(wf/workflows|v1.0/activity-spec).*")) + .build(); + } +}
\ No newline at end of file diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/server/config/WebServerConfig.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/server/config/WebServerConfig.java new file mode 100644 index 00000000..e760ecd1 --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/server/config/WebServerConfig.java @@ -0,0 +1,44 @@ +/* + * Copyright © 2016-2018 European Support Limited + * + * 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. + */ + +package org.onap.sdc.workflow.server.config; + +import org.eclipse.jetty.server.ServerConnector; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.web.embedded.jetty.JettyServerCustomizer; +import org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory; +import org.springframework.boot.web.server.WebServerFactoryCustomizer; +import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class WebServerConfig implements WebServerFactoryCustomizer<ConfigurableServletWebServerFactory> { + + @Value("${http.port}") + private int httpPort; + + @Override + public void customize(ConfigurableServletWebServerFactory container) { + if (container instanceof JettyServletWebServerFactory) { + JettyServletWebServerFactory containerFactory = (JettyServletWebServerFactory) container; + containerFactory.addServerCustomizers((JettyServerCustomizer) server -> { + ServerConnector connector = new ServerConnector(server); + connector.setPort(httpPort); + server.addConnector(connector); + }); + } + } +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/server/config/WorkflowZusammenConfigProvider.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/server/config/WorkflowZusammenConfigProvider.java new file mode 100644 index 00000000..dbd2d6de --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/server/config/WorkflowZusammenConfigProvider.java @@ -0,0 +1,48 @@ +/* + * Copyright © 2018 European Support Limited + * + * 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. + */ + +package org.onap.sdc.workflow.server.config; + +import lombok.Getter; +import org.onap.sdc.common.zusammen.config.ZusammenConfigProvider; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Configuration; + +@Configuration +@Getter +public class WorkflowZusammenConfigProvider implements ZusammenConfigProvider { + + @Value("${spring.data.cassandra.keyspace-name}") + private String tenant; + @Value("${spring.data.cassandra.contact-points}") + private String cassandraAddresses; + @Value("${spring.data.cassandra.port}") + private String cassandraPort; + + @Value("${spring.data.cassandra.username}") + private String cassandraUser; + @Value("${spring.data.cassandra.password}") + private String cassandraPassword; + @Value("${zusammen.cassandra.isAuthenticate}") + private String cassandraAuth; + @Value("${spring.data.cassandra.ssl}") + + private String cassandraSSL; + @Value("${zusammen.cassandra.trustStorePath}") + private String cassandraTrustStorePath; + @Value("${zusammen.cassandra.trustStorePassword}") + private String cassandraTrustStorePassword; +}
\ No newline at end of file diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/server/filters/SessionContextFilter.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/server/filters/SessionContextFilter.java new file mode 100644 index 00000000..57cda856 --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/server/filters/SessionContextFilter.java @@ -0,0 +1,73 @@ +/* + * Copyright © 2018 European Support Limited + * + * 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. + */ + +package org.onap.sdc.workflow.server.filters; + +import java.io.IOException; +import javax.servlet.Filter; +import javax.servlet.FilterChain; +import javax.servlet.FilterConfig; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; +import javax.servlet.http.HttpServletRequest; +import org.onap.sdc.common.session.SessionContextProvider; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +@Component +public class SessionContextFilter implements Filter { + + private final SessionContextProvider sessionContextProvider; + @Value("${spring.data.cassandra.keyspace-name}") + private String tenant; + + @Autowired + public SessionContextFilter(SessionContextProvider sessionContextProvider) { + this.sessionContextProvider = sessionContextProvider; + } + + @Override + public void init(FilterConfig filterConfig) { + // not implemented + } + + @Override + public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) + throws IOException, ServletException { + try { + if (servletRequest instanceof HttpServletRequest) { + sessionContextProvider.create(getUser(servletRequest), tenant); + } + + filterChain.doFilter(servletRequest, servletResponse); + } finally { + sessionContextProvider.close(); + } + } + + @Override + public void destroy() { + // not implemented + } + + private String getUser(ServletRequest servletRequest) { + return "GLOBAL_USER"; + // TODO: 7/11/2018 get user from header when collaboration will be supported + //((HttpServletRequest) servletRequest).getHeader(USER_ID_HEADER_PARAM); + } +} diff --git a/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/server/resolvers/UserIdResolver.java b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/server/resolvers/UserIdResolver.java new file mode 100644 index 00000000..80cb07a8 --- /dev/null +++ b/sdc-workflow-designer-be/src/main/java/org/onap/sdc/workflow/server/resolvers/UserIdResolver.java @@ -0,0 +1,71 @@ +/* + * Copyright © 2018 European Support Limited + * + * 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. + */ + +package org.onap.sdc.workflow.server.resolvers; + +import static org.onap.sdc.workflow.api.RestParams.USER_ID_HEADER; + +import java.util.Objects; +import javax.servlet.http.HttpServletRequest; +import org.onap.sdc.workflow.services.annotations.UserId; +import org.springframework.core.MethodParameter; +import org.springframework.web.bind.ServletRequestBindingException; +import org.springframework.web.bind.support.WebDataBinderFactory; +import org.springframework.web.context.request.NativeWebRequest; +import org.springframework.web.method.support.HandlerMethodArgumentResolver; +import org.springframework.web.method.support.ModelAndViewContainer; + +/** + * Resolves a user ID from an HTTP header and injects it into a parameter of type {@link String} annotated with {@link + * UserId}. The header is considered mandatory, therefore an error is returned to the client if no user ID was sent. + * + * @author evitaliy + * @since 21 Aug 2018 + */ +public class UserIdResolver implements HandlerMethodArgumentResolver { + + private static final String ERROR_MESSAGE = "Missing mandatory request header '" + USER_ID_HEADER + "'"; + + @Override + public boolean supportsParameter(MethodParameter methodParameter) { + + if (!methodParameter.hasParameterAnnotation(UserId.class)) { + return false; + } + + Class<?> parameterType = methodParameter.getParameterType(); + if (!parameterType.equals(String.class)) { + throw new IllegalStateException("Cannot inject user ID into a parameter of type " + + parameterType.getTypeName()); + } + + return true; + } + + @Override + public Object resolveArgument(MethodParameter methodParameter, ModelAndViewContainer modelAndViewContainer, + NativeWebRequest nativeWebRequest, WebDataBinderFactory webDataBinderFactory) + throws ServletRequestBindingException { + + HttpServletRequest httpServletRequest = nativeWebRequest.getNativeRequest(HttpServletRequest.class); + String userHeader = Objects.requireNonNull(httpServletRequest).getHeader(USER_ID_HEADER); + if (userHeader == null) { + throw new ServletRequestBindingException(ERROR_MESSAGE); + } + + return userHeader; + } +}
\ No newline at end of file |