From dcfbf6e6c20b271e319a19b9fdc384781f282f16 Mon Sep 17 00:00:00 2001 From: Geoffrey Frogeye Date: Sun, 29 Jan 2017 18:21:26 +0100 Subject: [PATCH] Revert "Recopie de l'exemple d'OAuth" --- .gitignore | 1 - etunicorn-server.iml | 104 +++++--------------------------------------------------------------------------------------------------- pom.xml | 8 -------- src/main/java/etunicorn/CustomUserDetailsService.java | 76 ---------------------------------------------------------------------------- src/main/java/etunicorn/OAuth2ServerConfiguration.java | 87 --------------------------------------------------------------------------------------- src/main/java/etunicorn/Personne.java | 8 -------- src/main/java/etunicorn/PersonneController.java | 5 +++++ src/main/java/etunicorn/UserDetailsService.java | 11 +++++++++++ src/main/java/etunicorn/WebSecurityConfiguration.java | 33 --------------------------------- src/main/main.iml | 5 +---- 10 files changed, 22 insertions(+), 316 deletions(-) delete mode 100644 src/main/java/etunicorn/CustomUserDetailsService.java delete mode 100644 src/main/java/etunicorn/OAuth2ServerConfiguration.java create mode 100644 src/main/java/etunicorn/UserDetailsService.java delete mode 100644 src/main/java/etunicorn/WebSecurityConfiguration.java diff --git a/.gitignore b/.gitignore index d54b284..c4a4981 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,3 @@ .idea/libraries/ target/ demo*/ -*.ldif diff --git a/etunicorn-server.iml b/etunicorn-server.iml index f3e470d..39860dd 100644 --- a/etunicorn-server.iml +++ b/etunicorn-server.iml @@ -5,7 +5,6 @@ - @@ -29,90 +28,8 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -124,6 +41,7 @@ + @@ -143,7 +61,9 @@ + + @@ -158,25 +78,11 @@ - - - - - - - - - - - - - - - \ No newline at end of file + diff --git a/pom.xml b/pom.xml index 85cb0cb..27dc2ba 100644 --- a/pom.xml +++ b/pom.xml @@ -27,10 +27,6 @@ spring-boot-starter-test - org.springframework.boot - spring-boot-starter-security - - com.jayway.jsonpath json-path @@ -38,10 +34,6 @@ com.h2database h2 - - org.springframework.security.oauth - spring-security-oauth2 - diff --git a/src/main/java/etunicorn/CustomUserDetailsService.java b/src/main/java/etunicorn/CustomUserDetailsService.java deleted file mode 100644 index d89234d..0000000 --- a/src/main/java/etunicorn/CustomUserDetailsService.java +++ /dev/null @@ -1,76 +0,0 @@ -package etunicorn; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.security.core.GrantedAuthority; -import org.springframework.security.core.userdetails.UserDetails; -import org.springframework.security.core.userdetails.UserDetailsService; -import org.springframework.security.core.userdetails.UsernameNotFoundException; -import org.springframework.stereotype.Service; - -import java.util.Collection; - -/** - * Created by geoffrey on 29/01/17. - */ -@Service -public class CustomUserDetailsService implements UserDetailsService { - - private final PersonneRepository personneRepository; - - @Autowired - public CustomUserDetailsService(PersonneRepository personneRepository) { - this.personneRepository = personneRepository; - } - - @Override - public UserDetails loadUserByUsername(String login) throws UsernameNotFoundException { - Personne personne = personneRepository.findByLogin(login); - if (personne == null) { - throw new UsernameNotFoundException(String.format("L'utilisateur %s n'existe pas !", login)); - } - return new PersonneRepositoryUserDetails(personne); - } - - private final static class PersonneRepositoryUserDetails extends Personne implements UserDetails { - - public PersonneRepositoryUserDetails(Personne personne) { - super(personne); - } - - @Override - public Collection getAuthorities() { - // return getRoles(); - return null; - } - - @Override - public String getPassword() { - return "test"; - } - - @Override - public String getUsername() { - return getLogin(); - } - - @Override - public boolean isAccountNonExpired() { - return true; - } - - @Override - public boolean isAccountNonLocked() { - return true; - } - - @Override - public boolean isCredentialsNonExpired() { - return true; - } - - @Override - public boolean isEnabled() { - return true; - } - } -} diff --git a/src/main/java/etunicorn/OAuth2ServerConfiguration.java b/src/main/java/etunicorn/OAuth2ServerConfiguration.java deleted file mode 100644 index e7dc93e..0000000 --- a/src/main/java/etunicorn/OAuth2ServerConfiguration.java +++ /dev/null @@ -1,87 +0,0 @@ -package etunicorn; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Primary; -import org.springframework.security.authentication.AuthenticationManager; -import org.springframework.security.config.annotation.web.builders.HttpSecurity; -import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer; -import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter; -import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer; -import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer; -import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter; -import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer; -import org.springframework.security.oauth2.config.annotation.web.configurers.ResourceServerSecurityConfigurer; -import org.springframework.security.oauth2.provider.token.DefaultTokenServices; -import org.springframework.security.oauth2.provider.token.TokenStore; -import org.springframework.security.oauth2.provider.token.store.InMemoryTokenStore; - -/** - * Created by geoffrey on 29/01/17. - */ -@Configuration -public class OAuth2ServerConfiguration { - private static final String RESOURCE_ID = "etunicornservice"; - - @Configuration - @EnableResourceServer - protected static class ResourceServerConfiguration extends ResourceServerConfigurerAdapter { - - @Override - public void configure(ResourceServerSecurityConfigurer resources) { - resources.resourceId(RESOURCE_ID); - } - - @Override - public void configure(HttpSecurity http) throws Exception { - http.authorizeRequests() - .antMatchers("/personne").authenticated(); - } - } - - @Configuration - @EnableAuthorizationServer - protected static class AuthorizationServerConfiguration extends AuthorizationServerConfigurerAdapter { - - private TokenStore tokenStore = new InMemoryTokenStore(); - - @Autowired - @Qualifier("authenticationManagerBean") - private AuthenticationManager authenticationManager; - - @Autowired - private CustomUserDetailsService userDetailsService; - - @Override - public void configure(ClientDetailsServiceConfigurer clients) throws Exception { - clients - .inMemory() - .withClient("clientapp") - .authorizedGrantTypes("password", "refresh_token") - .authorities("USER") - .scopes("read", "write") - .resourceIds(RESOURCE_ID) - .secret("123456"); - } - - @Override - public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception { - endpoints - .tokenStore(this.tokenStore) - .authenticationManager(this.authenticationManager) - .userDetailsService(userDetailsService); - } - - @Bean - @Primary - public DefaultTokenServices tokenServices() { - DefaultTokenServices tokenServices = new DefaultTokenServices(); - tokenServices.setSupportRefreshToken(true); - tokenServices.setTokenStore(this.tokenStore); - return tokenServices; - } - } - -} diff --git a/src/main/java/etunicorn/Personne.java b/src/main/java/etunicorn/Personne.java index c431bda..ada8cd2 100644 --- a/src/main/java/etunicorn/Personne.java +++ b/src/main/java/etunicorn/Personne.java @@ -24,14 +24,6 @@ public class Personne { public Personne() { } - public Personne(Personne personne) { - super(); - this.id = personne.getId(); - this.carte = personne.getCarte(); - this.naissance = personne.getNaissance(); - this.login = personne.getLogin(); - } - public int getId() { return id; } diff --git a/src/main/java/etunicorn/PersonneController.java b/src/main/java/etunicorn/PersonneController.java index 92cda94..f4f41ae 100644 --- a/src/main/java/etunicorn/PersonneController.java +++ b/src/main/java/etunicorn/PersonneController.java @@ -5,11 +5,16 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; import java.math.BigDecimal; +import java.text.DateFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; +import java.util.Locale; /** * Created by geoffrey on 28/01/17. diff --git a/src/main/java/etunicorn/UserDetailsService.java b/src/main/java/etunicorn/UserDetailsService.java new file mode 100644 index 0000000..36242f7 --- /dev/null +++ b/src/main/java/etunicorn/UserDetailsService.java @@ -0,0 +1,11 @@ +package etunicorn; + +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.core.userdetails.UsernameNotFoundException; + +/** + * Created by geoffrey on 29/01/17. + */ +public interface UserDetailsService { + UserDetails loadByUsername(String s) throws UsernameNotFoundException; +} diff --git a/src/main/java/etunicorn/WebSecurityConfiguration.java b/src/main/java/etunicorn/WebSecurityConfiguration.java deleted file mode 100644 index 7b16e58..0000000 --- a/src/main/java/etunicorn/WebSecurityConfiguration.java +++ /dev/null @@ -1,33 +0,0 @@ -package etunicorn; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.security.authentication.AuthenticationManager; -import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; -import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; -import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; - -/** - * Created by geoffrey on 29/01/17. - */ -@Configuration -@EnableWebSecurity -public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter { - - @Autowired - private CustomUserDetailsService userDetailsService; - - @Override - protected void configure(AuthenticationManagerBuilder auth) throws Exception { - auth.userDetailsService(userDetailsService); - } - - @Override - @Bean - public AuthenticationManager authenticationManagerBean() throws Exception { - return super.authenticationManagerBean(); - } - - -} diff --git a/src/main/main.iml b/src/main/main.iml index eccadbc..e9ea5f1 100644 --- a/src/main/main.iml +++ b/src/main/main.iml @@ -25,8 +25,5 @@ - - - - \ No newline at end of file + -- libgit2 0.21.2