초기소스
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
package com.wb.domainserver.security.user;
|
||||
|
||||
|
||||
import org.springframework.security.authentication.AbstractAuthenticationToken;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public class CustomAuthenticationToken extends AbstractAuthenticationToken {
|
||||
|
||||
|
||||
private final UserDetails principal;
|
||||
|
||||
public CustomAuthenticationToken(UserDetails principal, Collection<? extends GrantedAuthority> authorities) {
|
||||
super(authorities);
|
||||
this.principal = principal;
|
||||
setAuthenticated(true); // 인증 상태 적용
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getCredentials() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getPrincipal() {
|
||||
return this.principal;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,253 @@
|
||||
package com.wb.domainserver.security.user;
|
||||
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public class SecurityUser implements UserDetails {
|
||||
private String id;
|
||||
private String mbrId;
|
||||
private String sopmalCd;
|
||||
private String mbrDvCd;
|
||||
private long userInnb;
|
||||
private String userName;
|
||||
private String mbtlnb;
|
||||
private String accessUrl;
|
||||
private String clientId;
|
||||
private String originalHost;
|
||||
private String sysDvCd;
|
||||
private String tentGroup;
|
||||
private String reprsntBrand;
|
||||
private String teamInnb;
|
||||
private String mngrDv;
|
||||
private String tentcpnNm;
|
||||
private String itrntDv;
|
||||
private String strOperDv;
|
||||
|
||||
|
||||
public String getItrntDv() {
|
||||
return itrntDv;
|
||||
}
|
||||
|
||||
public void setItrntDv(String itrntDv) {
|
||||
this.itrntDv = itrntDv;
|
||||
}
|
||||
|
||||
public String getStrOperDv() {
|
||||
return strOperDv;
|
||||
}
|
||||
|
||||
public void setStrOperDv(String strOperDv) {
|
||||
this.strOperDv = strOperDv;
|
||||
}
|
||||
|
||||
|
||||
public String getTentcpnNm() {
|
||||
return tentcpnNm;
|
||||
}
|
||||
|
||||
public void setTentcpnNm(String tentcpnNm) {
|
||||
this.tentcpnNm = tentcpnNm;
|
||||
}
|
||||
|
||||
|
||||
private List<GrantedAuthority> grantedAuthorityList;
|
||||
private boolean accessToRestrictedPolicy;
|
||||
|
||||
public static SecurityUser builder() {
|
||||
return new SecurityUser();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public SecurityUser withAccessToRestrictedPolicy(boolean restrictedPolicy) {
|
||||
this.accessToRestrictedPolicy = restrictedPolicy;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean hasAccessToRestrictedPolicy() {
|
||||
return accessToRestrictedPolicy;
|
||||
}
|
||||
|
||||
public SecurityUser withGrantedAuthorityList(List<GrantedAuthority> grantedAuthorityList) {
|
||||
this.grantedAuthorityList = grantedAuthorityList;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<? extends GrantedAuthority> getAuthorities() {
|
||||
return this.grantedAuthorityList;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public String getPassword() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsername() {
|
||||
return this.userName;
|
||||
}
|
||||
|
||||
public SecurityUser withUserInnb(long userInnb) {
|
||||
this.userInnb = userInnb;
|
||||
return this;
|
||||
}
|
||||
|
||||
public long getUserInnb() {
|
||||
return this.userInnb;
|
||||
}
|
||||
|
||||
public String getMbrDvCd() { return mbrDvCd; }
|
||||
|
||||
public SecurityUser withMbrDvCd(String mbrDvCd) {
|
||||
this.mbrDvCd = mbrDvCd;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAccountNonExpired() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAccountNonLocked() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCredentialsNonExpired() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public SecurityUser withId(String id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public SecurityUser withUserName(String userName) {
|
||||
this.userName = userName;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SecurityUser withMbtlnb(String mbtlnb) {
|
||||
this.mbtlnb = mbtlnb;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SecurityUser withSopmalCd(String sopmalCd) {
|
||||
this.sopmalCd = sopmalCd;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SecurityUser withAccessUrl(String accessUrl) {
|
||||
this.accessUrl = accessUrl;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SecurityUser withClientId(String clientId) {
|
||||
this.clientId = clientId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SecurityUser withOriginalHost(String originalHost) {
|
||||
this.originalHost = originalHost;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SecurityUser withSysDvCd(String sysDvCd) {
|
||||
this.sysDvCd = sysDvCd;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SecurityUser withMngrDv(String mngrDv) {
|
||||
this.mngrDv = mngrDv;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SecurityUser withTeamInnb(String teamInnb) {
|
||||
this.teamInnb = teamInnb;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SecurityUser withTentGroup(String tentGroup) {
|
||||
this.tentGroup = tentGroup;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SecurityUser withReprsntBrand(String reprsntBrand) {
|
||||
this.reprsntBrand = reprsntBrand;
|
||||
return this;
|
||||
}
|
||||
public SecurityUser withTentcpnNm(String tentcpnNm) {
|
||||
this.tentcpnNm = tentcpnNm;
|
||||
return this;
|
||||
}
|
||||
public SecurityUser withItrntDv(String itrntDv) {
|
||||
this.itrntDv = itrntDv;
|
||||
return this;
|
||||
}
|
||||
public SecurityUser withStrOperDv(String strOperDv) {
|
||||
this.strOperDv = strOperDv;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public String getSopmalCd() {
|
||||
return this.sopmalCd;
|
||||
|
||||
}
|
||||
|
||||
public String getMbtlnb() {
|
||||
return this.mbtlnb;
|
||||
}
|
||||
|
||||
public String getAccessUrl() {
|
||||
return this.accessUrl;
|
||||
}
|
||||
|
||||
public String getClientId() {
|
||||
return this.clientId;
|
||||
}
|
||||
|
||||
public String getOriginalHost() {
|
||||
return this.originalHost;
|
||||
}
|
||||
|
||||
public String getSysDvCd() {
|
||||
return this.sysDvCd;
|
||||
}
|
||||
|
||||
public String getTentGroup() {
|
||||
return this.tentGroup;
|
||||
}
|
||||
|
||||
public String getReprsntBrand() {
|
||||
return this.reprsntBrand;
|
||||
}
|
||||
|
||||
public SecurityUser withMbrId(String mbrId) {
|
||||
this.mbrId = mbrId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getMbrId() {return this.mbrId;}
|
||||
public String getTeamInnb() {return this.teamInnb;}
|
||||
public String getMngrDv() {
|
||||
return this.mngrDv;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
package com.wb.domainserver.security.user;
|
||||
|
||||
import com.wb.domainserver.realm.RealmContextHolder;
|
||||
import com.wb.domainserver.security.authentication.MemberJwtToken;
|
||||
import com.wb.domainserver.security.jwt.handler.JwtHelper;
|
||||
import com.wb.domainserver.security.jwt.vo.TokenInfo;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class SecurityUserDetailService implements UserDetailsService {
|
||||
|
||||
private final SecurityUserMapper securityUserMapper;
|
||||
|
||||
private final JwtHelper accessTokenHelper;
|
||||
|
||||
public SecurityUserDetailService(
|
||||
SecurityUserMapper securityUserMapper, JwtHelper accessTokenHelper){
|
||||
this.securityUserMapper = securityUserMapper;
|
||||
this.accessTokenHelper = accessTokenHelper ;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserDetails loadUserByUsername(String accessToken) throws UsernameNotFoundException {
|
||||
|
||||
// accessToken 만료여부 일경우 CustomAuthenticationEntryPoint 처리 유도
|
||||
if(accessTokenHelper.expireToken(accessToken)){
|
||||
return null;
|
||||
}
|
||||
|
||||
//accessToken DB 조회 검증
|
||||
//존재 하지 않을 경우 인증 실패
|
||||
MemberJwtToken token = accessTokenHelper.parse(accessToken);
|
||||
String realm = RealmContextHolder.getRealm().toLowerCase();
|
||||
TokenInfo accessTokenInfo = new TokenInfo("ACT", accessToken, token.getUserInnb(), realm);
|
||||
if(securityUserMapper.validateAccessToken(accessTokenInfo)){
|
||||
return null;
|
||||
}
|
||||
|
||||
return tokenToUserDetails(token);
|
||||
|
||||
|
||||
}
|
||||
|
||||
private UserDetails tokenToUserDetails (MemberJwtToken token) {
|
||||
|
||||
|
||||
|
||||
return SecurityUser.builder()
|
||||
.withId(token.getId())
|
||||
.withMbrId(token.getMbrId())
|
||||
.withSopmalCd(token.getSopmalCd())
|
||||
.withMbrDvCd(token.getMbrDvCd())
|
||||
.withUserInnb(token.getUserInnb())
|
||||
.withUserName(token.getMbrNm())
|
||||
.withMbtlnb(token.getMbtlnb())
|
||||
.withAccessUrl(token.getAccessUrl())
|
||||
.withClientId(token.getClientId())
|
||||
.withSysDvCd(token.getSysDvCd())
|
||||
.withMngrDv(token.getMngrDv())
|
||||
.withTentcpnNm(token.getTentcpnNm())
|
||||
.withItrntDv(token.getItrntDv())
|
||||
.withStrOperDv(token.getStrOperDv())
|
||||
// .withTentGroup(token.getTentGroup())
|
||||
// .withReprsntBrand(token.getReprsntBrand())
|
||||
.withGrantedAuthorityList(token.getRoleType().stream()
|
||||
.map(SimpleGrantedAuthority::new)
|
||||
.collect(Collectors.toList())
|
||||
)
|
||||
.withAccessToRestrictedPolicy(checkRestrictedPolicy());
|
||||
}
|
||||
|
||||
|
||||
private boolean checkRestrictedPolicy() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public String getGrantType(String token) {
|
||||
return securityUserMapper.getGrantType(token);
|
||||
}
|
||||
|
||||
public List<String> getAvailablePathList(SecurityUser user) {
|
||||
return securityUserMapper.getAvailablePathList(user);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.wb.domainserver.security.user;
|
||||
|
||||
import com.wb.domainserver.security.jwt.vo.TokenInfo;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Mapper
|
||||
@Repository
|
||||
public interface SecurityUserMapper {
|
||||
Map<String, Object> loadUserByUsername(Map<String, Object> username);
|
||||
|
||||
String getGrantType(String token);
|
||||
|
||||
List<String> getAvailablePathList(SecurityUser user);
|
||||
|
||||
Map<String, Object> loadUserByManagername(String username);
|
||||
|
||||
String loadUsernameByToken(Map<String, Object> data);
|
||||
|
||||
boolean validateAccessToken(TokenInfo tokenInfo);
|
||||
}
|
||||
Reference in New Issue
Block a user