All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.springframework.security.config.annotation.web.oauth2.login.UserInfoEndpointDsl.kt Maven / Gradle / Ivy

/*
 * Copyright 2002-2022 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
 *
 *      https://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.
 */

package org.springframework.security.config.annotation.web.oauth2.login

import org.springframework.security.config.annotation.web.builders.HttpSecurity
import org.springframework.security.config.annotation.web.configurers.oauth2.client.OAuth2LoginConfigurer
import org.springframework.security.core.authority.mapping.GrantedAuthoritiesMapper
import org.springframework.security.oauth2.client.oidc.userinfo.OidcUserRequest
import org.springframework.security.oauth2.client.userinfo.OAuth2UserRequest
import org.springframework.security.oauth2.client.userinfo.OAuth2UserService
import org.springframework.security.oauth2.core.oidc.user.OidcUser
import org.springframework.security.oauth2.core.user.OAuth2User

/**
 * A Kotlin DSL to configure the Authorization Server's UserInfo Endpoint using
 * idiomatic Kotlin code.
 *
 * @author Eleftheria Stein
 * @since 5.3
 * @property userService the OAuth 2.0 service used for obtaining the user attributes of the End-User
 * from the UserInfo Endpoint.
 * @property oidcUserService the OpenID Connect 1.0 service used for obtaining the user attributes of the
 * End-User from the UserInfo Endpoint.
 * @property userAuthoritiesMapper the [GrantedAuthoritiesMapper] used for mapping [OAuth2User.getAuthorities]
 */
@OAuth2LoginSecurityMarker
class UserInfoEndpointDsl {
    var userService: OAuth2UserService? = null
    var oidcUserService: OAuth2UserService? = null
    var userAuthoritiesMapper: GrantedAuthoritiesMapper? = null

    internal fun get(): (OAuth2LoginConfigurer.UserInfoEndpointConfig) -> Unit {
        return { userInfoEndpoint ->
            userService?.also { userInfoEndpoint.userService(userService) }
            oidcUserService?.also { userInfoEndpoint.oidcUserService(oidcUserService) }
            userAuthoritiesMapper?.also { userInfoEndpoint.userAuthoritiesMapper(userAuthoritiesMapper) }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy