message) {
- return (result) -> {
- final HttpSession session = result.getRequest().getSession(false);
- assertThat(session).isNotNull().describedAs("HttpSession");
- Object exception = session.getAttribute(WebAttributes.AUTHENTICATION_EXCEPTION);
- assertThat(exception).isInstanceOf(Saml2AuthenticationException.class);
- Saml2AuthenticationException se = (Saml2AuthenticationException) exception;
- assertThat(se.getSaml2Error().getErrorCode()).isEqualTo(code);
- assertThat(message.matches(se.getSaml2Error().getDescription())).isTrue();
- };
- }
-
- @SpringBootConfiguration
- @EnableAutoConfiguration
- public static class SpringBootApplicationTestConfig {
-
- }
-
-}
diff --git a/servlet/spring-boot/java/saml2-login/src/integTest/java/example/Saml2Utils.java b/servlet/spring-boot/java/saml2-login/src/integTest/java/example/Saml2Utils.java
deleted file mode 100644
index 90f4884..0000000
--- a/servlet/spring-boot/java/saml2-login/src/integTest/java/example/Saml2Utils.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Copyright 2002-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 example;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.nio.charset.StandardCharsets;
-import java.util.zip.Deflater;
-import java.util.zip.DeflaterOutputStream;
-import java.util.zip.Inflater;
-import java.util.zip.InflaterOutputStream;
-
-import org.apache.commons.codec.binary.Base64;
-
-import org.springframework.security.saml2.Saml2Exception;
-
-/**
- * @since 5.3
- */
-final class Saml2Utils {
-
- private static Base64 BASE64 = new Base64(0, new byte[] { '\n' });
-
- private Saml2Utils() {
- }
-
- static String samlEncode(byte[] b) {
- return BASE64.encodeAsString(b);
- }
-
- static byte[] samlDecode(String s) {
- return BASE64.decode(s);
- }
-
- static byte[] samlDeflate(String s) {
- try {
- ByteArrayOutputStream b = new ByteArrayOutputStream();
- DeflaterOutputStream deflater = new DeflaterOutputStream(b, new Deflater(Deflater.DEFLATED, true));
- deflater.write(s.getBytes(StandardCharsets.UTF_8));
- deflater.finish();
- return b.toByteArray();
- }
- catch (IOException ex) {
- throw new Saml2Exception("Unable to deflate string", ex);
- }
- }
-
- static String samlInflate(byte[] b) {
- try {
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- InflaterOutputStream iout = new InflaterOutputStream(out, new Inflater(true));
- iout.write(b);
- iout.finish();
- return new String(out.toByteArray(), StandardCharsets.UTF_8);
- }
- catch (IOException ex) {
- throw new Saml2Exception("Unable to inflate string", ex);
- }
- }
-
-}
diff --git a/servlet/spring-boot/java/saml2-login/src/main/java/example/IndexController.java b/servlet/spring-boot/java/saml2-login/src/main/java/example/IndexController.java
index 9453f91..81c4c9f 100644
--- a/servlet/spring-boot/java/saml2-login/src/main/java/example/IndexController.java
+++ b/servlet/spring-boot/java/saml2-login/src/main/java/example/IndexController.java
@@ -16,14 +16,20 @@
package example;
+import org.springframework.security.core.annotation.AuthenticationPrincipal;
+import org.springframework.security.saml2.provider.service.authentication.Saml2AuthenticatedPrincipal;
import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
@Controller
public class IndexController {
@GetMapping("/")
- public String index() {
+ public String index(Model model, @AuthenticationPrincipal Saml2AuthenticatedPrincipal principal) {
+ String emailAddress = principal.getFirstAttribute("emailAddress");
+ model.addAttribute("emailAddress", emailAddress);
+ model.addAttribute("userAttributes", principal.getAttributes());
return "index";
}
diff --git a/servlet/spring-boot/java/saml2-login/src/main/resources/application.yml b/servlet/spring-boot/java/saml2-login/src/main/resources/application.yml
index afee02e..865c79a 100644
--- a/servlet/spring-boot/java/saml2-login/src/main/resources/application.yml
+++ b/servlet/spring-boot/java/saml2-login/src/main/resources/application.yml
@@ -3,12 +3,6 @@ spring:
saml2:
relyingparty:
registration:
- simplesamlphp:
- signing.credentials:
- - private-key-location: "classpath:credentials/rp-private.key"
- certificate-location: "classpath:credentials/rp-certificate.crt"
+ one:
identityprovider:
- entity-id: https://simplesaml-for-spring-saml.cfapps.io/saml2/idp/metadata.php
- verification.credentials:
- - certificate-location: "classpath:credentials/idp-certificate.crt"
- sso-url: https://simplesaml-for-spring-saml.cfapps.io/saml2/idp/SSOService.php
+ metadata-uri: https://simplesaml-for-spring-saml.cfapps.io/saml2/idp/metadata.php
diff --git a/servlet/spring-boot/java/saml2-login/src/main/resources/templates/index.html b/servlet/spring-boot/java/saml2-login/src/main/resources/templates/index.html
index e278cbe..6073dfb 100644
--- a/servlet/spring-boot/java/saml2-login/src/main/resources/templates/index.html
+++ b/servlet/spring-boot/java/saml2-login/src/main/resources/templates/index.html
@@ -17,19 +17,30 @@
- Spring Security - SAML 2.0 Login
-
+ Spring Security - SAML 2.0 Login
+
+
-
- SAML 2.0 Login with Spring Security
- You are successfully logged in as
+
+SAML 2.0 Login with Spring Security
+You are successfully logged in as
+You're email address is
+All Your Attributes
+
+
+
+