-
Notifications
You must be signed in to change notification settings - Fork 21
GH-125 event_webhook module for webhook sign verification #118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
15c8edd
e9aaf18
75a5678
f0d83a1
914e0e7
cd94980
1f64507
01f11d5
2af9561
2b59c46
8fa9f04
6d5b8bb
a2f77f6
5d1859d
250cc7f
df90b84
2bdc23e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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> | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would really like to get rid of this cache. |
||
|
|
||
| @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 + | ||
| '}'; | ||
| } | ||
| } |
There was a problem hiding this comment.
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