diff --git a/notification-core/src/main/java/org/opengroup/osdu/notification/auth/EntitlementsClientFactory.java b/notification-core/src/main/java/org/opengroup/osdu/notification/auth/EntitlementsClientFactory.java index 53a5427d160a4abb8949c8cfbd55274ea19c5eb0..e3af93eb357105fba607f68c0d7d802cc1c6d474 100644 --- a/notification-core/src/main/java/org/opengroup/osdu/notification/auth/EntitlementsClientFactory.java +++ b/notification-core/src/main/java/org/opengroup/osdu/notification/auth/EntitlementsClientFactory.java @@ -19,24 +19,39 @@ package org.opengroup.osdu.notification.auth; import org.opengroup.osdu.core.common.entitlements.EntitlementsAPIConfig; import org.opengroup.osdu.core.common.entitlements.EntitlementsFactory; import org.opengroup.osdu.core.common.entitlements.IEntitlementsFactory; +import org.opengroup.osdu.core.common.http.json.HttpResponseBodyMapper; import org.opengroup.osdu.notification.provider.interfaces.IAppProperties; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.config.AbstractFactoryBean; import org.springframework.stereotype.Component; +import javax.inject.Inject; + + @Component public class EntitlementsClientFactory extends AbstractFactoryBean<IEntitlementsFactory> { - @Autowired - private IAppProperties config; + @Value("${AUTHORIZE_API}") + public String AUTHORIZE_API; + + @Value("${AUTHORIZE_API_KEY:}") + public String AUTHORIZE_API_KEY; + + @Inject + private HttpResponseBodyMapper httpResponseBodyMapper; @Override - protected IEntitlementsFactory createInstance() { - return new EntitlementsFactory(EntitlementsAPIConfig.builder().rootUrl(config.getAuthorizeAPI()).build()); + protected IEntitlementsFactory createInstance() { + return new EntitlementsFactory(EntitlementsAPIConfig + .builder() + .rootUrl(AUTHORIZE_API) + .apiKey(AUTHORIZE_API_KEY) + .build(), httpResponseBodyMapper); } @Override public Class<?> getObjectType() { return IEntitlementsFactory.class; } -} \ No newline at end of file +} diff --git a/notification-core/src/main/java/org/opengroup/osdu/notification/utils/NotificationFilter.java b/notification-core/src/main/java/org/opengroup/osdu/notification/utils/NotificationFilter.java new file mode 100644 index 0000000000000000000000000000000000000000..8c4ccf80d9490e37ce172012d272125f97b541f0 --- /dev/null +++ b/notification-core/src/main/java/org/opengroup/osdu/notification/utils/NotificationFilter.java @@ -0,0 +1,61 @@ +// Copyright © 2020 Amazon Web Services +// Copyright 2017-2019, Schlumberger +// +// 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.opengroup.osdu.notification.utils; + +import org.opengroup.osdu.core.common.http.ResponseHeadersFactory; +import org.opengroup.osdu.core.common.model.http.DpsHeaders; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +import javax.inject.Inject; +import javax.servlet.*; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.util.Map; + + +@Component +public class NotificationFilter implements Filter { + + @Inject + private DpsHeaders dpsHeaders; + + private ResponseHeadersFactory responseHeadersFactory = new ResponseHeadersFactory(); + + // defaults to * for any front-end, string must be comma-delimited if more than one domain + @Value("${ACCESS_CONTROL_ALLOW_ORIGIN_DOMAINS:*}") + String ACCESS_CONTROL_ALLOW_ORIGIN_DOMAINS; + + @Override + public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) + throws IOException, ServletException { + chain.doFilter(request, response); + + HttpServletResponse httpResponse = (HttpServletResponse) response; + + this.dpsHeaders.addCorrelationIdIfMissing(); + + Map<String, String> responseHeaders = responseHeadersFactory.getResponseHeaders(ACCESS_CONTROL_ALLOW_ORIGIN_DOMAINS); + for (Map.Entry<String, String> header : responseHeaders.entrySet()) { + httpResponse.setHeader(header.getKey(), header.getValue()); + } + httpResponse.addHeader(DpsHeaders.CORRELATION_ID, this.dpsHeaders.getCorrelationId()); + } + + @Override + public void destroy() { + } +} diff --git a/pom.xml b/pom.xml index 5d3e0c9346eba4fe879c065879336abe80e5cfb1..4caf9612669be910b60040db8d416791ab0ee9b4 100644 --- a/pom.xml +++ b/pom.xml @@ -25,7 +25,7 @@ <java.version>8</java.version> <maven.compiler.target>${java.version}</maven.compiler.target> <maven.compiler.source>${java.version}</maven.compiler.source> - <os-core-common.version>0.3.6</os-core-common.version> + <os-core-common.version>0.3.27</os-core-common.version> </properties> <licenses> diff --git a/provider/notification-aws/pom.xml b/provider/notification-aws/pom.xml index afadab0411b33db848d13f379f64cdb3880b8655..ae16e39fdb7b660b576dc06f1609e9747e321aa6 100644 --- a/provider/notification-aws/pom.xml +++ b/provider/notification-aws/pom.xml @@ -48,7 +48,7 @@ <dependency> <groupId>org.opengroup.osdu.core.aws</groupId> <artifactId>os-core-lib-aws</artifactId> - <version>0.3.16</version> + <version>0.3.17</version> </dependency> <!-- https://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk-secretsmanager -->