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
86591026
Commit
86591026
authored
Apr 02, 2020
by
Madhura Bhave
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add configuration options for SAML authentication requests
Closes gh-20584
parent
6a0d6208
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
203 additions
and
7 deletions
+203
-7
Saml2RelyingPartyProperties.java
...configure/security/saml2/Saml2RelyingPartyProperties.java
+55
-3
Saml2RelyingPartyRegistrationConfiguration.java
...ity/saml2/Saml2RelyingPartyRegistrationConfiguration.java
+14
-1
Saml2RelyingPartyAutoConfigurationTests.java
...curity/saml2/Saml2RelyingPartyAutoConfigurationTests.java
+30
-1
Saml2RelyingPartyPropertiesTests.java
...gure/security/saml2/Saml2RelyingPartyPropertiesTests.java
+99
-0
application.yml
...saml2-service-provider/src/main/resources/application.yml
+5
-2
No files found.
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/saml2/Saml2RelyingPartyProperties.java
View file @
86591026
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
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.
...
...
@@ -23,6 +23,7 @@ import java.util.Map;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.core.io.Resource
;
import
org.springframework.security.saml2.provider.service.registration.Saml2MessageBinding
;
/**
* SAML2 relying party properties.
...
...
@@ -124,6 +125,8 @@ public class Saml2RelyingPartyProperties {
*/
private
String
ssoUrl
;
private
SingleSignOn
singleSignOn
=
new
SingleSignOn
();
private
Verification
verification
=
new
Verification
();
public
String
getEntityId
()
{
...
...
@@ -134,18 +137,67 @@ public class Saml2RelyingPartyProperties {
this
.
entityId
=
entityId
;
}
@Deprecated
public
String
getSsoUrl
()
{
return
this
.
ssoUrl
;
return
this
.
getSingleSignOn
().
getUrl
()
;
}
@Deprecated
public
void
setSsoUrl
(
String
ssoUrl
)
{
this
.
ssoUrl
=
ssoUrl
;
this
.
singleSignOn
.
setUrl
(
ssoUrl
);
}
public
SingleSignOn
getSingleSignOn
()
{
return
this
.
singleSignOn
;
}
public
Verification
getVerification
()
{
return
this
.
verification
;
}
public
static
class
SingleSignOn
{
/**
* Remote endpoint to send authentication requests to.
*/
private
String
url
;
/**
* Whether to redirect or post authentication requests.
*/
private
Saml2MessageBinding
binding
=
Saml2MessageBinding
.
REDIRECT
;
/**
* Whether to sign authentication requests.
*/
private
boolean
signRequest
=
true
;
public
String
getUrl
()
{
return
this
.
url
;
}
public
void
setUrl
(
String
url
)
{
this
.
url
=
url
;
}
public
Saml2MessageBinding
getBinding
()
{
return
this
.
binding
;
}
public
void
setBinding
(
Saml2MessageBinding
binding
)
{
this
.
binding
=
binding
;
}
public
boolean
isSignRequest
()
{
return
this
.
signRequest
;
}
public
void
setSignRequest
(
boolean
signRequest
)
{
this
.
signRequest
=
signRequest
;
}
}
public
static
class
Verification
{
/**
...
...
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/saml2/Saml2RelyingPartyRegistrationConfiguration.java
View file @
86591026
...
...
@@ -66,15 +66,28 @@ class Saml2RelyingPartyRegistrationConfiguration {
}
private
RelyingPartyRegistration
asRegistration
(
String
id
,
Registration
properties
)
{
boolean
signRequest
=
properties
.
getIdentityprovider
().
getSingleSignOn
().
isSignRequest
();
validateSigningCredentials
(
properties
,
signRequest
);
RelyingPartyRegistration
.
Builder
builder
=
RelyingPartyRegistration
.
withRegistrationId
(
id
);
builder
.
assertionConsumerServiceUrlTemplate
(
"{baseUrl}"
+
Saml2WebSsoAuthenticationFilter
.
DEFAULT_FILTER_PROCESSES_URI
);
builder
.
providerDetails
((
details
)
->
details
.
webSsoUrl
(
properties
.
getIdentityprovider
().
getSsoUrl
()));
builder
.
providerDetails
(
(
details
)
->
details
.
webSsoUrl
(
properties
.
getIdentityprovider
().
getSingleSignOn
().
getUrl
()));
builder
.
providerDetails
((
details
)
->
details
.
entityId
(
properties
.
getIdentityprovider
().
getEntityId
()));
builder
.
providerDetails
(
(
details
)
->
details
.
binding
(
properties
.
getIdentityprovider
().
getSingleSignOn
().
getBinding
()));
builder
.
providerDetails
((
details
)
->
details
.
signAuthNRequest
(
signRequest
));
builder
.
credentials
((
credentials
)
->
credentials
.
addAll
(
asCredentials
(
properties
)));
return
builder
.
build
();
}
private
void
validateSigningCredentials
(
Registration
properties
,
boolean
signRequest
)
{
if
(
signRequest
)
{
Assert
.
state
(!
properties
.
getSigning
().
getCredentials
().
isEmpty
(),
"Signing credentials must not be empty when authentication requests require signing."
);
}
}
private
List
<
Saml2X509Credential
>
asCredentials
(
Registration
properties
)
{
List
<
Saml2X509Credential
>
credentials
=
new
ArrayList
<>();
properties
.
getSigning
().
getCredentials
().
stream
().
map
(
this
::
asSigningCredential
).
forEach
(
credentials:
:
add
);
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/saml2/Saml2RelyingPartyAutoConfigurationTests.java
View file @
86591026
...
...
@@ -34,6 +34,7 @@ import org.springframework.security.config.BeanIds;
import
org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter
;
import
org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistration
;
import
org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistrationRepository
;
import
org.springframework.security.saml2.provider.service.registration.Saml2MessageBinding
;
import
org.springframework.security.saml2.provider.service.servlet.filter.Saml2WebSsoAuthenticationFilter
;
import
org.springframework.security.web.FilterChainProxy
;
import
org.springframework.security.web.SecurityFilterChain
;
...
...
@@ -85,11 +86,28 @@ public class Saml2RelyingPartyAutoConfigurationTests {
.
isEqualTo
(
"https://simplesaml-for-spring-saml.cfapps.io/saml2/idp/metadata.php"
);
assertThat
(
registration
.
getAssertionConsumerServiceUrlTemplate
())
.
isEqualTo
(
"{baseUrl}"
+
Saml2WebSsoAuthenticationFilter
.
DEFAULT_FILTER_PROCESSES_URI
);
assertThat
(
registration
.
getProviderDetails
().
getBinding
()).
isEqualTo
(
Saml2MessageBinding
.
POST
);
assertThat
(
registration
.
getProviderDetails
().
isSignAuthNRequest
()).
isEqualTo
(
false
);
assertThat
(
registration
.
getSigningCredentials
()).
isNotNull
();
assertThat
(
registration
.
getVerificationCredentials
()).
isNotNull
();
});
}
@Test
void
autoConfigurationWhenSignRequestsTrueAndNoSigningCredentialsShouldThrowException
()
{
this
.
contextRunner
.
withPropertyValues
(
getPropertyValuesWithoutSigningCredentials
(
true
)).
run
((
context
)
->
{
assertThat
(
context
).
hasFailed
();
assertThat
(
context
.
getStartupFailure
()).
hasMessageContaining
(
"Signing credentials must not be empty when authentication requests require signing."
);
});
}
@Test
void
autoConfigurationWhenSignRequestsFalseAndNoSigningCredentialsShouldNotThrowException
()
{
this
.
contextRunner
.
withPropertyValues
(
getPropertyValuesWithoutSigningCredentials
(
false
))
.
run
((
context
)
->
assertThat
(
context
).
hasSingleBean
(
RelyingPartyRegistrationRepository
.
class
));
}
@Test
void
relyingPartyRegistrationRepositoryShouldBeConditionalOnMissingBean
()
{
this
.
contextRunner
.
withPropertyValues
(
getPropertyValues
())
...
...
@@ -112,11 +130,22 @@ public class Saml2RelyingPartyAutoConfigurationTests {
.
run
((
context
)
->
assertThat
(
hasFilter
(
context
,
Saml2WebSsoAuthenticationFilter
.
class
)).
isFalse
());
}
private
String
[]
getPropertyValuesWithoutSigningCredentials
(
boolean
signRequests
)
{
return
new
String
[]
{
PREFIX
+
".foo.identityprovider.single-sign-on.url=https://simplesaml-for-spring-saml.cfapps.io/saml2/idp/SSOService.php"
,
PREFIX
+
".foo.identityprovider.single-sign-on.binding=post"
,
PREFIX
+
".foo.identityprovider.single-sign-on.sign-request="
+
signRequests
,
PREFIX
+
".foo.identityprovider.entity-id=https://simplesaml-for-spring-saml.cfapps.io/saml2/idp/metadata.php"
,
PREFIX
+
".foo.identityprovider.verification.credentials[0].certificate-location=classpath:saml/certificate-location"
};
}
private
String
[]
getPropertyValues
()
{
return
new
String
[]
{
PREFIX
+
".foo.signing.credentials[0].private-key-location=classpath:saml/private-key-location"
,
PREFIX
+
".foo.signing.credentials[0].certificate-location=classpath:saml/certificate-location"
,
PREFIX
+
".foo.identityprovider.sso-url=https://simplesaml-for-spring-saml.cfapps.io/saml2/idp/SSOService.php"
,
PREFIX
+
".foo.identityprovider.single-sign-on.url=https://simplesaml-for-spring-saml.cfapps.io/saml2/idp/SSOService.php"
,
PREFIX
+
".foo.identityprovider.single-sign-on.binding=post"
,
PREFIX
+
".foo.identityprovider.single-sign-on.sign-request=false"
,
PREFIX
+
".foo.identityprovider.entity-id=https://simplesaml-for-spring-saml.cfapps.io/saml2/idp/metadata.php"
,
PREFIX
+
".foo.identityprovider.verification.credentials[0].certificate-location=classpath:saml/certificate-location"
};
}
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/saml2/Saml2RelyingPartyPropertiesTests.java
0 → 100644
View file @
86591026
/*
* Copyright 2012-2020 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
.
boot
.
autoconfigure
.
security
.
saml2
;
import
java.util.Collections
;
import
java.util.Map
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.boot.context.properties.bind.Bindable
;
import
org.springframework.boot.context.properties.bind.Binder
;
import
org.springframework.boot.context.properties.source.ConfigurationPropertySource
;
import
org.springframework.boot.context.properties.source.MapConfigurationPropertySource
;
import
org.springframework.security.saml2.provider.service.registration.Saml2MessageBinding
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Tests for {@link Saml2RelyingPartyProperties}.
*
* @author Madhura Bhave
*/
class
Saml2RelyingPartyPropertiesTests
{
private
final
Saml2RelyingPartyProperties
properties
=
new
Saml2RelyingPartyProperties
();
@Deprecated
@Test
void
customizeSsoUrlDeprecated
()
{
bind
(
"spring.security.saml2.relyingparty.registration.simplesamlphp.identity-provider.single-sign-on.url"
,
"https://simplesaml-for-spring-saml/SSOService.php"
);
assertThat
(
this
.
properties
.
getRegistration
().
get
(
"simplesamlphp"
).
getIdentityprovider
().
getSingleSignOn
().
getUrl
())
.
isEqualTo
(
"https://simplesaml-for-spring-saml/SSOService.php"
);
}
@Test
void
customizeSsoUrl
()
{
bind
(
"spring.security.saml2.relyingparty.registration.simplesamlphp.identity-provider.single-sign-on.url"
,
"https://simplesaml-for-spring-saml/SSOService.php"
);
assertThat
(
this
.
properties
.
getRegistration
().
get
(
"simplesamlphp"
).
getIdentityprovider
().
getSingleSignOn
().
getUrl
())
.
isEqualTo
(
"https://simplesaml-for-spring-saml/SSOService.php"
);
}
@Test
void
customizeSsoBindingDefaultsToRedirect
()
{
this
.
properties
.
getRegistration
().
put
(
"simplesamlphp"
,
new
Saml2RelyingPartyProperties
.
Registration
());
assertThat
(
this
.
properties
.
getRegistration
().
get
(
"simplesamlphp"
).
getIdentityprovider
().
getSingleSignOn
()
.
getBinding
()).
isEqualTo
(
Saml2MessageBinding
.
REDIRECT
);
}
@Test
void
customizeSsoBinding
()
{
bind
(
"spring.security.saml2.relyingparty.registration.simplesamlphp.identity-provider.single-sign-on.binding"
,
"post"
);
assertThat
(
this
.
properties
.
getRegistration
().
get
(
"simplesamlphp"
).
getIdentityprovider
().
getSingleSignOn
()
.
getBinding
()).
isEqualTo
(
Saml2MessageBinding
.
POST
);
}
@Test
void
customizeSsoSignRequests
()
{
bind
(
"spring.security.saml2.relyingparty.registration.simplesamlphp.identity-provider.single-sign-on.sign-request"
,
"false"
);
assertThat
(
this
.
properties
.
getRegistration
().
get
(
"simplesamlphp"
).
getIdentityprovider
().
getSingleSignOn
()
.
isSignRequest
()).
isEqualTo
(
false
);
}
@Test
void
customizeSsoSignRequestsIsTrueByDefault
()
{
this
.
properties
.
getRegistration
().
put
(
"simplesamlphp"
,
new
Saml2RelyingPartyProperties
.
Registration
());
assertThat
(
this
.
properties
.
getRegistration
().
get
(
"simplesamlphp"
).
getIdentityprovider
().
getSingleSignOn
()
.
isSignRequest
()).
isEqualTo
(
true
);
}
private
void
bind
(
String
name
,
String
value
)
{
bind
(
Collections
.
singletonMap
(
name
,
value
));
}
private
void
bind
(
Map
<
String
,
String
>
map
)
{
ConfigurationPropertySource
source
=
new
MapConfigurationPropertySource
(
map
);
new
Binder
(
source
).
bind
(
"spring.security.saml2.relyingparty"
,
Bindable
.
ofInstance
(
this
.
properties
));
}
}
spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-saml2-service-provider/src/main/resources/application.yml
View file @
86591026
...
...
@@ -13,7 +13,8 @@ spring:
credentials
:
-
certificate-location
:
"
classpath:saml/certificate.txt"
entity-id
:
simplesaml
sso-url
:
https://simplesaml-for-spring-saml/SSOService.php
single-sign-on
:
url
:
https://simplesaml-for-spring-saml/SSOService.php
okta
:
signing
:
credentials
:
...
...
@@ -24,4 +25,6 @@ spring:
credentials
:
-
certificate-location
:
"
classpath:saml/certificate.txt"
entity-id
:
okta-id-1234
sso-url
:
https://okta-for-spring/saml2/idp/SSOService.php
single-sign-on
:
url
:
https://okta-for-spring/saml2/idp/SSOService.php
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