사용자 관리
This commit is contained in:
@@ -13,9 +13,13 @@ import io.netty.channel.EventLoopGroup;
|
||||
import io.netty.channel.nio.NioEventLoopGroup;
|
||||
import io.netty.channel.socket.nio.NioSocketChannel;
|
||||
import io.netty.handler.codec.http.*;
|
||||
import io.netty.handler.ssl.SslContext;
|
||||
import io.netty.handler.ssl.SslContextBuilder;
|
||||
import io.netty.handler.ssl.util.InsecureTrustManagerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.net.ssl.SSLException;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@Service
|
||||
@@ -40,6 +44,16 @@ public class NettyApiClient {
|
||||
.handler(new ChannelInitializer<Channel>() {
|
||||
@Override
|
||||
public void initChannel(Channel ch) {
|
||||
if (server.getScheme().equalsIgnoreCase("https")){
|
||||
try {
|
||||
final SslContext sslCtx = SslContextBuilder.forClient()
|
||||
.trustManager(InsecureTrustManagerFactory.INSTANCE).build();
|
||||
ch.pipeline().addLast(sslCtx.newHandler(ch.alloc(), host, port));// Add SSL handler
|
||||
} catch (SSLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
ch.pipeline().addLast(new HttpClientCodec());
|
||||
ch.pipeline().addLast(new HttpObjectAggregator(65536));
|
||||
ch.pipeline().addLast(new HttpContentDecompressor());
|
||||
|
||||
+3
-2
@@ -1,5 +1,6 @@
|
||||
package com.eactive.httpmockserver.common.security;
|
||||
|
||||
import com.eactive.httpmockserver.user.entity.StaffUser;
|
||||
import com.eactive.httpmockserver.user.entity.User;
|
||||
import com.eactive.httpmockserver.user.service.UserService;
|
||||
import com.eactive.httpmockserver.common.exception.NotFoundException;
|
||||
@@ -24,7 +25,7 @@ public class CurrentUserArgumentResolver implements HandlerMethodArgumentResolve
|
||||
@Override
|
||||
public boolean supportsParameter(MethodParameter parameter) {
|
||||
return parameter.getParameterAnnotation(CurrentUser.class) != null &&
|
||||
parameter.getParameterType().equals(User.class);
|
||||
parameter.getParameterType().equals(StaffUser.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -35,7 +36,7 @@ public class CurrentUserArgumentResolver implements HandlerMethodArgumentResolve
|
||||
if (authentication == null || !authentication.isAuthenticated()) {
|
||||
throw new UserNotLoginException();
|
||||
}
|
||||
User user = null;
|
||||
StaffUser user = null;
|
||||
try {
|
||||
user = userService.findByEsntlId((String) PropertyUtils.getProperty(authentication.getPrincipal(), "esntlId"));
|
||||
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
package com.eactive.httpmockserver.config;
|
||||
|
||||
import com.eactive.httpmockserver.common.interceptor.AuthenticInterceptor;
|
||||
import com.eactive.httpmockserver.common.security.CurrentUserArgumentResolver;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.web.PageableHandlerMethodArgumentResolver;
|
||||
import org.springframework.http.CacheControl;
|
||||
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
|
||||
import org.springframework.web.servlet.config.annotation.*;
|
||||
import org.springframework.web.servlet.resource.PathResourceResolver;
|
||||
|
||||
@@ -35,6 +39,23 @@ public class WebMvcConfig implements WebMvcConfigurer {
|
||||
return authenticInterceptor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {
|
||||
resolvers.add(currentUserArgumentResolver());
|
||||
resolvers.add(pageableHandlerMethodArgumentResolver());
|
||||
}
|
||||
@Bean
|
||||
public CurrentUserArgumentResolver currentUserArgumentResolver() {
|
||||
return new CurrentUserArgumentResolver();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public PageableHandlerMethodArgumentResolver pageableHandlerMethodArgumentResolver() {
|
||||
PageableHandlerMethodArgumentResolver pageableHandlerMethodArgumentResolver = new PageableHandlerMethodArgumentResolver();
|
||||
pageableHandlerMethodArgumentResolver.setOneIndexedParameters(true); //1부터 시작
|
||||
pageableHandlerMethodArgumentResolver.setFallbackPageable(PageRequest.of(0, 10)); //파라미터 없을 때 기본 페이지
|
||||
return pageableHandlerMethodArgumentResolver;
|
||||
}
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
registry.addInterceptor(authenticInterceptor())
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.eactive.httpmockserver.user.controller;
|
||||
|
||||
import com.eactive.httpmockserver.user.dto.PasswordChangeRequestDTO;
|
||||
import com.eactive.httpmockserver.user.entity.StaffUser;
|
||||
import com.eactive.httpmockserver.user.entity.User;
|
||||
import com.eactive.httpmockserver.user.service.UserService;
|
||||
import com.eactive.httpmockserver.common.security.CurrentUser;
|
||||
@@ -31,7 +32,7 @@ public class AccountController {
|
||||
@PostMapping(value = "/update_password.do")
|
||||
@Transactional
|
||||
public String updatePassword(ModelMap model, @ModelAttribute("passwordChangeRequest") PasswordChangeRequestDTO passwordChangeRequestDTO,
|
||||
@CurrentUser User user,
|
||||
@CurrentUser StaffUser user,
|
||||
BindingResult result) {
|
||||
|
||||
validator.validate(passwordChangeRequestDTO, result);
|
||||
|
||||
@@ -44,7 +44,6 @@ public class StaffUser extends User {
|
||||
@Transient
|
||||
private String password2;
|
||||
|
||||
|
||||
/**
|
||||
* 비밀번호정답
|
||||
*/
|
||||
@@ -63,6 +62,11 @@ public class StaffUser extends User {
|
||||
@Column(name = "USER_NM", nullable = false)
|
||||
private String username;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "USER_GROUP_ID")
|
||||
private UserGroup group;
|
||||
|
||||
|
||||
@Override
|
||||
public UserStatus getStatus() {
|
||||
return status;
|
||||
@@ -137,6 +141,13 @@ public class StaffUser extends User {
|
||||
return "USR";
|
||||
}
|
||||
|
||||
public UserGroup getGroup() {
|
||||
return group;
|
||||
}
|
||||
|
||||
public void setGroup(UserGroup group) {
|
||||
this.group = group;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
|
||||
@@ -65,7 +65,7 @@ public class UserService implements UserDetailsService {
|
||||
public void updateUser(User user) {
|
||||
staffUserRepository.save((StaffUser) user);
|
||||
}
|
||||
public User findByEsntlId(String esntlId) {
|
||||
public StaffUser findByEsntlId(String esntlId) {
|
||||
return staffUserRepository.findById(esntlId).orElseThrow(() -> new UserNotFoundException(USER_NOT_FOUND_MESSAGE));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user