Skip to content

Commit

Permalink
Format code with standardjs, prettier and google-java-format
Browse files Browse the repository at this point in the history
This commit fixes the style issues introduced in 001f560 according to the output
from standardjs, prettier and google-java-format.

Details: https://deepsource.io/gh/DaNaRim/smart-parking/transform/5eb11e3e-e771-4432-bbba-372170d5c9a3/
  • Loading branch information
deepsource-autofix[bot] committed Sep 8, 2022
1 parent 001f560 commit d3c89c4
Showing 1 changed file with 91 additions and 92 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.explorers.smartparking.config.security;

import static com.explorers.smartparking.config.spring.MvcConfig.RESOURCES;

import com.explorers.smartparking.user.persistence.model.RoleName;
import com.explorers.smartparking.user.web.failHandler.AuthenticationFailureHandler;
import java.util.concurrent.TimeUnit;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
Expand All @@ -11,100 +14,96 @@
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

import java.util.concurrent.TimeUnit;

import static com.explorers.smartparking.config.spring.MvcConfig.RESOURCES;

@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

private final AuthenticationFailureHandler authenticationFailureHandler;
private final UserDetailsServiceImpl userDetailsService;
private final SecurityProperties securityProperties;

public SecurityConfig(AuthenticationFailureHandler authenticationFailureHandler,
UserDetailsServiceImpl userDetailsService,
SecurityProperties securityProperties) {
this.authenticationFailureHandler = authenticationFailureHandler;
this.userDetailsService = userDetailsService;
this.securityProperties = securityProperties;
}

//skipcq: JAVA-W1042
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userDetailsService);
}

//skipcq: JAVA-W1042
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.mvcMatchers(
RESOURCES.stream()
.map(resource -> "/" + resource + "/**")
.toArray(String[]::new)
).permitAll()
.mvcMatchers(
"/", "/{lang}",
"/login", "/{lang}/login",
"/registration", "/{lang}/registration",
"/registerUser",
"/registrationConfirm",
"/resendRegistrationToken",
"/forgotPassword",
"/sendPassResetToken",
"/resetPasswordPage",
"/updateForgotPassword",
"/updateForgottenPassword",
"/errors/badToken").permitAll()
.mvcMatchers(
"/user/**",
"/parking",
"/park/**").hasRole(RoleName.USER.name())
.mvcMatchers("/guard/**").hasRole(RoleName.GUARD.name())
.mvcMatchers("/parkAdmin/**").hasRole(RoleName.ADMIN.name())
.mvcMatchers("/superAdmin/**").hasRole(RoleName.SUPER_ADMIN.name())
.anyRequest().authenticated()

.and()
.csrf()


// .and()
// .exceptionHandling()
// .accessDeniedPage("/forbidden")

.and()
.formLogin()
.loginPage("/login").permitAll()
.usernameParameter("username")
.passwordParameter("password")
.defaultSuccessUrl("/parking", true)
.failureHandler(authenticationFailureHandler)

.and()
.logout()
.clearAuthentication(true)
.invalidateHttpSession(true)
.logoutUrl("/logout")
.logoutSuccessUrl("/login")
.deleteCookies("JSESSIONID", "remember-me")

.and()
.rememberMe()
.key(securityProperties.rememberMeKey())
.rememberMeParameter("remember-me")
.tokenValiditySeconds((int) TimeUnit.DAYS.toSeconds(21))
.userDetailsService(userDetailsService)
.useSecureCookie(true);
}

@Bean
public PasswordEncoder encoder() {
return new BCryptPasswordEncoder(11);
}

private final AuthenticationFailureHandler authenticationFailureHandler;
private final UserDetailsServiceImpl userDetailsService;
private final SecurityProperties securityProperties;

public SecurityConfig(
AuthenticationFailureHandler authenticationFailureHandler,
UserDetailsServiceImpl userDetailsService,
SecurityProperties securityProperties) {
this.authenticationFailureHandler = authenticationFailureHandler;
this.userDetailsService = userDetailsService;
this.securityProperties = securityProperties;
}

// skipcq: JAVA-W1042
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userDetailsService);
}

// skipcq: JAVA-W1042
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.mvcMatchers(
RESOURCES.stream().map(resource -> "/" + resource + "/**").toArray(String[]::new))
.permitAll()
.mvcMatchers(
"/",
"/{lang}",
"/login",
"/{lang}/login",
"/registration",
"/{lang}/registration",
"/registerUser",
"/registrationConfirm",
"/resendRegistrationToken",
"/forgotPassword",
"/sendPassResetToken",
"/resetPasswordPage",
"/updateForgotPassword",
"/updateForgottenPassword",
"/errors/badToken")
.permitAll()
.mvcMatchers("/user/**", "/parking", "/park/**")
.hasRole(RoleName.USER.name())
.mvcMatchers("/guard/**")
.hasRole(RoleName.GUARD.name())
.mvcMatchers("/parkAdmin/**")
.hasRole(RoleName.ADMIN.name())
.mvcMatchers("/superAdmin/**")
.hasRole(RoleName.SUPER_ADMIN.name())
.anyRequest()
.authenticated()
.and()
.csrf()

// .and()
// .exceptionHandling()
// .accessDeniedPage("/forbidden")

.and()
.formLogin()
.loginPage("/login")
.permitAll()
.usernameParameter("username")
.passwordParameter("password")
.defaultSuccessUrl("/parking", true)
.failureHandler(authenticationFailureHandler)
.and()
.logout()
.clearAuthentication(true)
.invalidateHttpSession(true)
.logoutUrl("/logout")
.logoutSuccessUrl("/login")
.deleteCookies("JSESSIONID", "remember-me")
.and()
.rememberMe()
.key(securityProperties.rememberMeKey())
.rememberMeParameter("remember-me")
.tokenValiditySeconds((int) TimeUnit.DAYS.toSeconds(21))
.userDetailsService(userDetailsService)
.useSecureCookie(true);
}

@Bean
public PasswordEncoder encoder() {
return new BCryptPasswordEncoder(11);
}
}

0 comments on commit d3c89c4

Please sign in to comment.