Skip to content
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

Add OAuth2 Support #354

Merged
merged 66 commits into from
Apr 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
8dc674b
Add OAuth Support
arvindkrishnakumar-okta Apr 2, 2020
d272d22
Add OAuth Support - Minor Refactor
arvindkrishnakumar-okta Apr 2, 2020
01393d5
Add OAuth Support - added Unit tests and did some refactoring
arvindkrishnakumar-okta Apr 2, 2020
004810d
Add Oauth support: Developmental Commit
arvindkrishnakumar-okta Apr 6, 2020
3ba2478
Add OAuth support - developmental commit
arvindkrishnakumar-okta Apr 6, 2020
ac7b84c
Add Oauth support: Developmental Commit
arvindkrishnakumar-okta Apr 6, 2020
7206ae1
Add Oauth support: Developmental Commit
arvindkrishnakumar-okta Apr 6, 2020
ba352bc
Add Oauth support: Developmental Commit
arvindkrishnakumar-okta Apr 6, 2020
9c8fc00
Add Oauth support: Developmental Commit
arvindkrishnakumar-okta Apr 6, 2020
9b5acbe
Add Oauth support: Developmental Commit
arvindkrishnakumar-okta Apr 7, 2020
8185e26
Add Oauth support: Ready for review
arvindkrishnakumar-okta Apr 7, 2020
64085e6
Add Oauth support: Ready for review
arvindkrishnakumar-okta Apr 7, 2020
5af3f97
Removed key
arvindkrishnakumar-okta Apr 8, 2020
1847600
Refactored to address majority of the comments (few more comments lef…
arvindkrishnakumar-okta Apr 8, 2020
efb667d
Refactored to address majority of the comments (few more comments lef…
arvindkrishnakumar-okta Apr 8, 2020
338585c
Refactored to address majority of the comments (few more comments lef…
arvindkrishnakumar-okta Apr 8, 2020
805c5e9
Minor refactoring of DefaultClientBuilder class
arvindkrishnakumar-okta Apr 8, 2020
23e9a36
Changes to effect dynamic refresh and storage of access token (ITs to…
arvindkrishnakumar-okta Apr 8, 2020
a7c644a
Cleanup done (ITs to follow in next push)
arvindkrishnakumar-okta Apr 8, 2020
e0ec88e
Cleanup done (ITs to follow in next push)
arvindkrishnakumar-okta Apr 9, 2020
c445f4f
Review comments addressed (some)
arvindkrishnakumar-okta Apr 9, 2020
3a81761
Removed okta-http-okhttp dep from impl/pom.xml
arvindkrishnakumar-okta Apr 9, 2020
fcdac3d
okta-http-okhttp added with test scope in impl/pom.xml
arvindkrishnakumar-okta Apr 9, 2020
3436026
Improvements inline with review comments
arvindkrishnakumar-okta Apr 9, 2020
9c338bd
Improvements inline with review comments
arvindkrishnakumar-okta Apr 9, 2020
45485eb
Deprecate setAuthenticationScheme() as suggested in review
arvindkrishnakumar-okta Apr 10, 2020
e27b8eb
Deprecate setAuthenticationScheme() as suggested in review
arvindkrishnakumar-okta Apr 10, 2020
3cf9b0d
Use BaseClient as recommended in review comments
arvindkrishnakumar-okta Apr 10, 2020
bc51fa4
Minor refactoring
arvindkrishnakumar-okta Apr 10, 2020
1818cb1
Added some unit tests and refactored code around the tests
arvindkrishnakumar-okta Apr 13, 2020
f0f89cd
Addressed comments
arvindkrishnakumar-okta Apr 13, 2020
b882401
Addressed comments
arvindkrishnakumar-okta Apr 13, 2020
d94803b
Addressed all review comments; Added UTs & IT; Refactored code
arvindkrishnakumar-okta Apr 15, 2020
6a449f2
Refactoring done
arvindkrishnakumar-okta Apr 15, 2020
13b29a2
Refactoring done
arvindkrishnakumar-okta Apr 15, 2020
30f17d8
Addressed few nit comments
arvindkrishnakumar-okta Apr 16, 2020
869b4ec
Added @since to new and updated code
arvindkrishnakumar-okta Apr 16, 2020
b9f4ad7
scopes is now dealt as a set instead of list - per review comment
arvindkrishnakumar-okta Apr 16, 2020
2ccc551
Refactored code
arvindkrishnakumar-okta Apr 16, 2020
bf5b183
Refactored code
arvindkrishnakumar-okta Apr 16, 2020
09da983
PMD warnings fixed and refactored code around it
arvindkrishnakumar-okta Apr 16, 2020
574a024
Clear OAuth2 env variables before unit tests
arvindkrishnakumar-okta Apr 17, 2020
579ffa7
Get OAuth2IT to run along with old ITs without breaking selectively d…
arvindkrishnakumar-okta Apr 17, 2020
4f4ca27
Fixed @since version to javadoc
arvindkrishnakumar-okta Apr 17, 2020
f3c8eff
Minor refactoring
arvindkrishnakumar-okta Apr 17, 2020
db7430e
Minor refactoring
arvindkrishnakumar-okta Apr 17, 2020
9dca466
Minor refactoring
arvindkrishnakumar-okta Apr 17, 2020
3483659
Minor refactoring
arvindkrishnakumar-okta Apr 20, 2020
2b5ae39
Minor refactoring
arvindkrishnakumar-okta Apr 20, 2020
a22c27e
Minor refactoring
arvindkrishnakumar-okta Apr 20, 2020
89685d6
Restored client provider changes to effect OAuth2IT test
arvindkrishnakumar-okta Apr 20, 2020
2554688
Improvements in accordance with review comments
arvindkrishnakumar-okta Apr 21, 2020
4f76eb0
Improvements in accordance with review comments
arvindkrishnakumar-okta Apr 21, 2020
ad2095a
Improvements in accordance with review comments
arvindkrishnakumar-okta Apr 21, 2020
6f7af0a
Improvements in accordance with review comments
arvindkrishnakumar-okta Apr 21, 2020
6553058
Improvements in accordance with review comments
arvindkrishnakumar-okta Apr 21, 2020
af16193
Improvements in accordance with review comments
arvindkrishnakumar-okta Apr 21, 2020
bea5965
Improvements in accordance with review comments
arvindkrishnakumar-okta Apr 21, 2020
04c5c3e
Review comments addressed
arvindkrishnakumar-okta Apr 23, 2020
efc0894
Added double null check on OAuth2AccessToken object for synchronization
arvindkrishnakumar-okta Apr 23, 2020
2703c15
Updated licence header in findbugs-exclude.xml
arvindkrishnakumar-okta Apr 23, 2020
45c1b44
Refactored concurrency code in OAuth2RequestAuthenticator and added u…
arvindkrishnakumar-okta Apr 24, 2020
7a6dd62
Refactored concurrency test
arvindkrishnakumar-okta Apr 24, 2020
e0e2699
Merge branch 'master' into feature_add_oauth2_support
arvindkrishnakumar-okta Apr 24, 2020
ea4f521
Review comments addressed
arvindkrishnakumar-okta Apr 27, 2020
a44242a
Reverted the added OAuth2 specific changes to README as this will be …
arvindkrishnakumar-okta Apr 29, 2020
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
5 changes: 4 additions & 1 deletion THIRD-PARTY-NOTICES
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright 2017 Okta
Copyright 2017-Present Okta, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -21,6 +21,8 @@ This project includes:
AutoService under Apache 2.0
AutoService Processor under Apache 2.0
Bean Validation API under The Apache Software License, Version 2.0
Bouncy Castle PKIX, CMS, EAC, TSP, PKCS, OCSP, CMP, and CRMF APIs under Bouncy Castle Licence
Bouncy Castle Provider under Bouncy Castle Licence
commonmark-java core under BSD 2-Clause License
Commons CLI under The Apache Software License, Version 2.0
Commons IO under The Apache Software License, Version 2.0
Expand All @@ -33,6 +35,7 @@ This project includes:
JavaMail API jar under CDDL or GPLv2+CE
javax.annotation API under CDDL + GPLv2 with classpath exception
JCL 1.2 implemented over SLF4J under Apache License, Version 2.0
JJWT :: API under Apache License, Version 2.0
jmustache under The (New) BSD License
Joda-Time under Apache 2
JOpt Simple under The MIT License
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@
* The Authentication Scheme setting is helpful in cases where the code is run in a platform where the header information for
* outgoing HTTP requests is modified and thus causing communication issues.
* <p>
* The SSWS (Okta session bearer token) should be used for the management SDK, {code NONE} should be used for non
* authenticated requests.
* One of SSWS (Okta session bearer token) (or) OAUTH2 authentication schemes should be used for the management SDK, {@code NONE}
* should be used for unauthenticated requests.
*
* @since 0.5.0
*/
public enum AuthenticationScheme {

SSWS("com.okta.sdk.impl.http.authc.SswsAuthenticator"), //SSWS Authentication
OAUTH2_PRIVATE_KEY("com.okta.sdk.impl.http.authc.OAuth2RequestAuthenticator"), //OAuth2
NONE(DisabledAuthenticator.class);

private final String requestAuthenticatorClassName;
Expand Down
66 changes: 66 additions & 0 deletions api/src/main/java/com/okta/sdk/client/AuthorizationMode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright 2020-Present Okta, Inc.
*
* 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 com.okta.sdk.client;

import java.util.HashMap;
import java.util.Map;

/**
* Enumeration that defines the mapping between available Authentication schemes and Authorization modes.
*/
public enum AuthorizationMode {

SSWS("SSWS", AuthenticationScheme.SSWS), // SSWS
PRIVATE_KEY("PrivateKey", AuthenticationScheme.OAUTH2_PRIVATE_KEY), // OAuth2
NONE("NONE", AuthenticationScheme.NONE); // None

private final String label;
private final AuthenticationScheme authenticationScheme;

private static final Map<AuthenticationScheme, AuthorizationMode> lookup = new HashMap<>();

static {
for (AuthorizationMode authorizationMode : AuthorizationMode.values()) {
lookup.put(authorizationMode.getAuthenticationScheme(), authorizationMode);
}
}

AuthorizationMode(String label, AuthenticationScheme authenticationScheme) {
this.label = label;
this.authenticationScheme = authenticationScheme;
}

public String getLabel() {
return this.label;
}

public AuthenticationScheme getAuthenticationScheme() {
return this.authenticationScheme;
}

public static AuthorizationMode get(AuthenticationScheme authenticationScheme) {
return lookup.get(authenticationScheme);
}

public static AuthorizationMode getAuthorizationMode(String label) {
for (AuthorizationMode authorizationMode : values()) {
if (authorizationMode.getLabel().equals(label)) {
return authorizationMode;
}
}
throw new IllegalArgumentException();
}
}
53 changes: 53 additions & 0 deletions api/src/main/java/com/okta/sdk/client/ClientBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import com.okta.sdk.authc.credentials.ClientCredentials;
import com.okta.sdk.cache.CacheManager;

import java.util.Set;

/**
* A <a href="http://en.wikipedia.org/wiki/Builder_pattern">Builder design pattern</a> used to
* construct {@link com.okta.sdk.client.Client} instances.
Expand Down Expand Up @@ -206,6 +208,10 @@ public interface ClientBuilder {
String DEFAULT_CLIENT_PROXY_HOST_PROPERTY_NAME = "okta.client.proxy.host";
String DEFAULT_CLIENT_PROXY_USERNAME_PROPERTY_NAME = "okta.client.proxy.username";
String DEFAULT_CLIENT_PROXY_PASSWORD_PROPERTY_NAME = "okta.client.proxy.password";
String DEFAULT_CLIENT_AUTHORIZATION_MODE_PROPERTY_NAME = "okta.client.authorizationMode";
String DEFAULT_CLIENT_ID_PROPERTY_NAME = "okta.client.clientId";
String DEFAULT_CLIENT_SCOPES_PROPERTY_NAME = "okta.client.scopes";
String DEFAULT_CLIENT_PRIVATE_KEY_PROPERTY_NAME = "okta.client.privateKey";
String DEFAULT_CLIENT_REQUEST_TIMEOUT_PROPERTY_NAME = "okta.client.requestTimeout";
String DEFAULT_CLIENT_RETRY_MAX_ATTEMPTS_PROPERTY_NAME = "okta.client.rateLimit.maxRetries";
String DEFAULT_CLIENT_TESTING_DISABLE_HTTPS_CHECK_PROPERTY_NAME = "okta.testing.disableHttpsCheck";
Expand Down Expand Up @@ -306,9 +312,56 @@ public interface ClientBuilder {
*
* @param authenticationScheme the type of authentication to be used for communication with the Okta API server.
* @return the ClientBuilder instance for method chaining
*
* @deprecated since 1.6.0 use {@link #setAuthorizationMode(AuthorizationMode)} to indicate the authentication scheme.
*/
@Deprecated
ClientBuilder setAuthenticationScheme(AuthenticationScheme authenticationScheme);

/**
* Allows specifying an authorization mode.
*
* @param authorizationMode mode of authorization for requests to the Okta API server.
* @return the ClientBuilder instance for method chaining.
*
* @since 1.6.0
*/
ClientBuilder setAuthorizationMode(AuthorizationMode authorizationMode);

/**
* Allows specifying a list of scopes directly instead of relying on the
* default location + override/fallback behavior defined in the {@link ClientBuilder documentation above}.
*
* @param scopes set of scopes for which the client requests access.
* @return the ClientBuilder instance for method chaining.
*
* @since 1.6.0
*/
ClientBuilder setScopes(Set<String> scopes);

/**
* Allows specifying the private key (PEM file) path (for private key jwt authentication) directly instead
arvindkrishnakumar-okta marked this conversation as resolved.
Show resolved Hide resolved
* of relying on the default location + override/fallback behavior defined
* in the {@link ClientBuilder documentation above}.
*
* @param privateKey the fully qualified string path to the private key (PEM file).
* @return the ClientBuilder instance for method chaining.
*
* @since 1.6.0
*/
ClientBuilder setPrivateKey(String privateKey);

/**
* Allows specifying the client ID instead of relying on the default location + override/fallback behavior defined
* in the {@link ClientBuilder documentation above}.
*
* @param clientId string representing the client ID.
* @return the ClientBuilder instance for method chaining.
*
* @since 1.6.0
*/
ClientBuilder setClientId(String clientId);

/**
* Sets both the timeout until a connection is established and the socket timeout (i.e. a maximum period of inactivity
* between two consecutive data packets). A timeout value of zero is interpreted as an infinite timeout.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
/**
* Example snippets used for this projects README.md.
* <p>
* Manually run {@code mvn okta-code-snippet:snip} after chaging this file to update the README.md.
* Manually run {@code mvn okta-code-snippet:snip} after changing this file to update the README.md.
*/
@SuppressWarnings({"unused"})
public class ReadmeSnippets {
Expand Down Expand Up @@ -219,4 +219,5 @@ private void disableCaching() {
.setCacheManager(Caches.newDisabledCacheManager())
.build();
}
}
}

22 changes: 22 additions & 0 deletions impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,28 @@
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
bdemers marked this conversation as resolved.
Show resolved Hide resolved
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk15on</artifactId>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-api</artifactId>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-impl</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-jackson</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
Expand Down
Loading