Spring Security Login 无法正常工作并返回根 URL

问题描述 投票:0回答:0

在我的应用程序中,当成功登录时,我有登录表单来访问“uproject.hmtl”。但是由于错误,它返回到登录页面。当我检查 TRACE 日志中正确提供的用户详细信息时。导航栏也能正常工作,但在日志中我得到以下评论,

2023-04-24T03:41:02.959+03:00 TRACE 8136 --- [nio-8081-exec-9] o.s.s.w.a.www.BasicAuthenticationFilter  : Did not process authentication request since failed to find username and password in Basic Authorization header

是否与导致返回登录页面而不是“uproject.html”的错误有关

剩余的日志,

2023-04-24T03:41:02.947+03:00 TRACE 8136 --- [nio-8081-exec-9] o.s.security.web.FilterChainProxy        : Trying to match request against DefaultSecurityFilterChain [RequestMatcher=any request, Filters=[org.springframework.security.web.session.DisableEncodeUrlFilter@cf662d6, org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter@749acc53, org.springframework.security.web.context.SecurityContextHolderFilter@53c930f9, org.springframework.security.web.header.HeaderWriterFilter@5a4ab9aa, org.springframework.security.web.csrf.CsrfFilter@37d80860, org.springframework.security.web.authentication.logout.LogoutFilter@625c84cf, org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter@216bc5c9, org.springframework.security.web.authentication.www.BasicAuthenticationFilter@78fe204a, org.springframework.security.web.savedrequest.RequestCacheAwareFilter@1de9d507, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@43477ff4, org.springframework.security.web.authentication.AnonymousAuthenticationFilter@7def5efa, org.springframework.security.web.access.ExceptionTranslationFilter@3a3abd1, org.springframework.security.web.access.intercept.AuthorizationFilter@57387b7b]] (1/1)
2023-04-24T03:41:02.948+03:00 DEBUG 8136 --- [nio-8081-exec-9] o.s.security.web.FilterChainProxy        : Securing GET /assets/img/crosscheck_navbar_logo.png
2023-04-24T03:41:02.950+03:00 TRACE 8136 --- [nio-8081-exec-9] o.s.security.web.FilterChainProxy        : Invoking DisableEncodeUrlFilter (1/13)
2023-04-24T03:41:02.953+03:00 TRACE 8136 --- [nio-8081-exec-9] o.s.security.web.FilterChainProxy        : Invoking WebAsyncManagerIntegrationFilter (2/13)
2023-04-24T03:41:02.953+03:00 TRACE 8136 --- [io-8081-exec-10] o.s.security.web.FilterChainProxy        : Trying to match request against DefaultSecurityFilterChain [RequestMatcher=any request, Filters=[org.springframework.security.web.session.DisableEncodeUrlFilter@cf662d6, org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter@749acc53, org.springframework.security.web.context.SecurityContextHolderFilter@53c930f9, org.springframework.security.web.header.HeaderWriterFilter@5a4ab9aa, org.springframework.security.web.csrf.CsrfFilter@37d80860, org.springframework.security.web.authentication.logout.LogoutFilter@625c84cf, org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter@216bc5c9, org.springframework.security.web.authentication.www.BasicAuthenticationFilter@78fe204a, org.springframework.security.web.savedrequest.RequestCacheAwareFilter@1de9d507, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@43477ff4, org.springframework.security.web.authentication.AnonymousAuthenticationFilter@7def5efa, org.springframework.security.web.access.ExceptionTranslationFilter@3a3abd1, org.springframework.security.web.access.intercept.AuthorizationFilter@57387b7b]] (1/1)
2023-04-24T03:41:02.954+03:00 DEBUG 8136 --- [io-8081-exec-10] o.s.security.web.FilterChainProxy        : Securing GET /assets/img/crosscheck_login_logo.png
2023-04-24T03:41:02.954+03:00 TRACE 8136 --- [nio-8081-exec-9] o.s.security.web.FilterChainProxy        : Invoking SecurityContextHolderFilter (3/13)
2023-04-24T03:41:02.955+03:00 TRACE 8136 --- [nio-8081-exec-9] o.s.security.web.FilterChainProxy        : Invoking HeaderWriterFilter (4/13)
2023-04-24T03:41:02.955+03:00 TRACE 8136 --- [io-8081-exec-10] o.s.security.web.FilterChainProxy        : Invoking DisableEncodeUrlFilter (1/13)
2023-04-24T03:41:02.955+03:00 TRACE 8136 --- [nio-8081-exec-9] o.s.security.web.FilterChainProxy        : Invoking CsrfFilter (5/13)
2023-04-24T03:41:02.956+03:00 TRACE 8136 --- [nio-8081-exec-9] o.s.security.web.csrf.CsrfFilter         : Did not protect against CSRF since request did not match CsrfNotRequired [TRACE, HEAD, GET, OPTIONS]
2023-04-24T03:41:02.957+03:00 TRACE 8136 --- [nio-8081-exec-9] o.s.security.web.FilterChainProxy        : Invoking LogoutFilter (6/13)
2023-04-24T03:41:02.957+03:00 TRACE 8136 --- [nio-8081-exec-9] o.s.s.w.a.logout.LogoutFilter            : Did not match request to Ant [pattern='/logout', POST]
2023-04-24T03:41:02.957+03:00 TRACE 8136 --- [io-8081-exec-10] o.s.security.web.FilterChainProxy        : Invoking WebAsyncManagerIntegrationFilter (2/13)
2023-04-24T03:41:02.958+03:00 TRACE 8136 --- [nio-8081-exec-9] o.s.security.web.FilterChainProxy        : Invoking UsernamePasswordAuthenticationFilter (7/13)
2023-04-24T03:41:02.958+03:00 TRACE 8136 --- [io-8081-exec-10] o.s.security.web.FilterChainProxy        : Invoking SecurityContextHolderFilter (3/13)
2023-04-24T03:41:02.958+03:00 TRACE 8136 --- [nio-8081-exec-9] w.a.UsernamePasswordAuthenticationFilter : Did not match request to Ant [pattern='/process-login', POST]
2023-04-24T03:41:02.958+03:00 TRACE 8136 --- [nio-8081-exec-9] o.s.security.web.FilterChainProxy        : Invoking BasicAuthenticationFilter (8/13)
2023-04-24T03:41:02.958+03:00 TRACE 8136 --- [io-8081-exec-10] o.s.security.web.FilterChainProxy        : Invoking HeaderWriterFilter (4/13)
2023-04-24T03:41:02.959+03:00 TRACE 8136 --- [nio-8081-exec-9] o.s.s.w.a.www.BasicAuthenticationFilter  : Did not process authentication request since failed to find username and password in Basic Authorization header
2023-04-24T03:41:02.959+03:00 TRACE 8136 --- [io-8081-exec-10] o.s.security.web.FilterChainProxy        : Invoking CsrfFilter (5/13)
2023-04-24T03:41:02.959+03:00 TRACE 8136 --- [nio-8081-exec-9] o.s.security.web.FilterChainProxy        : Invoking RequestCacheAwareFilter (9/13)
2023-04-24T03:41:02.959+03:00 TRACE 8136 --- [io-8081-exec-10] o.s.security.web.csrf.CsrfFilter         : Did not protect against CSRF since request did not match CsrfNotRequired [TRACE, HEAD, GET, OPTIONS]
2023-04-24T03:41:02.959+03:00 TRACE 8136 --- [nio-8081-exec-9] o.s.s.w.s.HttpSessionRequestCache        : matchingRequestParameterName is required for getMatchingRequest to lookup a value, but not provided
2023-04-24T03:41:02.959+03:00 TRACE 8136 --- [io-8081-exec-10] o.s.security.web.FilterChainProxy        : Invoking LogoutFilter (6/13)
2023-04-24T03:41:02.959+03:00 TRACE 8136 --- [nio-8081-exec-9] o.s.security.web.FilterChainProxy        : Invoking SecurityContextHolderAwareRequestFilter (10/13)
2023-04-24T03:41:02.960+03:00 TRACE 8136 --- [io-8081-exec-10] o.s.s.w.a.logout.LogoutFilter            : Did not match request to Ant [pattern='/logout', POST]
2023-04-24T03:41:02.960+03:00 TRACE 8136 --- [io-8081-exec-10] o.s.security.web.FilterChainProxy        : Invoking UsernamePasswordAuthenticationFilter (7/13)
2023-04-24T03:41:02.960+03:00 TRACE 8136 --- [io-8081-exec-10] w.a.UsernamePasswordAuthenticationFilter : Did not match request to Ant [pattern='/process-login', POST]
2023-04-24T03:41:02.960+03:00 TRACE 8136 --- [io-8081-exec-10] o.s.security.web.FilterChainProxy        : Invoking BasicAuthenticationFilter (8/13)
2023-04-24T03:41:02.961+03:00 TRACE 8136 --- [io-8081-exec-10] o.s.s.w.a.www.BasicAuthenticationFilter  : Did not process authentication request since failed to find username and password in Basic Authorization header
2023-04-24T03:41:02.961+03:00 TRACE 8136 --- [nio-8081-exec-9] o.s.security.web.FilterChainProxy        : Invoking AnonymousAuthenticationFilter (11/13)
2023-04-24T03:41:02.961+03:00 TRACE 8136 --- [io-8081-exec-10] o.s.security.web.FilterChainProxy        : Invoking RequestCacheAwareFilter (9/13)
2023-04-24T03:41:02.962+03:00 TRACE 8136 --- [nio-8081-exec-9] o.s.security.web.FilterChainProxy        : Invoking ExceptionTranslationFilter (12/13)
2023-04-24T03:41:02.962+03:00 TRACE 8136 --- [io-8081-exec-10] o.s.s.w.s.HttpSessionRequestCache        : matchingRequestParameterName is required for getMatchingRequest to lookup a value, but not provided
2023-04-24T03:41:02.962+03:00 TRACE 8136 --- [io-8081-exec-10] o.s.security.web.FilterChainProxy        : Invoking SecurityContextHolderAwareRequestFilter (10/13)
2023-04-24T03:41:02.963+03:00 TRACE 8136 --- [io-8081-exec-10] o.s.security.web.FilterChainProxy        : Invoking AnonymousAuthenticationFilter (11/13)
2023-04-24T03:41:02.963+03:00 TRACE 8136 --- [nio-8081-exec-9] o.s.security.web.FilterChainProxy        : Invoking AuthorizationFilter (13/13)
2023-04-24T03:41:02.964+03:00 TRACE 8136 --- [io-8081-exec-10] o.s.security.web.FilterChainProxy        : Invoking ExceptionTranslationFilter (12/13)
2023-04-24T03:41:02.964+03:00 TRACE 8136 --- [io-8081-exec-10] o.s.security.web.FilterChainProxy        : Invoking AuthorizationFilter (13/13)
2023-04-24T03:41:02.964+03:00 TRACE 8136 --- [nio-8081-exec-9] estMatcherDelegatingAuthorizationManager : Authorizing SecurityContextHolderAwareRequestWrapper[ org.springframework.security.web.header.HeaderWriterFilter$HeaderWriterRequest@1c4ba382]
2023-04-24T03:41:02.966+03:00 TRACE 8136 --- [io-8081-exec-10] estMatcherDelegatingAuthorizationManager : Authorizing SecurityContextHolderAwareRequestWrapper[ org.springframework.security.web.header.HeaderWriterFilter$HeaderWriterRequest@2aaca604]
2023-04-24T03:41:02.976+03:00 TRACE 8136 --- [io-8081-exec-10] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped to HandlerExecutionChain with [ResourceHttpRequestHandler [classpath [META-INF/resources/], classpath [resources/], classpath [static/], classpath [public/], ServletContext [/]]] and 4 interceptors
2023-04-24T03:41:02.975+03:00 TRACE 8136 --- [nio-8081-exec-9] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped to HandlerExecutionChain with [ResourceHttpRequestHandler [classpath [META-INF/resources/], classpath [resources/], classpath [static/], classpath [public/], ServletContext [/]]] and 4 interceptors
2023-04-24T03:41:02.980+03:00 TRACE 8136 --- [io-8081-exec-10] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped to HandlerExecutionChain with [ResourceHttpRequestHandler [classpath [META-INF/resources/], classpath [resources/], classpath [static/], classpath [public/], ServletContext [/]]] and 4 interceptors
2023-04-24T03:41:02.983+03:00 TRACE 8136 --- [nio-8081-exec-9] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped to HandlerExecutionChain with [ResourceHttpRequestHandler [classpath [META-INF/resources/], classpath [resources/], classpath [static/], classpath [public/], ServletContext [/]]] and 4 interceptors
2023-04-24T03:41:02.988+03:00 TRACE 8136 --- [nio-8081-exec-9] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped to HandlerExecutionChain with [ResourceHttpRequestHandler [classpath [META-INF/resources/], classpath [resources/], classpath [static/], classpath [public/], ServletContext [/]]] and 4 interceptors
2023-04-24T03:41:02.991+03:00 TRACE 8136 --- [io-8081-exec-10] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped to HandlerExecutionChain with [ResourceHttpRequestHandler [classpath [META-INF/resources/], classpath [resources/], classpath [static/], classpath [public/], ServletContext [/]]] and 4 interceptors
2023-04-24T03:41:02.993+03:00 TRACE 8136 --- [io-8081-exec-10] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped to HandlerExecutionChain with [ResourceHttpRequestHandler [classpath [META-INF/resources/], classpath [resources/], classpath [static/], classpath [public/], ServletContext [/]]] and 4 interceptors
2023-04-24T03:41:02.990+03:00 TRACE 8136 --- [nio-8081-exec-9] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped to HandlerExecutionChain with [ResourceHttpRequestHandler [classpath [META-INF/resources/], classpath [resources/], classpath [static/], classpath [public/], ServletContext [/]]] and 4 interceptors
2023-04-24T03:41:03.006+03:00 TRACE 8136 --- [nio-8081-exec-9] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped to HandlerExecutionChain with [ResourceHttpRequestHandler [classpath [META-INF/resources/], classpath [resources/], classpath [static/], classpath [public/], ServletContext [/]]] and 4 interceptors
2023-04-24T03:41:03.007+03:00 TRACE 8136 --- [nio-8081-exec-9] estMatcherDelegatingAuthorizationManager : Checking authorization on SecurityContextHolderAwareRequestWrapper[ org.springframework.security.web.header.HeaderWriterFilter$HeaderWriterRequest@1c4ba382] using org.springframework.security.config.annotation.web.configurers.AuthorizeHttpRequestsConfigurer$$Lambda$1395/0x0000000801508608@2cb56903
2023-04-24T03:41:03.010+03:00 DEBUG 8136 --- [nio-8081-exec-9] o.s.security.web.FilterChainProxy        : Secured GET /assets/img/crosscheck_navbar_logo.png
2023-04-24T03:41:02.995+03:00 TRACE 8136 --- [io-8081-exec-10] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped to HandlerExecutionChain with [ResourceHttpRequestHandler [classpath [META-INF/resources/], classpath [resources/], classpath [static/], classpath [public/], ServletContext [/]]] and 4 interceptors
2023-04-24T03:41:03.010+03:00 TRACE 8136 --- [io-8081-exec-10] estMatcherDelegatingAuthorizationManager : Checking authorization on SecurityContextHolderAwareRequestWrapper[ org.springframework.security.web.header.HeaderWriterFilter$HeaderWriterRequest@2aaca604] using org.springframework.security.config.annotation.web.configurers.AuthorizeHttpRequestsConfigurer$$Lambda$1395/0x0000000801508608@2cb56903
2023-04-24T03:41:03.011+03:00 TRACE 8136 --- [nio-8081-exec-9] o.s.web.servlet.DispatcherServlet        : GET "/crosscheck/assets/img/crosscheck_navbar_logo.png", parameters={}, headers={masked} in DispatcherServlet 'dispatcherServlet'
2023-04-24T03:41:03.011+03:00 DEBUG 8136 --- [io-8081-exec-10] o.s.security.web.FilterChainProxy        : Secured GET /assets/img/crosscheck_login_logo.png
2023-04-24T03:41:03.012+03:00 TRACE 8136 --- [io-8081-exec-10] o.s.web.servlet.DispatcherServlet        : GET "/crosscheck/assets/img/crosscheck_login_logo.png", parameters={}, headers={masked} in DispatcherServlet 'dispatcherServlet'
2023-04-24T03:41:03.017+03:00 TRACE 8136 --- [io-8081-exec-10] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped to HandlerExecutionChain with [ResourceHttpRequestHandler [classpath [META-INF/resources/], classpath [resources/], classpath [static/], classpath [public/], ServletContext [/]]] and 4 interceptors
2023-04-24T03:41:03.023+03:00 TRACE 8136 --- [nio-8081-exec-9] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped to HandlerExecutionChain with [ResourceHttpRequestHandler [classpath [META-INF/resources/], classpath [resources/], classpath [static/], classpath [public/], ServletContext [/]]] and 4 interceptors
2023-04-24T03:41:03.045+03:00 TRACE 8136 --- [io-8081-exec-10] o.s.w.s.r.ResourceHttpRequestHandler     : Applying default cacheSeconds=0
2023-04-24T03:41:03.072+03:00 TRACE 8136 --- [io-8081-exec-10] o.s.s.w.header.writers.HstsHeaderWriter  : Not injecting HSTS header since it did not match request to [Is Secure]
2023-04-24T03:41:03.075+03:00 TRACE 8136 --- [io-8081-exec-10] o.s.web.servlet.DispatcherServlet        : No view rendering, null ModelAndView returned.
2023-04-24T03:41:03.076+03:00 DEBUG 8136 --- [io-8081-exec-10] o.s.web.servlet.DispatcherServlet        : Completed 200 OK, headers={masked}
2023-04-24T03:41:03.077+03:00 TRACE 8136 --- [io-8081-exec-10] w.c.HttpSessionSecurityContextRepository : Retrieved SecurityContextImpl [Authentication=UsernamePasswordAuthenticationToken [Principal=org.springframework.security.core.userdetails.User [[email protected], Password=[PROTECTED], Enabled=true, AccountNonExpired=true, credentialsNonExpired=true, AccountNonLocked=true, Granted Authorities=[ROLE_USER]], Credentials=[PROTECTED], Authenticated=true, Details=WebAuthenticationDetails [RemoteIpAddress=0:0:0:0:0:0:0:1, SessionId=4A95F8889E24EED8A68DC6CD7A956E3E], Granted Authorities=[ROLE_USER]]] from SPRING_SECURITY_CONTEXT
2023-04-24T03:41:03.078+03:00 TRACE 8136 --- [io-8081-exec-10] o.s.s.w.a.AnonymousAuthenticationFilter  : Did not set SecurityContextHolder since already authenticated UsernamePasswordAuthenticationToken [Principal=org.springframework.security.core.userdetails.User [[email protected], Password=[PROTECTED], Enabled=true, AccountNonExpired=true, credentialsNonExpired=true, AccountNonLocked=true, Granted Authorities=[ROLE_USER]], Credentials=[PROTECTED], Authenticated=true, Details=WebAuthenticationDetails [RemoteIpAddress=0:0:0:0:0:0:0:1, SessionId=4A95F8889E24EED8A68DC6CD7A956E3E], Granted Authorities=[ROLE_USER]]
2023-04-24T03:41:03.089+03:00 TRACE 8136 --- [nio-8081-exec-9] o.s.w.s.r.ResourceHttpRequestHandler     : Applying default cacheSeconds=0
2023-04-24T03:41:03.110+03:00 TRACE 8136 --- [nio-8081-exec-9] o.s.s.w.header.writers.HstsHeaderWriter  : Not injecting HSTS header since it did not match request to [Is Secure]
2023-04-24T03:41:03.115+03:00 TRACE 8136 --- [nio-8081-exec-9] o.s.web.servlet.DispatcherServlet        : No view rendering, null ModelAndView returned.
2023-04-24T03:41:03.116+03:00 DEBUG 8136 --- [nio-8081-exec-9] o.s.web.servlet.DispatcherServlet        : Completed 200 OK, headers={masked}
2023-04-24T03:41:03.117+03:00 TRACE 8136 --- [nio-8081-exec-9] w.c.HttpSessionSecurityContextRepository : Retrieved SecurityContextImpl [Authentication=UsernamePasswordAuthenticationToken [Principal=org.springframework.security.core.userdetails.User [[email protected], Password=[PROTECTED], Enabled=true, AccountNonExpired=true, credentialsNonExpired=true, AccountNonLocked=true, Granted Authorities=[ROLE_USER]], Credentials=[PROTECTED], Authenticated=true, Details=WebAuthenticationDetails [RemoteIpAddress=0:0:0:0:0:0:0:1, SessionId=4A95F8889E24EED8A68DC6CD7A956E3E], Granted Authorities=[ROLE_USER]]] from SPRING_SECURITY_CONTEXT
2023-04-24T03:41:03.117+03:00 TRACE 8136 --- [nio-8081-exec-9] o.s.s.w.a.AnonymousAuthenticationFilter  : Did not set SecurityContextHolder since already authenticated UsernamePasswordAuthenticationToken [Principal=org.springframework.security.core.userdetails.User [[email protected], Password=[PROTECTED], Enabled=true, AccountNonExpired=true, credentialsNonExpired=true, AccountNonLocked=true, Granted Authorities=[ROLE_USER]], Credentials=[PROTECTED], Authenticated=true, Details=WebAuthenticationDetails [RemoteIpAddress=0:0:0:0:0:0:0:1, SessionId=4A95F8889E24EED8A68DC6CD7A956E3E], Granted Authorities=[ROLE_USER]]

我有一个控制器,

@Controller
public class MainController {

    @GetMapping("/")
    public String displayHomePage (Model model){
        return "login";
    }
    @GetMapping("/login")
    public String displayLoginPage (Model model){
        return "login";
    }
    @GetMapping("/nfeatures")
    public String displayNFeaturesPage (Model model){
        return "nfeatures";
    }
    @GetMapping("/uprojects")
    public String displayUProjectsPage (Model model) {
        return "uprojects";
    }
    @GetMapping("/pricing")
    public String displayPricingPage (Model model){
        return "pricing";
    }

   /* @GetMapping(value="/logout")
    public String logoutPage (HttpServletRequest request, HttpServletResponse response) {
        Authentication auth = SecurityContextHolder.getContext().getAuthentication();
        if (auth != null){
            new SecurityContextLogoutHandler().logout(request, response, auth);
        }
        return "redirect:/login?logout";//You can redirect wherever you want, but generally it's a good practice to show login screen again.
    }*/
}

还有我的登录页面(它也是主页),在头部,我没有在下面提供,有引导 CDN 和 jquery 的链接。

<body>
<div th:replace="~{fragments/header :: header}"></div>
<div class="container">
    <div class="row mt-5 align-items-center">
        <div class="d-flex flex-row justify-content-center">
            <img th:src="@{/assets/img/crosscheck_login_logo.png}" class="img-fluid mx-auto">
        </div>
        <div class="mx-auto" style="width: 400px;">
            <div th:if="${param.error}">
                <div class="alert alert-danger" role="alert">Invalid Email or Password !!!</div>
            </div>
            <div th:if="${param.logout}">
                <div class="alert alert-success" role="alert">You have been logged out !!!</div>
            </div>
            <div class="alert alert-warning" role="alert" th:if="${tokenError != null}">
                <p th:text="${tokenError}"></p>
            </div>
            <div class="alert alert-warning" role="alert" th:if="${verifiedAccountMsg != null}">
                <p th:text="${verifiedAccountMsg}"></p>
            </div>
            <form
                    class="form-horizontal"
                    method="post"
                    role="form"
                    th:action="@{/process-login}"
            >
                <div class="mb-2">
                    <label class="col-sm-2 col-form-label col-form-label-sm" for="email">Email</label>
                    <input class="form-control" id="email" name="email" placeholder="Enter email address"
                           type="email">
                </div>
                <div class="mb-2">
                    <label class="col-sm-2 col-form-label col-form-label-sm" for="password">Password</label>
                    <input class="form-control" id="password" name="password" placeholder="Enter password"
                           type="password">
                </div>
                <div class="mb-2">
                    <button class="btn btn-secondary mb-2" type="submit" value="login">Login</button>
                    or <a class="link-primary" th:href="@{/registration}">Register</a>
                </div>
                <div class="mb-2">
                    <a class="link-primary" th:href="@{/forgotpass}">Forgot Password</a>
                </div>
            </form>
        </div>
    </div>
</div>
<footer th:replace="~{fragments/footer :: footer}"></footer>
</body>

还有我的用户详细信息服务类,

@Override
public UserDetails loadUserByUsername(String Email) throws UsernameNotFoundException {

    CCUser usercc = userRepository.findByEmail(Email);
    if (usercc != null) {
        boolean enabled = !usercc.isCcUserVerify();
        return User.withUsername(usercc.getEmail())
                .password(usercc.getPassword())
                .disabled(enabled)
                .authorities(usercc.getRoles().stream().map((role) -> new SimpleGrantedAuthority(role.getEmail())).collect(Collectors.toList())).build();
    } else {
        throw new UsernameNotFoundException("Invalid email or password");
    }
}

最后我想声明该应用程序适用于 mysql 数据库。

mysql spring-boot spring-security thymeleaf
© www.soinside.com 2019 - 2024. All rights reserved.