应该为外部 class 指定类型参数

Type arguments should be specified for an outer class

I am implementing oauth2 security in my application through create an config class but I don't know where I make mistake I get following type of compile time error

Type arguments should be specified for an outer class 'ExpressionUrlAuthorizationConfigurer'. Use full class name to specify them

SecurityConfig.kt

package com.main.serviceproduct.config

import org.springframework.context.annotation.Configuration
import org.springframework.security.config.Customizer
import org.springframework.security.config.annotation.web.builders.HttpSecurity
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter
import org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer.ExpressionInterceptUrlRegistry
import org.springframework.security.config.annotation.web.configurers.oauth2.server.resource.OAuth2ResourceServerConfigurer

@Configuration
@EnableWebSecurity
class SecurityConfig : WebSecurityConfigurerAdapter() {
    @Throws(Exception::class)
    override fun configure(security: HttpSecurity){
        security.authorizeRequests(Customizer { authorize: ExpressionInterceptUrlRegistry ->
            authorize.anyRequest().authenticated()
        })
            .oauth2ResourceServer{obj: OAuth2ResourceServerConfigurer<HttpSecurity?>->obj.jwt()}
    }

}

security.authorizeRequests(Customizer { authorize: ExpressionInterceptUrlRegistry ->
            authorize.anyRequest().authenticated()

I got error on above line at this point authorize: ExpressionInterceptUrlRegistry

因为ExpressionInterceptUrlRegistry是一个内部(非静态)class所以它需要外部classExpressionUrlAuthorizationConfigurer<T>的类型信息,这实际上是一个HttpSecurity.

下面应该有效:

@Configuration
@EnableWebSecurity
open class SecurityConfig : WebSecurityConfigurerAdapter() {
    @Throws(Exception::class)
    override fun configure(security: HttpSecurity){
        security.authorizeRequests(Customizer { authorize: ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry ->
            authorize.anyRequest().authenticated()
        })
            .oauth2ResourceServer{obj: OAuth2ResourceServerConfigurer<HttpSecurity?> ->obj.jwt()}
    }

}