Source

Grails Spring Security Taobao / SpringSecurityTaobaoGrailsPlugin.groovy

/* Copyright 2006-2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*      http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import org.codehaus.groovy.grails.plugins.springsecurity.SecurityFilterPosition
import org.codehaus.groovy.grails.plugins.springsecurity.SpringSecurityUtils
import org.springframework.security.core.session.SessionRegistryImpl
import org.springframework.security.web.authentication.session.ConcurrentSessionControlStrategy
import org.springframework.security.web.session.ConcurrentSessionFilter

import com.mingidea.security.taobao.*

/**
* @author <a href='mailto:simon.r.leung@gmail.com'>Simon Leung</a>
*/
class SpringSecurityTaobaoGrailsPlugin {
    // the plugin version
    def version = "1.0.4"
    // the version or versions of Grails the plugin is designed for
    def grailsVersion = "2.1 > *"
    // the other plugins this plugin depends on
    def dependsOn = [springSecurityCore: '1.2.7.3 > *']
    // resources that are excluded from plugin packaging
    List pluginExcludes = [
        'grails-app/domain/**',
        'grails-app/controllers/**',
        'grails-app/views/**',
        'docs/**',
        'src/docs/**',
		'src/groovy/**'
    ]

    def author = "Simon Leung"
    def authorEmail = "simon.r.leung@gmail.com"
    def title = "Spring Security Taobao Plugin"
    def description = "Taobao open api authentication support for the Spring Security plugin."

	def license = "APACHE"
	def developers = [
	        [ name: "Simon Leung", email: "simon.r.leung@gmail.com" ]
		]
	def issueManagement = [ system: "bitbucket", url: "https://bitbucket.org/mingidea/grails-spring-security-taobao/issues" ]
	def scm = [ url: "https://bitbucket.org/mingidea/grails-spring-security-taobao" ]

    // URL to the plugin's documentation
    def documentation = "http://grails.org/plugin/spring-security-taobao"

    def doWithSpring = {
        def conf = SpringSecurityUtils.securityConfig
        if (!conf || !conf.active) {
            return
        }

        SpringSecurityUtils.loadSecondaryConfig 'DefaultTaobaoSecurityConfig'
        // have to get again after overlaying DefaultTaobaoSecurityConfig
        conf = SpringSecurityUtils.securityConfig

        if (!conf.taobao.active) {
            return
        }

        println 'Configuring Spring Security Taobao ...'

        SpringSecurityUtils.registerProvider 'taobaoAuthenticationProvider'
        SpringSecurityUtils.registerFilter 'taobaoAuthenticationFilter', SecurityFilterPosition.OPENID_FILTER
		SpringSecurityUtils.registerFilter 'concurrentSessionFilter', SecurityFilterPosition.CONCURRENT_SESSION_FILTER

        taobaoAuthenticationProvider(TaobaoAuthenticationProvider) {
			
            appSecretMap = conf.taobao.appSecretMap
            taobaoAuthenticationDao = ref('taobaoAuthenticationDao')
        }

        taobaoAuthenticationFilter(TaobaoAuthenticationProcessingFilter){
            authenticationManager = ref('authenticationManager')
            sessionAuthenticationStrategy = ref('sessionAuthenticationStrategy')
            
            //ref to grails spring security core plugin
            authenticationSuccessHandler = ref('authenticationSuccessHandler')
            authenticationFailureHandler = ref('authenticationFailureHandler')
            rememberMeServices = ref('rememberMeServices')
            allowSessionCreation = conf.apf.allowSessionCreation
        }
		
		sessionAuthenticationStrategy(ConcurrentSessionControlStrategy, ref('sessionRegistry')) {
			maximumSessions = conf.maxConcurrentSessions //default is -1 for unlimited sessions
		}
		
		concurrentSessionFilter(ConcurrentSessionFilter) {
			sessionRegistry = ref('sessionRegistry')
			expiredUrl = conf.expiredUrl
		}
		
		sessionRegistry(SessionRegistryImpl)
    }

    def doWithApplicationContext = { applicationContext ->
    }
}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.