Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
eefa0ada
Commit
eefa0ada
authored
Jul 24, 2018
by
Madhura Bhave
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow property overrides for OIDC Configuration Provider
Closes gh-13869
parent
5011bc64
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
9 deletions
+57
-9
OAuth2ClientPropertiesRegistrationAdapter.java
...th2/client/OAuth2ClientPropertiesRegistrationAdapter.java
+9
-9
OAuth2ClientPropertiesRegistrationAdapterTests.java
...lient/OAuth2ClientPropertiesRegistrationAdapterTests.java
+48
-0
No files found.
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2ClientPropertiesRegistrationAdapter.java
View file @
eefa0ada
...
@@ -56,14 +56,11 @@ public final class OAuth2ClientPropertiesRegistrationAdapter {
...
@@ -56,14 +56,11 @@ public final class OAuth2ClientPropertiesRegistrationAdapter {
private
static
ClientRegistration
getClientRegistration
(
String
registrationId
,
private
static
ClientRegistration
getClientRegistration
(
String
registrationId
,
Registration
properties
,
Map
<
String
,
Provider
>
providers
)
{
Registration
properties
,
Map
<
String
,
Provider
>
providers
)
{
String
issuer
=
getIssuerIfPossible
(
registrationId
,
properties
.
getProvider
(),
Builder
builder
=
getBuilderFromIssuerIfPossible
(
registrationId
,
providers
);
properties
.
getProvider
(),
providers
);
if
(
issuer
!=
null
)
{
if
(
builder
==
null
)
{
return
OidcConfigurationProvider
.
issuer
(
issuer
).
registrationId
(
registrationId
)
builder
=
getBuilder
(
registrationId
,
properties
.
getProvider
(),
providers
);
.
clientId
(
properties
.
getClientId
())
.
clientSecret
(
properties
.
getClientSecret
()).
build
();
}
}
Builder
builder
=
getBuilder
(
registrationId
,
properties
.
getProvider
(),
providers
);
PropertyMapper
map
=
PropertyMapper
.
get
().
alwaysApplyingWhenNonNull
();
PropertyMapper
map
=
PropertyMapper
.
get
().
alwaysApplyingWhenNonNull
();
map
.
from
(
properties:
:
getClientId
).
to
(
builder:
:
clientId
);
map
.
from
(
properties:
:
getClientId
).
to
(
builder:
:
clientId
);
map
.
from
(
properties:
:
getClientSecret
).
to
(
builder:
:
clientSecret
);
map
.
from
(
properties:
:
getClientSecret
).
to
(
builder:
:
clientSecret
);
...
@@ -79,7 +76,7 @@ public final class OAuth2ClientPropertiesRegistrationAdapter {
...
@@ -79,7 +76,7 @@ public final class OAuth2ClientPropertiesRegistrationAdapter {
return
builder
.
build
();
return
builder
.
build
();
}
}
private
static
String
get
IssuerIfPossible
(
String
registrationId
,
private
static
Builder
getBuilderFrom
IssuerIfPossible
(
String
registrationId
,
String
configuredProviderId
,
Map
<
String
,
Provider
>
providers
)
{
String
configuredProviderId
,
Map
<
String
,
Provider
>
providers
)
{
String
providerId
=
(
configuredProviderId
!=
null
?
configuredProviderId
String
providerId
=
(
configuredProviderId
!=
null
?
configuredProviderId
:
registrationId
);
:
registrationId
);
...
@@ -87,7 +84,10 @@ public final class OAuth2ClientPropertiesRegistrationAdapter {
...
@@ -87,7 +84,10 @@ public final class OAuth2ClientPropertiesRegistrationAdapter {
Provider
provider
=
providers
.
get
(
providerId
);
Provider
provider
=
providers
.
get
(
providerId
);
String
issuer
=
provider
.
getIssuerUri
();
String
issuer
=
provider
.
getIssuerUri
();
if
(
issuer
!=
null
)
{
if
(
issuer
!=
null
)
{
return
cleanIssuerPath
(
issuer
);
String
cleanedIssuer
=
cleanIssuerPath
(
issuer
);
Builder
builder
=
OidcConfigurationProvider
.
issuer
(
cleanedIssuer
)
.
registrationId
(
registrationId
);
return
getBuilder
(
builder
,
provider
);
}
}
}
}
return
null
;
return
null
;
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2ClientPropertiesRegistrationAdapterTests.java
View file @
eefa0ada
...
@@ -255,6 +255,54 @@ public class OAuth2ClientPropertiesRegistrationAdapterTests {
...
@@ -255,6 +255,54 @@ public class OAuth2ClientPropertiesRegistrationAdapterTests {
testOidcConfiguration
(
registration
,
"okta-oidc"
);
testOidcConfiguration
(
registration
,
"okta-oidc"
);
}
}
@Test
public
void
oidcProviderConfigurationWithCustomConfigurationOverridesProviderDefaults
()
throws
Exception
{
this
.
server
=
new
MockWebServer
();
this
.
server
.
start
();
String
issuer
=
this
.
server
.
url
(
""
).
toString
();
String
cleanIssuerPath
=
cleanIssuerPath
(
issuer
);
setupMockResponse
(
cleanIssuerPath
);
Registration
registration
=
new
Registration
();
registration
.
setProvider
(
"okta-oidc"
);
registration
.
setClientId
(
"clientId"
);
registration
.
setClientSecret
(
"clientSecret"
);
registration
.
setClientAuthenticationMethod
(
"post"
);
registration
.
setRedirectUriTemplate
(
"http://example.com/redirect"
);
registration
.
setScope
(
Collections
.
singleton
(
"user"
));
Provider
provider
=
new
Provider
();
provider
.
setIssuerUri
(
issuer
);
provider
.
setAuthorizationUri
(
"http://example.com/auth"
);
provider
.
setTokenUri
(
"http://example.com/token"
);
provider
.
setUserInfoUri
(
"http://example.com/info"
);
provider
.
setUserNameAttribute
(
"sub"
);
provider
.
setJwkSetUri
(
"http://example.com/jwk"
);
OAuth2ClientProperties
properties
=
new
OAuth2ClientProperties
();
properties
.
getProvider
().
put
(
"okta-oidc"
,
provider
);
properties
.
getRegistration
().
put
(
"okta"
,
registration
);
Map
<
String
,
ClientRegistration
>
registrations
=
OAuth2ClientPropertiesRegistrationAdapter
.
getClientRegistrations
(
properties
);
ClientRegistration
adapted
=
registrations
.
get
(
"okta"
);
ProviderDetails
providerDetails
=
adapted
.
getProviderDetails
();
assertThat
(
adapted
.
getClientAuthenticationMethod
())
.
isEqualTo
(
ClientAuthenticationMethod
.
POST
);
assertThat
(
adapted
.
getAuthorizationGrantType
())
.
isEqualTo
(
AuthorizationGrantType
.
AUTHORIZATION_CODE
);
assertThat
(
adapted
.
getRegistrationId
()).
isEqualTo
(
"okta"
);
assertThat
(
adapted
.
getClientName
()).
isEqualTo
(
cleanIssuerPath
);
assertThat
(
adapted
.
getScopes
()).
containsOnly
(
"user"
);
assertThat
(
adapted
.
getRedirectUriTemplate
())
.
isEqualTo
(
"http://example.com/redirect"
);
assertThat
(
providerDetails
.
getAuthorizationUri
())
.
isEqualTo
(
"http://example.com/auth"
);
assertThat
(
providerDetails
.
getTokenUri
()).
isEqualTo
(
"http://example.com/token"
);
assertThat
(
providerDetails
.
getJwkSetUri
()).
isEqualTo
(
"http://example.com/jwk"
);
assertThat
(
providerDetails
.
getUserInfoEndpoint
().
getUri
())
.
isEqualTo
(
"http://example.com/info"
);
assertThat
(
providerDetails
.
getUserInfoEndpoint
().
getUserNameAttributeName
())
.
isEqualTo
(
"sub"
);
}
private
void
testOidcConfiguration
(
Registration
registration
,
String
providerId
)
private
void
testOidcConfiguration
(
Registration
registration
,
String
providerId
)
throws
Exception
{
throws
Exception
{
this
.
server
=
new
MockWebServer
();
this
.
server
=
new
MockWebServer
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment