Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,17 @@
<groupId>io.github.openfeign</groupId>
<artifactId>feign-core</artifactId>
</dependency>

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's revert this unnecessary change of core/pom.xml

<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-jackson</artifactId>
</dependency>

<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-slf4j</artifactId>
</dependency>

<dependency>
<groupId>io.github.openfeign.form</groupId>
<artifactId>feign-form</artifactId>
Expand All @@ -73,5 +76,4 @@
</dependency>

</dependencies>

</project>
63 changes: 63 additions & 0 deletions events_webhook/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2017 Adobe. All rights reserved.
This file is licensed to you 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 REPRESENTATIONS
OF ANY KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>com.adobe.aio</groupId>
<artifactId>aio-lib-java</artifactId>
<version>1.0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

<name>Adobe I/O - Events Webhook Library</name>
<description>Adobe I/O - Java SDK - Events Webhook Library</description>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<artifactId>aio-lib-java-events-webhook</artifactId>

<dependencies>
<dependency>
<groupId>com.adobe.aio</groupId>
<artifactId>aio-lib-java-core</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>com.adobe.aio</groupId>
<artifactId>aio-lib-java-ims</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to remove this

</dependency>

<!--- test specific -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>

</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright 2017 Adobe. All rights reserved.
* This file is licensed to you 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 REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
package com.adobe.aio.event.webhook.api;

import feign.Param;
import feign.RequestLine;

public interface PublicKeyCdnApi {
@RequestLine(value = "GET {pubKeyPath}")
String getPubKeyFromCDN(@Param("pubKeyPath") String pubKeyPath);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2017 Adobe. All rights reserved.
* This file is licensed to you 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 REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
package com.adobe.aio.event.webhook.cache;

import com.adobe.aio.event.webhook.model.CacheableObject;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;

public interface CacheService {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would really like to get rid of this cache.
our customer can easily use any cache service/framework they want.
this PR should only be about showing how to validate the message headers' signature and no more


@Nullable
Object get(@Nonnull String key);

void put(@Nonnull String key, @Nonnull Object value);

boolean isExpired(CacheableObject cacheable);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* Copyright 2017 Adobe. All rights reserved.
* This file is licensed to you 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 REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
package com.adobe.aio.event.webhook.cache;

import com.adobe.aio.event.webhook.model.CacheableObject;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


public class CacheServiceImpl implements CacheService {

private static final Logger logger = LoggerFactory.getLogger(CacheServiceImpl.class);
private static final int DEFAULT_TTL_IN_MINUTES = 1440;
private static final Date CURRENT_SYSTEM_DATE = new Date();

Map<String, Object> cacheMap;

@Nullable
@Override
public String get(@Nonnull String key) {
CacheableObject obj = (CacheableObject) cacheMap.get(key);
if (obj != null) {
if (isExpired(obj)) {
logger.debug("public key object in cache is expired..invalidating entry for key {}", key);
cacheMap.remove(key);
return null;
} else {
return obj.getValue();
}
}
return null;
}

@Override
public void put(@Nonnull String key, @Nonnull Object value) {
putWithExpiry(key, value, DEFAULT_TTL_IN_MINUTES);
}

public void putWithExpiry(@Nonnull String key, @Nonnull Object value, int ttlInMinutes) {
CacheableObject cacheableObject = new CacheableObject(key, (String) value,
getExpirationDate(ttlInMinutes));
cacheMap.put(key, cacheableObject);
}

@Override
public boolean isExpired(CacheableObject cacheableObject) {
return CURRENT_SYSTEM_DATE.after(cacheableObject.getPubKeyExpiryDate());
}

private CacheServiceImpl initialiseCacheMap() {
this.cacheMap = new HashMap<>();
return this;
}

public static CacheBuilder cacheBuilder() {
return new CacheBuilder();
}

public static class CacheBuilder {
public CacheServiceImpl buildCache() {
return new CacheServiceImpl()
.initialiseCacheMap();
}
}

private Date getExpirationDate(int minutesToLive) {
Date expirationDate = new java.util.Date();
java.util.Calendar cal = java.util.Calendar.getInstance();
cal.setTime(expirationDate);
cal.add(cal.MINUTE, minutesToLive);
expirationDate = cal.getTime();
return expirationDate;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright 2017 Adobe. All rights reserved.
* This file is licensed to you 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 REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
package com.adobe.aio.event.webhook.feign;

import com.adobe.aio.event.webhook.api.PublicKeyCdnApi;
import com.adobe.aio.event.webhook.service.PubKeyService;
import com.adobe.aio.util.feign.FeignUtil;

public class FeignPubKeyService implements PubKeyService {

private final PublicKeyCdnApi publicKeyCdnApi;

public FeignPubKeyService(final String pubKeyCdnBaseUrl) {
this.publicKeyCdnApi = FeignUtil.getBaseBuilder()
.target(PublicKeyCdnApi.class, pubKeyCdnBaseUrl);
}

@Override
public String getPubKeyFromCDN(String pubKeyPath) {
String pubKey = publicKeyCdnApi.getPubKeyFromCDN(pubKeyPath);
return pubKey;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright 2017 Adobe. All rights reserved.
* This file is licensed to you 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 REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
package com.adobe.aio.event.webhook.model;

import java.util.Date;
import java.util.Objects;

public class CacheableObject {

private String key;
private String value;
private Date pubKeyExpiryDate;

public CacheableObject(String key, String value, Date expiryInMinutes) {
this.key = key;
this.value = value;
this.pubKeyExpiryDate = expiryInMinutes;
}

public String getKey() {
return key;
}

public String getValue() {
return value;
}

public Date getPubKeyExpiryDate() {
return pubKeyExpiryDate;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
CacheableObject that = (CacheableObject) o;
return Objects.equals(key, that.key) && Objects.equals(value, that.value)
&& Objects.equals(pubKeyExpiryDate, that.pubKeyExpiryDate);
}

@Override
public int hashCode() {
return Objects.hash(key, value, pubKeyExpiryDate);
}

@Override
public String toString() {
return "CacheableObject{" +
"key='" + key + '\'' +
", value='" + value + '\'' +
", pubKeyExpiryDate=" + pubKeyExpiryDate +
'}';
}
}
Loading