-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from OSGP/feature/optional-access-token
FDP-893: Make access token optional
- Loading branch information
Showing
19 changed files
with
208 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
...n-client/src/integrationTest/kotlin/com/gxf/utilities/spring/oauth/NoTokenProviderTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.gxf.utilities.spring.oauth | ||
|
||
import com.gxf.utilities.spring.oauth.providers.NoTokenProvider | ||
import com.gxf.utilities.spring.oauth.providers.TokenProvider | ||
import org.junit.jupiter.api.Test | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.test.context.TestPropertySource | ||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig | ||
|
||
|
||
@SpringJUnitConfig(OAuthTokenClientContext::class) | ||
@TestPropertySource("classpath:oauth-disabled.properties") | ||
class NoTokenProviderTest { | ||
|
||
@Autowired | ||
lateinit var tokenProvider: TokenProvider | ||
|
||
@Test | ||
fun test() { | ||
assert(tokenProvider is NoTokenProvider) | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...lient/src/integrationTest/kotlin/com/gxf/utilities/spring/oauth/OAuthTokenProviderTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.gxf.utilities.spring.oauth | ||
|
||
import com.gxf.utilities.spring.oauth.providers.OAuthTokenProvider | ||
import com.gxf.utilities.spring.oauth.providers.TokenProvider | ||
import org.junit.jupiter.api.Test | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.test.context.TestPropertySource | ||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig | ||
|
||
|
||
@SpringJUnitConfig(OAuthTokenClientContext::class) | ||
@TestPropertySource("classpath:oauth-enabled.properties") | ||
class OAuthTokenProviderTest { | ||
|
||
@Autowired | ||
lateinit var tokenProvider: TokenProvider | ||
|
||
@Test | ||
fun test() { | ||
assert(tokenProvider is OAuthTokenProvider) | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
oauth-token-client/src/integrationTest/resources/keys/certificate.crt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
-----BEGIN CERTIFICATE----- | ||
MIIDczCCAlsCFFZ9i8q7ww4tBsuq1NslyXCB4Mj9MA0GCSqGSIb3DQEBCwUAMHYx | ||
CzAJBgNVBAYTAk5MMRMwEQYDVQQIDApHZWxkZXJsYW5kMQ8wDQYDVQQHDAZBcm5o | ||
ZW0xFTATBgNVBAoMDEFsbGlhbmRlciBOVjEQMA4GA1UECwwHSW9UIEZEUDEYMBYG | ||
A1UEAwwPZ3hmLWxzbWV0ZW4tdHN0MB4XDTIyMDcwNTA5MjUwOFoXDTIzMDcwNTA5 | ||
MjUwOFowdjELMAkGA1UEBhMCTkwxEzARBgNVBAgMCkdlbGRlcmxhbmQxDzANBgNV | ||
BAcMBkFybmhlbTEVMBMGA1UECgwMQWxsaWFuZGVyIE5WMRAwDgYDVQQLDAdJb1Qg | ||
RkRQMRgwFgYDVQQDDA9neGYtbHNtZXRlbi10c3QwggEiMA0GCSqGSIb3DQEBAQUA | ||
A4IBDwAwggEKAoIBAQDOS7Tr+imTy0IB+8gdq0z1bI2N3hJtY+uLvymqyyjfWv8i | ||
ATAu0OZgaYcXj/vcls01lMSLE2nF+z+yFivD0ErZ7dQc9v9+NSMon8M8BaP9o+o6 | ||
50xeHGlUFEcelhpfMUH9yVaWhh1BE6Mt3ZfxzFZNq30E/9Vnal9dniUoBtGxzf7x | ||
HnNxT1l1AS1Kbj4ft/+iDkZHIoAOvkndvLlgQaF1JryWuZYU83F1xT8HztmRXSrT | ||
+dNpCiYJZPh9/CWpqrC/lGlK28m1x7EJN60vw8f54dfsT+En1TcP/u9hz7cPRRIa | ||
FpHI5PScfTrmRsWWbNOETh5pcB1JWvV9q2iV3LPtAgMBAAEwDQYJKoZIhvcNAQEL | ||
BQADggEBAJqZjQlHMYh0VYwxlXshBAZh79vKX/dBalUd7yvse2Q5g2FaXnXlmybT | ||
B5c20N4QAOgDWFhcSyD5kBFKif245l56KGZ1wLn3ZUn9wWNLHDXWLZMRPgwGkKz4 | ||
WQrYv19mSobGbvMa5wypw5KgcBeXpcQmzD43EtmBQzFwRSQ+uQTmVAmfYgktsUPb | ||
xODett5N2XYQLEv31tMc9J5FUOwMeer6VrLPVcQvFrbCJ5x0O3n7dhH1eyQ3OGIJ | ||
N9E27gCkEK59IPHCW9yvmcWqr58BqckDiHjBuZdQAZ/Zq1B/PFc4Fuf2PcFETRxl | ||
1g2FHvm9qmM/ol961jhGYq0Bt2Seimo= | ||
-----END CERTIFICATE----- |
28 changes: 28 additions & 0 deletions
28
oauth-token-client/src/integrationTest/resources/keys/private-key.key
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
-----BEGIN PRIVATE KEY----- | ||
MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDOS7Tr+imTy0IB |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K5s1JJ22+BK5TDiHJeqvD8 | ||
u9IIkRC46wKBgQCWZokgyzTKtTfoT0hXDsrIa2XIKPwDmSrSwvCF1CIB6B9l2YIH | ||
09W6gEV7OQtso9EeByORBFnsf4XH+JwPlh1qx6FDQH6SuS3/3fUNkLMMAopLZ06h | ||
f6ERVhsoAf16F+j1578P6GXB4n5ac+uiOKgl69Gs4bwIoWAKV221Hl1URQKBgFEv | ||
yrIf7FjuIs3OxXSiutYdqIgvGqaCqrqsNCryAVIcH++Z47wWj5psPgM8I3xje1gt | ||
6EWji7LnxBvI5W+vAlmnYbmLyEOJ4Ck+uikMdexJD1ESpm/B87y5PiQ5KgVYnfX4 | ||
bXfB613eIeMsDyJONaAi3Gmq2kbjaSBAd1HdMGDnAoGAbwOHbvixgJSQOiLO8Tb6 | ||
DW8nkpHGexvMO4gLKHTnHLduTXfi3P/3RsoR/uNOp8yeZqZtjE4XZkGLXAfCQ7uz | ||
qgODUqk36Fwu3SVoN/hXGJrOAWRobxfO8EQLp3JRr492yZnIPO/r3ydq18m/IEpe | ||
/KJ/h0ZjDm4gWtcxDuFBMEA= | ||
-----END PRIVATE KEY----- |
2 changes: 2 additions & 0 deletions
2
oauth-token-client/src/integrationTest/resources/oauth-disabled.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
### OAUTH ### | ||
oauth.client.enabled=false |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 0 additions & 19 deletions
19
...oken-client/src/main/kotlin/com/gxf/utilities/spring/oauth/config/OauthClientCondition.kt
This file was deleted.
Oops, something went wrong.
17 changes: 17 additions & 0 deletions
17
...-client/src/main/kotlin/com/gxf/utilities/spring/oauth/config/condition/OAuthCondition.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
SPDX-FileCopyrightText: Contributors to the GXF project | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package com.gxf.utilities.spring.oauth.config.condition | ||
|
||
import org.springframework.context.annotation.Condition | ||
import org.springframework.context.annotation.ConditionContext | ||
|
||
/** | ||
* Condition to enable or disable the Oauth Client components | ||
*/ | ||
abstract class OAuthCondition : Condition { | ||
fun oAuthEnabled(context: ConditionContext) = | ||
context.environment.getProperty("oauth.client.enabled").equals("true", ignoreCase = true) | ||
} |
17 changes: 17 additions & 0 deletions
17
...src/main/kotlin/com/gxf/utilities/spring/oauth/config/condition/OAuthDisabledCondition.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
SPDX-FileCopyrightText: Contributors to the GXF project | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package com.gxf.utilities.spring.oauth.config.condition | ||
|
||
import org.springframework.context.annotation.ConditionContext | ||
import org.springframework.core.type.AnnotatedTypeMetadata | ||
|
||
/** | ||
* Condition if OAuth is disabled | ||
*/ | ||
class OAuthDisabledCondition : OAuthCondition() { | ||
override fun matches(context: ConditionContext, metadata: AnnotatedTypeMetadata): Boolean = | ||
!oAuthEnabled(context) | ||
} |
17 changes: 17 additions & 0 deletions
17
.../src/main/kotlin/com/gxf/utilities/spring/oauth/config/condition/OAuthEnabledCondition.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
SPDX-FileCopyrightText: Contributors to the GXF project | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package com.gxf.utilities.spring.oauth.config.condition | ||
|
||
import org.springframework.context.annotation.ConditionContext | ||
import org.springframework.core.type.AnnotatedTypeMetadata | ||
|
||
/** | ||
* Condition if OAuth is enabled | ||
*/ | ||
class OAuthEnabledCondition : OAuthCondition() { | ||
override fun matches(context: ConditionContext, metadata: AnnotatedTypeMetadata): Boolean = | ||
oAuthEnabled(context) | ||
} |
16 changes: 16 additions & 0 deletions
16
...-token-client/src/main/kotlin/com/gxf/utilities/spring/oauth/providers/NoTokenProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.gxf.utilities.spring.oauth.providers | ||
|
||
import com.gxf.utilities.spring.oauth.config.condition.OAuthDisabledCondition | ||
import org.springframework.context.annotation.Conditional | ||
import org.springframework.stereotype.Service | ||
import java.util.* | ||
|
||
@Service | ||
@Conditional(OAuthDisabledCondition::class) | ||
class NoTokenProvider : TokenProvider { | ||
/** | ||
* Returns an empty optional indicating that no oauth provider is configured. | ||
*/ | ||
override fun getAccessToken(): Optional<String> = | ||
Optional.empty<String>() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
oauth-token-client/src/main/kotlin/com/gxf/utilities/spring/oauth/providers/TokenProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.gxf.utilities.spring.oauth.providers | ||
|
||
import java.util.* | ||
|
||
interface TokenProvider { | ||
/** | ||
* Retrieve an access token for instance from an oauth provider. | ||
* Tokens are cached internally, there is no need to cache them outside of this library. | ||
*/ | ||
fun getAccessToken(): Optional<String> | ||
} |
20 changes: 0 additions & 20 deletions
20
oauth-token-client/src/test/kotlin/com/gxf/utilities/spring/oauth/OAuthTokenClientTest.kt
This file was deleted.
Oops, something went wrong.