spring - Spring Boot Security ,基于表单的登录以调用自定义 API 进行身份验证
问题描述
所以想知道这是否可能。我正在尝试使用已经存在的验证用户的发布 API 在 Spring Boot 中验证我的其余 API。
我正在使用基于 fromLogin 的身份验证并尝试调用该 Rest Controller 并通过传递 post 参数来使用该登录 API。在那里,我正在创建 spring 安全上下文
,我试图在登录提交时调用登录的 POST API。身份验证不起作用。
我们可以使用表单登录来实现这一点吗?如果我对 Spring Boot 安全性的理解很新,请告诉我
我的代码有点像这样
控制器
@RestController
@RequestMapping("/somemapping")
public class AuthController {
@RequestMapping(value = "/login", method = RequestMethod.POST)
public UserData authenticateUser(@RequestBody(required = true) UserInfo userInfo, HttpServletRequest request) {
// get user data goes here
UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(
userdata.getUsername(), userdata.getPassword(), new ArrayList < > ());
authentication.setDetails(userdata);
SecurityContextHolder.getContext().setAuthentication(authentication);
send the info to caller
return userdata;
}
//安全适配器
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/somemapping/**", "/login*", ).permitAll()
.anyRequest().authenticated().and()
.formLogin().loginPage("/")
.and().authenticationEntryPoint(authenticationPoint);
}
解决方案
推荐阅读
- embedded - 示例代码中的中断条件在哪里
- python - 用于 FPGrowth 的 Pyspark 数据帧格式 -> 输入列必须是数组,但得到 bigint
- .net - 如何在剃刀页面中获取对象
- reactjs - 如何在 React Redux 中按大小过滤产品
- java - 折叠任一以返回不同的值
- python - webdriver无法登录instagram
- python - pyspark 检查列中的值是否遵循固定格式
- c# - 在与 switch 表达式中的对象模式匹配后取消引用可能的空引用 (CS8602)
- python - 在pycharm中使用虚拟环境以调试模式运行django程序?
- sql - 使用 OR 条件加入并仅使用 MIN(Column)