您的位置:首页 > 编程语言 > Java开发

Grails 之 Acegi Plugin 转移到Spring Security Core Plugin

2012-09-01 11:02 106 查看
现在Acegi Plugin插件已经停止开发了,已经转移到了Spring Security Core Plugin了。它们虽然师出同门,还是有很多地方需要调整的。

以下是官方文档,新入手看了这些还是有点蒙的,具体在文章后面进行解说。


3 Migrating from the Acegi Plugin

If you formerly used the Acegi plugin, change your application configuration settings as follows.

SettingSpring Security PluginAcegi Plugin
Enabled by default
true
false
Cache UserDetails by default
false
true
Configuration location
grails-app/conf/ Config.groovy
grails-app/conf/ SecurityConfig.groovy
Security service
springSecurityService
authenticateService
The table shows names of corresponding configuration properties.

The plugin's configuration values all start with
grails.plugins.springsecurity
to distinguish them from similarly named options in Grails and from other plugins. You must specify
all property overrides with the
grails.plugins.springsecurity
suffix. For example, you specify the attribute
password.algorithm
as:

grails.plugins.springsecurity.password.algorithm='SHA-512'


in
Config.groovy


Acegi PluginSpring Security Plugin
activeactive
loginUserDomainClassuserLookup.userDomainClassName
userNameuserLookup.usernamePropertyName
enableduserLookup.enabledPropertyName
passworduserLookup.passwordPropertyName
relationalAuthoritiesuserLookup.authoritiesPropertyName
getAuthoritiesMethodN/A
authorityDomainClassauthority.className
authorityFieldauthority.nameField
authenticationFailureUrlfailureHandler.defaultFailureUrl
ajaxAuthenticationFailureUrlfailureHandler.ajaxAuthFailUrl
defaultTargetUrlsuccessHandler.defaultTargetUrl
alwaysUseDefaultTargetUrlsuccessHandler.alwaysUseDefault
filterProcessesUrlapf.filterProcessesUrl
keyanon.key
userAttributeanon.userAttribute
loginFormUrlauth.loginFormUrl
forceHttpsauth.forceHttps
ajaxLoginFormUrlauth.ajaxLoginFormUrl
afterLogoutUrllogout.afterLogoutUrl
errorPageadh.errorPage
ajaxErrorPageadh.ajaxErrorPage
ajaxHeaderajaxHeader
algorithmpassword.algorithm
encodeHashAsBase64password.encodeHashAsBase64
cookieNamerememberMe.cookieName
alwaysRememberrememberMe.alwaysRemember
tokenValiditySecondsrememberMe.tokenValiditySeconds
parameterrememberMe.parameter
rememberMeKeyrememberMe.key
useLoggerregisterLoggerListener
useRequestMapDomainClasssecurityConfigType = "Requestmap"
requestMapClassrequestMap.className
requestMapPathFieldrequestMap.urlField
requestMapConfigAttributeFieldrequestMap.configAttributeField
useControllerAnnotationssecurityConfigType = "Annotation"
controllerAnnotationsMatchercontrollerAnnotations.matcher
controllerAnnotationsMatchesLowercasecontrollerAnnotations.lowercase
controllerAnnotationStaticRulescontrollerAnnotations.staticRules
controllerAnnotationsRejectIfNoRulerejectIfNoRule
requestMapStringN/A - securityConfigType = "InterceptUrlMap" is very similar
realmNamebasic.realmName
basicProcessingFilteruseBasicAuth
switchUserProcessingFilteruseSwitchUserFilter
swswitchUserUrlswitchUser.switchUserUrl
swexitUserUrlswitchUser.exitUserUrl
swtargetUrlswitchUser.targetUrl
useMailN/A - registration is supported in the UI plugin
mailHostN/A - registration is supported in the UI plugin
mailUsernameN/A - registration is supported in the UI plugin
mailPasswordN/A - registration is supported in the UI plugin
mailProtocolN/A - registration is supported in the UI plugin
mailFromN/A - registration is supported in the UI plugin
mailPortN/A - registration is supported in the UI plugin
defaultRoleN/A - registration is supported in the UI plugin
useOpenIdN/A - supported in the OpenID plugin
openIdNonceMaxSecondsN/A - supported in the OpenID plugin
useLdapN/A - supported in the LDAP plugin
ldapRetrieveGroupRolesN/A - supported in the LDAP plugin
ldapRetrieveDatabaseRolesN/A - supported in the LDAP plugin
ldapSearchSubtreeN/A - supported in the LDAP plugin
ldapGroupRoleAttributeN/A - supported in the LDAP plugin
ldapPasswordAttributeNameN/A - supported in the LDAP plugin
ldapServerN/A - supported in the LDAP plugin
ldapManagerDnN/A - supported in the LDAP plugin
ldapManagerPasswordN/A - supported in the LDAP plugin
ldapSearchBaseN/A - supported in the LDAP plugin
ldapSearchFilterN/A - supported in the LDAP plugin
ldapGroupSearchBaseN/A - supported in the LDAP plugin
ldapGroupSearchFilterN/A - supported in the LDAP plugin
ldapUsePasswordN/A - supported in the LDAP plugin
useKerberosN/A - will be supported in a secondary plugin
kerberosLoginConfigFileN/A - will be supported in a secondary plugin
kerberosRealmN/A - will be supported in a secondary plugin
kerberosKdcN/A - will be supported in a secondary plugin
kerberosRetrieveDatabaseRolesN/A - will be supported in a secondary plugin
useHttpSessionEventPublisheruseHttpSessionEventPublisher
cacheUserscacheUsers
useCASN/A - supported in the CAS plugin
cas.casServerN/A - supported in the CAS plugin
cas.casServerPortN/A - supported in the CAS plugin
cas.casServerSecureN/A - supported in the CAS plugin
cas.localhostSecureN/A - supported in the CAS plugin
cas.failureURLN/A - supported in the CAS plugin
cas.defaultTargetURLN/A - supported in the CAS plugin
cas.fullLoginURLN/A - supported in the CAS plugin
cas.fullServiceURLN/A - supported in the CAS plugin
cas.authenticationProviderKeyN/A - supported in the CAS plugin
cas.userDetailsServiceN/A - supported in the CAS plugin
cas.sendRenewN/A - supported in the CAS plugin
cas.proxyReceptorUrlN/A - supported in the CAS plugin
cas.filterProcessesUrlN/A - supported in the CAS plugin
useNtlmN/A - will be supported in a secondary plugin
ntlm.stripDomainN/A - will be supported in a secondary plugin
ntlm.retryOnAuthFailureN/A - will be supported in a secondary plugin
ntlm.forceIdentificationN/A - will be supported in a secondary plugin
ntlm.defaultDomainN/A - will be supported in a secondary plugin
ntlm.netbiosWINSN/A - will be supported in a secondary plugin
httpPortportMapper.httpPort
httpsPortportMapper.httpsPort
secureChannelDefinitionSourceN/A, use secureChannel.definition
channelConfigsecureChannel.definition
ipRestrictionsipRestrictions
useFacebookN/A - will be supported in the Facebook plugin
facebook.filterProcessesUrlN/A - will be supported in the Facebook plugin
facebook.authenticationUrlRootN/A - will be supported in the Facebook plugin
facebook.apiKeyN/A - will be supported in the Facebook plugin
facebook.secretKeyN/A - will be supported in the Facebook plugin
问题一、

Acegi Plugin插件是在rails-app/conf/ SecurityConfig.groovy里面的,而Spring Security是在grails-app/conf/Config.groovy的,这点不复杂,官方文档也有说道。

问题二、

很多命名已经更改了,这个上文也有提到,如果没什么印象,可在看看上面的官方文档。

问题三、

这个问题比较关键Acegi Plugin插件默认的密码编码是与Spring Security默认编码是不一样的,所以需要在Config.groovy里面指定编码,如果以前使用的是MD5则需要重新配置为MD5,如下:

grails {
plugins {
springsecurity {
...
password.algorithm = "MD5"
...
}
}
}


读取配置文件

Spring Security CorePlugin读取配置文件的方式为 SpringSecurityUtils.securityConfig

页面读取登录信息

采用了sec标签,如<sec:ifLoggedIn>,更多标签可见:http://grails-plugins.github.com/grails-spring-security-core/docs/manual/guide/6%20Helper%20Classes.html#6.1%20SecurityTagLib

工具类与service类,目前能够用到的主要是这两个类里面的方法

org.codehaus.groovy.grails.plugins.springsecurity.SpringSecurityUtils

grails.plugins.springsecurity.SpringSecurityService
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: