Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

spring boot basic authentication

@Configuration
@EnableWebSecurity
public class CustomWebSecurityConfigurerAdapter extends WebSecurityConfigurerAdapter {

    @Autowired
    private MyBasicAuthenticationEntryPoint authenticationEntryPoint;

    @Autowired
    public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
        auth.inMemoryAuthentication()
          .withUser("user1").password(passwordEncoder().encode("user1Pass"))
          .authorities("ROLE_USER");
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests()
          .antMatchers("/securityNone").permitAll()
          .anyRequest().authenticated()
          .and()
          .httpBasic()
          .authenticationEntryPoint(authenticationEntryPoint);

        http.addFilterAfter(new CustomFilter(),
          BasicAuthenticationFilter.class);
    }

    @Bean
    public PasswordEncoder passwordEncoder() {
        return new BCryptPasswordEncoder();
    }
}
Comment

spring boot basic authentication

SecurityConfig.java
package com.howtodoinjava.rest.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.WebSecurityConfigurerAdapter;
 
@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter
{
    @Override
    protected void configure(HttpSecurity http) throws Exception 
    {
        http
         .csrf().disable()
         .authorizeRequests().anyRequest().authenticated()
         .and()
         .httpBasic();
    }
  
    @Autowired
    public void configureGlobal(AuthenticationManagerBuilder auth) 
            throws Exception 
    {
        auth.inMemoryAuthentication()
          .withUser("admin")
          .password("{noop}password")
          .roles("USER");
    }
}
Comment

authentication in spring boot

git clone -b start https://github.com/oktadeveloper/okta-spring-boot-app-with-auth-example.git
Comment

PREVIOUS NEXT
Code Example
Java :: calculating the percentile in java 
Java :: java unicode characters 
Java :: creating a properties object using a file 
Java :: java print array of objects 
Java :: prime factors of a number 
Java :: join strings in java 
Java :: lopping rows rethinkdb 
Java :: Java Access LinkedList elements 
Java :: output folder director 
Java :: calculate the area of two squares in java by using a method 
Java :: Java public no-arg constructor 
Java :: https://graph.instagram.com/14.0/10218560180051171 
Java :: how to declare a variable when using loops Java 
Java :: Develop the Java application called Shapes. For this program, use only for loops and the following print statements below to generate the shapes below: 
Java :: bluetooth chat example android client 
Java :: Java try Keyword 
Java :: list in list 
Java :: how to hide search from menu android studio from activity 
Java :: longest subarray with equal 0 and 1 
Java :: guava-18.0.jar 
Java :: jmonkey shapes 
Java :: netbeans how to get string from jcombobox 
Java :: setlist arraylist java swing example 
Java :: os compatible java path separator 
Java :: OCA Exam Questions 
Java :: java how to slit a dtring and trim at the same time 
Java :: check if two characters are equal java 
Java :: how to come from 2nd fragment to first fragment android 
Java :: convert jython object to java object 
Java :: java.lang.stackoverflowerror null onetomany 
ADD CONTENT
Topic
Content
Source link
Name
4+8 =