diff options
Diffstat (limited to 'bpmn/mso-infrastructure-bpmn')
12 files changed, 286 insertions, 91 deletions
diff --git a/bpmn/mso-infrastructure-bpmn/pom.xml b/bpmn/mso-infrastructure-bpmn/pom.xml index 25913eabba..c3c26ef5e7 100644 --- a/bpmn/mso-infrastructure-bpmn/pom.xml +++ b/bpmn/mso-infrastructure-bpmn/pom.xml @@ -93,10 +93,19 @@ <artifactId>maven-jar-plugin</artifactId> <executions> <execution> - <id>tests</id> + <id>tests-jar</id> + <goals> + <goal>test-jar</goal> + </goals> + <configuration> + <skip>false</skip> + </configuration> </execution> <execution> <id>original</id> + <configuration> + <skip>false</skip> + </configuration> </execution> </executions> </plugin> @@ -295,5 +304,16 @@ <version>1.7.0</version> <scope>test</scope> </dependency> + <dependency> + <groupId>org.onap.aaf.authz</groupId> + <artifactId>aaf-cadi-aaf</artifactId> + <version>2.1.9</version> + <exclusions> + <exclusion> + <groupId>javax.servlet</groupId> + <artifactId>servlet-api</artifactId> + </exclusion> + </exclusions> + </dependency> </dependencies> </project> diff --git a/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/common/workflow/service/WorkflowAsyncResource.java b/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/common/workflow/service/WorkflowAsyncResource.java index ace6e1937d..4fb63651eb 100644 --- a/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/common/workflow/service/WorkflowAsyncResource.java +++ b/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/common/workflow/service/WorkflowAsyncResource.java @@ -102,7 +102,11 @@ public class WorkflowAsyncResource extends ProcessEngineAwareService { MDC.put(ONAPLogConstants.MDCs.REQUEST_ID, getRequestId(inputVariables)); processor.startProcess(processKey, variableMap); WorkflowResponse response = waitForResponse(inputVariables); - return Response.status(202).entity(response).build(); + if (response.getMessageCode() == 500) { + return Response.status(500).entity(response).build(); + } else { + return Response.status(202).entity(response).build(); + } } catch (WorkflowProcessorException e) { WorkflowResponse response = e.getWorkflowResponse(); return Response.status(500).entity(response).build(); @@ -112,7 +116,7 @@ public class WorkflowAsyncResource extends ProcessEngineAwareService { } } - private WorkflowResponse waitForResponse(Map<String, Object> inputVariables) throws Exception { + protected WorkflowResponse waitForResponse(Map<String, Object> inputVariables) throws Exception { String requestId = getRequestId(inputVariables); long currentWaitTime = 0; long waitTime = getWaitTime(inputVariables); diff --git a/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/common/workflow/service/WorkflowResource.java b/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/common/workflow/service/WorkflowResource.java index bcc3739c32..6debcfbff6 100644 --- a/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/common/workflow/service/WorkflowResource.java +++ b/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/common/workflow/service/WorkflowResource.java @@ -333,8 +333,6 @@ public class WorkflowResource extends ProcessEngineAwareService { public void run() { setLogContext(processKey, inputVariables); - long startTime = System.currentTimeMillis(); - try { RuntimeService runtimeService = getProcessEngineServices().getRuntimeService(); @@ -557,7 +555,6 @@ public class WorkflowResource extends ProcessEngineAwareService { // TODO filter only set of variables WorkflowResponse response = new WorkflowResponse(); - long startTime = System.currentTimeMillis(); try { ProcessEngineServices engine = getProcessEngineServices(); List<HistoricVariableInstance> variables = engine.getHistoryService().createHistoricVariableInstanceQuery() diff --git a/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/core/plugins/AsyncTaskExecutor.java b/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/core/plugins/AsyncTaskExecutor.java deleted file mode 100644 index 56526c7f89..0000000000 --- a/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/core/plugins/AsyncTaskExecutor.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.onap.so.bpmn.core.plugins; - -import org.camunda.bpm.engine.delegate.ExecutionListener; -import org.camunda.bpm.engine.impl.bpmn.parser.AbstractBpmnParseListener; -import org.camunda.bpm.engine.impl.pvm.process.ActivityImpl; -import org.camunda.bpm.engine.impl.pvm.process.ScopeImpl; -import org.camunda.bpm.engine.impl.util.xml.Element; -import org.springframework.stereotype.Component; - -@Component -public class AsyncTaskExecutor extends AbstractBpmnParseListener { - - private void injectTaskExecutorExecutionListener(ActivityImpl activity) { - activity.addListener(ExecutionListener.EVENTNAME_END, new AsyncTaskExecutorListener()); - } - - @Override - public void parseEndEvent(Element endEventElement, ScopeImpl scope, ActivityImpl activity) { - injectTaskExecutorExecutionListener(activity); - } -} diff --git a/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/core/plugins/BPMNProcessCompletePlugin.java b/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/core/plugins/BPMNProcessCompletePlugin.java deleted file mode 100644 index 96c6af42ed..0000000000 --- a/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/core/plugins/BPMNProcessCompletePlugin.java +++ /dev/null @@ -1,51 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Modifications Copyright (c) 2019 Samsung - * ================================================================================ - * 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========================================================= - */ - -package org.onap.so.bpmn.core.plugins; - -import java.util.ArrayList; -import java.util.List; -import org.camunda.bpm.engine.impl.bpmn.parser.BpmnParseListener; -import org.camunda.bpm.engine.impl.cfg.AbstractProcessEnginePlugin; -import org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - - - -@Component -public class BPMNProcessCompletePlugin extends AbstractProcessEnginePlugin { - - @Autowired - private AsyncTaskExecutor asyncTaskExecutor; - - @Override - public void preInit(ProcessEngineConfigurationImpl processEngineConfiguration) { - List<BpmnParseListener> preParseListeners = processEngineConfiguration.getCustomPreBPMNParseListeners(); - if (preParseListeners == null) { - preParseListeners = new ArrayList<>(); - processEngineConfiguration.setCustomPreBPMNParseListeners(preParseListeners); - } - preParseListeners.add(asyncTaskExecutor); - } - -} diff --git a/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/infrastructure/SecurityFilters.java b/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/infrastructure/SecurityFilters.java new file mode 100644 index 0000000000..bdc1c504f0 --- /dev/null +++ b/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/infrastructure/SecurityFilters.java @@ -0,0 +1,41 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 2019 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. + * 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========================================================= + */ + +package org.onap.so.bpmn.infrastructure; + +import org.springframework.boot.web.servlet.FilterRegistrationBean; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Profile; +import org.springframework.core.Ordered; + +@Configuration +@Profile("aaf") +public class SecurityFilters { + + @Bean + public FilterRegistrationBean<SoCadiFilter> loginRegistrationBean() { + FilterRegistrationBean<SoCadiFilter> filterRegistrationBean = new FilterRegistrationBean<>(); + filterRegistrationBean.setFilter(new SoCadiFilter()); + filterRegistrationBean.setName("cadiFilter"); + filterRegistrationBean.setOrder(Ordered.HIGHEST_PRECEDENCE); + return filterRegistrationBean; + } +} diff --git a/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/infrastructure/SoCadiFilter.java b/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/infrastructure/SoCadiFilter.java new file mode 100644 index 0000000000..cb60d5d219 --- /dev/null +++ b/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/infrastructure/SoCadiFilter.java @@ -0,0 +1,117 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP SO + * ================================================================================ + * Copyright (C) 2017-2018 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. + * 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============================================ + * =================================================================== + * + */ +package org.onap.so.bpmn.infrastructure; + +import javax.servlet.FilterConfig; +import javax.servlet.ServletException; +import org.onap.aaf.cadi.config.Config; +import org.onap.aaf.cadi.filter.CadiFilter; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Profile; +import org.springframework.stereotype.Component; + +@Component +@Profile("aaf") +public class SoCadiFilter extends CadiFilter { + + protected final Logger logger = LoggerFactory.getLogger(SoCadiFilter.class); + + private static String AFT_ENVIRONMENT_VAR = "AFT_ENVIRONMENT"; + private static String AAF_API_VERSION = "aaf_api_version"; + + @Value("${mso.config.cadi.cadiLoglevel:#{null}}") + private String cadiLoglevel; + + @Value("${mso.config.cadi.cadiKeyFile:#{null}}") + private String cadiKeyFile; + + @Value("${mso.config.cadi.cadiTruststorePassword:#{null}}") + private String cadiTrustStorePassword; + + @Value("${mso.config.cadi.cadiTrustStore:#{null}}") + private String cadiTrustStore; + + @Value("${mso.config.cadi.cadiLatitude:#{null}}") + private String cadiLatitude; + + @Value("${mso.config.cadi.cadiLongitude:#{null}}") + private String cadiLongitude; + + @Value("${mso.config.cadi.aafEnv:#{null}}") + private String aafEnv; + + @Value("${mso.config.cadi.aafApiVersion:#{null}}") + private String aafApiVersion; + + @Value("${mso.config.cadi.aafRootNs:#{null}}") + private String aafRootNs; + + @Value("${mso.config.cadi.aafId:#{null}}") + private String aafMechId; + + @Value("${mso.config.cadi.aafPassword:#{null}}") + private String aafMechIdPassword; + + @Value("${mso.config.cadi.aafLocateUrl:#{null}}") + private String aafLocateUrl; + + @Value("${mso.config.cadi.aafUrl:#{null}}") + private String aafUrl; + + @Value("${mso.config.cadi.apiEnforcement:#{null}}") + private String apiEnforcement; + + private void checkIfNullProperty(String key, String value) { + /* + * When value is null, it is not defined in application.yaml set nothing in System properties + */ + if (value != null) { + System.setProperty(key, value); + } + } + + @Override + public void init(FilterConfig filterConfig) throws ServletException { + checkIfNullProperty(Config.CADI_LOGLEVEL, cadiLoglevel); + checkIfNullProperty(Config.CADI_KEYFILE, cadiKeyFile); + checkIfNullProperty(Config.CADI_TRUSTSTORE, cadiTrustStore); + checkIfNullProperty(Config.CADI_TRUSTSTORE_PASSWORD, cadiTrustStorePassword); + checkIfNullProperty(Config.CADI_LATITUDE, cadiLatitude); + checkIfNullProperty(Config.CADI_LONGITUDE, cadiLongitude); + checkIfNullProperty(Config.AAF_ENV, aafEnv); + checkIfNullProperty(Config.AAF_API_VERSION, aafApiVersion); + checkIfNullProperty(Config.AAF_ROOT_NS, aafRootNs); + checkIfNullProperty(Config.AAF_APPID, aafMechId); + checkIfNullProperty(Config.AAF_APPPASS, aafMechIdPassword); + checkIfNullProperty(Config.AAF_LOCATE_URL, aafLocateUrl); + checkIfNullProperty(Config.AAF_URL, aafUrl); + checkIfNullProperty(Config.CADI_API_ENFORCEMENT, apiEnforcement); + // checkIfNullProperty(AFT_ENVIRONMENT_VAR, aftEnv); + logger.debug(" *** init Filter Config *** "); + super.init(filterConfig); + } + + +} diff --git a/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/infrastructure/WebSecurityConfigImpl.java b/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/infrastructure/WebSecurityConfigImpl.java index 1ed3214214..bcc38ec9e0 100644 --- a/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/infrastructure/WebSecurityConfigImpl.java +++ b/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/infrastructure/WebSecurityConfigImpl.java @@ -24,28 +24,57 @@ package org.onap.so.bpmn.infrastructure; import org.onap.so.security.MSOSpringFirewall; import org.onap.so.security.WebSecurityConfig; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Profile; +import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.builders.WebSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; import org.springframework.security.web.firewall.StrictHttpFirewall; import org.springframework.util.StringUtils; +@Configuration @EnableWebSecurity public class WebSecurityConfigImpl extends WebSecurityConfig { - @Override - protected void configure(HttpSecurity http) throws Exception { - http.csrf().disable().authorizeRequests().antMatchers("/manage/health", "/manage/info").permitAll() - .antMatchers("/async/services/**", "/workflow/services/*", "/SDNCAdapterCallbackService", - "/WorkflowMessage", "/vnfAdapterNotify", "/vnfAdapterRestNotify") - .hasAnyRole(StringUtils.collectionToDelimitedString(getRoles(), ",")).and().httpBasic(); - } + @Profile({"basic", "test"}) + @Bean + public WebSecurityConfigurerAdapter basicAuth() { + return new WebSecurityConfigurerAdapter() { + @Override + protected void configure(HttpSecurity http) throws Exception { + http.csrf().disable().authorizeRequests().antMatchers("/manage/health", "/manage/info").permitAll() + .antMatchers("/async/services/**", "/workflow/services/*", "/SDNCAdapterCallbackService", + "/WorkflowMessage", "/vnfAdapterNotify", "/vnfAdapterRestNotify") + .hasAnyRole(StringUtils.collectionToDelimitedString(getRoles(), ",")).and().httpBasic(); + } + + @Override + public void configure(WebSecurity web) throws Exception { + super.configure(web); + StrictHttpFirewall firewall = new MSOSpringFirewall(); + web.httpFirewall(firewall); + } - @Override - public void configure(WebSecurity web) throws Exception { - super.configure(web); - StrictHttpFirewall firewall = new MSOSpringFirewall(); - web.httpFirewall(firewall); + @Override + protected void configure(AuthenticationManagerBuilder auth) throws Exception { + auth.userDetailsService(WebSecurityConfigImpl.this.userDetailsService()) + .passwordEncoder(WebSecurityConfigImpl.this.passwordEncoder()); + } + + }; } + @Profile("aaf") + @Bean + public WebSecurityConfigurerAdapter noAuth() { + return new WebSecurityConfigurerAdapter() { + @Override + protected void configure(HttpSecurity http) throws Exception { + http.authorizeRequests().anyRequest().permitAll(); + } + }; + } } diff --git a/bpmn/mso-infrastructure-bpmn/src/main/resources/application-aaf.yaml b/bpmn/mso-infrastructure-bpmn/src/main/resources/application-aaf.yaml new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/bpmn/mso-infrastructure-bpmn/src/main/resources/application-aaf.yaml diff --git a/bpmn/mso-infrastructure-bpmn/src/main/resources/application-basic.yaml b/bpmn/mso-infrastructure-bpmn/src/main/resources/application-basic.yaml new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/bpmn/mso-infrastructure-bpmn/src/main/resources/application-basic.yaml diff --git a/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/common/workflow/service/WorkflowAsyncResourceTest.java b/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/common/workflow/service/WorkflowAsyncResourceTest.java new file mode 100644 index 0000000000..df9a23019a --- /dev/null +++ b/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/common/workflow/service/WorkflowAsyncResourceTest.java @@ -0,0 +1,59 @@ +package org.onap.so.bpmn.common.workflow.service; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.doReturn; +import static org.mockito.ArgumentMatchers.anyMap; +import java.util.HashMap; +import java.util.Map; +import javax.ws.rs.core.Response; +import org.camunda.bpm.engine.variable.impl.VariableMapImpl; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Spy; +import org.mockito.junit.MockitoJUnitRunner; +import org.onap.so.bpmn.common.workflow.context.WorkflowResponse; + +@RunWith(MockitoJUnitRunner.class) +public class WorkflowAsyncResourceTest { + + @InjectMocks + @Spy + private WorkflowAsyncResource workflowAsyncResource; + + @Mock + private WorkflowProcessor processor; + + private WorkflowResponse workflowResponse; + private VariableMapImpl varMap; + + @Before + public void before() { + workflowResponse = new WorkflowResponse(); + varMap = new VariableMapImpl(); + Map<String, Object> variables = new HashMap<String, Object>(); + Map<String, Object> requestIdMap = new HashMap<String, Object>(); + requestIdMap.put("value", "123"); + requestIdMap.put("type", "String"); + variables.put("mso-request-id", requestIdMap); + varMap.put("variables", variables); + } + + @Test + public void startProcessInstanceByKey200Test() throws Exception { + workflowResponse.setMessageCode(200); + doReturn(workflowResponse).when(workflowAsyncResource).waitForResponse(anyMap()); + Response response = workflowAsyncResource.startProcessInstanceByKey("123", varMap); + assertEquals(202, response.getStatus()); + } + + @Test + public void startProcessInstanceByKey500Test() throws Exception { + workflowResponse.setMessageCode(500); + doReturn(workflowResponse).when(workflowAsyncResource).waitForResponse(anyMap()); + Response response = workflowAsyncResource.startProcessInstanceByKey("123", varMap); + assertEquals(500, response.getStatus()); + } +} diff --git a/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/DmaapClientTestImpl.java b/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/DmaapClientTestImpl.java index 078317885c..43fbc59b3d 100644 --- a/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/DmaapClientTestImpl.java +++ b/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/DmaapClientTestImpl.java @@ -34,7 +34,7 @@ public class DmaapClientTestImpl implements DmaapClient { private Runnable informConsumer; @Override - public void registerForUpdate(String pnfCorrelationId, Runnable informConsumer, Map<String, String> updateInfo) { + public void registerForUpdate(String pnfCorrelationId, Runnable informConsumer) { this.pnfCorrelationId = pnfCorrelationId; this.informConsumer = informConsumer; } |