-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes gh-479
- Loading branch information
Showing
19 changed files
with
459 additions
and
77 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
70 changes: 70 additions & 0 deletions
70
...ava/org/springframework/security/oauth2/server/authorization/context/ProviderContext.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,70 @@ | ||
/* | ||
* Copyright 2020-2022 the original author or 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 org.springframework.security.oauth2.server.authorization.context; | ||
|
||
import java.util.function.Supplier; | ||
|
||
import org.springframework.lang.Nullable; | ||
import org.springframework.security.oauth2.server.authorization.config.ProviderSettings; | ||
import org.springframework.util.Assert; | ||
|
||
/** | ||
* A context that holds information of the Provider. | ||
* | ||
* @author Joe Grandja | ||
* @since 0.2.2 | ||
* @see ProviderSettings | ||
* @see ProviderContextHolder | ||
*/ | ||
public final class ProviderContext { | ||
private final ProviderSettings providerSettings; | ||
private final Supplier<String> issuerSupplier; | ||
|
||
/** | ||
* Constructs a {@code ProviderContext} using the provided parameters. | ||
* | ||
* @param providerSettings the provider settings | ||
* @param issuerSupplier a {@code Supplier} for the {@code URL} of the Provider's issuer identifier | ||
*/ | ||
public ProviderContext(ProviderSettings providerSettings, @Nullable Supplier<String> issuerSupplier) { | ||
Assert.notNull(providerSettings, "providerSettings cannot be null"); | ||
this.providerSettings = providerSettings; | ||
this.issuerSupplier = issuerSupplier; | ||
} | ||
|
||
/** | ||
* Returns the {@link ProviderSettings}. | ||
* | ||
* @return the {@link ProviderSettings} | ||
*/ | ||
public ProviderSettings getProviderSettings() { | ||
return this.providerSettings; | ||
} | ||
|
||
/** | ||
* Returns the {@code URL} of the Provider's issuer identifier. | ||
* The issuer identifier is resolved from the constructor parameter {@code Supplier<String>} | ||
* or if not provided then defaults to {@link ProviderSettings#getIssuer()}. | ||
* | ||
* @return the {@code URL} of the Provider's issuer identifier | ||
*/ | ||
public String getIssuer() { | ||
return this.issuerSupplier != null ? | ||
this.issuerSupplier.get() : | ||
getProviderSettings().getIssuer(); | ||
} | ||
|
||
} |
63 changes: 63 additions & 0 deletions
63
...g/springframework/security/oauth2/server/authorization/context/ProviderContextHolder.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,63 @@ | ||
/* | ||
* Copyright 2020-2022 the original author or 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 org.springframework.security.oauth2.server.authorization.context; | ||
|
||
import org.springframework.security.oauth2.server.authorization.web.ProviderContextFilter; | ||
|
||
/** | ||
* A holder of {@link ProviderContext} that associates it with the current thread using a {@code ThreadLocal}. | ||
* | ||
* @author Joe Grandja | ||
* @since 0.2.2 | ||
* @see ProviderContext | ||
* @see ProviderContextFilter | ||
*/ | ||
public final class ProviderContextHolder { | ||
private static final ThreadLocal<ProviderContext> holder = new ThreadLocal<>(); | ||
|
||
private ProviderContextHolder() { | ||
} | ||
|
||
/** | ||
* Returns the {@link ProviderContext} bound to the current thread. | ||
* | ||
* @return the {@link ProviderContext} | ||
*/ | ||
public static ProviderContext getProviderContext() { | ||
return holder.get(); | ||
} | ||
|
||
/** | ||
* Bind the given {@link ProviderContext} to the current thread. | ||
* | ||
* @param providerContext the {@link ProviderContext} | ||
*/ | ||
public static void setProviderContext(ProviderContext providerContext) { | ||
if (providerContext == null) { | ||
resetProviderContext(); | ||
} else { | ||
holder.set(providerContext); | ||
} | ||
} | ||
|
||
/** | ||
* Reset the {@link ProviderContext} bound to the current thread. | ||
*/ | ||
public static void resetProviderContext() { | ||
holder.remove(); | ||
} | ||
|
||
} |
Oops, something went wrong.