关键词:
我正在尝试使用spring security实现自定义登录。所以我添加了maven依赖项。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
和我的安全配置课程
package it.mine.my.web.config;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter
{
@Override
protected void configure( HttpSecurity http ) throws Exception
{
http
.authorizeRequests()
.antMatchers( "/login" )
.permitAll()
.anyRequest()
.authenticated()
.and()
.formLogin()
.loginProcessingUrl( "/process" )
.loginPage( "/login" )
.usernameParameter( "username" )
.passwordParameter( "password" )
.defaultSuccessUrl( "/test", true )
.permitAll();
}
}
然后我创建了一个LoginController,如下所示。
package it.mine.my.web.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import java.util.Locale;
@Controller
public class LoginController
{
@RequestMapping(value = "/login", method = RequestMethod.GET)
public String login( @RequestParam(value = "error", required = false) String error, @RequestParam(value = "successMsg", required = false) String success, Model model, Locale loale )
{
model.addAttribute( "error", error != null );
model.addAttribute( "errorMsg", error );
model.addAttribute( "success", success != null );
model.addAttribute( "successMsg", success );
model.addAttribute( "locale", loale.getLanguage() );
return "login";
}
}
项目结构
运行此应用程序并在浏览器中点击http://localhost:8080/login后会出现以下错误。
Intellij IDEA控制台说,
org.thymeleaf.exceptions.TemplateInputException: Error resolving template "login", template might not exist or might not be accessible by any of the configured Template Resolvers
任何建议表示赞赏!
谢谢!
这个问题来自Thymeleaf。它告诉你它无法在“templates”目录中找到“登录”页面。
还要检查页面是否有正确的配置:
<html xmlns:th="http://www.thymeleaf.org">
windows添加自定义开机用户登录启动程序
默认的启动程序Ctrl+shift->Esc调用任务管理器-->启动项选项即可完成计算机开机自启动选项,不过这里只有系统默认添加的。添加自定义开机启动程序Windows+R调用运行窗口输入Gpedit.msc点击确定启动本地组策略编辑器 ... 查看详情
spring-security个性化用户认证流程——自定义登录成功/失败的处理(代码片段)
1.自定义登录成功处理什么需要自定义登录成功处理,因为登录行为不止只有一种,有可能是ajax请求,而默认的则是form提交跳转的行为,这个时候就不是我们想要的一种结果。如果自定义登录成功之后的行为?只需要实现Authenti... 查看详情
自定义登录表单无法使用 Spring Security
】自定义登录表单无法使用SpringSecurity【英文标题】:CustomLoginFormisnotworkingusingSpringSecurity【发布时间】:2018-11-2605:16:35【问题描述】:我正在学习SpringMVC并尝试在我的应用程序中实现SpringSecurity。我创建了自定义登录并尝试使用... 查看详情
未调用 Spring Security 自定义登录表单
】未调用SpringSecurity自定义登录表单【英文标题】:Springsecuritycustomloginformnotinvoked【发布时间】:2015-11-3009:21:47【问题描述】:我正在尝试将SpringMVCWeb应用程序配置为使用自定义登录表单进行使用注释的身份验证。我的问题是自... 查看详情
spring boot 自定义登录页面
】springboot自定义登录页面【英文标题】:springbootcustomloginpage【发布时间】:2016-10-3112:01:44【问题描述】:我正在尝试为我的引导应用程序添加一个自定义登录页面。我正在关注this教程。我无法使用我的自定义登录页面。这是我... 查看详情
Django Allauth 自定义登录模板不起作用
】DjangoAllauth自定义登录模板不起作用【英文标题】:DjangoAllauthCustomizedLoginTemplateNotWorking【发布时间】:2021-10-3120:32:29【问题描述】:我已经使用引导样式和widget_tweaks自定义了allauth的登录模板。当我尝试使用该模板登录时,它... 查看详情
自定义登录在 Spring 中不起作用
】自定义登录在Spring中不起作用【英文标题】:CustomLoginnotworkinginSpring【发布时间】:2015-02-0814:08:35【问题描述】:我们正在尝试创建自定义登录页面。我们的configure方法写如下@Overrideprotectedvoidconfigure(HttpSecurityhttp)throwsException//h... 查看详情
使用 Spring Webflux 自定义 OAUTH2 登录的登录页面
】使用SpringWebflux自定义OAUTH2登录的登录页面【英文标题】:CustomizingloginpageforOAUTH2loginwithSpringWebflux【发布时间】:2021-12-0102:06:40【问题描述】:我正在寻找自定义我的oauth2登录页面。我正在使用SpringCloudGateway,所以这是SpringSecur... 查看详情
Spring Security 自定义登录的工作原理
】SpringSecurity自定义登录的工作原理【英文标题】:HowSpringSecurity\'scustomloginworks【发布时间】:2017-02-2307:36:10【问题描述】:我正在尝试通过SpringSecurity。我必须实现一个自定义登录表单,所以我需要很好地理解我的配置意味着... 查看详情
Spring Boot Oauth 自定义登录表单
】SpringBootOauth自定义登录表单【英文标题】:SpringBootOauthCustomLoginForm【发布时间】:2016-09-1417:16:15【问题描述】:我按照春季教程“使用OAuth2进行SSO:AngularJS和SpringSecurity第V部分”。在自定义登录表单不再起作用之后,我将“aut... 查看详情
无法在 Spring Boot Security 中登录到我的自定义登录页面
】无法在SpringBootSecurity中登录到我的自定义登录页面【英文标题】:Can\'tlogintomycustomloginpageinspringbootsecurity【发布时间】:2015-04-2509:29:19【问题描述】:我的问题是:当我尝试在我的自定义登录页面上登录时,它会再次将我重定... 查看详情
如何使用 Spring Security 自定义登录页面?
】如何使用SpringSecurity自定义登录页面?【英文标题】:HowtouseSpringSecuritytocustomloginpage?【发布时间】:2017-06-0620:00:25【问题描述】:我在我的应用程序中使用SpringSecurity,这是对用户进行身份验证的安全部分,但登录页面由SpringS... 查看详情
自定义 Paypal 登录模板的任何选项
】自定义Paypal登录模板的任何选项【英文标题】:AnyOptionforCustomPaypalLogintemplate【发布时间】:2021-04-2518:26:22【问题描述】:paypal仪表板中在paypalconnectenterimagedescriptionhere中更改Paypal徽标的任何选项@【问题讨论】:【参考方案1】... 查看详情
使用自定义登录页面登录后 Spring Security Thymeleaf 页面 403
】使用自定义登录页面登录后SpringSecurityThymeleaf页面403【英文标题】:SpringSecurityThyemleafpage403afterloginusingcustomloginpage【发布时间】:2020-08-1601:47:39【问题描述】:我正在使用thymeleaf和springsecurity用户名和密码身份验证设置Web应用... 查看详情
是否可以使用jsp登录表单作为spring security的自定义登录表单
】是否可以使用jsp登录表单作为springsecurity的自定义登录表单【英文标题】:Isitpossibletousejsploginformasacustomloginformforspringsecurity【发布时间】:2020-01-0104:13:53【问题描述】:我有一个springboot项目,所有视图都是jsp页面我的问题是... 查看详情
Spring security自定义登录页面不允许我进入[关闭]
】Springsecurity自定义登录页面不允许我进入[关闭]【英文标题】:Springsecuritycustomizedloginpagedoesn\'tallowmein[closed]【发布时间】:2021-06-1720:28:39【问题描述】:通过自定义登录页面登录应用程序时遇到问题。应用程序控制台没有错误... 查看详情
Spring security自定义登录页面不重定向
】Springsecurity自定义登录页面不重定向【英文标题】:SpringsecurityCustomloginpagenotredirecting【发布时间】:2021-01-2621:18:54【问题描述】:我正在使用jsfservlet并创建了自定义登录页面,使用了带有动作j_spring_security_check的表单,方法POS... 查看详情
如何在grails中自定义spring security插件登录页面
】如何在grails中自定义springsecurity插件登录页面【英文标题】:HowtocustomizespringsecuritypluginLoginpageingrails【发布时间】:2016-11-2510:35:05【问题描述】:我尝试在springsecuritycore3.1.1中自定义登录页面,但没有成功。我在视图目录中创... 查看详情