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
1ea921bf
Commit
1ea921bf
authored
Dec 22, 2017
by
Phillip Webb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Migrate to OAuth2Client to use PropertyMapper
See gh-9018
parent
ba86b684
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
30 deletions
+20
-30
OAuth2ClientPropertiesRegistrationAdapter.java
...th2/client/OAuth2ClientPropertiesRegistrationAdapter.java
+20
-30
No files found.
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2ClientPropertiesRegistrationAdapter.java
View file @
1ea921bf
...
@@ -18,12 +18,10 @@ package org.springframework.boot.autoconfigure.security.oauth2.client;
...
@@ -18,12 +18,10 @@ package org.springframework.boot.autoconfigure.security.oauth2.client;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.function.Consumer
;
import
java.util.function.Function
;
import
java.util.function.Supplier
;
import
org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientProperties.Provider
;
import
org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientProperties.Provider
;
import
org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientProperties.Registration
;
import
org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientProperties.Registration
;
import
org.springframework.boot.context.properties.PropertyMapper
;
import
org.springframework.boot.context.properties.bind.convert.BinderConversionService
;
import
org.springframework.boot.context.properties.bind.convert.BinderConversionService
;
import
org.springframework.core.convert.ConversionException
;
import
org.springframework.core.convert.ConversionException
;
import
org.springframework.security.config.oauth2.client.CommonOAuth2Provider
;
import
org.springframework.security.config.oauth2.client.CommonOAuth2Provider
;
...
@@ -56,16 +54,19 @@ final class OAuth2ClientPropertiesRegistrationAdapter {
...
@@ -56,16 +54,19 @@ 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
)
{
Builder
builder
=
getBuilder
(
registrationId
,
properties
.
getProvider
(),
providers
);
Builder
builder
=
getBuilder
(
registrationId
,
properties
.
getProvider
(),
providers
);
copyIfNotNull
(
properties:
:
getClientId
,
builder:
:
clientId
);
PropertyMapper
map
=
PropertyMapper
.
get
().
alwaysApplyingWhenNonNull
();
copyIfNotNull
(
properties:
:
getClientSecret
,
builder:
:
clientSecret
);
map
.
from
(
properties:
:
getClientId
).
to
(
builder:
:
clientId
);
copyIfNotNull
(
properties:
:
getClientAuthenticationMethod
,
map
.
from
(
properties:
:
getClientSecret
).
to
(
builder:
:
clientSecret
);
builder:
:
clientAuthenticationMethod
,
ClientAuthenticationMethod:
:
new
);
map
.
from
(
properties:
:
getClientAuthenticationMethod
)
copyIfNotNull
(
properties:
:
getAuthorizationGrantType
,
.
as
(
ClientAuthenticationMethod:
:
new
)
builder:
:
authorizationGrantType
,
AuthorizationGrantType:
:
new
);
.
to
(
builder:
:
clientAuthenticationMethod
);
copyIfNotNull
(
properties:
:
getRedirectUriTemplate
,
builder:
:
redirectUriTemplate
);
map
.
from
(
properties:
:
getAuthorizationGrantType
).
as
(
AuthorizationGrantType:
:
new
)
copyIfNotNull
(
properties:
:
getScope
,
builder:
:
scope
,
.
to
(
builder:
:
authorizationGrantType
);
(
scope
)
->
scope
.
toArray
(
new
String
[
scope
.
size
()]));
map
.
from
(
properties:
:
getRedirectUriTemplate
).
to
(
builder:
:
redirectUriTemplate
);
copyIfNotNull
(
properties:
:
getClientName
,
builder:
:
clientName
);
map
.
from
(
properties:
:
getScope
)
.
as
((
scope
)
->
scope
.
toArray
(
new
String
[
scope
.
size
()]))
.
to
(
builder:
:
scope
);
map
.
from
(
properties:
:
getClientName
).
to
(
builder:
:
clientName
);
return
builder
.
build
();
return
builder
.
build
();
}
}
...
@@ -95,11 +96,12 @@ final class OAuth2ClientPropertiesRegistrationAdapter {
...
@@ -95,11 +96,12 @@ final class OAuth2ClientPropertiesRegistrationAdapter {
}
}
private
static
Builder
getBuilder
(
Builder
builder
,
Provider
provider
)
{
private
static
Builder
getBuilder
(
Builder
builder
,
Provider
provider
)
{
copyIfNotNull
(
provider:
:
getAuthorizationUri
,
builder:
:
authorizationUri
);
PropertyMapper
map
=
PropertyMapper
.
get
().
alwaysApplyingWhenNonNull
();
copyIfNotNull
(
provider:
:
getTokenUri
,
builder:
:
tokenUri
);
map
.
from
(
provider:
:
getAuthorizationUri
).
to
(
builder:
:
authorizationUri
);
copyIfNotNull
(
provider:
:
getUserInfoUri
,
builder:
:
userInfoUri
);
map
.
from
(
provider:
:
getTokenUri
).
to
(
builder:
:
tokenUri
);
copyIfNotNull
(
provider:
:
getJwkSetUri
,
builder:
:
jwkSetUri
);
map
.
from
(
provider:
:
getUserInfoUri
).
to
(
builder:
:
userInfoUri
);
copyIfNotNull
(
provider:
:
getUserNameAttribute
,
builder:
:
userNameAttributeName
);
map
.
from
(
provider:
:
getJwkSetUri
).
to
(
builder:
:
jwkSetUri
);
map
.
from
(
provider:
:
getUserNameAttribute
).
to
(
builder:
:
userNameAttributeName
);
return
builder
;
return
builder
;
}
}
...
@@ -113,16 +115,4 @@ final class OAuth2ClientPropertiesRegistrationAdapter {
...
@@ -113,16 +115,4 @@ final class OAuth2ClientPropertiesRegistrationAdapter {
}
}
}
}
private
static
<
T
>
void
copyIfNotNull
(
Supplier
<
T
>
supplier
,
Consumer
<
T
>
consumer
)
{
copyIfNotNull
(
supplier
,
consumer
,
Function
.
identity
());
}
private
static
<
S
,
C
>
void
copyIfNotNull
(
Supplier
<
S
>
supplier
,
Consumer
<
C
>
consumer
,
Function
<
S
,
C
>
converter
)
{
S
value
=
supplier
.
get
();
if
(
value
!=
null
)
{
consumer
.
accept
(
converter
.
apply
(
value
));
}
}
}
}
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