get the authenticated user in spring controller method

2024-04-13 Thread Helge Wiemann
Hi all, I am quite new to Shiro and currently moving from Spring Security to Shiro. One question: After a user is successfully authenticated and authorized, what is the best way to get the user in a Spring controller method? With used Spring Security it was something like that:

Re: get the authenticated user in spring controller method

2024-04-13 Thread lenny
Hi, Take a look at Shiro’s SpringBoot 3 example. This should get your started: https://github.com/apache/shiro/blob/main/samples/spring-boot-3-web/src/main/java/org/apache/shiro/samples/HelloController.java

Re: get the authenticated user in spring controller method

2024-04-13 Thread lenny
He Principal type depends on the Realm that you are using. The Principal type of Map is for example purposes only. In your code, you would substitute the type passed into byType() method with the appropriate type. Or you can use Subject.getPrincipal() that returns Object type and cast to

Re: get the authenticated user in spring controller method

2024-04-13 Thread Helge Wiemann
Hi, thanks for the sample code. But I questions because I got some problems to understand the code:     Collection principalMaps = subject.getPrincipals().byType(Map.class);     if (CollectionUtils.isEmpty(principalMaps)) {     name = subject.getPrincipal().toString();