Skip to content

Commit

Permalink
fix: security permition to all endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
Hsbalazs committed Jul 2, 2024
1 parent 19c689a commit 1db3da5
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.springframework.context.annotation.Configuration;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

/**
* Configuration class for setting up application-wide beans.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.greenfoxacademy.backend.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.web.SecurityFilterChain;

import static org.springframework.security.config.Customizer.withDefaults;

Check warning on line 9 in backend/src/main/java/com/greenfoxacademy/backend/config/SecurityConfig.java

View workflow job for this annotation

GitHub Actions / build

[testtool] reported by reviewdog 🐶 Import statement for 'org.springframework.security.config.Customizer.withDefaults' is in the wrong order. Should be in the 'STATIC' group, expecting not assigned imports on this line. Raw Output: /github/workspace/./backend/src/main/java/com/greenfoxacademy/backend/config/SecurityConfig.java:9:1: warning: Import statement for 'org.springframework.security.config.Customizer.withDefaults' is in the wrong order. Should be in the 'STATIC' group, expecting not assigned imports on this line. (com.puppycrawl.tools.checkstyle.checks.imports.CustomImportOrderCheck)

@Configuration

Check warning on line 11 in backend/src/main/java/com/greenfoxacademy/backend/config/SecurityConfig.java

View workflow job for this annotation

GitHub Actions / build

[testtool] reported by reviewdog 🐶 Missing a Javadoc comment. Raw Output: /github/workspace/./backend/src/main/java/com/greenfoxacademy/backend/config/SecurityConfig.java:11:1: warning: Missing a Javadoc comment. (com.puppycrawl.tools.checkstyle.checks.javadoc.MissingJavadocTypeCheck)
@EnableWebSecurity(debug = true)
public class SecurityConfig {

@Bean

Check warning on line 15 in backend/src/main/java/com/greenfoxacademy/backend/config/SecurityConfig.java

View workflow job for this annotation

GitHub Actions / build

[testtool] reported by reviewdog 🐶 Missing a Javadoc comment. Raw Output: /github/workspace/./backend/src/main/java/com/greenfoxacademy/backend/config/SecurityConfig.java:15:3: warning: Missing a Javadoc comment. (com.puppycrawl.tools.checkstyle.checks.javadoc.MissingJavadocMethodCheck)
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
// @formatter:off
http
.authorizeHttpRequests((authorize) -> authorize
.anyRequest().permitAll()
)
.httpBasic(withDefaults())
.formLogin(withDefaults());
// @formatter:on
return http.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,27 @@
@Service
@RequiredArgsConstructor
public class UserServiceImpl implements UserService {
private final PasswordEncoder passwordEncoder;

private final UserRepository userRepository;
private ModelMapper modelMapper;

@Override
public void register(RegisterUserDto userDto) {
User user = this.mapToEntity(userDto);
user.setPassword(passwordEncoder.encode(userDto.getPassword()));
userRepository.save(user);
}

private RegisterUserDto mapToDto(User user) {
RegisterUserDto registerUserDto = modelMapper.map(user, RegisterUserDto.class);
return registerUserDto;
}

private User mapToEntity(RegisterUserDto userDto) {
User user = modelMapper.map(userDto, User.class);
return user;
}
private final PasswordEncoder passwordEncoder;

private final UserRepository userRepository;
private ModelMapper modelMapper;

@Override
public void register(RegisterUserDto userDto) {
User user = this.mapToEntity(userDto);
user.setPassword(passwordEncoder.encode(userDto.getPassword()));
userRepository.save(user);
}

private RegisterUserDto mapToDto(User user) {
RegisterUserDto registerUserDto = modelMapper.map(user, RegisterUserDto.class);
return registerUserDto;
}

private User mapToEntity(RegisterUserDto userDto) {
User user = modelMapper.map(userDto, User.class);
return user;
}
}


0 comments on commit 1db3da5

Please sign in to comment.