-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from kungfuwushu/authentication
web services signup/signin
- Loading branch information
Showing
27 changed files
with
1,005 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
{ | ||
"java.configuration.updateBuildConfiguration": "automatic" | ||
"java.configuration.updateBuildConfiguration": "automatic", | ||
"files.exclude": { | ||
"**/.classpath": true, | ||
"**/.project": true, | ||
"**/.settings": true, | ||
"**/.factorypath": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
src/main/java/fr/kungfunantes/backend/config/SecurityConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package fr.kungfunantes.backend.config; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.http.HttpMethod; | ||
import org.springframework.security.authentication.AuthenticationManager; | ||
import org.springframework.security.config.BeanIds; | ||
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; | ||
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; | ||
import org.springframework.security.config.annotation.web.builders.HttpSecurity; | ||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; | ||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; | ||
import org.springframework.security.config.http.SessionCreationPolicy; | ||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; | ||
import org.springframework.security.crypto.password.PasswordEncoder; | ||
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; | ||
|
||
import fr.kungfunantes.backend.security.CustomUserDetailsService; | ||
import fr.kungfunantes.backend.security.JwtAuthenticationEntryPoint; | ||
import fr.kungfunantes.backend.security.JwtAuthenticationFilter; | ||
|
||
@Configuration | ||
@EnableWebSecurity | ||
@EnableGlobalMethodSecurity(securedEnabled = true, jsr250Enabled = true, prePostEnabled = true) | ||
public class SecurityConfig extends WebSecurityConfigurerAdapter { | ||
@Autowired | ||
CustomUserDetailsService customUserDetailsService; | ||
|
||
@Autowired | ||
private JwtAuthenticationEntryPoint unauthorizedHandler; | ||
|
||
@Bean | ||
public JwtAuthenticationFilter jwtAuthenticationFilter() { | ||
return new JwtAuthenticationFilter(); | ||
} | ||
|
||
@Override | ||
public void configure(AuthenticationManagerBuilder authenticationManagerBuilder) throws Exception { | ||
authenticationManagerBuilder.userDetailsService(customUserDetailsService).passwordEncoder(getPasswordEncoder()); | ||
} | ||
|
||
@Bean(BeanIds.AUTHENTICATION_MANAGER) | ||
@Override | ||
public AuthenticationManager authenticationManagerBean() throws Exception { | ||
return super.authenticationManagerBean(); | ||
} | ||
|
||
@Bean | ||
protected PasswordEncoder getPasswordEncoder() { | ||
return new BCryptPasswordEncoder(); | ||
} | ||
|
||
@Override | ||
protected void configure(HttpSecurity http) throws Exception { | ||
//@formatter:off | ||
http | ||
.cors() | ||
.and() | ||
.csrf() | ||
.disable() | ||
.exceptionHandling() | ||
.authenticationEntryPoint(unauthorizedHandler) | ||
.and() | ||
.sessionManagement() | ||
.sessionCreationPolicy(SessionCreationPolicy.STATELESS) | ||
.and() | ||
.authorizeRequests() | ||
.antMatchers("/", | ||
"/favicon.ico", | ||
"/**/*.png", | ||
"/**/*.gif", | ||
"/**/*.svg", | ||
"/**/*.jpg", | ||
"/**/*.html", | ||
"/**/*.css", | ||
"/**/*.js") | ||
.permitAll() | ||
.antMatchers("/auth/**") | ||
.permitAll() | ||
.antMatchers("/user/checkUsernameAvailability", "/user/checkEmailAvailability") | ||
.permitAll() | ||
.antMatchers(HttpMethod.GET, "/groups/**", "/users/**") | ||
.permitAll() | ||
.anyRequest() | ||
.authenticated(); | ||
//@formatter:on | ||
|
||
// Add our custom JWT security filter | ||
http.addFilterBefore(jwtAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/main/java/fr/kungfunantes/backend/exception/AppException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package fr.kungfunantes.backend.exception; | ||
|
||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
|
||
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) | ||
public class AppException extends RuntimeException { | ||
private static final long serialVersionUID = 1L; | ||
|
||
public AppException(String message) { | ||
super(message); | ||
} | ||
|
||
public AppException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/fr/kungfunantes/backend/exception/BadRequestException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package fr.kungfunantes.backend.exception; | ||
|
||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
|
||
@ResponseStatus(HttpStatus.BAD_REQUEST) | ||
public class BadRequestException extends RuntimeException { | ||
private static final long serialVersionUID = 1L; | ||
|
||
public BadRequestException(String message) { | ||
super(message); | ||
} | ||
|
||
public BadRequestException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
} |
Oops, something went wrong.