Note Be sure to turn on use-expression=true.
The functions supported in the authentication expression are: Denyall, Hasanyrole, Hasrole, hasipaddress, Isanonymouse, isauthenticated, isfullyauthenticated, Isrememberme, Permitall, supported variables are autentication, principal.
HTTPS interception. Some special URLs must be securely connected with HTTPS. The wording is as follows.
<intercept-url pattern= "/admin" requires-channel= "https"/><intercept-url pattern= "/public" Requires-channel= "http"/>
Protecting viewsThe JSP file accesses the variables related to authentication, or displays different content depending on the visitor's identity.
Access authentication details. such as access to login user name.
<sec:authentication property= "Principal.username"/>
Different content is displayed depending on the identity. Take a look at the example below.
<sec:authorize access= "Hasrole (' Role_vip ')" > You is vip.</sec:authorize>
Authentication methodSpring supports the following authentication methods: XML-based configuration, JDBC-based, LDAP-based, OpenID, CAS, X509, JAAS.
Based on the XML configuration. Write the user name and password in the configuration file.
<security:user-service id= "UserService" > <user name= "root" password= "123456" authorities= "ROLE_VIP, Role_admin "/> <user name=" test "password=" test "authorities=" ROLE_VIP "/></security:user-service ><security:authentication-manager> <authentication-provider user-service-ref= "UserService"/> </security:authentication-manager>
Based on JDBC.
<security:jdbc-user-service id= "UserService" data-source-ref= "DataSource" users-by-username-query= "Select username,password,enabled from user where username=? ' authorities-by-username-query= ' Select username,authoritiy from User_auth "/>
Based on LDAP.
<security:authentication-manager alias= "AuthenticationManager" > <security: Ldap-authentication-provider user-search-filter= "(uid={0})" Group-search-filter= "member={0}" > < Security:password-compare hash= "MD5"/> <security:ldap-server url= "Ldap://example.com/dc=test"/> </security:ldap-authentication-provider></security:authentication-manager>
Remember to log inMyvipkey is the token key name in the cookie, and the expiration time, user name, and token key are saved in the token.
Intercept method callsEnable secure interception of annotation methods.
<global-method-security secured-annotations= "Enabled"/>
Intercept according to identity.
@Secured ("ROLE_VIP") public void Test () {}
Filter the return value.
@PostFilter ("FilterObject.user.username = = principal.name") public list<user> getuserlist () {}
Cross-cutting authorization<global-method-security> <protect-pointcut access= "ROLE_VIP" expression= "Execution (@ Com.example.User * * * * (String)) "/></global-method-security>
Spring Framework: Spring security