-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
endsession endpoint for Oracle Cloud Identity Domain
- Loading branch information
Showing
10 changed files
with
120 additions
and
15 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
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
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
66 changes: 66 additions & 0 deletions
66
security/src/main/java/io/micronaut/security/token/ClaimsUtils.java
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,66 @@ | ||
/* | ||
* Copyright 2017-2024 original authors | ||
* | ||
* 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 | ||
* | ||
* https://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 io.micronaut.security.token; | ||
|
||
import io.micronaut.core.annotation.Internal; | ||
import io.micronaut.core.annotation.NonNull; | ||
|
||
/** | ||
* Utility class to compare claims. | ||
* @author Sergio del Amo | ||
* @since 4.12.0 | ||
*/ | ||
@Internal | ||
public final class ClaimsUtils { | ||
private static final String HTTP = "http://"; | ||
private static final String HTTPS = "https://"; | ||
private static final String EMPTY = ""; | ||
private static final String SLASH = "/"; | ||
|
||
private ClaimsUtils() { | ||
} | ||
|
||
/** | ||
* For example, for input {@code "https://idcs-214ecfa9143532ca8c3fba0ecb1fe65b.identity.oraclecloud.com"} and {@code identity.oraclecloud.com}, it returns {@code true}. | ||
* @param expectedClaim Expected Claim | ||
* @param claim Claim | ||
* @return Whether the expected claim ends with the supplied claim. Both claims are compared without leading protocol and trailing slash. | ||
*/ | ||
public static boolean endsWithIgnoringProtocolAndTrailingSlash(@NonNull String expectedClaim, @NonNull String claim) { | ||
return removeLeadingProtocolAndTrailingSlash(expectedClaim).endsWith(removeLeadingProtocolAndTrailingSlash(claim)); | ||
} | ||
|
||
/** | ||
* For example for input {@code https://identity.oraclecloud.com/}, it returns {@code identity.oraclecloud.com}. | ||
* @param claim Token Claim | ||
* @return Token Claim without leading protocol and trailing slash | ||
*/ | ||
@NonNull | ||
static String removeLeadingProtocolAndTrailingSlash(@NonNull String claim) { | ||
return removeTrailingSlash(removeProtocol(claim)); | ||
} | ||
|
||
@NonNull | ||
private static String removeTrailingSlash(@NonNull String iss) { | ||
return iss.endsWith(SLASH) ? iss.substring(0, iss.length() - 1) : iss; | ||
} | ||
|
||
@NonNull | ||
private static String removeProtocol(@NonNull String iss) { | ||
return iss.replace(HTTP, EMPTY) | ||
.replace(HTTPS, EMPTY); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
security/src/test/java/io/micronaut/security/token/ClaimsUtilsTest.java
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,38 @@ | ||
package io.micronaut.security.token; | ||
|
||
import junit.framework.TestCase; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
|
||
import java.util.stream.Stream; | ||
|
||
import static org.junit.jupiter.params.provider.Arguments.arguments; | ||
|
||
public class ClaimsUtilsTest extends TestCase { | ||
|
||
static Stream<Arguments> paramsProvider() { | ||
return Stream.of( | ||
arguments("https://identity.oraclecloud.com", "identity.oraclecloud.com"), | ||
arguments("https://identity.oraclecloud.com/", "identity.oraclecloud.com"), | ||
arguments("http://identity.oraclecloud.com/", "identity.oraclecloud.com"), | ||
arguments("identity.oraclecloud.com", "identity.oraclecloud.com")); | ||
} | ||
|
||
static Stream<Arguments> startsWithParamsProvider() { | ||
return Stream.of( | ||
arguments("https://idcs-214ecfa9143532ca8c3fba0ecb1fe65b.identity.oraclecloud.com", "https://identity.oraclecloud.com/")); | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("startsWithParamsProvider") | ||
void endsWithIgnoring(String configClaim, String claim) { | ||
assertTrue(ClaimsUtils.endsWithIgnoringProtocolAndTrailingSlash(configClaim, claim)); | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("paramsProvider") | ||
void cleanupClaim(String claim, String expected) { | ||
assertEquals(expected, ClaimsUtils.removeLeadingProtocolAndTrailingSlash(claim)); | ||
} | ||
} |