Skip to content

Commit

Permalink
GH-186 bumped up the version to 2.0.0-SNAPSHOT
Browse files Browse the repository at this point in the history
as I was at it:
* removed a few more `deprecated` methods
* consolidated the oAuth and JWT interceptors in just one class
  • Loading branch information
francoisledroff committed Aug 29, 2024
1 parent 8df106e commit 60336e8
Show file tree
Hide file tree
Showing 29 changed files with 184 additions and 393 deletions.
2 changes: 1 addition & 1 deletion aem/aio_aem_events/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<groupId>com.adobe.aio.aem</groupId>
<artifactId>aio-aem</artifactId>
<relativePath>../pom.xml</relativePath>
<version>1.2.0-SNAPSHOT</version>
<version>2.0.0-SNAPSHOT</version>
</parent>

<artifactId>aio-aem-events</artifactId>
Expand Down
4 changes: 2 additions & 2 deletions aem/core_aem/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ service looks up the following OSGI configuration keys:
* `aio.consumer.org.id` your Adobe Developer Console consumer orgnaization id (`project.org.id`)
* `aio.ims.org.id` your Adobe Developer Console IMS Organization ID (`project.org.ims_org_id`)
* `aio.workspace.id` your Adobe Developer Console workspace Id (`project.workspace.id`)
* `aio.api.key` your Adobe Developer Console jwt credential API Key (or Client ID)
* `aio.api.key` your Adobe Developer Console credential API Key (or Client ID)

When using JWT credentials also set
* `aio.credential.id` your Adobe Developer Console jwt credential id
Expand All @@ -28,7 +28,7 @@ When using JWT credentials also set
* `aio.encoded.pkcs8` your private key (in a base64 encoded pkcs8 format)

When using OAuth credentials also set
* `aio.client.secret` your Adobe Developer Console jwt credential client secret
* `aio.client.secret` your Adobe Developer Console oAuth credential client secret
* `aio_oauth_scopes` a comma separated list of OAuth scopes associated with your API, see your Adobe Developer Console OAuth scopes (project.workspace.details.credentials[i].oauth_server_to_server.scopes)

For more details on the above please refer to
Expand Down
2 changes: 1 addition & 1 deletion aem/core_aem/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<groupId>com.adobe.aio.aem</groupId>
<artifactId>aio-aem</artifactId>
<relativePath>../pom.xml</relativePath>
<version>1.2.0-SNAPSHOT</version>
<version>2.0.0-SNAPSHOT</version>
</parent>

<artifactId>aio-aem-core</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion aem/events_ingress_aem/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<groupId>com.adobe.aio.aem</groupId>
<artifactId>aio-aem</artifactId>
<relativePath>../pom.xml</relativePath>
<version>1.2.0-SNAPSHOT</version>
<version>2.0.0-SNAPSHOT</version>
</parent>

<artifactId>aio-aem-events-publish</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion aem/events_mgmt_aem/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<groupId>com.adobe.aio.aem</groupId>
<artifactId>aio-aem</artifactId>
<relativePath>../pom.xml</relativePath>
<version>1.2.0-SNAPSHOT</version>
<version>2.0.0-SNAPSHOT</version>
</parent>

<artifactId>aio-aem-events-mgmt</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion aem/events_osgi_mapping/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<groupId>com.adobe.aio.aem</groupId>
<artifactId>aio-aem</artifactId>
<relativePath>../pom.xml</relativePath>
<version>1.2.0-SNAPSHOT</version>
<version>2.0.0-SNAPSHOT</version>
</parent>

<artifactId>aio-aem-events-osgi-mapping</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion aem/lib_osgi/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<groupId>com.adobe.aio.aem</groupId>
<artifactId>aio-aem</artifactId>
<relativePath>../pom.xml</relativePath>
<version>1.2.0-SNAPSHOT</version>
<version>2.0.0-SNAPSHOT</version>
</parent>

<artifactId>aio-lib-osgi</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion aem/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<groupId>com.adobe.aio</groupId>
<artifactId>aio-lib-java</artifactId>
<relativePath>../pom.xml</relativePath>
<version>1.2.0-SNAPSHOT</version>
<version>2.0.0-SNAPSHOT</version>
</parent>

<groupId>com.adobe.aio.aem</groupId>
Expand Down
2 changes: 1 addition & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<parent>
<groupId>com.adobe.aio</groupId>
<artifactId>aio-lib-java</artifactId>
<version>1.2.0-SNAPSHOT</version>
<version>2.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
13 changes: 0 additions & 13 deletions core/src/main/java/com/adobe/aio/workspace/Workspace.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,19 +134,6 @@ public boolean isAuthJWT() {
return authContext!=null && authContext instanceof JwtContext;
}

/**
* @deprecated This will be removed in v2.0 of the library.
* use JwtContext getCredentialId() instead
* @see JwtContext#getCredentialId()
*/
@Deprecated
public String getCredentialId() {
if (authContext instanceof JwtContext) {
return ((JwtContext) authContext).getCredentialId();
} else {
return null;
}
}

@Override
public boolean equals(Object o) {
Expand Down
2 changes: 1 addition & 1 deletion events_ingress/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<parent>
<groupId>com.adobe.aio</groupId>
<artifactId>aio-lib-java</artifactId>
<version>1.2.0-SNAPSHOT</version>
<version>2.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion events_journal/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<parent>
<groupId>com.adobe.aio</groupId>
<artifactId>aio-lib-java</artifactId>
<version>1.2.0-SNAPSHOT</version>
<version>2.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion events_mgmt/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<parent>
<groupId>com.adobe.aio</groupId>
<artifactId>aio-lib-java</artifactId>
<version>1.2.0-SNAPSHOT</version>
<version>2.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion events_test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<parent>
<groupId>com.adobe.aio</groupId>
<artifactId>aio-lib-java</artifactId>
<version>1.2.0-SNAPSHOT</version>
<version>2.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion events_webhook/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<parent>
<groupId>com.adobe.aio</groupId>
<artifactId>aio-lib-java</artifactId>
<version>1.2.0-SNAPSHOT</version>
<version>2.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion events_xdm/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<parent>
<groupId>com.adobe.aio</groupId>
<artifactId>aio-lib-java</artifactId>
<version>1.2.0-SNAPSHOT</version>
<version>2.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion ims/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<parent>
<groupId>com.adobe.aio</groupId>
<artifactId>aio-lib-java</artifactId>
<version>1.2.0-SNAPSHOT</version>
<version>2.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
25 changes: 3 additions & 22 deletions ims/src/main/java/com/adobe/aio/ims/ImsService.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,16 @@

public interface ImsService {

/**
* Returns an {@link AccessToken} that can be used for other AIO API Calls.
*
* @deprecated this will be removed in v2.0 as JWT token exchange is deprecated
* use getAccessToken() instead
* @return AccessToken a valid API authentication token
* @see #getAccessToken()
*/
@Deprecated()
AccessToken getJwtExchangeAccessToken();

/**
* Checks that the access token is still valid.
* Checks that the jwt access token is still valid.
*
* @deprecated this will be removed in v2.0 as JWT token exchange is deprecated
* @deprecated this will be removed as JWT token exchange is deprecated
* @param jwtAccessToken the jwt token to check
* @return true if the provided access token is still valid, false otherwise
*/
@Deprecated()
boolean validateAccessToken(String jwtAccessToken);

/**
* Returns an {@link AccessToken} that can be used for other AIO API Calls.
* @deprecated use getAccessToken() instead
* @return AccessToken a valid API authentication token
* @see #getAccessToken()
*/
@Deprecated()
AccessToken getOAuthAccessToken();
boolean validateJwtAccessToken(String jwtAccessToken);

/**
* Looking up the contextual Workspace, it will use
Expand Down
20 changes: 7 additions & 13 deletions ims/src/main/java/com/adobe/aio/ims/feign/AuthInterceptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@

import static com.adobe.aio.util.Constants.*;

public abstract class AuthInterceptor implements RequestInterceptor {
public class AuthInterceptor implements RequestInterceptor {

private volatile Long expirationTimeMillis;
private volatile AccessToken accessToken;
private final ImsService imsService;

protected AuthInterceptor(final ImsService imsService) {
this.imsService = imsService;
protected AuthInterceptor (final Workspace workspace) {
this.imsService = ImsService.builder().workspace(workspace).build();
}

@Override
Expand All @@ -27,7 +27,9 @@ ImsService getImsService() {
return this.imsService;
}

abstract AccessToken fetchAccessToken();
AccessToken fetchAccessToken() {
return getImsService().getAccessToken();
}

synchronized String getAccessToken() {
if (expirationTimeMillis == null || System.currentTimeMillis() >= expirationTimeMillis) {
Expand Down Expand Up @@ -70,15 +72,7 @@ public Builder workspace(Workspace workspace) {
}

public AuthInterceptor build() {
if (workspace.isAuthOAuth()) {
return new OAuthInterceptor(ImsService.builder().workspace(workspace).build());
}
else if (workspace.isAuthJWT()) {
return new JWTAuthInterceptor(ImsService.builder().workspace(workspace).build());
}
else {
throw new IllegalStateException("Unable to build auth interceptor for workspace: neither jwt nor oAuth");
}
return new AuthInterceptor(workspace);
}
}

Expand Down
44 changes: 21 additions & 23 deletions ims/src/main/java/com/adobe/aio/ims/feign/FeignImsService.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,30 +40,38 @@ public FeignImsService(final Workspace workspace) {
}

@Override
public AccessToken getJwtExchangeAccessToken() {
if (!workspace.isAuthJWT()) {
throw new IllegalStateException("AuthContext in workspace not of type `JwtContext`.");
public AccessToken getAccessToken() {
if (workspace.isAuthJWT()) {
return getJwtExchangeAccessToken();
} else if (workspace.isAuthOAuth()) {
return getOAuthAccessToken();
} else {
throw new IllegalStateException("AuthContext in workspace not of type `OAuthContext` or `JwtContext`.");
}
JwtContext context = (JwtContext) workspace.getAuthContext();
context.validate();

JwtTokenBuilder builder = new JwtTokenBuilder(workspace);
String token = builder.build();
return imsApi.getJwtAccessToken(workspace.getApiKey(), context.getClientSecret(), token);
}


@Override
public boolean validateAccessToken(String jwtAccessToken) {
public boolean validateJwtAccessToken(String jwtAccessToken) {
if (!workspace.isAuthJWT()) {
logger.error("AuthContext in workspace not of type `JwtContext`... this only validates JWT Token");
return false;
}
return imsApi.validateJwtToken(ACCESS_TOKEN, workspace.getApiKey(), jwtAccessToken).getValid();
}

@Override
public AccessToken getOAuthAccessToken() {
private AccessToken getJwtExchangeAccessToken() {
if (!workspace.isAuthJWT()) {
throw new IllegalStateException("AuthContext in workspace not of type `JwtContext`.");
}
JwtContext context = (JwtContext) workspace.getAuthContext();
context.validate();

JwtTokenBuilder builder = new JwtTokenBuilder(workspace);
String token = builder.build();
return imsApi.getJwtAccessToken(workspace.getApiKey(), context.getClientSecret(), token);
}

private AccessToken getOAuthAccessToken() {
if (!workspace.isAuthOAuth()) {
throw new IllegalStateException("AuthContext in workspace not of type `OAuthContext`.");
}
Expand All @@ -72,15 +80,5 @@ public AccessToken getOAuthAccessToken() {
return imsApi.getOAuthAccessToken(workspace.getApiKey(), context.getClientSecret(), scopes);
}

@Override
public AccessToken getAccessToken() {
if (workspace.isAuthJWT()) {
return getJwtExchangeAccessToken();
} else if (workspace.isAuthOAuth()) {
return getOAuthAccessToken();
} else {
throw new IllegalStateException("AuthContext in workspace not of type `OAuthContext` or `JwtContext`.");
}
}
}

31 changes: 0 additions & 31 deletions ims/src/main/java/com/adobe/aio/ims/feign/JWTAuthInterceptor.java

This file was deleted.

26 changes: 0 additions & 26 deletions ims/src/main/java/com/adobe/aio/ims/feign/OAuthInterceptor.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
package com.adobe.aio.ims;

import com.adobe.aio.ims.feign.AuthInterceptor;
import com.adobe.aio.ims.feign.OAuthInterceptor;
import com.adobe.aio.util.WorkspaceUtil;
import com.adobe.aio.workspace.Workspace;
import feign.RequestInterceptor;
Expand Down
Loading

0 comments on commit 60336e8

Please sign in to comment.