Skip to content

Commit aac3321

Browse files
author
dlavoie
committed
Spring Security integration.
1 parent 3d8e138 commit aac3321

File tree

4 files changed

+53
-0
lines changed

4 files changed

+53
-0
lines changed

Diff for: redis-message-server/pom.xml

+8
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,13 @@
6565
<groupId>com.cspinformatique.redis.message</groupId>
6666
<artifactId>redis-message-core</artifactId>
6767
</dependency>
68+
<dependency>
69+
<groupId>org.springframework.security</groupId>
70+
<artifactId>spring-security-web</artifactId>
71+
</dependency>
72+
<dependency>
73+
<groupId>org.springframework.security</groupId>
74+
<artifactId>spring-security-config</artifactId>
75+
</dependency>
6876
</dependencies>
6977
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.cspinformatique.redis.server.config;
2+
3+
import org.springframework.beans.factory.annotation.Autowired;
4+
import org.springframework.context.annotation.Configuration;
5+
import org.springframework.context.annotation.PropertySource;
6+
import org.springframework.core.env.Environment;
7+
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
8+
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
9+
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
10+
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
11+
12+
@Configuration
13+
@EnableWebSecurity
14+
@PropertySource("classpath:security/credentials.properties")
15+
public class SecurityConfig extends WebSecurityConfigurerAdapter {
16+
@Autowired
17+
private Environment env;
18+
19+
@Autowired
20+
public void configureGlobal(AuthenticationManagerBuilder auth)
21+
throws Exception {
22+
auth.inMemoryAuthentication()
23+
.withUser(env.getRequiredProperty("redis.notifier.user"))
24+
.password(env.getRequiredProperty("redis.notifier.password"))
25+
.roles("NOTIFIER");
26+
}
27+
28+
@Override
29+
protected void configure(HttpSecurity http) throws Exception {
30+
http.authorizeRequests().antMatchers("/**")
31+
.access("hasRole('ROLE_NOTIFIER')").and().httpBasic();
32+
33+
http.csrf().disable();
34+
}
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.cspinformatique.redis.server.security;
2+
3+
import org.springframework.security.web.context.AbstractSecurityWebApplicationInitializer;
4+
5+
public class SpringSecurityInitializer extends
6+
AbstractSecurityWebApplicationInitializer {
7+
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
redis.notifier.user=notifier
2+
redis.notifier.password=3Sf8!29nZ

0 commit comments

Comments
 (0)