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

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 .
主站蜘蛛池模板: 武汉市| 德昌县| 资溪县| 舒兰市| 和田县| 彭州市| 兴国县| 太和县| 东港市| 塔城市| 安丘市| 乌拉特中旗| 柞水县| 丁青县| 汉寿县| 平阳县| 湘西| 奉化市| 无极县| 涪陵区| 广饶县| 乌恰县| 偏关县| 青岛市| 伽师县| 讷河市| 濉溪县| 朔州市| 老河口市| 巴林右旗| 石河子市| 阿图什市| 平阳县| 讷河市| 集安市| 清苑县| 五常市| 云霄县| 延寿县| 肃北| 杭锦旗|