使用默认的密码加密方式
This commit is contained in:
+2
-2
@@ -1,10 +1,10 @@
|
||||
package com.micro.fast.security.browser.config;
|
||||
|
||||
import com.micro.fast.security.browser.service.MsPasswordEncode;
|
||||
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.WebSecurityConfigurerAdapter;
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
|
||||
/**
|
||||
@@ -37,7 +37,7 @@ public class BrowserSecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
*/
|
||||
@Bean
|
||||
public PasswordEncoder passwordEncoder(){
|
||||
return new MsPasswordEncode();
|
||||
return new BCryptPasswordEncoder();
|
||||
}
|
||||
|
||||
|
||||
|
||||
-39
@@ -1,39 +0,0 @@
|
||||
package com.micro.fast.security.browser.service;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
||||
/**
|
||||
* Created by root on 12/4/17.
|
||||
* 处理密码的校验
|
||||
*/
|
||||
@Service
|
||||
public class MsPasswordEncode implements PasswordEncoder {
|
||||
private static final Logger log = LoggerFactory.getLogger(PasswordEncoder.class);
|
||||
/**
|
||||
* 在注册用户的时候进行密码的加密,这个方法是自己调的spring security不会自己调用,需要自己在合适的地方调用
|
||||
* @param charSequence
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String encode(CharSequence charSequence) {
|
||||
log.info("encode{}",charSequence.toString());
|
||||
return charSequence.toString()+"1";
|
||||
}
|
||||
|
||||
/**
|
||||
* 定义自己的密码校验逻辑,这个方法spring security会在登录的时候自己调用
|
||||
* @param charSequence 用户输入的密码
|
||||
* @param s 从根据用户名获取密码的逻辑中返回的密码
|
||||
*/
|
||||
@Override
|
||||
public boolean matches(CharSequence charSequence, String s) {
|
||||
if (encode(charSequence).equals(s)){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
+5
-4
@@ -9,14 +9,13 @@ import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* Created by root on 12/4/17.
|
||||
*
|
||||
*/
|
||||
@Service
|
||||
@Component
|
||||
public class MsUserDetialsService implements UserDetailsService {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(MsUserDetialsService.class);
|
||||
@@ -32,7 +31,9 @@ public class MsUserDetialsService implements UserDetailsService {
|
||||
@Override
|
||||
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
|
||||
log.info("根据username:{}获取密码",username);
|
||||
//从数据库中去查找用户的密码 1112 是从数据库中查询出来的用户的密码
|
||||
//从数据库中去查找用户的密码 1112 是从数据库中查询出来的用户的密
|
||||
return new User(username,passwordEncoder.encode("1112"), AuthorityUtils.commaSeparatedStringToAuthorityList("admin"));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
+1
@@ -13,3 +13,4 @@ spring:
|
||||
# basic:
|
||||
# enabled: true
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user