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

com.formkiq.server.config.OAuth2ServerConfig Maven / Gradle / Ivy

There is a newer version: 0.6.1
Show newest version
/*
 * Copyright (C) 2016 FormKiQ Inc.
 *
 * 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.
 */

package com.formkiq.server.config;

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer;
import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer;
import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer;
import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerSecurityConfigurer;
import org.springframework.security.oauth2.provider.client.JdbcClientDetailsService;
import org.springframework.security.oauth2.provider.code.JdbcAuthorizationCodeServices;

import com.formkiq.server.service.OAuthUserDetailsService;

/**
 * OAuth2ServerConfig.
 *
 */
@Configuration
@EnableAuthorizationServer
public class OAuth2ServerConfig extends AuthorizationServerConfigurerAdapter {

    /** AuthenticationManager. */
    @Autowired
    private AuthenticationManager authenticationManager;

    /** OAuthUserDetailsService. */
    @Autowired
    private OAuthUserDetailsService oauthUserDetailsService;

    /** DataSource. */
    @Autowired
    private DataSource dataSource;

    /** PasswordEncoder. */
    @Autowired
    private PasswordEncoder passwordEncoder;

    /** JdbcClientDetailsService. */
    @Autowired
    private JdbcClientDetailsService jdbcClientDetailsService;

    @Override
    public void configure(final AuthorizationServerSecurityConfigurer security)
            throws Exception {
        security.passwordEncoder(this.passwordEncoder);
    }

    @Override
    public void configure(
            final AuthorizationServerEndpointsConfigurer endpoints)
            throws Exception {

        RaceConditionFixedJdbcTokenStore tokenStore
            = new RaceConditionFixedJdbcTokenStore(this.dataSource);
        endpoints.tokenStore(tokenStore);

        endpoints.authenticationManager(this.authenticationManager);
        endpoints.userDetailsService(this.oauthUserDetailsService);

        JdbcAuthorizationCodeServices authorizationCodeService
            = new JdbcAuthorizationCodeServices(this.dataSource);
        endpoints.authorizationCodeServices(authorizationCodeService);
    }

    @Override
    public void configure(final ClientDetailsServiceConfigurer client)
            throws Exception {
        client.withClientDetails(this.jdbcClientDetailsService);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy