15
15
*/
16
16
package org .springframework .security .samples ;
17
17
18
+ import java .security .KeyException ;
19
+ import java .security .PrivateKey ;
20
+ import java .security .PublicKey ;
21
+ import java .security .cert .CertificateException ;
22
+ import java .util .UUID ;
23
+
18
24
import org .springframework .beans .factory .annotation .Autowired ;
19
25
import org .springframework .boot .SpringBootConfiguration ;
20
26
import org .springframework .boot .autoconfigure .EnableAutoConfiguration ;
54
60
import org .opensaml .xmlsec .signature .support .SignatureSupport ;
55
61
import org .w3c .dom .Element ;
56
62
57
- import java .security .KeyException ;
58
- import java .security .PrivateKey ;
59
- import java .security .PublicKey ;
60
- import java .security .cert .CertificateException ;
61
- import java .util .UUID ;
62
-
63
63
import static java .nio .charset .StandardCharsets .UTF_8 ;
64
64
import static org .hamcrest .Matchers .containsString ;
65
65
import static org .hamcrest .Matchers .startsWith ;
82
82
@ AutoConfigureMockMvc
83
83
public class ServiceProviderSampleTests {
84
84
85
- static final String LOCAL_SP_ENTITY_ID = "http://localhost:8080/sample-sp " ;
85
+ static final String LOCAL_SP_ENTITY_ID = "http://localhost:8080/saml2/service-provider-metadata/simplesamlphp " ;
86
86
87
87
@ Autowired
88
88
MockMvc mockMvc ;
@@ -95,23 +95,22 @@ public static class SpringBootApplicationTestConfig {
95
95
96
96
@ Test
97
97
public void redirectToLoginPageSingleProvider () throws Exception {
98
- mockMvc .perform (get ("http://localhost:8080/sample-sp/ some/url" ). contextPath ( "/sample-sp " ))
98
+ mockMvc .perform (get ("http://localhost:8080/some/url" ))
99
99
.andExpect (status ().is3xxRedirection ())
100
- .andExpect (redirectedUrl ("http://localhost:8080/sample-sp/ saml2/authenticate/simplesamlphp" ));
100
+ .andExpect (redirectedUrl ("http://localhost:8080/saml2/authenticate/simplesamlphp" ));
101
101
}
102
102
103
103
@ Test
104
104
public void testAuthNRequest () throws Exception {
105
- mockMvc .perform (get ("http://localhost:8080/sample-sp/ saml2/authenticate/simplesamlphp" ). contextPath ( "/sample-sp " ))
105
+ mockMvc .perform (get ("http://localhost:8080/saml2/authenticate/simplesamlphp" ))
106
106
.andExpect (status ().is3xxRedirection ())
107
107
.andExpect (header ().string ("Location" , startsWith ("https://simplesaml-for-spring-saml.cfapps.io/saml2/idp/SSOService.php?SAMLRequest=" )));
108
108
}
109
109
110
110
@ Test
111
111
public void testRelayState () throws Exception {
112
112
mockMvc .perform (
113
- get ("http://localhost:8080/sample-sp/saml2/authenticate/simplesamlphp" )
114
- .contextPath ("/sample-sp" )
113
+ get ("http://localhost:8080/saml2/authenticate/simplesamlphp" )
115
114
.param ("RelayState" , "relay state value with spaces" )
116
115
)
117
116
.andExpect (status ().is3xxRedirection ())
@@ -126,10 +125,10 @@ public void signedResponse() throws Exception {
126
125
Response response = buildResponse (assertion );
127
126
signXmlObject (response , getSigningCredential (idpCertificate , idpPrivateKey , UsageType .SIGNING ));
128
127
String xml = toXml (response );
129
- mockMvc .perform (post ("http://localhost:8080/sample-sp/ saml2/SSO/simplesamlphp" ). contextPath ( "/sample-sp " )
128
+ mockMvc .perform (post ("http://localhost:8080/saml2/SSO/simplesamlphp" )
130
129
.contentType (MediaType .APPLICATION_FORM_URLENCODED )
131
130
.param ("SAMLResponse" , OpenSamlActionTestingSupport .encode (xml .getBytes (UTF_8 ))))
132
- .andExpect (status ().is3xxRedirection ()).andExpect (redirectedUrl ("/sample-sp/ " ))
131
+ .andExpect (status ().is3xxRedirection ()).andExpect (redirectedUrl ("/" ))
133
132
.andExpect (authenticated ().withUsername (username ));
134
133
}
135
134
@@ -141,10 +140,10 @@ public void signedAssertion() throws Exception {
141
140
signXmlObject (assertion , getSigningCredential (idpCertificate , idpPrivateKey , UsageType .SIGNING ));
142
141
String xml = toXml (response );
143
142
final ResultActions actions = mockMvc
144
- .perform (post ("http://localhost:8080/sample-sp/ saml2/SSO/simplesamlphp" ). contextPath ( "/sample-sp " )
143
+ .perform (post ("http://localhost:8080/saml2/SSO/simplesamlphp" )
145
144
.contentType (MediaType .APPLICATION_FORM_URLENCODED )
146
145
.param ("SAMLResponse" , OpenSamlActionTestingSupport .encode (xml .getBytes (UTF_8 ))))
147
- .andExpect (status ().is3xxRedirection ()).andExpect (redirectedUrl ("/sample-sp/ " ))
146
+ .andExpect (status ().is3xxRedirection ()).andExpect (redirectedUrl ("/" ))
148
147
.andExpect (authenticated ().withUsername (username ));
149
148
}
150
149
@@ -153,11 +152,11 @@ public void unsigned() throws Exception {
153
152
Assertion assertion =
buildAssertion (
"[email protected] " );
154
153
Response response = buildResponse (assertion );
155
154
String xml = toXml (response );
156
- mockMvc .perform (post ("http://localhost:8080/sample-sp/ saml2/SSO/simplesamlphp" ). contextPath ( "/sample-sp " )
155
+ mockMvc .perform (post ("http://localhost:8080/saml2/SSO/simplesamlphp" )
157
156
.contentType (MediaType .APPLICATION_FORM_URLENCODED )
158
157
.param ("SAMLResponse" , OpenSamlActionTestingSupport .encode (xml .getBytes (UTF_8 ))))
159
158
.andExpect (status ().is3xxRedirection ())
160
- .andExpect (redirectedUrl ("/sample-sp/ login?error=saml2-error" ))
159
+ .andExpect (redirectedUrl ("/login?error=saml2-error" ))
161
160
.andExpect (unauthenticated ());
162
161
}
163
162
@@ -171,10 +170,10 @@ public void signedResponseEncryptedAssertion() throws Exception {
171
170
signXmlObject (assertion , getSigningCredential (idpCertificate , idpPrivateKey , UsageType .SIGNING ));
172
171
String xml = toXml (response );
173
172
final ResultActions actions = mockMvc
174
- .perform (post ("http://localhost:8080/sample-sp/ saml2/SSO/simplesamlphp" ). contextPath ( "/sample-sp " )
173
+ .perform (post ("http://localhost:8080/saml2/SSO/simplesamlphp" )
175
174
.contentType (MediaType .APPLICATION_FORM_URLENCODED )
176
175
.param ("SAMLResponse" , OpenSamlActionTestingSupport .encode (xml .getBytes (UTF_8 ))))
177
- .andExpect (status ().is3xxRedirection ()).andExpect (redirectedUrl ("/sample-sp/ " ))
176
+ .andExpect (status ().is3xxRedirection ()).andExpect (redirectedUrl ("/" ))
178
177
.andExpect (authenticated ().withUsername (username ));
179
178
}
180
179
@@ -187,10 +186,10 @@ public void unsignedResponseEncryptedAssertion() throws Exception {
187
186
Response response = buildResponse (encryptedAssertion );
188
187
String xml = toXml (response );
189
188
final ResultActions actions = mockMvc
190
- .perform (post ("http://localhost:8080/sample-sp/ saml2/SSO/simplesamlphp" ). contextPath ( "/sample-sp " )
189
+ .perform (post ("http://localhost:8080/saml2/SSO/simplesamlphp" )
191
190
.contentType (MediaType .APPLICATION_FORM_URLENCODED )
192
191
.param ("SAMLResponse" , OpenSamlActionTestingSupport .encode (xml .getBytes (UTF_8 ))))
193
- .andExpect (status ().is3xxRedirection ()).andExpect (redirectedUrl ("/sample-sp/ " ))
192
+ .andExpect (status ().is3xxRedirection ()).andExpect (redirectedUrl ("/" ))
194
193
.andExpect (authenticated ().withUsername (username ));
195
194
}
196
195
@@ -206,10 +205,10 @@ public void signedResponseEncryptedNameId() throws Exception {
206
205
signXmlObject (assertion , getSigningCredential (idpCertificate , idpPrivateKey , UsageType .SIGNING ));
207
206
String xml = toXml (response );
208
207
final ResultActions actions = mockMvc
209
- .perform (post ("http://localhost:8080/sample-sp/ saml2/SSO/simplesamlphp" ). contextPath ( "/sample-sp " )
208
+ .perform (post ("http://localhost:8080/saml2/SSO/simplesamlphp" )
210
209
.contentType (MediaType .APPLICATION_FORM_URLENCODED )
211
210
.param ("SAMLResponse" , OpenSamlActionTestingSupport .encode (xml .getBytes (UTF_8 ))))
212
- .andExpect (status ().is3xxRedirection ()).andExpect (redirectedUrl ("/sample-sp/ " ))
211
+ .andExpect (status ().is3xxRedirection ()).andExpect (redirectedUrl ("/" ))
213
212
.andExpect (authenticated ().withUsername (username ));
214
213
}
215
214
@@ -228,7 +227,7 @@ private Response buildResponse(EncryptedAssertion assertion) {
228
227
private Response buildResponse () {
229
228
Response response = OpenSamlActionTestingSupport .buildResponse ();
230
229
response .setID ("_" + UUID .randomUUID ().toString ());
231
- response .setDestination ("http://localhost:8080/sample-sp/ saml2/SSO/simplesamlphp" );
230
+ response .setDestination ("http://localhost:8080/saml2/SSO/simplesamlphp" );
232
231
response .setIssuer (buildIssuer ("https://simplesaml-for-spring-saml.cfapps.io/saml2/idp/metadata.php" ));
233
232
return response ;
234
233
}
@@ -246,7 +245,7 @@ private Assertion buildAssertion(String username) {
246
245
// as appropriate
247
246
subjectConfirmation .setMethod (SubjectConfirmation .METHOD_BEARER );
248
247
final SubjectConfirmationData confirmationData = buildSubjectConfirmationData (LOCAL_SP_ENTITY_ID );
249
- confirmationData .setRecipient ("http://localhost:8080/sample-sp/ saml2/SSO/simplesamlphp" );
248
+ confirmationData .setRecipient ("http://localhost:8080/saml2/SSO/simplesamlphp" );
250
249
subjectConfirmation .setSubjectConfirmationData (confirmationData );
251
250
assertion .getSubject ().getSubjectConfirmations ().add (subjectConfirmation );
252
251
return assertion ;
0 commit comments