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

com.healthy.security.server.HealthyResourceServerConfig Maven / Gradle / Ivy

There is a newer version: 1.3.7
Show newest version
package com.healthy.security.server;

import com.healthy.common.security.authentication.FormAuthenticationConfig;
import com.healthy.common.security.authentication.mobile.SmsCodeAuthenticationSecurityConfig;
import com.healthy.common.security.authorize.AuthorizeConfigManager;
import com.healthy.common.security.code.ValidateCodeSecurityConfig;
import com.healthy.security.app.authentication.openid.OpenIdAuthenticationSecurityConfig;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.oauth2.client.OAuth2ClientContext;
import org.springframework.security.oauth2.client.OAuth2RestTemplate;
import org.springframework.security.oauth2.client.resource.OAuth2ProtectedResourceDetails;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;
import org.springframework.security.oauth2.config.annotation.web.configurers.ResourceServerSecurityConfigurer;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.social.security.SpringSocialConfigurer;

import javax.annotation.Resource;

/**
 * HealthyResourceServerConfig
 *
 * @author xiaomingzhang
 */
@Configuration
@EnableResourceServer
public class HealthyResourceServerConfig extends ResourceServerConfigurerAdapter {

	@Resource
	private SmsCodeAuthenticationSecurityConfig smsCodeAuthenticationSecurityConfig;

	@Resource
	private OpenIdAuthenticationSecurityConfig openIdAuthenticationSecurityConfig;

	@Resource
	private ValidateCodeSecurityConfig validateCodeSecurityConfig;

	@Resource
	private SpringSocialConfigurer healthySocialSecurityConfig;

	@Resource
	private AuthorizeConfigManager authorizeConfigManager;

	@Resource
	private FormAuthenticationConfig formAuthenticationConfig;

	@Resource
	private AccessDeniedHandler accessDeniedHandler;

	@Resource
	private AuthenticationEntryPoint authenticationEntryPoint;

	@Bean
	@ConditionalOnProperty(prefix = "security.oauth2.client", name = "client-id")
	public OAuth2RestTemplate oauth2RestTemplate(OAuth2ProtectedResourceDetails resource,
			@Qualifier("oauth2ClientContext") OAuth2ClientContext context) {
		return new OAuth2RestTemplate(resource, context);
	}

	@Override
	public void configure(ResourceServerSecurityConfigurer resources) {
		resources.accessDeniedHandler(accessDeniedHandler).authenticationEntryPoint(authenticationEntryPoint);
	}

	@Override
	public void configure(HttpSecurity http) throws Exception {
		formAuthenticationConfig.configure(http);

		http.apply(validateCodeSecurityConfig).and().apply(smsCodeAuthenticationSecurityConfig).and()
				.apply(healthySocialSecurityConfig).and().apply(openIdAuthenticationSecurityConfig).and().csrf()
				.disable();

		authorizeConfigManager.config(http.authorizeRequests());
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy