简体   繁体   English

如何在springboot中使用html模板使用JWT认证?

[英]How to use html template in springboot using JWT Authentication?

For a few days I have begun to learn to work with springboot and particularly with spring security for user authentication, for this I have decided to make an apirest using a system in which the user authenticates and can access the service according to their specific role.几天来,我已经开始学习使用 springboot,特别是使用 spring 安全性进行用户身份验证,为此我决定使用用户进行身份验证并可以根据其特定角色访问服务的系统来做一个 apirest。

I used this post as a guide: https://grokonez.com/spring-framework/spring-boot/spring-security-jwt-authentication-postgresql-restapis-springboot-spring-mvc-spring-jpa我用这篇文章作为指导: https://grokonez.com/spring-framework/spring-boot/spring-security-jwt-authentication-postgresql-restapis-springboot-spring-mvc-spring-jpa

in which it is used Spring Security JWT Authentication PostgreSQL - RestAPIs SpringBoot Spring MVC Spring JPA in which it is used Spring Security JWT Authentication PostgreSQL - RestAPIs SpringBoot Spring MVC Spring JPA

I would like to integrate it with html templates, perhaps using thymeleaf dependency in pom.xml, bootstrap and jquery (not with Agular React or Vuejs since this is the way I should do it in my work due to a compatibility problem) I would like to integrate it with html templates, perhaps using thymeleaf dependency in pom.xml, bootstrap and jquery (not with Agular React or Vuejs since this is the way I should do it in my work due to a compatibility problem)

I have also seen several tutorials where thymeleaf is used but does not include JWT Authentication我还看到了几个使用 thymeleaf 但不包括 JWT 身份验证的教程

Could someone tell me how to complete this exercise?有人能告诉我如何完成这个练习吗? Any tutorial explaining how to do it?任何教程解释如何做到这一点?

I assume the anotations like @PreAuthorize("hasRole('USER')") from your link should work the same for thymeleaf endpoints.我假设链接中的@PreAuthorize("hasRole('USER')")之类的注释对于 thymeleaf 端点应该是一样的。

eg.:例如。:

@Controller
public class ThymeleafController {

    @GetMapping("/hello")
    @PreAuthorize("hasRole('USER')")
    public String hello() {
        return "thymeleaf-template";
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM