小编Mod*_*odi的帖子

Spring boot - @ConditionalOnProperty或@ConditionalOnExpression

我正在使用Spring-Boot-1.1.7.我的目的是根据string类型的属性值将bean添加到我的上下文中.

我的意思是,我可以看到许多布尔值的例子,例如:

@ConditionalOnExpression("${xxx.enabled:true}")
Run Code Online (Sandbox Code Playgroud)

但我想要一个基于属性值的表达式,例如:

@ConditionalOnExpression("${server.host==localhost} or ${server.port==8080} ")
Run Code Online (Sandbox Code Playgroud)

或类似的东西.

有人能告诉我一个如何做的例子吗?

spring-boot

17
推荐指数
2
解决办法
2万
查看次数

Spring Data - MongoDB索引DBRef

我正在使用spring-data-mongodb-1.2.0.RELEASE.我有两个类A和B,其中B有一个对A的引用,它用@DBRef注释.

A类:

@Document(collection = "a")
public class A {
@Id
public String id;

/** The TicketGrantingTicket this is associated with. */
@Field
public String name;

public A(String id, String name) {
    this.id = id;
    this.name = name;
}
}
Run Code Online (Sandbox Code Playgroud)

B级:

@Document(collection = "b")
public class B {

@Id
public String id;

@Field
public String name;

@DBRef
@Indexed
public A a;

public B(String id, String name, A a) {
    super();
    this.id = id;
    this.name = name;
    this.a = a;
}
} …
Run Code Online (Sandbox Code Playgroud)

indexing mongodb dbref spring-data-mongodb

10
推荐指数
2
解决办法
8996
查看次数

QueryDSL删除方法

我正在使用带有QueryDSL 2.9.0的spring-data-mongodb 1.2.0.

为什么不QueryDslPredicateExecutordelete(Predicate predicate)方法?

有解决方法吗?

querydsl spring-data spring-data-mongodb

8
推荐指数
1
解决办法
2983
查看次数

如何在Spring Security中设置自定义无效会话策略

我正在开发一个基于Spring-Boot - 1.1.6,Spring -Security -3.2.5等的Web应用程序.

我正在使用基于Java的配置:

@Configuration
@EnableWebMvcSecurity
public class SecurityCtxConfig extends WebSecurityConfigurerAdapter {


    @Bean
    DelegatingAuthenticationEntryPoint delegatingAuthenticationEntryPoint() {
        LinkedHashMap<RequestMatcher, AuthenticationEntryPoint> map = new LinkedHashMap<RequestMatcher, AuthenticationEntryPoint>();
        Http403ForbiddenEntryPoint defaultEntryPoint = new Http403ForbiddenEntryPoint();
        map.put(AnyRequestMatcher.INSTANCE, defaultEntryPoint);
        DelegatingAuthenticationEntryPoint retVal = new DelegatingAuthenticationEntryPoint(map);
        retVal.setDefaultEntryPoint(defaultEntryPoint);
        return retVal;
    }


    @Override
    protected void configure(HttpSecurity http) throws Exception {
        ExceptionHandlingConfigurer<HttpSecurity> exceptionHandling = http.exceptionHandling();
        exceptionHandling.authenticationEntryPoint(delegatingAuthenticationEntryPoint());
        http.logout().logoutSuccessHandler(new LogoutSuccessHandler() {

            @Override
            public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication arg2)
                    throws IOException, ServletException {
                response.setStatus(HttpServletResponse.SC_OK);
            }
        });
    }

}
Run Code Online (Sandbox Code Playgroud)

要求是在会话cookie无效或丢失的情况下返回Http状态401(无论原因)我看到了InvalidSessionStrategy但是我找不到设置它的方法SessionManagementFilter.有人可以告诉我如何实施我的计划或另一个符合要求的计划

spring-security

6
推荐指数
3
解决办法
7115
查看次数

添加要在Servlet 3+环境中的spring-security过滤器之后调用的自定义过滤器

我正在使用Spring-Security 3.2.4和Spring Boot 1.1.0(以及相关的依赖版本4.X).我正在编写一个将在嵌入式tomcat中运行的Web应用程序.

我正在尝试添加两个额外的过滤器(与Spring安全无关),其中一个将在Spring-Security-FilterChainProxy之前调用,另一个将在Spring-Security-FilterChainProxy之后调用.

我的Spring-Security配置文件:

@Configuration
@EnableWebMvcSecurity
public class SecurityCtxConfig extends WebSecurityConfigurerAdapter {

@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
    auth
    .inMemoryAuthentication()
        .withUser("user").password("pass").roles("USER");
}

@Override
protected void configure(HttpSecurity http) throws Exception {
    http.csrf()
            .disable()
            .authorizeRequests()
            .anyRequest()
            .authenticated()
            .and()
            .formLogin()
            .usernameParameter("user").passwordParameter("password");
}
}
Run Code Online (Sandbox Code Playgroud)

和Main类(Application.class):

@Configuration
@ComponentScan
@EnableAutoConfiguration
public class Application {

    @Bean
RequestFilter beforeSpringSecurityFilter(){
    return new RequestFilter();
}

@Bean
RequestFilter afterSpringSecurityFilter(){
    return new RequestFilter();
}

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}
Run Code Online (Sandbox Code Playgroud)

和Filter实现:

public class RequestFilter …
Run Code Online (Sandbox Code Playgroud)

spring-mvc spring-security spring-boot

5
推荐指数
2
解决办法
1万
查看次数