类改名

This commit is contained in:
79493 2022-10-10 16:22:53 +08:00
parent a109fec720
commit 4323c9394f
6 changed files with 16 additions and 12 deletions

View File

@ -12,7 +12,7 @@ import java.util.Collection;
* @date 2022/9/28 * @date 2022/9/28
* */ * */
public class EntUserDetails extends User { public class UserDetailsAndId extends User {
private String id; private String id;
@ -25,7 +25,7 @@ public class EntUserDetails extends User {
this.id = id; this.id = id;
} }
public EntUserDetails(String username, String password, Collection<? extends GrantedAuthority> authorities,String id) { public UserDetailsAndId(String username, String password, Collection<? extends GrantedAuthority> authorities,String id) {
super(username, password, authorities); super(username, password, authorities);
setId(id); setId(id);
} }

View File

@ -1,6 +1,7 @@
package com.rzyc.service; package com.rzyc.service;
import com.rzyc.config.EntUserDetails;
import com.rzyc.config.UserDetailsAndId;
import com.rzyc.mapper.AuthorityKeyMapper; import com.rzyc.mapper.AuthorityKeyMapper;
import com.rzyc.mapper.ent.EntUserMapper; import com.rzyc.mapper.ent.EntUserMapper;
import com.rzyc.model.AuthorityKey; import com.rzyc.model.AuthorityKey;
@ -65,7 +66,7 @@ public class UserDetailsServiceImpl implements UserDetailsService {
stringBuilder.append(s.getCategory() +":"+s.getAuthKey()); stringBuilder.append(s.getCategory() +":"+s.getAuthKey());
authority.add(new SimpleGrantedAuthority(stringBuilder.toString())); authority.add(new SimpleGrantedAuthority(stringBuilder.toString()));
} }
return new EntUserDetails(entUser.getName(), passwordEncoder.encode(entUser.getPasswd()), authority,entUser.getEntUserId()); return new UserDetailsAndId(entUser.getName(), passwordEncoder.encode(entUser.getPasswd()), authority,entUser.getEntUserId());
} }
} }

View File

@ -2,7 +2,8 @@ package com.rzyc.service;
import com.common.utils.jwt.JwtUtil; import com.common.utils.jwt.JwtUtil;
import com.rzyc.config.EntUserDetails;
import com.rzyc.config.UserDetailsAndId;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.BadCredentialsException; import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
@ -51,7 +52,7 @@ public class UserLoginService {
UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(userDetails, null, userDetails.getAuthorities()); UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(userDetails, null, userDetails.getAuthorities());
SecurityContextHolder.getContext().setAuthentication(authentication); SecurityContextHolder.getContext().setAuthentication(authentication);
//企业用户id //企业用户id
String id = ((EntUserDetails)SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getId(); String id = ((UserDetailsAndId)SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getId();
token = JwtUtil.createToken(id); token = JwtUtil.createToken(id);
} catch (AuthenticationException e) { } catch (AuthenticationException e) {
e.printStackTrace(); e.printStackTrace();

View File

@ -12,7 +12,7 @@ import java.util.Collection;
* @date 2022/9/28 * @date 2022/9/28
* */ * */
public class EntUserDetails extends User { public class UserDetailsAndId extends User {
private String id; private String id;
@ -25,7 +25,7 @@ public class EntUserDetails extends User {
this.id = id; this.id = id;
} }
public EntUserDetails(String username, String password, Collection<? extends GrantedAuthority> authorities, String id) { public UserDetailsAndId(String username, String password, Collection<? extends GrantedAuthority> authorities, String id) {
super(username, password, authorities); super(username, password, authorities);
setId(id); setId(id);
} }

View File

@ -1,6 +1,7 @@
package com.rzyc.service; package com.rzyc.service;
import com.rzyc.config.EntUserDetails;
import com.rzyc.config.UserDetailsAndId;
import com.rzyc.mapper.AuthorityKeyMapper; import com.rzyc.mapper.AuthorityKeyMapper;
import com.rzyc.mapper.ent.EntUserMapper; import com.rzyc.mapper.ent.EntUserMapper;
import com.rzyc.model.AuthorityKey; import com.rzyc.model.AuthorityKey;
@ -65,7 +66,7 @@ public class UserDetailsServiceImpl implements UserDetailsService {
stringBuilder.append(s.getCategory() +":"+s.getAuthKey()); stringBuilder.append(s.getCategory() +":"+s.getAuthKey());
authority.add(new SimpleGrantedAuthority(stringBuilder.toString())); authority.add(new SimpleGrantedAuthority(stringBuilder.toString()));
} }
return new EntUserDetails(entUser.getName(), passwordEncoder.encode(entUser.getPasswd()), authority,entUser.getEntUserId()); return new UserDetailsAndId(entUser.getName(), passwordEncoder.encode(entUser.getPasswd()), authority,entUser.getEntUserId());
} }
} }

View File

@ -2,7 +2,8 @@ package com.rzyc.service;
import com.common.utils.jwt.JwtUtil; import com.common.utils.jwt.JwtUtil;
import com.rzyc.config.EntUserDetails;
import com.rzyc.config.UserDetailsAndId;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.BadCredentialsException; import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
@ -52,7 +53,7 @@ public class UserLoginService {
UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(userDetails, null, userDetails.getAuthorities()); UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(userDetails, null, userDetails.getAuthorities());
SecurityContextHolder.getContext().setAuthentication(authentication); SecurityContextHolder.getContext().setAuthentication(authentication);
//企业用户id //企业用户id
String id = ((EntUserDetails)SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getId(); String id = ((UserDetailsAndId)SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getId();
token = JwtUtil.createToken(id); token = JwtUtil.createToken(id);
} catch (AuthenticationException e) { } catch (AuthenticationException e) {
e.printStackTrace(); e.printStackTrace();