spring-java-config

Confusion around Spring Security anonymous access using Java Config

蹲街弑〆低调 提交于 2019-12-04 20:26:26
问题 I am using the following Java Config with Spring Security: protected void configure(HttpSecurity http) throws Exception { http .authorizeRequests() .anyRequest().authenticated() .and() .httpBasic(); } Based on this configuration, all requests are authenticated. When you hit a controller without being authenticated, the AnonymousAuthenticationFilter will create an Authentication object for you with username=anonymousUser, role=ROLE_ANONYMOUS . I am trying to provide anonymous access to a a

How do I configure Spring to partially and optionally override properties?

给你一囗甜甜゛ 提交于 2019-12-04 14:32:26
问题 I would like to have a properties setup which can, on certain environments, override specific properties. For example, our default JDBC properties for dev are: db.driverClassName=com.mysql.jdbc.Driver db.url=jdbc:mysql://localhost:3306/ourdb db.username=root db.password= The problem is that some of our devs would like to have a different username/password on the db, or possibly even a non locally hosted db. The same is true for our rabbitMQ configuration, which currently uses a similar

how to convert jndi lookup from xml to java config

拜拜、爱过 提交于 2019-12-04 11:50:59
问题 Currently I'm converting the xml to java config. But I stuck at some part that I have been research for several days. Here the problem: Xml config: <jee:jndi-lookup id="dbDataSource" jndi-name="${db.jndi}" resource-ref="true" /> <beans:bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate" > <beans:property name="dataSource" ref="dbDataSource"></beans:property> </beans:bean> So far I managed to convert this code: <jee:jndi-lookup id="dbDataSource" jndi-name="${db.jndi}"

Annotation/java config based application starts to look for xml config file when moved from weblogic12c(12.1.3) to weblogic12cR2 (12.2.1)

最后都变了- 提交于 2019-12-04 10:06:03
My spring java-config application packed as war runs wihout problem on weblogic 12.1.3 so I tried to deploy same war into weblogic 12.2.1 where it causes java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/DispatcherServlet-servlet.xml] . It seems like DispatcherServlet servlet is initialized with XmlWebApplicationContext (default one) instead of AnnotationConfigEmbeddedWebApplicationContext in 12.2.1 even when war is the same. Has someone any idea what was changed in weblogic implementation since previous version what is causing this problem? Using same war : in

Send emails with Spring by using Java annotations

巧了我就是萌 提交于 2019-12-04 08:21:09
问题 How could I send an email with Spring 4 (and Spring Boot ) by using a pure annotation-based approach (according to the Java Configurations rules)? 回答1: A simple solution (where you will be using an SMTP server with no authentication) for configuring the email service would by @Configuration public class MailConfig { @Value("${email.host}") private String host; @Value("${email.port}") private Integer port; @Bean public JavaMailSender javaMailService() { JavaMailSenderImpl javaMailSender = new

Single Sign Out with Spring Security and CAS

别说谁变了你拦得住时间么 提交于 2019-12-04 05:43:15
Using pure Spring Java Config I'm having troubles getting Spring and CAS to perform Single Sign Out. I have Single Sign On working with the configuration below. I use a simple JSP page to do a form POST to the url https://nginx.shane.com/app/logout and I include the CSRF value in the POST'd data. It all appears to work with no errors but when I go to a secured page it just lets me back in without requiring to login. Any ideas? @Configuration @EnableWebSecurity public class SecurityWebAppConfig extends WebSecurityConfigurerAdapter { @Bean protected ServiceProperties serviceProperties() {

Autowire setter override with Java Config

五迷三道 提交于 2019-12-04 01:49:17
问题 Consider the following class: public class MyBean { private A a; @Autowired(required=true) public void setA(A a) { this.a = a; } public A getA() { return a; } } There are cases when one need need to override the autowired injection, for example when Spring cannot find a single candidate for the injection. In XML I can have the following example: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema

How do I add an Access Denied Handler in spring-security-javaconfig

岁酱吖の 提交于 2019-12-03 23:16:12
I'm using the spring-security-javaconfig library for spring security. If I were using xml config files, I'd use something like this to define a custom Access Denied page: <http auto-config="true"> <intercept-url pattern="/admin*" access="ROLE_ADMIN" /> <access-denied-handler ref="accessDeniedHandler"/> </http> Here is my security configuration class so far: @Configuration @EnableWebSecurity public class SecurityConfigurator extends WebSecurityConfigurerAdapter { @Override protected void registerAuthentication(AuthenticationManagerBuilder auth) throws Exception { auth.inMemoryAuthentication()

Apache Shiro JdbcRealm with JavaConfig and Spring Boot

偶尔善良 提交于 2019-12-03 20:33:37
问题 I'm trying to configure my Spring Boot application to use Apache Shiro as its security framework. I have everything working with a PropertiesRealm, now I'm trying to get it working with a JdbcRealm and Spring Boot's built-in H2 database. Here's my dependencies in my pom.xml: <dependency> <groupId>org.apache.shiro</groupId> <artifactId>shiro-core</artifactId> <version>1.2.3</version> </dependency> <dependency> <groupId>org.apache.shiro</groupId> <artifactId>shiro-spring</artifactId> <version>1

Skippable exception classes for Spring Batch with java based configuration

别说谁变了你拦得住时间么 提交于 2019-12-03 17:50:21
问题 I configure a step in XML like this: <batch:step id="slaveStep"> <batch:tasklet> <batch:chunk reader="reader" processor="processor" writer="writer" commit-interval="10" skip-limit="100000"> <batch:skippable-exception-classes> <batch:include class="MyException"/> </batch:skippable-exception-classes> </batch:chunk> </batch:tasklet> </batch:step> In the java configuration I use a StepBuilder like this: @Bean public StepBuilder stepBuilder(String stepName) { return new StepBuilder(stepName); }