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

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

/*
 * 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.token.store.JdbcTokenStore;

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 {

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

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

    @Override
    public void configure(final ClientDetailsServiceConfigurer client)
            throws Exception {
//        client.withClientDetails(this.authenticationProvider);
        client.withClientDetails(this.jdbcClientDetailsService);
//        clients.inMemory()
//                .withClient("acme")
//                .secret("acmesecret")
//                .authorizedGrantTypes("authorization_code", "refresh_token",
//                        "implicit", "password", "client_credentials")
//                .scopes("webshop").and()
//                .withClient("app")
//                .secret("secret")
//                .authorizedGrantTypes("authorization_code", "refresh_token",
//                        "implicit", "password", "client_credentials")
//                .scopes("webshop");
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy