官术网_书友最值得收藏!

Spring Security

Security for Java applications was always a pain for developers, especially in Java Enterprise Edition. There was a lot of boilerplate code to look up objects in the application servers, and the security layer was often heavily customized for the application.

In that chaotic scenario, the Spring Team decided to create a Spring Security project to help developers handle the security layer on the Java application.

In the beginning, the project had extensive support for Java Enterprise Edition and integration with EJB 3 security annotations. Nowadays, the project supports many different ways to handle authorization and authentication for Java applications.

Spring Security provides a comprehensive model to add authorization and authentication for Java applications. The framework can be configured with a couple of annotations, which makes the task of adding a security layer extremely easy. The other important characteristics concern how the framework can be extended. There are some interfaces that enable developers to customize the default framework behaviors, and it makes the framework customized for different application requirements.

It is an umbrella project, and it is subdivided into these modules:

  • spring-security-core
  • spring-security-remoting
  • spring-security-web
  • spring-security-config
  • spring-security-ldap
  • spring-security-acl
  • spring-security-cas
  • spring-security-openid
  • spring-security-test

These are the main modules, and there are many other projects to support a wide range of types of authentication. The module covers the following authentication and authorization types:

  • LDAP
  • HTTP Basic
  • OAuth
  • OAuth2
  • OpenID
  • CAAS
  • JAAS

The module also offers a domain-specific language (DSL) to provide an easy configuration. Let's see a simple example:

http
.formLogin()
.loginPage("/login")
.failureUrl("/login?error")
.and()
.authorizeRequests()
.antMatchers("/signup","/about").permitAll()
.antMatchers("/admin/**").hasRole("ADMIN")
.anyRequest().authenticated();
The example was extracted from the spring.io blog. For more details, go to https://spring.io/blog/2013/07/11/spring-security-java-config-preview-readability/.

As we can see, the DSL makes the configuration task extremely easy and very understandable.

Spring Security's main features are as follows:

  • Session management
  • Protection against attacks (CSRF, session fixation, and others)
  • Servlet API integration
  • Authentication and authorization

We will learn more about Spring Security in Chapter 8, Circuit Breakers and Security. We will also put it into practice.

@EnableWebSecurity is a common annotation .
主站蜘蛛池模板: 龙南县| 慈溪市| 兴国县| 兴隆县| 遵义市| 屏东县| 白城市| 扎鲁特旗| 河源市| 尼玛县| 弥勒县| 柳林县| 静乐县| 会东县| 洛扎县| 长宁县| 北票市| 阿拉善右旗| 恩施市| 皋兰县| 渝北区| 稷山县| 竹山县| 阆中市| 类乌齐县| 专栏| 富锦市| 额尔古纳市| 郸城县| 淄博市| 福贡县| 红桥区| 晋城| 化州市| 四会市| 长汀县| 无锡市| 民丰县| 青川县| 西贡区| 武清区|