Spring Security 3.0: Authentication and Authorization
Spring Security 3.0: Authentication and Authorization
<authentication-provider>
<user-service>
<user name="admin" password="sandtp"
authorities="ROLE_USER, ROLE_ADMIN"
/>
</user-service>
</authentication-provider>
</authentication-manager>
LDAP Authentication Provider
Declaration
<beans:bean id="ldapAuthProvider"
class="org.springframework.security.ldap.aut
hentication.LdapAuthenticationProvider">
<beans:constructor-arg
ref="bindAuthenticator" />
<beans:constructor-arg
ref="authoritiesPopulator" />
</beans:bean>
Bind Authenticator Declaration
<beans:bean id="bindAuthenticator"
class="org.springframework.security.ldap.authentication.BindAuthenticator">
<beans:constructor-arg ref="contextSource" />
<beans:property name="userDnPatterns">
<beans:list>
<beans:value>sAMAccountName={0}</beans:value>
</beans:list>
</beans:property>
<beans:property name="userSearch" ref="userSearch" />
</beans:bean>
<beans:bean id="contextSource"
class="org.springframework.security.ldap.DefaultSpringSecurityContextSource">
<beans:constructor-arg value="ldap://sntsoftware.ro:389/DC=sntsoftware,DC=ro" />
<beans:property name="userDn" value="CN=Ldap.Query.Service,CN=Users,DC=sntsoftware,DC=ro" />
<beans:property name="password" value="sandtp" />
</beans:bean>
<beans:bean id="userSearch"
class="org.springframework.security.ldap.search.FilterBasedLdapUserSearch">
<beans:constructor-arg index="0" value="" />
<beans:constructor-arg index="1" value="(sAMAccountName={0})" />
<beans:constructor-arg index="2" ref="contextSource" />
</beans:bean>
Authorities Populator
Declaration
<beans:bean id="authoritiesPopulator"
class="org.springframework.security.ldap.aut
hentication.UserDetailsServiceLdapAuthoritie
sPopulator">
<beans:constructor-arg
ref="userDetailsService"/>
</beans:bean>
UserDetailsService Declaration
<beans:bean id="userDetailsService"
class="org.springframework.security.core.userdetails.jdbc.JdbcDaoImpl">
<beans:property name="dataSource" ref="dataSource"/>
</beans:bean>
Persistent token
Remember-me : Simple hash-
based token
Remember-me : Persistent
Token
Remember-me Objects
Remember-me : Persistent
Token - Configuration
<beans:bean id="rememberMeServices"
class="org.springframework.security.web.authentication.rememberme.P
ersistentTokenBasedRememberMeServices">
<beans:property name="userDetailsService" ref="userDetailsService" />
<beans:property name="tokenRepository" ref="jdbcTokenRepository" />
<beans:property name="key" value="e37f4b31-0c45-11dd-bd0b-
0800200c9a66" />
</beans:bean>
<beans:bean id="jdbcTokenRepository"
class="org.springframework.security.web.authentication.rememberme.J
dbcTokenRepositoryImpl">
<beans:property name="dataSource" ref="dataSource" />
</beans:bean>
Database Schema for
JdbcDaoImpl
Agenda
@Secured({"ROLE_ADMIN", "ACL_OBJECT_READ", "AFTER_ACL_READ"})
MySecuredObject getSecuredObject(MySecuredObject obj);
2 types of verification:
Before invocation check access rights on
parameters
after invocation check access rights on returned
object
if access not granted AccessDeniedException
ACL Database Schema
ACL Database Schema (cont)
ACL_ENTRY.mask
ACL Data Model
ACL Service – Object Model
ACL Service – Declaration
(MySQL)
<beans:bean id="aclService"
class="org.springframework.security.acls.jdbc.JdbcMutableAclSe
rvice">
<beans:constructor-arg ref="dataSource"/>
<beans:constructor-arg ref="lookupStrategy"/>
<beans:constructor-arg ref="aclCache"/>
package com.snt.model.security;
import org.springframework.security.acls.domain.BasePermission;
public class ReadAdminCumulativePermission extends
org.springframework.security.acls.domain.CumulativePermission {
public ReadAdminCumulativePermission() {
set(BasePermission.READ);
set(BasePermission.ADMINISTRATION);
}
}
Access Decision Manager –
how does it work?
@Secured({"ROLE_ADMIN", "ACL_OBJECT_READ",
"AFTER_ACL_READ"})
public SecuredObject getSecuredObject(SecuredObject obj);
AclEntryVoter(AclService aclService,
java.lang.String processConfigAttribute,
Permission[] requirePermission)
boolean supports(java.lang.Class<?> clazz)
boolean supports(ConfigAttribute attribute)
int vote(Authentication authentication,
java.lang.Object object,
java.util.Collection<ConfigAttribute> attributes)
Access Decision Manager –
Cumulative Permissions Issue
Matching for permissions is done by Spring
Framework using “==”
Suppose Read and Write permissions are set
If you ask for isGranted(READ), it will not be
allowed!
You need to ask isGranted(READ && WRITE)
Solutions:
- modify the corresponding Spring Security code
- Enhancement provided in Spring Security 3.1:
http://jira.springframework.org/browse/SEC-1166
After Invocation Manager
After Invocation Providers
<global-method-security secured-
annotations="enabled" access-decision-manager-
ref="businessAccessDecisionManager">
<after-invocation-provider ref="afterAclRead"/>
<after-invocation-provider
ref="afterAclCollectionRead"/>
</global-method-security>
After Invocation Providers
(cont)
<beans:bean id="afterAclRead"
class="org.springframework.security.acls.afterinvocation.AclEntryAfterInvocationProvider">
<beans:constructor-arg ref="aclService"/>
<beans:constructor-arg>
<beans:list>
<beans:ref local="aclCumulativeReadAdminPermission"/>
</beans:list>
</beans:constructor-arg>
</beans:bean>
<beans:bean id="afterAclCollectionRead"
class="org.springframework.security.acls.afterinvocation.AclEntryAfterInvocationCollectionFi
lteringProvider">
<beans:constructor-arg ref="aclService"/>
<beans:constructor-arg>
<beans:list>
<beans:ref local="aclCumulativeReadAdminPermission"/>
</beans:list>
</beans:constructor-arg>
</beans:bean>
Thank you!
http://static.springsource.org/spring-
security/site/docs/3.0.x/reference/springse
curity.html
http://static.springsource.org/spring-
security/site/docs/3.0.x/apidocs/