spring-java-config

PreAuthorize not working on Controller

£可爱£侵袭症+ 提交于 2019-11-26 22:51:15
问题 I'm trying to define access rules at method-level but it's not working what so ever. SecurityConfiguration @Configuration @EnableWebSecurity @EnableGlobalMethodSecurity(prePostEnabled = true) public class SecurityConfiguration extends WebSecurityConfigurerAdapter { @Override public void configure(AuthenticationManagerBuilder auth) throws Exception { auth.inMemoryAuthentication(). withUser("user").password("user").roles("USER").and(). withUser("admin").password("admin").roles("ADMIN"); }

CharacterEncodingFilter don't work together with Spring Security 3.2.0

与世无争的帅哥 提交于 2019-11-26 20:06:51
I'm new to Spring MVC framework and I have got an issue that I can not resolve by myself. Everything started when I integrated spring security with my application, after that all unicode values from HTML form were not encoded (spring security works correctly). I came to conclusion that this is happening probably because my DelegatingFilterProxy is called as the first filter in the chain. Here is my configuration that I thought will work, but it doesn't: 1)I'm extending AbstractSecurityWebApplicationInitializer - from javadoc: Registers the DelegatingFilterProxy to use the

Spring Batch - Looping a reader/processor/writer step

孤者浪人 提交于 2019-11-26 16:48:19
问题 ANSWER Based on the accepted answer code the following adjustment to that code worked for me: // helper method to create a split flow out of a List of steps private static Flow createParallelFlow(List<Step> steps) { SimpleAsyncTaskExecutor taskExecutor = new SimpleAsyncTaskExecutor(); taskExecutor.setConcurrencyLimit(steps.size()); Flow[] flows = new Flow[steps.size()]; for (int i = 0; i < steps.size(); i++) { flows[i] = new FlowBuilder<SimpleFlow>(steps.get(i).getName()).start(steps.get(i))

Using GZIP compression with Spring Boot/MVC/JavaConfig with RESTful

只愿长相守 提交于 2019-11-26 15:50:00
We use Spring Boot/MVC with annotation-based java-config for series of RESTful services and we want to selectively enable HTTP GZIP stream compression on some API responses. I know I can do this manually in my controller and a byte[] @ResponseBody , however we'd prefer to rely on the SpringMVC infrastructure (filters/etc) and have it automatically do the JSON conversion and compression (ie the method returns a POJO). How can I enable GZIP compression in the ResponseBody or embedded Tomcat instance, and in a way we can selectively compress only some responses? Thanks! PS.: We don't currently

Spring Java Config: how do you create a prototype-scoped @Bean with runtime arguments?

不问归期 提交于 2019-11-26 14:55:26
Using Spring's Java Config, I need to acquire/instantiate a prototype-scoped bean with constructor arguments that are only obtainable at runtime. Consider the following code example (simplified for brevity): @Autowired private ApplicationContext appCtx; public void onRequest(Request request) { //request is already validated String name = request.getParameter("name"); Thing thing = appCtx.getBean(Thing.class, name); //System.out.println(thing.getName()); //prints name } where the Thing class is defined as follows: public class Thing { private final String name; @Autowired private SomeComponent

How do I remove the ROLE_ prefix from Spring Security with JavaConfig?

感情迁移 提交于 2019-11-26 14:45:26
问题 I'm trying to remove the "ROLE_" prefix in Spring Security. The first thing I tried was: http.servletApi().rolePrefix(""); That didn't work, so I tried creating a BeanPostProcessor as suggested in http://docs.spring.io/spring-security/site/migrate/current/3-to-4/html5/migrate-3-to-4-jc.html#m3to4-role-prefixing-disable. That didn't work either. Finally, I tried creating my own SecurityExpressionHandler : @Override protected void configure(HttpSecurity http) throws Exception { http

How To Inject AuthenticationManager using Java Configuration in a Custom Filter

谁说胖子不能爱 提交于 2019-11-26 12:06:07
I'm using Spring Security 3.2 and Spring 4.0.1 I'm working on converting an xml config into a Java config. When I annotate AuthenticationManager with @Autowired in my Filter, I'm getting an exception Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.security.authentication.AuthenticationManager] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {} I've tried injecting AuthenticationManagerFactoryBean but that also fails with a similar

How to java-configure separate datasources for spring batch data and business data? Should I even do it?

落花浮王杯 提交于 2019-11-26 10:34:51
问题 My main job does only read operations and the other one does some writing but on MyISAM engine which ignores transactions, so I wouldn\'t require necessarily transaction support. How can I configure Spring Batch to have its own datasource for the JobRepository , separate from the one holding the business data? The initial one datasource-configurations is done like the following: @Configuration public class StandaloneInfrastructureConfiguration { @Autowired Environment env; @Bean public

Spring Java Config: how do you create a prototype-scoped @Bean with runtime arguments?

不羁的心 提交于 2019-11-26 04:05:40
问题 Using Spring\'s Java Config, I need to acquire/instantiate a prototype-scoped bean with constructor arguments that are only obtainable at runtime. Consider the following code example (simplified for brevity): @Autowired private ApplicationContext appCtx; public void onRequest(Request request) { //request is already validated String name = request.getParameter(\"name\"); Thing thing = appCtx.getBean(Thing.class, name); //System.out.println(thing.getName()); //prints name } where the Thing

How To Inject AuthenticationManager using Java Configuration in a Custom Filter

一曲冷凌霜 提交于 2019-11-26 02:29:40
问题 I\'m using Spring Security 3.2 and Spring 4.0.1 I\'m working on converting an xml config into a Java config. When I annotate AuthenticationManager with @Autowired in my Filter, I\'m getting an exception Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.security.authentication.AuthenticationManager] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency