Java-Based Spring Security Configuration: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 35: Line 35:
</syntaxhighlight>
</syntaxhighlight>


=Securing Web Requests=
=Security Configuration=


[https://docs.spring.io/spring-security/site/docs/current/api/org/springframework/security/config/annotation/web/configuration/WebSecurityConfigurerAdapter.html WebSecurityConfigurerAdapter] can be used t o specify which web request should be secured and which not. This configuration is specified using the following method:
[https://docs.spring.io/spring-security/site/docs/current/api/org/springframework/security/config/annotation/web/configuration/WebSecurityConfigurerAdapter.html WebSecurityConfigurerAdapter] can be used t o specify which web request should be secured and which not. This configuration is specified using the following method:
Line 51: Line 51:
* how to log out.
* how to log out.
* cross-site request forgery protection.
* cross-site request forgery protection.
==Securing Requests==

Revision as of 05:17, 13 November 2018

External

Internal

Overview

This article describes Java-based Spring Security configuration. This method can be used to configure the following security aspects:

Configuration Class

import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

@Configuration
@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {

  @Override
  protected void configure(AuthenticationManagerBuilder auth) throws Exception {
    ...
  }

  @Override
  protected void configure(HttpSecurity http) throws Exception {
    ...
  }
}

Security Configuration

WebSecurityConfigurerAdapter can be used t o specify which web request should be secured and which not. This configuration is specified using the following method:

@Override
protected void configure(HttpSecurity http) throws Exception {
  ...
}

The HttpSecurity object can be used to configure how security is handled at the web level:

  • what security conditions should be met before allowing a request to be served.
  • the custom login page.
  • how to log out.
  • cross-site request forgery protection.

Securing Requests