From e1c4b2567139c385fcee85fe6c78c97cfb00bcf0 Mon Sep 17 00:00:00 2001 From: Rob Winch Date: Fri, 13 May 2022 17:02:48 -0500 Subject: [PATCH] Fix spring-session-sample-boot-hazelcast --- .../sample/config/UserControllerAdvise.java | 37 +++++++++++++++++++ .../src/main/resources/templates/layout.html | 7 ++-- 2 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 spring-session-samples/spring-session-sample-boot-hazelcast/src/main/java/sample/config/UserControllerAdvise.java diff --git a/spring-session-samples/spring-session-sample-boot-hazelcast/src/main/java/sample/config/UserControllerAdvise.java b/spring-session-samples/spring-session-sample-boot-hazelcast/src/main/java/sample/config/UserControllerAdvise.java new file mode 100644 index 00000000..0af458fa --- /dev/null +++ b/spring-session-samples/spring-session-sample-boot-hazelcast/src/main/java/sample/config/UserControllerAdvise.java @@ -0,0 +1,37 @@ +/* + * Copyright 2014-2022 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 sample.config; + +import java.security.Principal; + +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ModelAttribute; + +/** + * {@link ControllerAdvice} to expose user related attributes. + * + * @author Rob Winch + */ +@ControllerAdvice +public class UserControllerAdvise { + + @ModelAttribute("currentUserName") + String currentUser(Principal principal) { + return (principal != null) ? principal.getName() : null; + } + +} diff --git a/spring-session-samples/spring-session-sample-boot-hazelcast/src/main/resources/templates/layout.html b/spring-session-samples/spring-session-sample-boot-hazelcast/src/main/resources/templates/layout.html index 50be94b5..bb42db27 100644 --- a/spring-session-samples/spring-session-sample-boot-hazelcast/src/main/resources/templates/layout.html +++ b/spring-session-samples/spring-session-sample-boot-hazelcast/src/main/resources/templates/layout.html @@ -81,13 +81,12 @@
Spring Security Sample -