사용자 등록시 권한 부여
This commit is contained in:
+2
-1
@@ -3,13 +3,14 @@ package com.eactive.httpmockserver.common.exception;
|
|||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||||
import org.springframework.web.context.request.WebRequest;
|
import org.springframework.web.context.request.WebRequest;
|
||||||
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;
|
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
@RestControllerAdvice
|
@RestControllerAdvice(annotations = RestController.class)
|
||||||
public class CustomGlobalExceptionHandler extends ResponseEntityExceptionHandler {
|
public class CustomGlobalExceptionHandler extends ResponseEntityExceptionHandler {
|
||||||
|
|
||||||
@ExceptionHandler(NotFoundException.class)
|
@ExceptionHandler(NotFoundException.class)
|
||||||
|
|||||||
+1
-1
@@ -55,7 +55,7 @@ public class AuthenticInterceptor implements AsyncHandlerInterceptor {
|
|||||||
boolean found = findPattern(request.getRequestURI());
|
boolean found = findPattern(request.getRequestURI());
|
||||||
|
|
||||||
if (found) {
|
if (found) {
|
||||||
if (currentUser.getUserSecurity() != null && "ROLE_ADMIN".equals(currentUser.getUserSecurity().getAuthorCode())) {
|
if (currentUser.getUserSecurity() != null && "ROLE_ADMIN".equals(currentUser.getUserSecurity())) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
ModelAndView redirectLoginView = new ModelAndView("redirect:/");
|
ModelAndView redirectLoginView = new ModelAndView("redirect:/");
|
||||||
|
|||||||
@@ -28,7 +28,8 @@ public class WebMvcConfig implements WebMvcConfigurer {
|
|||||||
|
|
||||||
private List<String> listAdminAuthPattern() {
|
private List<String> listAdminAuthPattern() {
|
||||||
List<String> patterns = new ArrayList<>();
|
List<String> patterns = new ArrayList<>();
|
||||||
patterns.add("/mgmt/**/*.do");
|
patterns.add("/mgmt/users/*.do");
|
||||||
|
patterns.add("/mgmt/servers/*.do");
|
||||||
return patterns;
|
return patterns;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ public class AdminRegisterController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
StaffUser newUser = staffUserMapper.map(user);
|
StaffUser newUser = staffUserMapper.map(user);
|
||||||
|
newUser.setUserSecurity("ROLE_ADMIN");
|
||||||
staffUserService.create(newUser);
|
staffUserService.create(newUser);
|
||||||
return "redirect:/login";
|
return "redirect:/login";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,6 +55,8 @@ public class UserRegisterDTO implements Serializable {
|
|||||||
@NotEmpty
|
@NotEmpty
|
||||||
private String username;
|
private String username;
|
||||||
|
|
||||||
|
private String userSecurity;
|
||||||
|
|
||||||
public String getEsntlId() {
|
public String getEsntlId() {
|
||||||
return esntlId;
|
return esntlId;
|
||||||
}
|
}
|
||||||
@@ -110,4 +112,12 @@ public class UserRegisterDTO implements Serializable {
|
|||||||
public void setPassword2(String password2) {
|
public void setPassword2(String password2) {
|
||||||
this.password2 = password2;
|
this.password2 = password2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getUserSecurity() {
|
||||||
|
return userSecurity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUserSecurity(String userSecurity) {
|
||||||
|
this.userSecurity = userSecurity;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ public class UserUpdateDTO implements Serializable {
|
|||||||
@NotEmpty
|
@NotEmpty
|
||||||
private String mobilePhone;
|
private String mobilePhone;
|
||||||
|
|
||||||
|
private String userSecurity;
|
||||||
/**
|
/**
|
||||||
* 사용자명
|
* 사용자명
|
||||||
*/
|
*/
|
||||||
@@ -89,4 +90,12 @@ public class UserUpdateDTO implements Serializable {
|
|||||||
public void setLockAt(EnabledStatus lockAt) {
|
public void setLockAt(EnabledStatus lockAt) {
|
||||||
this.lockAt = lockAt;
|
this.lockAt = lockAt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getUserSecurity() {
|
||||||
|
return userSecurity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUserSecurity(String userSecurity) {
|
||||||
|
this.userSecurity = userSecurity;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ public class AnonymousUser extends User {
|
|||||||
|
|
||||||
public AnonymousUser() {
|
public AnonymousUser() {
|
||||||
this.userId = "ANONYMOUS";
|
this.userId = "ANONYMOUS";
|
||||||
this.setUserSecurity(new UserSecurity("ROLE_ANONYMOUS"));
|
this.setUserSecurity("ROLE_ANONYMOUS");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -51,9 +51,8 @@ public abstract class User extends Auditable implements Serializable, UserDetail
|
|||||||
@Transient
|
@Transient
|
||||||
private String ip;
|
private String ip;
|
||||||
|
|
||||||
@OneToOne(fetch = FetchType.EAGER)
|
@Column(name = "USER_SECURITY")
|
||||||
@JoinColumn(name = "ESNTL_ID", referencedColumnName = "SCRTY_DTRMN_TRGET_ID", insertable = false, updatable = false)
|
private String userSecurity;
|
||||||
private UserSecurity userSecurity;
|
|
||||||
|
|
||||||
public String getEsntlId() {
|
public String getEsntlId() {
|
||||||
return esntlId;
|
return esntlId;
|
||||||
@@ -125,7 +124,7 @@ public abstract class User extends Auditable implements Serializable, UserDetail
|
|||||||
@Transient
|
@Transient
|
||||||
public Collection<? extends GrantedAuthority> getAuthorities() {
|
public Collection<? extends GrantedAuthority> getAuthorities() {
|
||||||
if (userSecurity != null) {
|
if (userSecurity != null) {
|
||||||
return Arrays.asList(new SimpleGrantedAuthority(userSecurity.getAuthorCode()));
|
return Arrays.asList(new SimpleGrantedAuthority(this.userSecurity));
|
||||||
} else {
|
} else {
|
||||||
return Arrays.asList(new SimpleGrantedAuthority("ROLE_USER"));
|
return Arrays.asList(new SimpleGrantedAuthority("ROLE_USER"));
|
||||||
}
|
}
|
||||||
@@ -155,11 +154,11 @@ public abstract class User extends Auditable implements Serializable, UserDetail
|
|||||||
return getStatus().equals(UserStatus.ACTIVE);
|
return getStatus().equals(UserStatus.ACTIVE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserSecurity getUserSecurity() {
|
public String getUserSecurity() {
|
||||||
return userSecurity;
|
return userSecurity;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUserSecurity(UserSecurity userSecurity) {
|
public void setUserSecurity(String userSecurity) {
|
||||||
this.userSecurity = userSecurity;
|
this.userSecurity = userSecurity;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,68 +0,0 @@
|
|||||||
package com.eactive.httpmockserver.user.entity;
|
|
||||||
|
|
||||||
import javax.persistence.Column;
|
|
||||||
import javax.persistence.Entity;
|
|
||||||
import javax.persistence.Id;
|
|
||||||
import javax.persistence.Table;
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* COMTNEMPLYRSCRTYESTBS 사용자보안설정
|
|
||||||
*
|
|
||||||
* @author
|
|
||||||
* @version 1.0
|
|
||||||
*/
|
|
||||||
@Entity
|
|
||||||
@Table(name = "COMTNEMPLYRSCRTYESTBS")
|
|
||||||
public class UserSecurity implements Serializable {
|
|
||||||
public UserSecurity() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public UserSecurity(String authorCode) {
|
|
||||||
this.authorCode = authorCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 권한코드
|
|
||||||
*/
|
|
||||||
@Column(name = "AUTHOR_CODE", nullable = false)
|
|
||||||
private String authorCode;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 회원유형코드
|
|
||||||
*/
|
|
||||||
@Column(name = "MBER_TY_CODE", nullable = true)
|
|
||||||
private String memberTypeCode;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 보안설정대상ID
|
|
||||||
*/
|
|
||||||
@Id
|
|
||||||
@Column(name = "SCRTY_DTRMN_TRGET_ID", nullable = false)
|
|
||||||
private String userEsntlId;
|
|
||||||
|
|
||||||
|
|
||||||
public String getAuthorCode() {
|
|
||||||
return authorCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAuthorCode(String authorCode) {
|
|
||||||
this.authorCode = authorCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getMemberTypeCode() {
|
|
||||||
return memberTypeCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMemberTypeCode(String memberTypeCode) {
|
|
||||||
this.memberTypeCode = memberTypeCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getUserEsntlId() {
|
|
||||||
return userEsntlId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUserEsntlId(String userEsntlId) {
|
|
||||||
this.userEsntlId = userEsntlId;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -6,6 +6,7 @@ import com.eactive.httpmockserver.user.dto.UserUpdateDTO;
|
|||||||
import com.eactive.httpmockserver.user.entity.StaffUser;
|
import com.eactive.httpmockserver.user.entity.StaffUser;
|
||||||
import com.eactive.httpmockserver.common.mapper.CommonMapper;
|
import com.eactive.httpmockserver.common.mapper.CommonMapper;
|
||||||
import com.eactive.httpmockserver.common.util.EncryptionUtil;
|
import com.eactive.httpmockserver.common.util.EncryptionUtil;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.mapstruct.Mapper;
|
import org.mapstruct.Mapper;
|
||||||
import org.mapstruct.Mapping;
|
import org.mapstruct.Mapping;
|
||||||
import org.mapstruct.ReportingPolicy;
|
import org.mapstruct.ReportingPolicy;
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
package com.eactive.httpmockserver.user.repository;
|
|
||||||
|
|
||||||
import com.eactive.httpmockserver.user.entity.UserSecurity;
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
|
||||||
|
|
||||||
public interface UserSecurityRepository extends JpaRepository<UserSecurity, String> {
|
|
||||||
}
|
|
||||||
@@ -1,10 +1,8 @@
|
|||||||
package com.eactive.httpmockserver.user.service;
|
package com.eactive.httpmockserver.user.service;
|
||||||
|
|
||||||
import com.eactive.httpmockserver.user.entity.StaffUser;
|
import com.eactive.httpmockserver.user.entity.StaffUser;
|
||||||
import com.eactive.httpmockserver.user.entity.UserSecurity;
|
|
||||||
import com.eactive.httpmockserver.user.entity.UserStatus;
|
import com.eactive.httpmockserver.user.entity.UserStatus;
|
||||||
import com.eactive.httpmockserver.user.repository.StaffUserRepository;
|
import com.eactive.httpmockserver.user.repository.StaffUserRepository;
|
||||||
import com.eactive.httpmockserver.user.repository.UserSecurityRepository;
|
|
||||||
import com.eactive.httpmockserver.common.entity.EnabledStatus;
|
import com.eactive.httpmockserver.common.entity.EnabledStatus;
|
||||||
import com.eactive.httpmockserver.common.exception.UserNotFoundException;
|
import com.eactive.httpmockserver.common.exception.UserNotFoundException;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -25,9 +23,6 @@ public class StaffUserService {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private StaffUserRepository staffUserRepository;
|
private StaffUserRepository staffUserRepository;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private UserSecurityRepository userSecurityRepository;
|
|
||||||
|
|
||||||
public Page<StaffUser> findAll(Specification<StaffUser> spec, Pageable pageable) {
|
public Page<StaffUser> findAll(Specification<StaffUser> spec, Pageable pageable) {
|
||||||
return staffUserRepository.findAll(spec, pageable);
|
return staffUserRepository.findAll(spec, pageable);
|
||||||
}
|
}
|
||||||
@@ -47,6 +42,7 @@ public class StaffUserService {
|
|||||||
original.setLastLockDate(null);
|
original.setLastLockDate(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
original.setUserSecurity(user.getUserSecurity());
|
||||||
staffUserRepository.save(original);
|
staffUserRepository.save(original);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,12 +63,7 @@ public class StaffUserService {
|
|||||||
|
|
||||||
staffUserRepository.save(user);
|
staffUserRepository.save(user);
|
||||||
|
|
||||||
UserSecurity userSecurity = new UserSecurity();
|
|
||||||
userSecurity.setUserEsntlId(user.getEsntlId());
|
|
||||||
userSecurity.setAuthorCode("ROLE_ADMIN");
|
|
||||||
userSecurity.setMemberTypeCode("USR03");
|
|
||||||
|
|
||||||
userSecurityRepository.save(userSecurity);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
<a class="nav-link" href="/mgmt/routes/list_view.do">응답 관리</a>
|
<a class="nav-link" href="/mgmt/routes/list_view.do">응답 관리</a>
|
||||||
</li>
|
</li>
|
||||||
<li class="nav-item" sec:authorize="isAuthenticated()">
|
<li class="nav-item" sec:authorize="isAuthenticated()">
|
||||||
<a class="nav-link" href="/mgmt/api_tester.do">Tester</a>
|
<a class="nav-link" href="/mgmt/api_tester.do">테스터</a>
|
||||||
</li>
|
</li>
|
||||||
<li class="nav-item dropdown" sec:authorize="hasRole('ROLE_ADMIN')">
|
<li class="nav-item dropdown" sec:authorize="hasRole('ROLE_ADMIN')">
|
||||||
<a class="nav-link dropdown-toggle" href="#" id="mgmtDropDown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
|
<a class="nav-link dropdown-toggle" href="#" id="mgmtDropDown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
|
||||||
@@ -27,7 +27,7 @@
|
|||||||
</a>
|
</a>
|
||||||
<ul class="dropdown-menu" aria-labelledby="mgmtDropDown">
|
<ul class="dropdown-menu" aria-labelledby="mgmtDropDown">
|
||||||
<li><a class="dropdown-item" href="/mgmt/users/list_view.do">사용자 관리</a></li>
|
<li><a class="dropdown-item" href="/mgmt/users/list_view.do">사용자 관리</a></li>
|
||||||
<li><a class="dropdown-item" href="/mgmt/groups/list_view.do">그룹 관리</a></li>
|
<!-- <li><a class="dropdown-item" href="/mgmt/groups/list_view.do">그룹 관리</a></li>-->
|
||||||
<li><a class="dropdown-item" href="/mgmt/servers/list_view.do">서버 관리</a></li>
|
<li><a class="dropdown-item" href="/mgmt/servers/list_view.do">서버 관리</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
|
|||||||
@@ -47,6 +47,14 @@
|
|||||||
</th:block>
|
</th:block>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="form-floating mt-2">
|
||||||
|
<select class="form-select" th:field="*{userSecurity}">
|
||||||
|
<option th:selected="${user.userSecurity!= null && user.userSecurity == 'ROLE_ADMIN'}" value="ROLE_ADMIN">관리자</option>
|
||||||
|
<option th:selected="${user.userSecurity!= null && user.userSecurity == 'ROLE_USER'}" value="ROLE_USER">사용자</option>
|
||||||
|
</select>
|
||||||
|
<label class="form-label must">권한</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="form-floating mt-2">
|
<div class="form-floating mt-2">
|
||||||
<input type="text" class="form-control" th:classappend="${#fields.hasErrors('mobilePhone')}? 'is-invalid'" th:field="*{mobilePhone}" name="mobilePhone" id="mobilePhone" required/>
|
<input type="text" class="form-control" th:classappend="${#fields.hasErrors('mobilePhone')}? 'is-invalid'" th:field="*{mobilePhone}" name="mobilePhone" id="mobilePhone" required/>
|
||||||
<label for="mobilePhone" class="form-label must" th:text="#{mobilePhone}">연락처</label>
|
<label for="mobilePhone" class="form-label must" th:text="#{mobilePhone}">연락처</label>
|
||||||
|
|||||||
Reference in New Issue
Block a user