首页>代码>Spring Boot整合Spring Security + Spring LDAP实现用户登录权限验证配置实例>/ldap-auth/src/main/java/com/memorynotfound/ldap/controller/HomeController.java
package com.memorynotfound.ldap.controller; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.ldap.userdetails.LdapUserDetailsImpl; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class HomeController { private static Logger log = LoggerFactory.getLogger(HomeController.class); @GetMapping("/") public String index() { log.info("Getting UsernamePasswordAuthenticationToken from SecurityContextHolder"); UsernamePasswordAuthenticationToken authentication = (UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication(); log.info("Getting principal from UsernamePasswordAuthenticationToken"); LdapUserDetailsImpl principal = (LdapUserDetailsImpl) authentication.getPrincipal(); log.info("authentication: " + authentication); log.info("principal: " + principal); return "Spring Security + Spring LDAP Authentication Configuration Example"; } @GetMapping("/managers") public String managers(){ return "Hello managers"; } @GetMapping("/employees") public String employees(){ return "Hello employees"; } }
最近下载更多
没有眼的鱼 LV1
2023年12月22日
C544350851 LV26
2023年11月24日
forsaken123 LV1
2023年5月26日
evagsd LV6
2022年5月30日
1byte8bit LV8
2022年5月28日
zlfsgg LV3
2022年4月26日
笛卡尔积 LV6
2022年1月18日
山水一程 LV1
2021年10月18日
在线不是本人 LV12
2021年9月4日
湿巾不湿 LV1
2021年8月18日
最近浏览更多
没有眼的鱼 LV1
2023年12月22日
C544350851 LV26
2023年11月24日
duon12 LV1
2023年9月25日
forsaken123 LV1
2023年5月26日
懒耗子 LV3
2023年4月22日
随便取个名字_哈哈 LV27
2023年4月19日
zxc131313 LV12
2023年4月8日
csh0313 LV3
2022年12月28日
微信网友_6202330433490944
2022年11月2日
暂无贡献等级
好的好的 LV8
2022年8月10日