Java 类org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration 实例源码

项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:EndpointWebMvcAutoConfiguration.java   
public static ManagementServerPort get(Environment environment,
        BeanFactory beanFactory) {
    Integer serverPort = getPortProperty(environment, "server.");
    if (serverPort == null && hasCustomBeanDefinition(beanFactory,
            ServerProperties.class, ServerPropertiesAutoConfiguration.class)) {
        serverPort = getTemporaryBean(beanFactory, ServerProperties.class)
                .getPort();
    }
    Integer managementPort = getPortProperty(environment, "management.");
    if (managementPort == null && hasCustomBeanDefinition(beanFactory,
            ManagementServerProperties.class,
            ManagementServerPropertiesAutoConfiguration.class)) {
        managementPort = getTemporaryBean(beanFactory,
                ManagementServerProperties.class).getPort();
    }
    if (managementPort != null && managementPort < 0) {
        return DISABLE;
    }
    return ((managementPort == null)
            || (serverPort == null && managementPort.equals(8080))
            || (managementPort != 0 && managementPort.equals(serverPort)) ? SAME
                    : DIFFERENT);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:EndpointWebMvcAutoConfigurationTests.java   
@Test
public void contextPath() throws Exception {
    EnvironmentTestUtils.addEnvironment(this.applicationContext,
            "management.contextPath:/test");
    this.applicationContext.register(RootConfig.class, EndpointConfig.class,
            ServerPortConfig.class, PropertyPlaceholderAutoConfiguration.class,
            ManagementServerPropertiesAutoConfiguration.class,
            ServerPropertiesAutoConfiguration.class, JacksonAutoConfiguration.class,
            EmbeddedServletContainerAutoConfiguration.class,
            HttpMessageConvertersAutoConfiguration.class,
            DispatcherServletAutoConfiguration.class, WebMvcAutoConfiguration.class,
            EndpointWebMvcAutoConfiguration.class);
    this.applicationContext.refresh();
    assertContent("/controller", ports.get().server, "controlleroutput");
    assertContent("/test/endpoint", ports.get().server, "endpointoutput");
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:EndpointWebMvcAutoConfigurationTests.java   
@Test
public void overrideServerProperties() throws Exception {
    EnvironmentTestUtils.addEnvironment(this.applicationContext,
            "server.displayName:foo");
    this.applicationContext.register(RootConfig.class, EndpointConfig.class,
            ServerPortConfig.class, PropertyPlaceholderAutoConfiguration.class,
            ManagementServerPropertiesAutoConfiguration.class,
            ServerPropertiesAutoConfiguration.class, JacksonAutoConfiguration.class,
            EmbeddedServletContainerAutoConfiguration.class,
            HttpMessageConvertersAutoConfiguration.class,
            DispatcherServletAutoConfiguration.class, WebMvcAutoConfiguration.class,
            EndpointWebMvcAutoConfiguration.class);
    this.applicationContext.refresh();
    assertContent("/controller", ports.get().server, "controlleroutput");
    ServerProperties serverProperties = this.applicationContext
            .getBean(ServerProperties.class);
    assertThat(serverProperties.getDisplayName()).isEqualTo("foo");
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:SecurityAutoConfigurationTests.java   
@Test
public void testOverrideAuthenticationManagerWithBuilderAndInjectIntoSecurityFilter()
        throws Exception {
    this.context = new AnnotationConfigWebApplicationContext();
    this.context.setServletContext(new MockServletContext());
    this.context.register(AuthenticationManagerCustomizer.class,
            SecurityCustomizer.class, SecurityAutoConfiguration.class,
            ServerPropertiesAutoConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class);
    this.context.refresh();
    UsernamePasswordAuthenticationToken user = new UsernamePasswordAuthenticationToken(
            "foo", "bar",
            AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_USER"));
    assertThat(this.context.getBean(AuthenticationManager.class).authenticate(user))
            .isNotNull();
    pingAuthenticationListener();
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:SecurityAutoConfigurationTests.java   
@Test
public void testOverrideAuthenticationManagerWithBuilderAndInjectBuilderIntoSecurityFilter()
        throws Exception {
    this.context = new AnnotationConfigWebApplicationContext();
    this.context.setServletContext(new MockServletContext());
    this.context.register(AuthenticationManagerCustomizer.class,
            WorkaroundSecurityCustomizer.class, SecurityAutoConfiguration.class,
            ServerPropertiesAutoConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class);
    this.context.refresh();
    UsernamePasswordAuthenticationToken user = new UsernamePasswordAuthenticationToken(
            "foo", "bar",
            AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_USER"));
    assertThat(this.context.getBean(AuthenticationManager.class).authenticate(user))
            .isNotNull();
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:SecurityAutoConfigurationTests.java   
@Test
public void testJpaCoexistsHappily() throws Exception {
    this.context = new AnnotationConfigWebApplicationContext();
    this.context.setServletContext(new MockServletContext());
    EnvironmentTestUtils.addEnvironment(this.context,
            "spring.datasource.url:jdbc:hsqldb:mem:testsecdb");
    EnvironmentTestUtils.addEnvironment(this.context,
            "spring.datasource.initialize:false");
    this.context.register(EntityConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class,
            DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class,
            SecurityAutoConfiguration.class, ServerPropertiesAutoConfiguration.class);
    // This can fail if security @Conditionals force early instantiation of the
    // HibernateJpaAutoConfiguration (e.g. the EntityManagerFactory is not found)
    this.context.refresh();
    assertThat(this.context.getBean(JpaTransactionManager.class)).isNotNull();
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:SecurityAutoConfigurationTests.java   
@Test
public void testDefaultUsernamePassword() throws Exception {
    this.context = new AnnotationConfigWebApplicationContext();
    this.context.setServletContext(new MockServletContext());

    this.context.register(SecurityAutoConfiguration.class,
            ServerPropertiesAutoConfiguration.class);
    this.context.refresh();

    SecurityProperties security = this.context.getBean(SecurityProperties.class);
    AuthenticationManager manager = this.context.getBean(AuthenticationManager.class);

    UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(
            security.getUser().getName(), security.getUser().getPassword());
    assertThat(manager.authenticate(token)).isNotNull();
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:SecurityAutoConfigurationTests.java   
@Test
public void testCustomAuthenticationDoesNotAuthenticateWithBootSecurityUser()
        throws Exception {
    this.context = new AnnotationConfigWebApplicationContext();
    this.context.setServletContext(new MockServletContext());

    this.context.register(AuthenticationManagerCustomizer.class,
            SecurityAutoConfiguration.class, ServerPropertiesAutoConfiguration.class);
    this.context.refresh();

    SecurityProperties security = this.context.getBean(SecurityProperties.class);
    AuthenticationManager manager = this.context.getBean(AuthenticationManager.class);

    UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(
            security.getUser().getName(), security.getUser().getPassword());
    try {
        manager.authenticate(token);
        fail("Expected Exception");
    }
    catch (AuthenticationException success) {
        // Expected
    }

    token = new UsernamePasswordAuthenticationToken("foo", "bar");
    assertThat(manager.authenticate(token)).isNotNull();
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:SecurityAutoConfigurationTests.java   
@Test
public void defaultFilterDispatcherTypes() {
    this.context = new AnnotationConfigWebApplicationContext();
    this.context.setServletContext(new MockServletContext());
    this.context.register(SecurityAutoConfiguration.class,
            SecurityFilterAutoConfiguration.class,
            ServerPropertiesAutoConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class);
    this.context.refresh();
    DelegatingFilterProxyRegistrationBean bean = this.context.getBean(
            "securityFilterChainRegistration",
            DelegatingFilterProxyRegistrationBean.class);
    @SuppressWarnings("unchecked")
    EnumSet<DispatcherType> dispatcherTypes = (EnumSet<DispatcherType>) ReflectionTestUtils
            .getField(bean, "dispatcherTypes");
    assertThat(dispatcherTypes).isNull();
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:SecurityAutoConfigurationTests.java   
@Test
public void customFilterDispatcherTypes() {
    this.context = new AnnotationConfigWebApplicationContext();
    this.context.setServletContext(new MockServletContext());
    this.context.register(SecurityAutoConfiguration.class,
            SecurityFilterAutoConfiguration.class,
            ServerPropertiesAutoConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class);
    EnvironmentTestUtils.addEnvironment(this.context,
            "security.filter-dispatcher-types:INCLUDE,ERROR");
    this.context.refresh();
    DelegatingFilterProxyRegistrationBean bean = this.context.getBean(
            "securityFilterChainRegistration",
            DelegatingFilterProxyRegistrationBean.class);
    @SuppressWarnings("unchecked")
    EnumSet<DispatcherType> dispatcherTypes = (EnumSet<DispatcherType>) ReflectionTestUtils
            .getField(bean, "dispatcherTypes");
    assertThat(dispatcherTypes).containsOnly(DispatcherType.INCLUDE,
            DispatcherType.ERROR);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:SpringApplicationAdminJmxAutoConfigurationTests.java   
@Test
public void registerWithSimpleWebApp() throws Exception {
    this.context = new SpringApplicationBuilder()
            .sources(EmbeddedServletContainerAutoConfiguration.class,
                    ServerPropertiesAutoConfiguration.class,
                    DispatcherServletAutoConfiguration.class,
                    JmxAutoConfiguration.class,
                    SpringApplicationAdminJmxAutoConfiguration.class)
            .run("--" + ENABLE_ADMIN_PROP, "--server.port=0");
    assertThat(this.context).isInstanceOf(EmbeddedWebApplicationContext.class);
    assertThat(this.mBeanServer.getAttribute(createDefaultObjectName(),
            "EmbeddedWebApplication")).isEqualTo(Boolean.TRUE);
    int expected = ((EmbeddedWebApplicationContext) this.context)
            .getEmbeddedServletContainer().getPort();
    String actual = getProperty(createDefaultObjectName(), "local.server.port");
    assertThat(actual).isEqualTo(String.valueOf(expected));
}
项目:spring-boot-concourse    文件:EndpointWebMvcAutoConfiguration.java   
public static ManagementServerPort get(Environment environment,
        BeanFactory beanFactory) {
    Integer serverPort = getPortProperty(environment, "server.");
    if (serverPort == null && hasCustomBeanDefinition(beanFactory,
            ServerProperties.class, ServerPropertiesAutoConfiguration.class)) {
        serverPort = getTemporaryBean(beanFactory, ServerProperties.class)
                .getPort();
    }
    Integer managementPort = getPortProperty(environment, "management.");
    if (managementPort == null && hasCustomBeanDefinition(beanFactory,
            ManagementServerProperties.class,
            ManagementServerPropertiesAutoConfiguration.class)) {
        managementPort = getTemporaryBean(beanFactory,
                ManagementServerProperties.class).getPort();
    }
    if (managementPort != null && managementPort < 0) {
        return DISABLE;
    }
    return ((managementPort == null)
            || (serverPort == null && managementPort.equals(8080))
            || (managementPort != 0 && managementPort.equals(serverPort)) ? SAME
                    : DIFFERENT);
}
项目:spring-boot-concourse    文件:EndpointWebMvcAutoConfigurationTests.java   
@Test
public void contextPath() throws Exception {
    EnvironmentTestUtils.addEnvironment(this.applicationContext,
            "management.contextPath:/test");
    this.applicationContext.register(RootConfig.class, EndpointConfig.class,
            ServerPortConfig.class, PropertyPlaceholderAutoConfiguration.class,
            ManagementServerPropertiesAutoConfiguration.class,
            ServerPropertiesAutoConfiguration.class, JacksonAutoConfiguration.class,
            EmbeddedServletContainerAutoConfiguration.class,
            HttpMessageConvertersAutoConfiguration.class,
            DispatcherServletAutoConfiguration.class, WebMvcAutoConfiguration.class,
            EndpointWebMvcAutoConfiguration.class);
    this.applicationContext.refresh();
    assertContent("/controller", ports.get().server, "controlleroutput");
    assertContent("/test/endpoint", ports.get().server, "endpointoutput");
}
项目:spring-boot-concourse    文件:EndpointWebMvcAutoConfigurationTests.java   
@Test
public void overrideServerProperties() throws Exception {
    EnvironmentTestUtils.addEnvironment(this.applicationContext,
            "server.displayName:foo");
    this.applicationContext.register(RootConfig.class, EndpointConfig.class,
            ServerPortConfig.class, PropertyPlaceholderAutoConfiguration.class,
            ManagementServerPropertiesAutoConfiguration.class,
            ServerPropertiesAutoConfiguration.class, JacksonAutoConfiguration.class,
            EmbeddedServletContainerAutoConfiguration.class,
            HttpMessageConvertersAutoConfiguration.class,
            DispatcherServletAutoConfiguration.class, WebMvcAutoConfiguration.class,
            EndpointWebMvcAutoConfiguration.class);
    this.applicationContext.refresh();
    assertContent("/controller", ports.get().server, "controlleroutput");
    ServerProperties serverProperties = this.applicationContext
            .getBean(ServerProperties.class);
    assertThat(serverProperties.getDisplayName()).isEqualTo("foo");
}
项目:spring-boot-concourse    文件:SecurityAutoConfigurationTests.java   
@Test
public void testOverrideAuthenticationManagerWithBuilderAndInjectIntoSecurityFilter()
        throws Exception {
    this.context = new AnnotationConfigWebApplicationContext();
    this.context.setServletContext(new MockServletContext());
    this.context.register(AuthenticationManagerCustomizer.class,
            SecurityCustomizer.class, SecurityAutoConfiguration.class,
            ServerPropertiesAutoConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class);
    this.context.refresh();
    UsernamePasswordAuthenticationToken user = new UsernamePasswordAuthenticationToken(
            "foo", "bar",
            AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_USER"));
    assertThat(this.context.getBean(AuthenticationManager.class).authenticate(user))
            .isNotNull();
    pingAuthenticationListener();
}
项目:spring-boot-concourse    文件:SecurityAutoConfigurationTests.java   
@Test
public void testOverrideAuthenticationManagerWithBuilderAndInjectBuilderIntoSecurityFilter()
        throws Exception {
    this.context = new AnnotationConfigWebApplicationContext();
    this.context.setServletContext(new MockServletContext());
    this.context.register(AuthenticationManagerCustomizer.class,
            WorkaroundSecurityCustomizer.class, SecurityAutoConfiguration.class,
            ServerPropertiesAutoConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class);
    this.context.refresh();
    UsernamePasswordAuthenticationToken user = new UsernamePasswordAuthenticationToken(
            "foo", "bar",
            AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_USER"));
    assertThat(this.context.getBean(AuthenticationManager.class).authenticate(user))
            .isNotNull();
}
项目:spring-boot-concourse    文件:SecurityAutoConfigurationTests.java   
@Test
public void testJpaCoexistsHappily() throws Exception {
    this.context = new AnnotationConfigWebApplicationContext();
    this.context.setServletContext(new MockServletContext());
    EnvironmentTestUtils.addEnvironment(this.context,
            "spring.datasource.url:jdbc:hsqldb:mem:testsecdb");
    EnvironmentTestUtils.addEnvironment(this.context,
            "spring.datasource.initialize:false");
    this.context.register(EntityConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class,
            DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class,
            SecurityAutoConfiguration.class, ServerPropertiesAutoConfiguration.class);
    // This can fail if security @Conditionals force early instantiation of the
    // HibernateJpaAutoConfiguration (e.g. the EntityManagerFactory is not found)
    this.context.refresh();
    assertThat(this.context.getBean(JpaTransactionManager.class)).isNotNull();
}
项目:spring-boot-concourse    文件:SecurityAutoConfigurationTests.java   
@Test
public void testDefaultUsernamePassword() throws Exception {
    this.context = new AnnotationConfigWebApplicationContext();
    this.context.setServletContext(new MockServletContext());

    this.context.register(SecurityAutoConfiguration.class,
            ServerPropertiesAutoConfiguration.class);
    this.context.refresh();

    SecurityProperties security = this.context.getBean(SecurityProperties.class);
    AuthenticationManager manager = this.context.getBean(AuthenticationManager.class);

    UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(
            security.getUser().getName(), security.getUser().getPassword());
    assertThat(manager.authenticate(token)).isNotNull();
}
项目:spring-boot-concourse    文件:SecurityAutoConfigurationTests.java   
@Test
public void testCustomAuthenticationDoesNotAuthenticateWithBootSecurityUser()
        throws Exception {
    this.context = new AnnotationConfigWebApplicationContext();
    this.context.setServletContext(new MockServletContext());

    this.context.register(AuthenticationManagerCustomizer.class,
            SecurityAutoConfiguration.class, ServerPropertiesAutoConfiguration.class);
    this.context.refresh();

    SecurityProperties security = this.context.getBean(SecurityProperties.class);
    AuthenticationManager manager = this.context.getBean(AuthenticationManager.class);

    UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(
            security.getUser().getName(), security.getUser().getPassword());
    try {
        manager.authenticate(token);
        fail("Expected Exception");
    }
    catch (AuthenticationException success) {
        // Expected
    }

    token = new UsernamePasswordAuthenticationToken("foo", "bar");
    assertThat(manager.authenticate(token)).isNotNull();
}
项目:spring-boot-concourse    文件:SecurityAutoConfigurationTests.java   
@Test
public void defaultFilterDispatcherTypes() {
    this.context = new AnnotationConfigWebApplicationContext();
    this.context.setServletContext(new MockServletContext());
    this.context.register(SecurityAutoConfiguration.class,
            SecurityFilterAutoConfiguration.class,
            ServerPropertiesAutoConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class);
    this.context.refresh();
    DelegatingFilterProxyRegistrationBean bean = this.context.getBean(
            "securityFilterChainRegistration",
            DelegatingFilterProxyRegistrationBean.class);
    @SuppressWarnings("unchecked")
    EnumSet<DispatcherType> dispatcherTypes = (EnumSet<DispatcherType>) ReflectionTestUtils
            .getField(bean, "dispatcherTypes");
    assertThat(dispatcherTypes).isNull();
}
项目:spring-boot-concourse    文件:SecurityAutoConfigurationTests.java   
@Test
public void customFilterDispatcherTypes() {
    this.context = new AnnotationConfigWebApplicationContext();
    this.context.setServletContext(new MockServletContext());
    this.context.register(SecurityAutoConfiguration.class,
            SecurityFilterAutoConfiguration.class,
            ServerPropertiesAutoConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class);
    EnvironmentTestUtils.addEnvironment(this.context,
            "security.filter-dispatcher-types:INCLUDE,ERROR");
    this.context.refresh();
    DelegatingFilterProxyRegistrationBean bean = this.context.getBean(
            "securityFilterChainRegistration",
            DelegatingFilterProxyRegistrationBean.class);
    @SuppressWarnings("unchecked")
    EnumSet<DispatcherType> dispatcherTypes = (EnumSet<DispatcherType>) ReflectionTestUtils
            .getField(bean, "dispatcherTypes");
    assertThat(dispatcherTypes).containsOnly(DispatcherType.INCLUDE,
            DispatcherType.ERROR);
}
项目:spring-boot-concourse    文件:SpringApplicationAdminJmxAutoConfigurationTests.java   
@Test
public void registerWithSimpleWebApp() throws Exception {
    this.context = new SpringApplicationBuilder()
            .sources(EmbeddedServletContainerAutoConfiguration.class,
                    ServerPropertiesAutoConfiguration.class,
                    DispatcherServletAutoConfiguration.class,
                    JmxAutoConfiguration.class,
                    SpringApplicationAdminJmxAutoConfiguration.class)
            .run("--" + ENABLE_ADMIN_PROP, "--server.port=0");
    assertThat(this.context).isInstanceOf(EmbeddedWebApplicationContext.class);
    assertThat(this.mBeanServer.getAttribute(createDefaultObjectName(),
            "EmbeddedWebApplication")).isEqualTo(Boolean.TRUE);
    int expected = ((EmbeddedWebApplicationContext) this.context)
            .getEmbeddedServletContainer().getPort();
    String actual = getProperty(createDefaultObjectName(), "local.server.port");
    assertThat(actual).isEqualTo(String.valueOf(expected));
}
项目:contestparser    文件:EndpointWebMvcAutoConfigurationTests.java   
@Test
public void contextPath() throws Exception {
    EnvironmentTestUtils.addEnvironment(this.applicationContext,
            "management.contextPath:/test");
    this.applicationContext.register(RootConfig.class, EndpointConfig.class,
            ServerPortConfig.class, PropertyPlaceholderAutoConfiguration.class,
            ManagementServerPropertiesAutoConfiguration.class,
            ServerPropertiesAutoConfiguration.class, JacksonAutoConfiguration.class,
            EmbeddedServletContainerAutoConfiguration.class,
            HttpMessageConvertersAutoConfiguration.class,
            DispatcherServletAutoConfiguration.class, WebMvcAutoConfiguration.class,
            EndpointWebMvcAutoConfiguration.class);
    this.applicationContext.refresh();
    assertContent("/controller", ports.get().server, "controlleroutput");
    assertContent("/test/endpoint", ports.get().server, "endpointoutput");
    this.applicationContext.close();
    assertAllClosed();
}
项目:contestparser    文件:SecurityAutoConfigurationTests.java   
@Test
public void testOverrideAuthenticationManagerWithBuilderAndInjectIntoSecurityFilter()
        throws Exception {
    this.context = new AnnotationConfigWebApplicationContext();
    this.context.setServletContext(new MockServletContext());
    this.context.register(AuthenticationManagerCustomizer.class,
            SecurityCustomizer.class, SecurityAutoConfiguration.class,
            ServerPropertiesAutoConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class);
    this.context.refresh();
    UsernamePasswordAuthenticationToken user = new UsernamePasswordAuthenticationToken(
            "foo", "bar",
            AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_USER"));
    assertNotNull(
            this.context.getBean(AuthenticationManager.class).authenticate(user));
    pingAuthenticationListener();
}
项目:contestparser    文件:SecurityAutoConfigurationTests.java   
@Test
public void testOverrideAuthenticationManagerWithBuilderAndInjectBuilderIntoSecurityFilter()
        throws Exception {
    this.context = new AnnotationConfigWebApplicationContext();
    this.context.setServletContext(new MockServletContext());
    this.context.register(AuthenticationManagerCustomizer.class,
            WorkaroundSecurityCustomizer.class, SecurityAutoConfiguration.class,
            ServerPropertiesAutoConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class);
    this.context.refresh();
    UsernamePasswordAuthenticationToken user = new UsernamePasswordAuthenticationToken(
            "foo", "bar",
            AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_USER"));
    assertNotNull(
            this.context.getBean(AuthenticationManager.class).authenticate(user));
}
项目:contestparser    文件:SecurityAutoConfigurationTests.java   
@Test
public void testJpaCoexistsHappily() throws Exception {
    this.context = new AnnotationConfigWebApplicationContext();
    this.context.setServletContext(new MockServletContext());
    EnvironmentTestUtils.addEnvironment(this.context,
            "spring.datasource.url:jdbc:hsqldb:mem:testsecdb");
    EnvironmentTestUtils.addEnvironment(this.context,
            "spring.datasource.initialize:false");
    this.context.register(EntityConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class,
            DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class,
            SecurityAutoConfiguration.class, ServerPropertiesAutoConfiguration.class);
    // This can fail if security @Conditionals force early instantiation of the
    // HibernateJpaAutoConfiguration (e.g. the EntityManagerFactory is not found)
    this.context.refresh();
    assertNotNull(this.context.getBean(JpaTransactionManager.class));
}
项目:contestparser    文件:SecurityAutoConfigurationTests.java   
@Test
public void testDefaultUsernamePassword() throws Exception {
    this.context = new AnnotationConfigWebApplicationContext();
    this.context.setServletContext(new MockServletContext());

    this.context.register(SecurityAutoConfiguration.class,
            ServerPropertiesAutoConfiguration.class);
    this.context.refresh();

    SecurityProperties security = this.context.getBean(SecurityProperties.class);
    AuthenticationManager manager = this.context.getBean(AuthenticationManager.class);

    UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(
            security.getUser().getName(), security.getUser().getPassword());
    assertNotNull(manager.authenticate(token));
}
项目:contestparser    文件:SecurityAutoConfigurationTests.java   
@Test
public void testCustomAuthenticationDoesNotAuthenticateWithBootSecurityUser()
        throws Exception {
    this.context = new AnnotationConfigWebApplicationContext();
    this.context.setServletContext(new MockServletContext());

    this.context.register(AuthenticationManagerCustomizer.class,
            SecurityAutoConfiguration.class, ServerPropertiesAutoConfiguration.class);
    this.context.refresh();

    SecurityProperties security = this.context.getBean(SecurityProperties.class);
    AuthenticationManager manager = this.context.getBean(AuthenticationManager.class);

    UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(
            security.getUser().getName(), security.getUser().getPassword());
    try {
        manager.authenticate(token);
        fail("Expected Exception");
    }
    catch (AuthenticationException success) {
        // Expected
    }

    token = new UsernamePasswordAuthenticationToken("foo", "bar");
    assertNotNull(manager.authenticate(token));
}
项目:contestparser    文件:SpringApplicationAdminJmxAutoConfigurationTests.java   
@Test
public void registerWithSimpleWebApp() throws Exception {
    this.context = new SpringApplicationBuilder()
            .sources(EmbeddedServletContainerAutoConfiguration.class,
                    ServerPropertiesAutoConfiguration.class,
                    DispatcherServletAutoConfiguration.class,
                    JmxAutoConfiguration.class,
                    SpringApplicationAdminJmxAutoConfiguration.class)
            .run("--" + ENABLE_ADMIN_PROP, "--server.port=0");
    assertTrue(this.context instanceof EmbeddedWebApplicationContext);
    assertEquals(true, this.mBeanServer.getAttribute(createDefaultObjectName(),
            "EmbeddedWebApplication"));
    int expected = ((EmbeddedWebApplicationContext) this.context)
            .getEmbeddedServletContainer().getPort();
    String actual = getProperty(createDefaultObjectName(), "local.server.port");
    assertEquals(String.valueOf(expected), actual);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:AutoConfigurationReproTests.java   
@Test
public void doesNotEarlyInitializeFactoryBeans() throws Exception {
    SpringApplication application = new SpringApplication(EarlyInitConfig.class,
            PropertySourcesPlaceholderConfigurer.class,
            EmbeddedServletContainerAutoConfiguration.class,
            ServerPropertiesAutoConfiguration.class);
    this.context = application.run("--server.port=0");
    String bean = (String) this.context.getBean("earlyInit");
    assertThat(bean).isEqualTo("bucket");
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:SecurityAutoConfigurationTests.java   
@Test
public void testWebConfiguration() throws Exception {
    this.context = new AnnotationConfigWebApplicationContext();
    this.context.setServletContext(new MockServletContext());
    this.context.register(SecurityAutoConfiguration.class,
            ServerPropertiesAutoConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class);
    this.context.refresh();
    assertThat(this.context.getBean(AuthenticationManagerBuilder.class)).isNotNull();
    // 5 for static resources and one for the rest
    assertThat(this.context.getBean(FilterChainProxy.class).getFilterChains())
            .hasSize(6);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:SecurityAutoConfigurationTests.java   
@Test
public void testDefaultFilterOrderWithSecurityAdapter() throws Exception {
    this.context = new AnnotationConfigWebApplicationContext();
    this.context.setServletContext(new MockServletContext());
    this.context.register(WebSecurity.class, SecurityAutoConfiguration.class,
            SecurityFilterAutoConfiguration.class,
            ServerPropertiesAutoConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class);
    this.context.refresh();
    assertThat(this.context.getBean("securityFilterChainRegistration",
            DelegatingFilterProxyRegistrationBean.class).getOrder()).isEqualTo(
                    FilterRegistrationBean.REQUEST_WRAPPER_FILTER_MAX_ORDER - 100);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:SecurityAutoConfigurationTests.java   
@Test
public void testFilterIsNotRegisteredInNonWeb() throws Exception {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
    context.register(SecurityAutoConfiguration.class,
            SecurityFilterAutoConfiguration.class,
            ServerPropertiesAutoConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class);
    try {
        context.refresh();
        assertThat(context.containsBean("securityFilterChainRegistration")).isFalse();
    }
    finally {
        context.close();
    }
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:SecurityAutoConfigurationTests.java   
@Test
public void testDefaultFilterOrder() throws Exception {
    this.context = new AnnotationConfigWebApplicationContext();
    this.context.setServletContext(new MockServletContext());
    this.context.register(SecurityAutoConfiguration.class,
            SecurityFilterAutoConfiguration.class,
            ServerPropertiesAutoConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class);
    this.context.refresh();
    assertThat(this.context.getBean("securityFilterChainRegistration",
            DelegatingFilterProxyRegistrationBean.class).getOrder()).isEqualTo(
                    FilterRegistrationBean.REQUEST_WRAPPER_FILTER_MAX_ORDER - 100);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:SecurityAutoConfigurationTests.java   
@Test
public void testCustomFilterOrder() throws Exception {
    this.context = new AnnotationConfigWebApplicationContext();
    EnvironmentTestUtils.addEnvironment(this.context, "security.filter-order:12345");
    this.context.setServletContext(new MockServletContext());
    this.context.register(SecurityAutoConfiguration.class,
            SecurityFilterAutoConfiguration.class,
            ServerPropertiesAutoConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class);
    this.context.refresh();
    assertThat(this.context.getBean("securityFilterChainRegistration",
            DelegatingFilterProxyRegistrationBean.class).getOrder()).isEqualTo(12345);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:SecurityAutoConfigurationTests.java   
@Test
public void testDisableIgnoredStaticApplicationPaths() throws Exception {
    this.context = new AnnotationConfigWebApplicationContext();
    this.context.setServletContext(new MockServletContext());
    this.context.register(SecurityAutoConfiguration.class,
            ServerPropertiesAutoConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class);
    EnvironmentTestUtils.addEnvironment(this.context, "security.ignored:none");
    this.context.refresh();
    // Just the application endpoints now
    assertThat(this.context.getBean(FilterChainProxy.class).getFilterChains())
            .hasSize(1);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:SecurityAutoConfigurationTests.java   
@Test
public void testDisableBasicAuthOnApplicationPaths() throws Exception {
    this.context = new AnnotationConfigWebApplicationContext();
    this.context.setServletContext(new MockServletContext());
    this.context.register(SecurityAutoConfiguration.class,
            ServerPropertiesAutoConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class);
    EnvironmentTestUtils.addEnvironment(this.context, "security.basic.enabled:false");
    this.context.refresh();
    // Ignores and the "matches-none" filter only
    assertThat(this.context.getBeanNamesForType(FilterChainProxy.class).length)
            .isEqualTo(1);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:SecurityAutoConfigurationTests.java   
@Test
public void testAuthenticationManagerCreated() throws Exception {
    this.context = new AnnotationConfigWebApplicationContext();
    this.context.setServletContext(new MockServletContext());
    this.context.register(SecurityAutoConfiguration.class,
            ServerPropertiesAutoConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class);
    this.context.refresh();
    assertThat(this.context.getBean(AuthenticationManager.class)).isNotNull();
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:SecurityAutoConfigurationTests.java   
@Test
public void testOverrideAuthenticationManager() throws Exception {
    this.context = new AnnotationConfigWebApplicationContext();
    this.context.setServletContext(new MockServletContext());
    this.context.register(TestAuthenticationConfiguration.class,
            SecurityAutoConfiguration.class, ServerPropertiesAutoConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class);
    this.context.refresh();
    assertThat(this.context.getBean(AuthenticationManager.class))
            .isEqualTo(this.context.getBean(
                    TestAuthenticationConfiguration.class).authenticationManager);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:SecurityAutoConfigurationTests.java   
@Test
public void testDefaultAuthenticationManagerMakesUserDetailsAvailable()
        throws Exception {
    this.context = new AnnotationConfigWebApplicationContext();
    this.context.setServletContext(new MockServletContext());
    this.context.register(UserDetailsSecurityCustomizer.class,
            SecurityAutoConfiguration.class, ServerPropertiesAutoConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class);
    this.context.refresh();
    assertThat(this.context.getBean(UserDetailsSecurityCustomizer.class)
            .getUserDetails().loadUserByUsername("user")).isNotNull();
}