Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

spring secutiry urls redirecting

package dev.mwhyte.spring.sec.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
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;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;

@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

    private AuthenticationSuccessHandler authenticationSuccessHandler;

    @Autowired
    public WebSecurityConfig(AuthenticationSuccessHandler authenticationSuccessHandler) {
        this.authenticationSuccessHandler = authenticationSuccessHandler;
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
                .authorizeRequests()
                .antMatchers( "/css/**", "/images/**", "/favicon.ico").permitAll()
                .antMatchers("/admin").hasRole("ADMIN")
                .anyRequest().authenticated()
                .and()
                .formLogin()
                .loginPage("/login")
                .successHandler(authenticationSuccessHandler)
                .permitAll()
                .and()
                .logout()
                .permitAll()
                .and().csrf().disable(); // we'll enable this in a later blog post
    }

    @Autowired
    public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
        auth
                .inMemoryAuthentication()
                .withUser("user").password("{noop}pass").roles("USER")
                .and()
                .withUser("admin").password("{noop}pass").roles("ADMIN");
    }
}
Comment

spring secutiry urls redirecting

package dev.mwhyte.spring.sec.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
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;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;

@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

    private AuthenticationSuccessHandler authenticationSuccessHandler;

    @Autowired
    public WebSecurityConfig(AuthenticationSuccessHandler authenticationSuccessHandler) {
        this.authenticationSuccessHandler = authenticationSuccessHandler;
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
                .authorizeRequests()
                .antMatchers( "/css/**", "/images/**", "/favicon.ico").permitAll()
                .antMatchers("/admin").hasRole("ADMIN")
                .anyRequest().authenticated()
                .and()
                .formLogin()
                .loginPage("/login")
                .successHandler(authenticationSuccessHandler)
                .permitAll()
                .and()
                .logout()
                .permitAll()
                .and().csrf().disable(); // we'll enable this in a later blog post
    }

    @Autowired
    public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
        auth
                .inMemoryAuthentication()
                .withUser("user").password("{noop}pass").roles("USER")
                .and()
                .withUser("admin").password("{noop}pass").roles("ADMIN");
    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: java mcq test 
Java :: what is java.io example 
Java :: countdown timer with seekbar 
Java :: close current file android studio shortct 
Java :: java load configuration log 
Java :: Exercise. Create a simple Java program using array named SumOfArray.java that will accept an input of whole numbers or floating point numbers and will return the Sum result. The program must accept at least 5 numbers. 
Java :: javacal 
Java :: tick mark android 
Java :: arraycopy merging arrays 
Java :: 2d matrix multiplication 
Java :: time complexity of indexof java 
Java :: How can I add a listener on the ok button of JOptionPane 
Java :: zweidimensionales array erstellen java 
Java :: java function that returns the index of the largest value in an array 
Java :: computeifabsent hashmap java 
Java :: linearview 2 items next to each other 
Java :: setvisibility not working in fragment 
Java :: how to stop scanner object skipping 
Java :: intList 
Java :: java random 8 digit number 
Java :: JDA message 
Java :: java lambda expressions qunado foi implantada 
Java :: Algorithms - count 
Java :: turn on device location android programmatically 
Java :: java regex check if group exists 
Java :: Array pocket in java 
Java :: spring down load 
Java :: java how to call getReader twice 
Java :: site:stackoverflow.com List is abstract; cannot be instantiated public List<Integer result = new List<(); 
Java :: jadoh meaning 
ADD CONTENT
Topic
Content
Source link
Name
8+7 =