當前位置: 首頁>>代碼示例>>Java>>正文


Java SecurityAutoConfiguration類代碼示例

本文整理匯總了Java中org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration的典型用法代碼示例。如果您正苦於以下問題:Java SecurityAutoConfiguration類的具體用法?Java SecurityAutoConfiguration怎麽用?Java SecurityAutoConfiguration使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


SecurityAutoConfiguration類屬於org.springframework.boot.autoconfigure.security包,在下文中一共展示了SecurityAutoConfiguration類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testSpringAuthenticationProviderAsDefaultConfiguration

import org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration; //導入依賴的package包/類
@Test
public void testSpringAuthenticationProviderAsDefaultConfiguration()
		throws Exception {
	this.context = new AnnotationConfigWebApplicationContext();
	this.context.setServletContext(new MockServletContext());
	this.context.register(ManagementServerPropertiesAutoConfiguration.class);
	this.context.register(SecurityAutoConfiguration.class);
	this.context.register(SecurityConfiguration.class);
	this.context.register(CrshAutoConfiguration.class);
	this.context.refresh();
	PluginLifeCycle lifeCycle = this.context.getBean(PluginLifeCycle.class);
	AuthenticationPlugin<String> authenticationPlugin = null;
	String authentication = lifeCycle.getConfig().getProperty("crash.auth");
	assertThat(authentication).isNotNull();
	for (AuthenticationPlugin plugin : lifeCycle.getContext()
			.getPlugins(AuthenticationPlugin.class)) {
		if (authentication.equals(plugin.getName())) {
			authenticationPlugin = plugin;
			break;
		}
	}
	assertThat(authenticationPlugin.authenticate(SecurityConfiguration.USERNAME,
			SecurityConfiguration.PASSWORD)).isTrue();
	assertThat(authenticationPlugin.authenticate(UUID.randomUUID().toString(),
			SecurityConfiguration.PASSWORD)).isFalse();
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:27,代碼來源:CrshAutoConfigurationTests.java

示例2: testWebConfiguration

import org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration; //導入依賴的package包/類
@Test
public void testWebConfiguration() throws Exception {
	this.context = new AnnotationConfigWebApplicationContext();
	this.context.setServletContext(new MockServletContext());
	this.context.register(SecurityAutoConfiguration.class,
			WebMvcAutoConfiguration.class,
			ManagementWebSecurityAutoConfiguration.class,
			JacksonAutoConfiguration.class,
			HttpMessageConvertersAutoConfiguration.class,
			EndpointAutoConfiguration.class, EndpointWebMvcAutoConfiguration.class,
			ManagementServerPropertiesAutoConfiguration.class,
			PropertyPlaceholderAutoConfiguration.class);
	EnvironmentTestUtils.addEnvironment(this.context, "security.basic.enabled:false");
	this.context.refresh();
	assertThat(this.context.getBean(AuthenticationManagerBuilder.class)).isNotNull();
	FilterChainProxy filterChainProxy = this.context.getBean(FilterChainProxy.class);
	// 1 for static resources, one for management endpoints and one for the rest
	assertThat(filterChainProxy.getFilterChains()).hasSize(3);
	assertThat(filterChainProxy.getFilters("/beans")).isNotEmpty();
	assertThat(filterChainProxy.getFilters("/beans/")).isNotEmpty();
	assertThat(filterChainProxy.getFilters("/beans.foo")).isNotEmpty();
	assertThat(filterChainProxy.getFilters("/beans/foo/bar")).isNotEmpty();
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:24,代碼來源:ManagementWebSecurityAutoConfigurationTests.java

示例3: testWebConfiguration

import org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration; //導入依賴的package包/類
@Test
public void testWebConfiguration() throws Exception {
	this.context = new AnnotationConfigWebApplicationContext();
	this.context.setServletContext(new MockServletContext());
	this.context.register(SecurityAutoConfiguration.class,
			WebMvcAutoConfiguration.class,
			ManagementWebSecurityAutoConfiguration.class,
			JacksonAutoConfiguration.class,
			HttpMessageConvertersAutoConfiguration.class,
			EndpointAutoConfiguration.class, EndpointWebMvcAutoConfiguration.class,
			ManagementServerPropertiesAutoConfiguration.class,
			PropertyPlaceholderAutoConfiguration.class);
	EnvironmentTestUtils.addEnvironment(this.context, "security.basic.enabled:false");
	this.context.refresh();
	assertNotNull(this.context.getBean(AuthenticationManagerBuilder.class));
	FilterChainProxy filterChainProxy = this.context.getBean(FilterChainProxy.class);
	// 4 for static resources, one for management endpoints and one for the rest
	assertThat(filterChainProxy.getFilterChains(), hasSize(6));
	assertThat(filterChainProxy.getFilters("/beans"), hasSize(greaterThan(0)));
	assertThat(filterChainProxy.getFilters("/beans/"), hasSize(greaterThan(0)));
	assertThat(filterChainProxy.getFilters("/beans.foo"), hasSize(greaterThan(0)));
	assertThat(filterChainProxy.getFilters("/beans/foo/bar"),
			hasSize(greaterThan(0)));
}
 
開發者ID:Nephilim84,項目名稱:contestparser,代碼行數:25,代碼來源:ManagementWebSecurityAutoConfigurationTests.java

示例4: configuresADefaultUser

import org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration; //導入依賴的package包/類
@Test
public void configuresADefaultUser() {
    contextRunner
            .withPropertyValues("singleuser.name=michael")
            .withConfiguration(AutoConfigurations.of(SecurityAutoConfiguration.class, SingleUserAutoConfiguration.class))
            .run(context -> {
                assertThat(context.getBean(UserDetailsService.class).loadUserByUsername("michael")).isNotNull();
                assertThat(context).getBean(ReactiveUserDetailsService.class).isNull();
            });
}
 
開發者ID:michael-simons,項目名稱:configurable-single-user-spring-boot-starter,代碼行數:11,代碼來源:UserDetailsServiceConfigurationTest.java

示例5: configuresNoDefaultUserWhenAuthenticationManagerPresent

import org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration; //導入依賴的package包/類
@Test
public void configuresNoDefaultUserWhenAuthenticationManagerPresent() {
    contextRunner
            .withUserConfiguration(AuthenticationManagerIsPresent.class)
            .withConfiguration(AutoConfigurations.of(SecurityAutoConfiguration.class, SingleUserAutoConfiguration.class))
            .run(context -> {
                assertThat(context).getBean("singleUserDetailsMananger").isNull();
            });
}
 
開發者ID:michael-simons,項目名稱:configurable-single-user-spring-boot-starter,代碼行數:10,代碼來源:UserDetailsServiceConfigurationTest.java

示例6: configuresNoDefaultUserWhenAuthenticationProviderPresent

import org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration; //導入依賴的package包/類
@Test
public void configuresNoDefaultUserWhenAuthenticationProviderPresent() {
    contextRunner
            .withUserConfiguration(AuthenticationProviderIsPresent.class)
            .withConfiguration(AutoConfigurations.of(SecurityAutoConfiguration.class, SingleUserAutoConfiguration.class))
            .run(context -> {
                assertThat(context).getBean("singleUserDetailsMananger").isNull();
            });
}
 
開發者ID:michael-simons,項目名稱:configurable-single-user-spring-boot-starter,代碼行數:10,代碼來源:UserDetailsServiceConfigurationTest.java

示例7: configuresNoDefaultUserWhenUserDetailsServicePresent

import org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration; //導入依賴的package包/類
@Test
public void configuresNoDefaultUserWhenUserDetailsServicePresent() {
    contextRunner
            .withUserConfiguration(UserDetailsServiceIsPresent.class)
            .withConfiguration(AutoConfigurations.of(SecurityAutoConfiguration.class, SingleUserAutoConfiguration.class))
            .run(context -> {
                assertThat(context).getBean("singleUserDetailsMananger").isNull();
            });
}
 
開發者ID:michael-simons,項目名稱:configurable-single-user-spring-boot-starter,代碼行數:10,代碼來源:UserDetailsServiceConfigurationTest.java

示例8: testDisableIgnoredStaticApplicationPaths

import org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration; //導入依賴的package包/類
@Test
public void testDisableIgnoredStaticApplicationPaths() throws Exception {
	this.context = new AnnotationConfigWebApplicationContext();
	this.context.setServletContext(new MockServletContext());
	this.context.register(SecurityAutoConfiguration.class,
			ManagementWebSecurityAutoConfiguration.class,
			EndpointAutoConfiguration.class,
			ManagementServerPropertiesAutoConfiguration.class,
			PropertyPlaceholderAutoConfiguration.class);
	EnvironmentTestUtils.addEnvironment(this.context, "security.ignored:none");
	this.context.refresh();
	// Just the application and management endpoints now
	assertThat(this.context.getBean(FilterChainProxy.class).getFilterChains())
			.hasSize(2);
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:16,代碼來源:ManagementWebSecurityAutoConfigurationTests.java

示例9: testOverrideAuthenticationManager

import org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration; //導入依賴的package包/類
@Test
public void testOverrideAuthenticationManager() throws Exception {
	this.context = new AnnotationConfigWebApplicationContext();
	this.context.setServletContext(new MockServletContext());
	this.context.register(TestConfiguration.class, SecurityAutoConfiguration.class,
			ManagementWebSecurityAutoConfiguration.class,
			EndpointAutoConfiguration.class,
			ManagementServerPropertiesAutoConfiguration.class,
			PropertyPlaceholderAutoConfiguration.class);
	this.context.refresh();
	assertThat(this.context.getBean(AuthenticationManager.class)).isEqualTo(
			this.context.getBean(TestConfiguration.class).authenticationManager);
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:14,代碼來源:ManagementWebSecurityAutoConfigurationTests.java

示例10: testSecurityPropertiesNotAvailable

import org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration; //導入依賴的package包/類
@Test
public void testSecurityPropertiesNotAvailable() throws Exception {
	this.context = new AnnotationConfigWebApplicationContext();
	this.context.setServletContext(new MockServletContext());
	this.context.register(TestConfiguration.class, SecurityAutoConfiguration.class,
			ManagementWebSecurityAutoConfiguration.class,
			EndpointAutoConfiguration.class,
			ManagementServerPropertiesAutoConfiguration.class,
			PropertyPlaceholderAutoConfiguration.class);
	this.context.refresh();
	assertThat(this.context.getBean(AuthenticationManager.class)).isEqualTo(
			this.context.getBean(TestConfiguration.class).authenticationManager);
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:14,代碼來源:ManagementWebSecurityAutoConfigurationTests.java

示例11: realmSameForManagement

import org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration; //導入依賴的package包/類
@Test
public void realmSameForManagement() throws Exception {
	this.context = new AnnotationConfigWebApplicationContext();
	this.context.setServletContext(new MockServletContext());
	this.context.register(AuthenticationConfig.class, SecurityAutoConfiguration.class,
			ManagementWebSecurityAutoConfiguration.class,
			JacksonAutoConfiguration.class,
			HttpMessageConvertersAutoConfiguration.class,
			EndpointAutoConfiguration.class, EndpointWebMvcAutoConfiguration.class,
			ManagementServerPropertiesAutoConfiguration.class,
			WebMvcAutoConfiguration.class,
			PropertyPlaceholderAutoConfiguration.class);
	this.context.refresh();

	Filter filter = this.context.getBean("springSecurityFilterChain", Filter.class);
	MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
			.addFilters(filter).build();

	// no user (Main)
	mockMvc.perform(MockMvcRequestBuilders.get("/home"))
			.andExpect(MockMvcResultMatchers.status().isUnauthorized())
			.andExpect(springAuthenticateRealmHeader());

	// invalid user (Main)
	mockMvc.perform(
			MockMvcRequestBuilders.get("/home").header("authorization", "Basic xxx"))
			.andExpect(MockMvcResultMatchers.status().isUnauthorized())
			.andExpect(springAuthenticateRealmHeader());

	// no user (Management)
	mockMvc.perform(MockMvcRequestBuilders.get("/beans"))
			.andExpect(MockMvcResultMatchers.status().isUnauthorized())
			.andExpect(springAuthenticateRealmHeader());

	// invalid user (Management)
	mockMvc.perform(
			MockMvcRequestBuilders.get("/beans").header("authorization", "Basic xxx"))
			.andExpect(MockMvcResultMatchers.status().isUnauthorized())
			.andExpect(springAuthenticateRealmHeader());
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:41,代碼來源:ManagementWebSecurityAutoConfigurationTests.java

示例12: load

import org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration; //導入依賴的package包/類
private void load() {
	this.context = new AnnotationConfigEmbeddedWebApplicationContext();
	EnvironmentTestUtils.addEnvironment(this.context,
			"spring.session.store-type=hash-map");
	this.context.register(MockEmbeddedServletContainerConfiguration.class,
			TestRedisConfiguration.class, WebMvcAutoConfiguration.class,
			ServerPropertiesAutoConfiguration.class, SecurityAutoConfiguration.class,
			SessionAutoConfiguration.class,
			HttpMessageConvertersAutoConfiguration.class,
			PropertyPlaceholderAutoConfiguration.class,
			HttpEncodingAutoConfiguration.class);
	this.context.refresh();
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:14,代碼來源:FilterOrderingIntegrationTests.java

示例13: setup

import org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration; //導入依賴的package包/類
@Before
public void setup() {
	context = new AnnotationConfigApplicationContext();
	context.setId("testDataFlowConfig");
	context.register(DataFlowServerConfigurationTests.TestConfiguration.class, RedisAutoConfiguration.class,
			SecurityAutoConfiguration.class, DataFlowServerAutoConfiguration.class,
			DataFlowControllerAutoConfiguration.class, DataSourceAutoConfiguration.class,
			DataFlowServerConfiguration.class, PropertyPlaceholderAutoConfiguration.class,
			WebClientAutoConfiguration.class, HibernateJpaAutoConfiguration.class, WebConfiguration.class);
	environment = new StandardEnvironment();
	propertySources = environment.getPropertySources();
}
 
開發者ID:spring-cloud,項目名稱:spring-cloud-dataflow,代碼行數:13,代碼來源:DataFlowServerConfigurationTests.java

示例14: testSpringAuthenticationProviderAsDefaultConfiguration

import org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration; //導入依賴的package包/類
@Test
public void testSpringAuthenticationProviderAsDefaultConfiguration()
		throws Exception {
	this.context = new AnnotationConfigWebApplicationContext();
	this.context.setServletContext(new MockServletContext());
	this.context.register(ManagementServerPropertiesAutoConfiguration.class);
	this.context.register(SecurityAutoConfiguration.class);
	this.context.register(SecurityConfiguration.class);
	this.context.register(CrshAutoConfiguration.class);
	this.context.refresh();

	PluginLifeCycle lifeCycle = this.context.getBean(PluginLifeCycle.class);

	AuthenticationPlugin<String> authenticationPlugin = null;
	String authentication = lifeCycle.getConfig().getProperty("crash.auth");
	assertNotNull(authentication);
	for (AuthenticationPlugin plugin : lifeCycle.getContext()
			.getPlugins(AuthenticationPlugin.class)) {
		if (authentication.equals(plugin.getName())) {
			authenticationPlugin = plugin;
			break;
		}
	}
	assertTrue(authenticationPlugin.authenticate(SecurityConfiguration.USERNAME,
			SecurityConfiguration.PASSWORD));

	assertFalse(authenticationPlugin.authenticate(UUID.randomUUID().toString(),
			SecurityConfiguration.PASSWORD));
}
 
開發者ID:Nephilim84,項目名稱:contestparser,代碼行數:30,代碼來源:CrshAutoConfigurationTests.java

示例15: testDisableIgnoredStaticApplicationPaths

import org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration; //導入依賴的package包/類
@Test
public void testDisableIgnoredStaticApplicationPaths() throws Exception {
	this.context = new AnnotationConfigWebApplicationContext();
	this.context.setServletContext(new MockServletContext());
	this.context.register(SecurityAutoConfiguration.class,
			ManagementWebSecurityAutoConfiguration.class,
			EndpointAutoConfiguration.class,
			ManagementServerPropertiesAutoConfiguration.class,
			PropertyPlaceholderAutoConfiguration.class);
	EnvironmentTestUtils.addEnvironment(this.context, "security.ignored:none");
	this.context.refresh();
	// Just the application and management endpoints now
	assertEquals(2,
			this.context.getBean(FilterChainProxy.class).getFilterChains().size());
}
 
開發者ID:Nephilim84,項目名稱:contestparser,代碼行數:16,代碼來源:ManagementWebSecurityAutoConfigurationTests.java


注:本文中的org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。