반응형
SpringBoot Security를 이용하여, HTML에서 회원가입 시, DB저장 및 로그인 이용했는데
sha512를 적용하기로 하여 Security에서 제공하는 암호화를 사용하지 않기로함!
(tmi. js에서 sha512로 회원가입/ java에서 sha512로 로그인)
근데.. SpringBoot에서 Security의 사용버전(?)에 따라 패스워드 인코딩을 꼭 써줘야한다고 해서
발생했던 오류로는
there is no passwordencoder mapped for the id "null"
안쓸경우엔 {noop}을 password에 붙여야한다고 하는 해결방안이 있어서 적용했으나, 뭔가 로직이 꼬인듯 잘못 작성한건지
This application has no explicit mapping for /error, so you are seeing this as a fallback.
해당오류가 발생하고, 페이지를 못불러왔다.ㅠㅠ
암호화한 패스워드 앞에 {noop} 를 붙이는것보다 바람직한 해결방법
SecurityConfig.java
- NoOpPasswordEncoder 관련하여 취소선 그어지니 참조!
import org.springframework.security.crypto.password.NoOpPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
@Configuration
@EnableWebSecurity
@AllArgsConstructor
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired private AdminService adminService;
.
.
(중략)
.
.
@Override
public void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(new UserDetailsService() {
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
// TODO Auto-generated method stub
return (UserDetails)adminService.loadUserByUsername(username);
}
});
}
@Bean
public PasswordEncoder NoOpPasswordEncoder(){
return NoOpPasswordEncoder.getInstance();
}
[참고용]
AdminService.java
@Service
@RequiredArgsConstructor
public class AdminService implements UserDetailsService {
@Autowired
private AdminRepository adminRepository;
@Override
public UserDetails loadUserByUsername(String userid) throws UsernameNotFoundException {
Optional<AdminEntity> adminEntityWrapper = adminRepository.findByUserID(userid);
AdminEntity adminEntity = adminEntityWrapper.get();
List<GrantedAuthority> authorities = new ArrayList<>();
if (("admin").equals(userid) )
authorities.add(new SimpleGrantedAuthority(Role.ADMIN.getValue()));
System.out.println(adminEntity.getPassword());
return new User(adminEntity.getUserID(), adminEntity.getPassword(), authorities);
}
.
.
}
login.html
<form class="login100-form validate-form" th:action="@{/login}" method="post">
<input type="hidden" th:name="${_csrf.parameterName}" th:value="${_csrf.token}" />
<div class="wrap-input100 validate-input m-b-26" data-validate="UserID is required">
<input class="input100" type="text" name="userid" placeholder="Enter UserID">
</div>
<div class="wrap-input100 validate-input m-b-18" data-validate="Password is required">
<input class="input100" type="password" name="password" placeholder="Enter password" autocomplete="off">
</div>
.
.
<div class="container-login100-form-btn">
<button class="login100-form-btn" style="min-width: 130px; margin-right: 5%" type="submit">
Login
</button>
</div>
</form>
728x90
반응형
'개발아닌개발 > springboot' 카테고리의 다른 글
Autowired 안 될때 Bean 주입받아 해결하기(autowired Class is null 문제해결) (0) | 2022.01.10 |
---|---|
간단하게 Height 100%로 PDF viewer 만들기(PDFObject) (0) | 2022.01.05 |
[오류] Web server failed to start. Port 8080 was already in use. (0) | 2021.11.23 |
Map<String, Object>의 안에 Object를 int로 바꾸는 방법 (2) | 2021.11.10 |
[오류] JPA를 이용하여 UPDATE @query 사용 시, No results were returned by the query (0) | 2021.11.08 |
댓글