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
681abcc1
Commit
681abcc1
authored
Sep 02, 2020
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish "Configure SAML 2.0 Service Provider via Metadata"
See gh-23045
parent
5187c01e
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
27 additions
and
23 deletions
+27
-23
Saml2RelyingPartyProperties.java
...configure/security/saml2/Saml2RelyingPartyProperties.java
+1
-1
Saml2RelyingPartyRegistrationConfiguration.java
...ity/saml2/Saml2RelyingPartyRegistrationConfiguration.java
+20
-17
Saml2RelyingPartyAutoConfigurationTests.java
...curity/saml2/Saml2RelyingPartyAutoConfigurationTests.java
+4
-3
Saml2RelyingPartyPropertiesTests.java
...gure/security/saml2/Saml2RelyingPartyPropertiesTests.java
+1
-1
idp-metadata
...g-boot-autoconfigure/src/test/resources/saml/idp-metadata
+1
-1
No files found.
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/saml2/Saml2RelyingPartyProperties.java
View file @
681abcc1
...
...
@@ -141,7 +141,7 @@ public class Saml2RelyingPartyProperties {
private
String
entityId
;
/**
*
E
ndpoint for discovery-based configuration.
*
URI to the metadata e
ndpoint for discovery-based configuration.
*/
private
String
metadataUri
;
...
...
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/saml2/Saml2RelyingPartyRegistrationConfiguration.java
View file @
681abcc1
...
...
@@ -22,6 +22,7 @@ import java.security.cert.X509Certificate;
import
java.security.interfaces.RSAPrivateKey
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.function.Consumer
;
import
java.util.stream.Collectors
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
...
...
@@ -37,6 +38,8 @@ import org.springframework.security.converter.RsaKeyConverters;
import
org.springframework.security.saml2.core.Saml2X509Credential
;
import
org.springframework.security.saml2.provider.service.registration.InMemoryRelyingPartyRegistrationRepository
;
import
org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistration
;
import
org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistration.AssertingPartyDetails
;
import
org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistration.Builder
;
import
org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistrationRepository
;
import
org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistrations
;
import
org.springframework.security.saml2.provider.service.servlet.filter.Saml2WebSsoAuthenticationFilter
;
...
...
@@ -67,26 +70,13 @@ class Saml2RelyingPartyRegistrationConfiguration {
}
private
RelyingPartyRegistration
asRegistration
(
String
id
,
Registration
properties
)
{
RelyingPartyRegistration
.
Builder
builder
;
boolean
usingMetadata
=
StringUtils
.
hasText
(
properties
.
getIdentityprovider
().
getMetadataUri
());
if
(
usingMetadata
)
{
builder
=
RelyingPartyRegistrations
.
fromMetadataLocation
(
properties
.
getIdentityprovider
().
getMetadataUri
())
.
registrationId
(
id
);
}
else
{
builder
=
RelyingPartyRegistration
.
withRegistrationId
(
id
);
}
Builder
builder
=
(
usingMetadata
)
?
RelyingPartyRegistrations
.
fromMetadataLocation
(
properties
.
getIdentityprovider
().
getMetadataUri
()).
registrationId
(
id
)
:
RelyingPartyRegistration
.
withRegistrationId
(
id
);
builder
.
assertionConsumerServiceLocation
(
"{baseUrl}"
+
Saml2WebSsoAuthenticationFilter
.
DEFAULT_FILTER_PROCESSES_URI
);
Saml2RelyingPartyProperties
.
Identityprovider
identityprovider
=
properties
.
getIdentityprovider
();
PropertyMapper
map
=
PropertyMapper
.
get
().
alwaysApplyingWhenNonNull
();
builder
.
assertingPartyDetails
((
details
)
->
{
map
.
from
(
identityprovider:
:
getEntityId
).
to
(
details:
:
entityId
);
map
.
from
(
identityprovider
.
getSinglesignon
()::
getBinding
).
to
(
details:
:
singleSignOnServiceBinding
);
map
.
from
(
identityprovider
.
getSinglesignon
()::
getUrl
).
to
(
details:
:
singleSignOnServiceLocation
);
map
.
from
(
identityprovider
.
getSinglesignon
()::
isSignRequest
).
when
((
signRequest
)
->
!
usingMetadata
)
.
to
(
details:
:
wantAuthnRequestsSigned
);
});
builder
.
assertingPartyDetails
(
mapIdentityProvider
(
properties
,
usingMetadata
));
builder
.
signingX509Credentials
((
credentials
)
->
properties
.
getSigning
().
getCredentials
().
stream
()
.
map
(
this
::
asSigningCredential
).
forEach
(
credentials:
:
add
));
builder
.
assertingPartyDetails
((
details
)
->
details
...
...
@@ -99,6 +89,19 @@ class Saml2RelyingPartyRegistrationConfiguration {
return
registration
;
}
private
Consumer
<
AssertingPartyDetails
.
Builder
>
mapIdentityProvider
(
Registration
properties
,
boolean
usingMetadata
)
{
PropertyMapper
map
=
PropertyMapper
.
get
().
alwaysApplyingWhenNonNull
();
Saml2RelyingPartyProperties
.
Identityprovider
identityprovider
=
properties
.
getIdentityprovider
();
return
(
details
)
->
{
map
.
from
(
identityprovider:
:
getEntityId
).
to
(
details:
:
entityId
);
map
.
from
(
identityprovider
.
getSinglesignon
()::
getBinding
).
to
(
details:
:
singleSignOnServiceBinding
);
map
.
from
(
identityprovider
.
getSinglesignon
()::
getUrl
).
to
(
details:
:
singleSignOnServiceLocation
);
map
.
from
(
identityprovider
.
getSinglesignon
()::
isSignRequest
).
when
((
signRequest
)
->
!
usingMetadata
)
.
to
(
details:
:
wantAuthnRequestsSigned
);
};
}
private
void
validateSigningCredentials
(
Registration
properties
,
boolean
signRequest
)
{
if
(
signRequest
)
{
Assert
.
state
(!
properties
.
getSigning
().
getCredentials
().
isEmpty
(),
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/saml2/Saml2RelyingPartyAutoConfigurationTests.java
View file @
681abcc1
...
...
@@ -35,6 +35,7 @@ import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.core.io.ClassPathResource
;
import
org.springframework.core.io.Resource
;
import
org.springframework.security.config.BeanIds
;
import
org.springframework.security.config.annotation.web.builders.HttpSecurity
;
import
org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter
;
...
...
@@ -122,7 +123,7 @@ class Saml2RelyingPartyAutoConfigurationTests {
try
(
MockWebServer
server
=
new
MockWebServer
())
{
server
.
start
();
String
metadataUrl
=
server
.
url
(
""
).
toString
();
setupMockResponse
(
server
);
setupMockResponse
(
server
,
new
ClassPathResource
(
"saml/idp-metadata"
)
);
this
.
contextRunner
.
withPropertyValues
(
PREFIX
+
".foo.identityprovider.metadata-uri="
+
metadataUrl
)
.
run
((
context
)
->
{
assertThat
(
context
).
hasSingleBean
(
RelyingPartyRegistrationRepository
.
class
);
...
...
@@ -195,8 +196,8 @@ class Saml2RelyingPartyAutoConfigurationTests {
return
filters
.
stream
().
anyMatch
(
filter:
:
isInstance
);
}
private
void
setupMockResponse
(
MockWebServer
server
)
throws
Exception
{
try
(
InputStream
metadataSource
=
new
ClassPathResource
(
"saml/idp-metadata"
)
.
getInputStream
())
{
private
void
setupMockResponse
(
MockWebServer
server
,
Resource
resourceBody
)
throws
Exception
{
try
(
InputStream
metadataSource
=
resourceBody
.
getInputStream
())
{
Buffer
metadataBuffer
=
new
Buffer
().
readFrom
(
metadataSource
);
MockResponse
metadataResponse
=
new
MockResponse
().
setBody
(
metadataBuffer
);
server
.
enqueue
(
metadataResponse
);
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/saml2/Saml2RelyingPartyPropertiesTests.java
View file @
681abcc1
...
...
@@ -103,7 +103,7 @@ class Saml2RelyingPartyPropertiesTests {
}
@Test
void
customizeIdentityProviderMetadataUr
l
()
{
void
customizeIdentityProviderMetadataUr
i
()
{
bind
(
"spring.security.saml2.relyingparty.registration.simplesamlphp.identityprovider.metadata-uri"
,
"https://idp.example.org/metadata"
);
assertThat
(
this
.
properties
.
getRegistration
().
get
(
"simplesamlphp"
).
getIdentityprovider
().
getMetadataUri
())
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/resources/saml/idp-metadata
View file @
681abcc1
...
...
@@ -39,4 +39,4 @@
<md:ContactPerson contactType="technical">
<md:EmailAddress>mailto:technical.contact@example.com</md:EmailAddress>
</md:ContactPerson>
</md:EntityDescriptor>
\ No newline at end of file
</md:EntityDescriptor>
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