spring mvc - How to configure thymeleaf-extras-springsecurity4 without xml? -


i'm trying use code snippet in view, content shown regardless of user's role.

<div sec:authorize="hasrole('role_admin')">             <!-- admin content --> </div> 

add build.gradle following dependency:

compile("org.springframework.boot:spring-boot-starter-security") 

you must add spring security configuration in example:

@configuration public class springsecurityconfig extends websecurityconfigureradapter {      @autowired     public void configureglobal(authenticationmanagerbuilder auth) throws exception {         auth                 .inmemoryauthentication()                 .withuser("admin").password("admin").roles("admin", "user")                 .and().withuser("user").password("user").roles("user");     }      @override     protected void configure(httpsecurity http) throws exception {         http.authorizerequests().antmatchers("/", "/index/**").permitall()                 .and().authorizerequests().antmatchers("/login", "logout").permitall()                 .and().formlogin().loginpage("/login").defaultsuccessurl("/").permitall()                 .and().logout()                         .deletecookies("remove")                         .invalidatehttpsession(true)                         .logouturl("/logout")                         .logoutsuccessurl("/logout-success")                         .logoutrequestmatcher(new antpathrequestmatcher("/logout"));     } } 

read more @ securing web application.


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -