Commit 34526d9216c3f643f81cfc0ebd17333576f6b9d9
1 parent
790d94b4
WIP Authentification
Showing
8 changed files
with
151 additions
and
5 deletions
Show diff stats
.gitignore
etunicorn-server.iml
@@ -5,6 +5,7 @@ | @@ -5,6 +5,7 @@ | ||
5 | <output-test url="file://$MODULE_DIR$/target/test-classes" /> | 5 | <output-test url="file://$MODULE_DIR$/target/test-classes" /> |
6 | <content url="file://$MODULE_DIR$"> | 6 | <content url="file://$MODULE_DIR$"> |
7 | <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" /> | 7 | <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" /> |
8 | + <sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" /> | ||
8 | <excludeFolder url="file://$MODULE_DIR$/target" /> | 9 | <excludeFolder url="file://$MODULE_DIR$/target" /> |
9 | </content> | 10 | </content> |
10 | <orderEntry type="inheritedJdk" /> | 11 | <orderEntry type="inheritedJdk" /> |
@@ -28,8 +29,6 @@ | @@ -28,8 +29,6 @@ | ||
28 | <orderEntry type="library" name="Maven: javax.validation:validation-api:1.1.0.Final" level="project" /> | 29 | <orderEntry type="library" name="Maven: javax.validation:validation-api:1.1.0.Final" level="project" /> |
29 | <orderEntry type="library" name="Maven: com.fasterxml:classmate:1.3.3" level="project" /> | 30 | <orderEntry type="library" name="Maven: com.fasterxml:classmate:1.3.3" level="project" /> |
30 | <orderEntry type="library" name="Maven: org.springframework:spring-web:4.3.6.RELEASE" level="project" /> | 31 | <orderEntry type="library" name="Maven: org.springframework:spring-web:4.3.6.RELEASE" level="project" /> |
31 | - <orderEntry type="library" name="Maven: org.springframework:spring-webmvc:4.3.6.RELEASE" level="project" /> | ||
32 | - <orderEntry type="library" name="Maven: org.springframework:spring-expression:4.3.6.RELEASE" level="project" /> | ||
33 | <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.8.6" level="project" /> | 32 | <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.8.6" level="project" /> |
34 | <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.8.6" level="project" /> | 33 | <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.8.6" level="project" /> |
35 | <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.8.6" level="project" /> | 34 | <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.8.6" level="project" /> |
@@ -41,7 +40,6 @@ | @@ -41,7 +40,6 @@ | ||
41 | <orderEntry type="library" name="Maven: org.slf4j:jcl-over-slf4j:1.7.22" level="project" /> | 40 | <orderEntry type="library" name="Maven: org.slf4j:jcl-over-slf4j:1.7.22" level="project" /> |
42 | <orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-data-jpa:1.4.4.RELEASE" level="project" /> | 41 | <orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-data-jpa:1.4.4.RELEASE" level="project" /> |
43 | <orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-aop:1.4.4.RELEASE" level="project" /> | 42 | <orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-aop:1.4.4.RELEASE" level="project" /> |
44 | - <orderEntry type="library" name="Maven: org.springframework:spring-aop:4.3.6.RELEASE" level="project" /> | ||
45 | <orderEntry type="library" name="Maven: org.aspectj:aspectjweaver:1.8.9" level="project" /> | 43 | <orderEntry type="library" name="Maven: org.aspectj:aspectjweaver:1.8.9" level="project" /> |
46 | <orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-jdbc:1.4.4.RELEASE" level="project" /> | 44 | <orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-jdbc:1.4.4.RELEASE" level="project" /> |
47 | <orderEntry type="library" name="Maven: org.apache.tomcat:tomcat-jdbc:8.5.11" level="project" /> | 45 | <orderEntry type="library" name="Maven: org.apache.tomcat:tomcat-jdbc:8.5.11" level="project" /> |
@@ -61,9 +59,7 @@ | @@ -61,9 +59,7 @@ | ||
61 | <orderEntry type="library" name="Maven: org.springframework.data:spring-data-jpa:1.10.7.RELEASE" level="project" /> | 59 | <orderEntry type="library" name="Maven: org.springframework.data:spring-data-jpa:1.10.7.RELEASE" level="project" /> |
62 | <orderEntry type="library" name="Maven: org.springframework.data:spring-data-commons:1.12.7.RELEASE" level="project" /> | 60 | <orderEntry type="library" name="Maven: org.springframework.data:spring-data-commons:1.12.7.RELEASE" level="project" /> |
63 | <orderEntry type="library" name="Maven: org.springframework:spring-orm:4.3.6.RELEASE" level="project" /> | 61 | <orderEntry type="library" name="Maven: org.springframework:spring-orm:4.3.6.RELEASE" level="project" /> |
64 | - <orderEntry type="library" name="Maven: org.springframework:spring-context:4.3.6.RELEASE" level="project" /> | ||
65 | <orderEntry type="library" name="Maven: org.springframework:spring-tx:4.3.6.RELEASE" level="project" /> | 62 | <orderEntry type="library" name="Maven: org.springframework:spring-tx:4.3.6.RELEASE" level="project" /> |
66 | - <orderEntry type="library" name="Maven: org.springframework:spring-beans:4.3.6.RELEASE" level="project" /> | ||
67 | <orderEntry type="library" name="Maven: org.springframework:spring-aspects:4.3.6.RELEASE" level="project" /> | 63 | <orderEntry type="library" name="Maven: org.springframework:spring-aspects:4.3.6.RELEASE" level="project" /> |
68 | <orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-test:1.4.4.RELEASE" level="project" /> | 64 | <orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-test:1.4.4.RELEASE" level="project" /> |
69 | <orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-test:1.4.4.RELEASE" level="project" /> | 65 | <orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-test:1.4.4.RELEASE" level="project" /> |
@@ -78,11 +74,25 @@ | @@ -78,11 +74,25 @@ | ||
78 | <orderEntry type="library" name="Maven: org.json:json:20140107" level="project" /> | 74 | <orderEntry type="library" name="Maven: org.json:json:20140107" level="project" /> |
79 | <orderEntry type="library" name="Maven: org.springframework:spring-core:4.3.6.RELEASE" level="project" /> | 75 | <orderEntry type="library" name="Maven: org.springframework:spring-core:4.3.6.RELEASE" level="project" /> |
80 | <orderEntry type="library" name="Maven: org.springframework:spring-test:4.3.6.RELEASE" level="project" /> | 76 | <orderEntry type="library" name="Maven: org.springframework:spring-test:4.3.6.RELEASE" level="project" /> |
77 | + <orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-security:1.4.4.RELEASE" level="project" /> | ||
78 | + <orderEntry type="library" name="Maven: org.springframework:spring-aop:4.3.6.RELEASE" level="project" /> | ||
79 | + <orderEntry type="library" name="Maven: org.springframework.security:spring-security-config:4.1.4.RELEASE" level="project" /> | ||
80 | + <orderEntry type="library" name="Maven: org.springframework.security:spring-security-web:4.1.4.RELEASE" level="project" /> | ||
81 | + <orderEntry type="library" name="Maven: org.springframework:spring-expression:4.3.6.RELEASE" level="project" /> | ||
81 | <orderEntry type="library" name="Maven: com.jayway.jsonpath:json-path:2.2.0" level="project" /> | 82 | <orderEntry type="library" name="Maven: com.jayway.jsonpath:json-path:2.2.0" level="project" /> |
82 | <orderEntry type="library" name="Maven: net.minidev:json-smart:2.2.1" level="project" /> | 83 | <orderEntry type="library" name="Maven: net.minidev:json-smart:2.2.1" level="project" /> |
83 | <orderEntry type="library" name="Maven: net.minidev:accessors-smart:1.1" level="project" /> | 84 | <orderEntry type="library" name="Maven: net.minidev:accessors-smart:1.1" level="project" /> |
84 | <orderEntry type="library" name="Maven: org.ow2.asm:asm:5.0.3" level="project" /> | 85 | <orderEntry type="library" name="Maven: org.ow2.asm:asm:5.0.3" level="project" /> |
85 | <orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.22" level="project" /> | 86 | <orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.22" level="project" /> |
86 | <orderEntry type="library" name="Maven: com.h2database:h2:1.4.193" level="project" /> | 87 | <orderEntry type="library" name="Maven: com.h2database:h2:1.4.193" level="project" /> |
88 | + <orderEntry type="library" name="Maven: org.springframework.security.oauth:spring-security-oauth2:2.0.12.RELEASE" level="project" /> | ||
89 | + <orderEntry type="library" name="Maven: org.springframework:spring-beans:4.3.6.RELEASE" level="project" /> | ||
90 | + <orderEntry type="library" name="Maven: org.springframework:spring-context:4.3.6.RELEASE" level="project" /> | ||
91 | + <orderEntry type="library" name="Maven: org.springframework:spring-webmvc:4.3.6.RELEASE" level="project" /> | ||
92 | + <orderEntry type="library" name="Maven: org.springframework.security:spring-security-core:4.1.4.RELEASE" level="project" /> | ||
93 | + <orderEntry type="library" name="Maven: aopalliance:aopalliance:1.0" level="project" /> | ||
94 | + <orderEntry type="library" name="Maven: commons-codec:commons-codec:1.10" level="project" /> | ||
95 | + <orderEntry type="library" name="Maven: org.codehaus.jackson:jackson-mapper-asl:1.9.13" level="project" /> | ||
96 | + <orderEntry type="library" name="Maven: org.codehaus.jackson:jackson-core-asl:1.9.13" level="project" /> | ||
87 | </component> | 97 | </component> |
88 | </module> | 98 | </module> |
89 | \ No newline at end of file | 99 | \ No newline at end of file |
pom.xml
@@ -27,6 +27,10 @@ | @@ -27,6 +27,10 @@ | ||
27 | <artifactId>spring-boot-starter-test</artifactId> | 27 | <artifactId>spring-boot-starter-test</artifactId> |
28 | </dependency> | 28 | </dependency> |
29 | <dependency> | 29 | <dependency> |
30 | + <groupId>org.springframework.boot</groupId> | ||
31 | + <artifactId>spring-boot-starter-security</artifactId> | ||
32 | + </dependency> | ||
33 | + <dependency> | ||
30 | <groupId>com.jayway.jsonpath</groupId> | 34 | <groupId>com.jayway.jsonpath</groupId> |
31 | <artifactId>json-path</artifactId> | 35 | <artifactId>json-path</artifactId> |
32 | </dependency> | 36 | </dependency> |
@@ -34,6 +38,10 @@ | @@ -34,6 +38,10 @@ | ||
34 | <groupId>com.h2database</groupId> | 38 | <groupId>com.h2database</groupId> |
35 | <artifactId>h2</artifactId> | 39 | <artifactId>h2</artifactId> |
36 | </dependency> | 40 | </dependency> |
41 | + <dependency> | ||
42 | + <groupId>org.springframework.security.oauth</groupId> | ||
43 | + <artifactId>spring-security-oauth2</artifactId> | ||
44 | + </dependency> | ||
37 | </dependencies> | 45 | </dependencies> |
38 | 46 | ||
39 | <properties> | 47 | <properties> |
src/main/java/etunicorn/CustomUserDetailsService.java
0 → 100644
@@ -0,0 +1,73 @@ | @@ -0,0 +1,73 @@ | ||
1 | +package etunicorn; | ||
2 | + | ||
3 | +import org.springframework.beans.factory.annotation.Autowired; | ||
4 | +import org.springframework.security.core.GrantedAuthority; | ||
5 | +import org.springframework.security.core.userdetails.UserDetails; | ||
6 | +import org.springframework.security.core.userdetails.UsernameNotFoundException; | ||
7 | + | ||
8 | +import java.util.Collection; | ||
9 | + | ||
10 | +/** | ||
11 | + * Created by geoffrey on 29/01/17. | ||
12 | + */ | ||
13 | +public class CustomUserDetailsService implements UserDetailsService { | ||
14 | + | ||
15 | + private final PersonneRepository personneRepository; | ||
16 | + | ||
17 | + @Autowired | ||
18 | + public CustomUserDetailsService(PersonneRepository personneRepository) { | ||
19 | + this.personneRepository = personneRepository; | ||
20 | + } | ||
21 | + | ||
22 | + @Override | ||
23 | + public UserDetails loadByUsername(String login) throws UsernameNotFoundException { | ||
24 | + Personne personne = personneRepository.findByLogin(login); | ||
25 | + if (personne == null) { | ||
26 | + throw new UsernameNotFoundException(String.format("L'utilisateur %s n'existe pas !", login)); | ||
27 | + } | ||
28 | + return new PersonneRepositoryUserDetails(personne); | ||
29 | + } | ||
30 | + | ||
31 | + private final static class PersonneRepositoryUserDetails extends Personne implements UserDetails { | ||
32 | + | ||
33 | + public PersonneRepositoryUserDetails(Personne personne) { | ||
34 | + super(personne); | ||
35 | + } | ||
36 | + | ||
37 | + @Override | ||
38 | + public Collection<? extends GrantedAuthority> getAuthorities() { | ||
39 | + // return getRoles(); | ||
40 | + return null; | ||
41 | + } | ||
42 | + | ||
43 | + @Override | ||
44 | + public String getPassword() { | ||
45 | + return "test"; | ||
46 | + } | ||
47 | + | ||
48 | + @Override | ||
49 | + public String getUsername() { | ||
50 | + return getLogin(); | ||
51 | + } | ||
52 | + | ||
53 | + @Override | ||
54 | + public boolean isAccountNonExpired() { | ||
55 | + return true; | ||
56 | + } | ||
57 | + | ||
58 | + @Override | ||
59 | + public boolean isAccountNonLocked() { | ||
60 | + return true; | ||
61 | + } | ||
62 | + | ||
63 | + @Override | ||
64 | + public boolean isCredentialsNonExpired() { | ||
65 | + return true; | ||
66 | + } | ||
67 | + | ||
68 | + @Override | ||
69 | + public boolean isEnabled() { | ||
70 | + return true; | ||
71 | + } | ||
72 | + } | ||
73 | +} |
src/main/java/etunicorn/Personne.java
@@ -24,6 +24,14 @@ public class Personne { | @@ -24,6 +24,14 @@ public class Personne { | ||
24 | public Personne() { | 24 | public Personne() { |
25 | } | 25 | } |
26 | 26 | ||
27 | + public Personne(Personne personne) { | ||
28 | + super(); | ||
29 | + this.id = personne.getId(); | ||
30 | + this.carte = personne.getCarte(); | ||
31 | + this.naissance = personne.getNaissance(); | ||
32 | + this.login = personne.getLogin(); | ||
33 | + } | ||
34 | + | ||
27 | public int getId() { | 35 | public int getId() { |
28 | return id; | 36 | return id; |
29 | } | 37 | } |
@@ -0,0 +1,11 @@ | @@ -0,0 +1,11 @@ | ||
1 | +package etunicorn; | ||
2 | + | ||
3 | +import org.springframework.security.core.userdetails.UserDetails; | ||
4 | +import org.springframework.security.core.userdetails.UsernameNotFoundException; | ||
5 | + | ||
6 | +/** | ||
7 | + * Created by geoffrey on 29/01/17. | ||
8 | + */ | ||
9 | +public interface UserDetailsService { | ||
10 | + UserDetails loadByUsername(String s) throws UsernameNotFoundException; | ||
11 | +} |
src/main/java/etunicorn/WebSecurityConfiguration.java
0 → 100644
@@ -0,0 +1,33 @@ | @@ -0,0 +1,33 @@ | ||
1 | +package etunicorn; | ||
2 | + | ||
3 | +import org.springframework.beans.factory.annotation.Autowired; | ||
4 | +import org.springframework.context.annotation.Bean; | ||
5 | +import org.springframework.context.annotation.Configuration; | ||
6 | +import org.springframework.security.authentication.AuthenticationManager; | ||
7 | +import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; | ||
8 | +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; | ||
9 | +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; | ||
10 | + | ||
11 | +/** | ||
12 | + * Created by geoffrey on 29/01/17. | ||
13 | + */ | ||
14 | +@Configuration | ||
15 | +@EnableWebSecurity | ||
16 | +public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter { | ||
17 | + | ||
18 | + @Autowired | ||
19 | + private CustomUserDetailsService userDetailsService; | ||
20 | + | ||
21 | + @Override | ||
22 | + protected void configure(AuthenticationManagerBuilder auth) throws Exception { | ||
23 | + auth.userDetailsService(userDetailsService); | ||
24 | + } | ||
25 | + | ||
26 | + @Override | ||
27 | + @Bean | ||
28 | + public AuthenticationManager authenticationManager() throws Exception { | ||
29 | + return super.authenticationManager(); | ||
30 | + } | ||
31 | + | ||
32 | + | ||
33 | +} |
src/main/main.iml
@@ -25,5 +25,7 @@ | @@ -25,5 +25,7 @@ | ||
25 | <orderEntry type="library" name="Maven: org.springframework:spring-context:4.3.6.RELEASE" level="project" /> | 25 | <orderEntry type="library" name="Maven: org.springframework:spring-context:4.3.6.RELEASE" level="project" /> |
26 | <orderEntry type="library" name="Maven: ch.qos.logback:logback-classic:1.1.9" level="project" /> | 26 | <orderEntry type="library" name="Maven: ch.qos.logback:logback-classic:1.1.9" level="project" /> |
27 | <orderEntry type="library" name="Maven: org.slf4j:log4j-over-slf4j:1.7.22" level="project" /> | 27 | <orderEntry type="library" name="Maven: org.slf4j:log4j-over-slf4j:1.7.22" level="project" /> |
28 | + <orderEntry type="library" name="Maven: org.springframework.security:spring-security-core:4.1.4.RELEASE" level="project" /> | ||
29 | + <orderEntry type="library" name="Maven: org.springframework.security:spring-security-config:4.1.4.RELEASE" level="project" /> | ||
28 | </component> | 30 | </component> |
29 | </module> | 31 | </module> |
30 | \ No newline at end of file | 32 | \ No newline at end of file |
-
mentioned in commit dcfbf6e6c20b271e319a19b9fdc384781f282f16