spring-java-config

PreAuthorize not working on Controller

此生再无相见时 提交于 2019-11-27 20:36:10
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"); } @Override protected void configure(HttpSecurity http) throws Exception { http .sessionManagement()

Apache CXF + Spring Java config (no XML)

落爺英雄遲暮 提交于 2019-11-27 17:29:57
问题 Trying to deploy a JAX-WS endpoint using Tomcat 7 Maven plugin and CXF 2.7.8. As a matter of preference, I don't want to have any XML config for Spring or CXF. I see several blogs, articles, posts using cxf-servlet.xml and CXFServlet but none whatsoever completely using Java config. Looking into the CXFServlet source code, it looks for the cxf-servlet.xml or anything in the servlet context under the key 'config-location' . I tried programmatically registering the endpoint instead of in cxf

Configuring AspectJ aspects using Spring IoC with JavaConfig?

社会主义新天地 提交于 2019-11-27 16:07:44
According to Spring's Documentation Configuring AspectJ aspects using Spring IoC in order to configure an aspect for Spring IOC, the following has to be added to the xml configuration: <bean id="profiler" class="com.xyz.profiler.Profiler" factory-method="aspectOf"> <property name="profilingStrategy" ref="jamonProfilingStrategy"/> </bean> As suggested by @SotiriosDelimanolis, rewriting this as the following in JavaConfig should to work: @Bean public com.xyz.profiler.Profiler profiler() { com.xyz.profiler.Profiler profiler = com.xyz.profiler.Profiler.aspectOf(); profiler.setProfilingStrategy

JavaConfiguration for Spring 4.0 + Security 3.2 + j_spring_security_check

[亡魂溺海] 提交于 2019-11-27 14:59:26
问题 Create a login page <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <!DOCTYPE html> <html> <head> <meta charset="ISO-8859-1"> <title>Test</title> <script src="static/js/jquery-1.10.2.min.js"></script> <script src="static/js/app-controller.js"></script> </head> <body> <div>Login</div> <form name="f" action="<c:url value="/j_spring_security_check"/>" method="POST"> <label for="password">Username</label> <input type="text" id="j_username" name="j_username"><br/> <label for=

Spring Batch - Looping a reader/processor/writer step

你说的曾经没有我的故事 提交于 2019-11-27 14:54:49
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)).build(); } return new FlowBuilder<SimpleFlow>("parallelStepsFlow") .split(taskExecutor) .add(flows)

Failed to Load ApplicationContext during Spring unit test

核能气质少年 提交于 2019-11-27 12:20:46
问题 I am trying to run a Junit functional test using Springs java-config for my application context. I am not sure if it is a problem with Spring or Junit... just not sure.. The application runs fine on my local server (hitting the db), but when I try to run my test it bombs out. I just moved from xml to java config so I can always import my xml context files (which I know works in my tests) but going forward I would rather just use my java config. My Test Class @RunWith(SpringJUnit4ClassRunner

In Spring-Security with Java Config, why does httpBasic POST want csrf token?

假如想象 提交于 2019-11-27 09:51:22
问题 I am using Spring-Security 3.2.0.RC2 with Java config. I set up a simple HttpSecurity config that asks for basic auth on /v1/**. GET requests work but POST requests fail with: HTTP Status 403 - Invalid CSRF Token 'null' was found on the request parameter '_csrf' or header 'X-CSRF-TOKEN'. My security config looks like this: @Configuration @EnableWebSecurity public class SecurityConfig extends WebSecurityConfigurerAdapter { @Resource private MyUserDetailsService userDetailsService; @Autowired /

disabling spring security in spring boot app

删除回忆录丶 提交于 2019-11-27 07:13:10
I have a spring boot web app with spring security configured. I want to disable authentication for a while (until needed). I add this to the application.properties : security.basic.enable: false management.security.enabled: false Here is some part of my But I still have a basic security included : There is a default security password generated at startup and I am still getting HTTP Authentication prompt box. My pom.xml : <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven

Why @JavaConfig not working in Spring MVC?

拈花ヽ惹草 提交于 2019-11-27 06:33:23
问题 I'm trying to setup Spring MVC project without dispatcher xml and web xml(i.e. without any xml at all). Hence, I'm using @JavaConfig technique of Spring. However, whenever I'm trying to start the application on my server my server it's not working(without throwing any exception it's getting HTTP 404). Here is the snapshot of the project structure... And here the code snippets: WebConfig.java @EnableWebMvc @Configuration @ComponentScan({ "com.controller" }) public class WebConfig extends

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

北城以北 提交于 2019-11-27 03:50:47
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 LocalContainerEntityManagerFactoryBean entityManagerFactory() { LocalContainerEntityManagerFactoryBean em =