(Reproduced) ACEGI security
June 25, 2010
Spring Acegi to use rights management keyword: spring access rights to the use of acegi About
For a typical Web application, complete authentication and authorization mechanisms are essential in SpringFramework in, Juergen Hoeller example JPetStore to provide some introduction to this area, but not enough, Acegi is a security mechanism designed to provide SpringFramework project, called Acegi Security System for Spring, the current version is 0.5.1, on its current offer, should meet most application needs.
The main purpose of this paper is to be able to explain how a Web application based on Spring framework to use Acegi, rather than the details of each of these interfaces, each class. Note that even if existing Spring applications, by following the steps described, you can immediately enjoy the Acegi provides authentication and authorization.
based work
in your Web application to add Acegi lib download package acegi-security.jar
web.xml
implement authentication and authorization of the most common method is through the filter, Acegi is also true, is usually required in the web.xml to add Acegi following five filter:
Acegi Channel Processing Filter net.sf.acegisecurity.util.FilterToBeanProxy
targetClass
net . sf.acegisecurity.securechannel.ChannelProcessingFilter Acegi Authentication Processing Filter net.sf . acegisecurity.util.FilterToBeanProxy
targetClass
net.sf.acegisecurity.ui.webapp.AuthenticationProcessingFilter Acegi HTTP BASIC Authorization Filter net.sf.acegisecurity.util.FilterToBeanProxy
targetClass
net.sf.acegisecurity.ui.basicauth.BasicProcessingFilter < filter> Acegi Security System for Spring Auto Integration Filter net.sf.acegisecurity.ui.AutoIntegrationFilter Acegi HTTP Request Security Filter net.sf.acegisecurity.util.FilterToBeanProxy
targetClass
net.sf.acegisecurity.intercept.web.SecurityEnforcementFilter
the first cause of confusion is net.sf.acegisecurity.util . FilterToBeanProxy, Acegi documentation on their explanation is: “What FilterToBeanProxy does is delegate the Filter methods through to a bean which is obtained from the Spring application context. This enables the bean to benefit from the Spring application context lifecycle support and configuration flexibility. “if they wish to get to the bottom, then, to see the source code should be easy to understand.
further down is to add filter-mapping a:
Acegi Channel Processing Filter / * Acegi Authentication Processing Filter / * Acegi HTTP BASIC Authorization Filter / * Acegi Security System for Spring Auto Integration Filter / * Acegi HTTP Request Security Filter / *
Here, the need Note the following three points:
1) the order of these filter can not be changed, not the order will not work;
2) If your application does not require secure transport, such as https, it will. ” Acegi Channel Processing Filter “to comment out the relevant content;
3) If your application does not need Spring remote access mechanism, such as Hessian and Burlap, the” Acegi HTTP BASIC Authorization Filter “to comment out the relevant content .
applicationContext.xml
applicationContext.xml in the next step is to add content, from just FilterToBeanFactory explanation can be seen, the real filter in the Spring applicationContext in the management :
1) First, your database must have a user name and password to save the table, Acegi table schema must be required as follows:
CREATE TABLE users (username VARCHAR (50) NOT NULL PRIMARY KEY, password VARCHAR (50) NOT NULL, enabled BIT NOT NULL); CREATE TABLE authorities (username VARCHAR (50) NOT NULL, authority VARCHAR (50) NOT NULL); CREATE UNIQUE INDEX ix_auth_username ON authorities (username, authority); ALTER TABLE authorities ADD CONSTRAINT fk_authorities_users foreign key (username)
January 7, 2012 at 3:07 pm