jdk 1.8 -> 17, @Component("...") 추가, 사용자 아이디 관련 변경

master
mjkhan21 1 year ago
parent be23e37a51
commit 212a1f76c2

@ -12,7 +12,7 @@
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version> <java.version>17</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source> <maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target> <maven.compiler.target>${java.version}</maven.compiler.target>
@ -126,8 +126,8 @@
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<configuration> <configuration>
<source>1.8</source> <source>${java.version}</source>
<target>1.8</target> <target>${java.version}</target>
<encoding>UTF-8</encoding> <encoding>UTF-8</encoding>
</configuration> </configuration>
</plugin> </plugin>

@ -1,6 +1,5 @@
package cokr.xit.base.security; package cokr.xit.base.security;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -146,7 +145,7 @@ public class SecuredUserInfo extends UserInfo implements UserDetails {
@Override @Override
public boolean isAccountNonLocked() { public boolean isAccountNonLocked() {
return isEnabled(); return "N".equalsIgnoreCase(getUser().getLocked());
} }
@Override @Override
@ -160,7 +159,7 @@ public class SecuredUserInfo extends UserInfo implements UserDetails {
} }
private SecuredUserInfo seal() { private SecuredUserInfo seal() {
authorities = Provider.get().getAccessContext().getAuthorities(Arrays.asList(Authority.ANONYMOUS)); authorities = Provider.get().getAccessContext().getAuthorities(List.of(Authority.ANONYMOUS));
sealed = true; sealed = true;
return this; return this;
} }

@ -1,12 +1,17 @@
package cokr.xit.base.security.access; package cokr.xit.base.security.access;
import java.util.Collection; import java.util.Collection;
import java.util.function.Supplier;
import javax.annotation.Resource; import javax.annotation.Resource;
import org.springframework.security.access.AccessDecisionVoter; import org.springframework.security.access.AccessDecisionVoter;
import org.springframework.security.access.ConfigAttribute; import org.springframework.security.access.ConfigAttribute;
import org.springframework.security.authorization.AuthorizationDecision;
import org.springframework.security.authorization.AuthorizationManager;
import org.springframework.security.core.Authentication; import org.springframework.security.core.Authentication;
import org.springframework.security.web.access.intercept.RequestAuthorizationContext;
import org.springframework.stereotype.Component;
import cokr.xit.base.security.AccessContext; import cokr.xit.base.security.AccessContext;
import cokr.xit.base.security.SecuredUserInfo; import cokr.xit.base.security.SecuredUserInfo;
@ -17,22 +22,14 @@ import cokr.xit.foundation.Access;
* . * .
* @author mjkhan * @author mjkhan
*/ */
public class ApplicationAccess extends AbstractComponent implements AccessDecisionVoter<Object> { @Component("applicationAccess")
private boolean controlAccess; public class ApplicationAccess
extends AbstractComponent
implements AccessDecisionVoter<Object>, AuthorizationManager<RequestAuthorizationContext> {
/** 권한별 가용 기능(URL) */ /** 권한별 가용 기능(URL) */
@Resource(name="accessContext") @Resource(name="accessContext")
protected AccessContext accessContext; protected AccessContext accessContext;
/** .
* @param controlAccess
* <ul><li> true</li>
* <li> false</li>
* </ul>
*/
public void setControlAccess(boolean controlAccess) {
this.controlAccess = controlAccess;
}
@Override @Override
public boolean supports(ConfigAttribute attribute) { public boolean supports(ConfigAttribute attribute) {
return true; return true;
@ -45,9 +42,10 @@ public class ApplicationAccess extends AbstractComponent implements AccessDecisi
@Override @Override
public int vote(Authentication authentication, Object obj, Collection<ConfigAttribute> attributes) { public int vote(Authentication authentication, Object obj, Collection<ConfigAttribute> attributes) {
if (!controlAccess) return ACCESS_GRANTED; return vote(Access.current().getAction());
}
String action = Access.current().getAction(); public int vote(String action) {
if (isEmpty(action)) if (isEmpty(action))
return ACCESS_GRANTED; return ACCESS_GRANTED;
@ -61,4 +59,17 @@ public class ApplicationAccess extends AbstractComponent implements AccessDecisi
*/ */
return ACCESS_DENIED; return ACCESS_DENIED;
} }
private static final AuthorizationDecision
granted = new AuthorizationDecision(true),
denied = new AuthorizationDecision(false);
@Override
public AuthorizationDecision check(Supplier<Authentication> authentication, RequestAuthorizationContext hreqCtx) {
switch (vote(authentication.get(), null, null)) {
case ACCESS_GRANTED: return granted;
case ACCESS_DENIED: return denied;
default: return null;
}
}
} }

@ -1,6 +1,5 @@
package cokr.xit.base.security.access.dao; package cokr.xit.base.security.access.dao;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -186,7 +185,7 @@ public interface AuthorityMapper extends AbstractMapper {
* @return * @return
*/ */
default List<String> getUserAuths(String userID) { default List<String> getUserAuths(String userID) {
List<DataObject> list = getUserAuths(params().set("userIDs", Arrays.asList(userID))); List<DataObject> list = getUserAuths(params().set("userIDs", List.of(userID)));
return list.stream() return list.stream()
.map(row -> row.string("AUTH_ID")) .map(row -> row.string("AUTH_ID"))
.collect(Collectors.toList()); .collect(Collectors.toList());

@ -11,7 +11,6 @@ import org.springframework.stereotype.Component;
import cokr.xit.base.security.authentication.AuthenticationPolicy; import cokr.xit.base.security.authentication.AuthenticationPolicy;
import cokr.xit.base.security.authentication.dao.PolicyMapper; import cokr.xit.base.security.authentication.dao.PolicyMapper;
import cokr.xit.base.user.dao.UserMapper; import cokr.xit.base.user.dao.UserMapper;
import cokr.xit.base.user.service.UserQuery;
import cokr.xit.foundation.AbstractComponent; import cokr.xit.foundation.AbstractComponent;
import cokr.xit.foundation.User; import cokr.xit.foundation.User;
import cokr.xit.foundation.component.QueryRequest; import cokr.xit.foundation.component.QueryRequest;
@ -32,12 +31,7 @@ public class AuthenticationBean extends AbstractComponent {
* @return * @return
*/ */
public User getUser(Map<String, Object> params) { public User getUser(Map<String, Object> params) {
UserQuery req = new UserQuery() return userMapper.getUser(params);
.setUserIDs((String)params.get("userID"));
req.setPassword(true);
List<User> users = userMapper.getUsers(req);
return !users.isEmpty() ? users.get(0) : null;
} }
/** . /** .

@ -86,10 +86,8 @@ public class AuthenticationServiceBean extends DaoAuthenticationProvider impleme
AuthenticationExtraDetails extraDetails = (AuthenticationExtraDetails)obj; AuthenticationExtraDetails extraDetails = (AuthenticationExtraDetails)obj;
Map<String, Object> params = extraDetails.getParams(); Map<String, Object> params = extraDetails.getParams();
log().debug("Authentication details: {}", params);
SecuredUserInfo userInfo = loadUser(params); SecuredUserInfo userInfo = loadUser(params);
boolean valid = validate(userInfo, params); boolean valid = validate(userInfo, params);
if (valid) if (valid)
checkAgainstPolicy(extraDetails, userInfo); checkAgainstPolicy(extraDetails, userInfo);

@ -30,16 +30,16 @@ public class AuthenticationSuccess extends SavedRequestAwareAuthenticationSucces
@Resource(name="objectMapper") @Resource(name="objectMapper")
private ObjectMapper objectMapper; private ObjectMapper objectMapper;
private boolean rememberUsername; private boolean rememberCredentials;
/** . /** .
* @param remember * @param remember
* <ul><li> true</li> * <ul><li> true</li>
* <li> false</li> * <li> false</li>
* </ul> * </ul>
*/ */
public void setRememberUsername(boolean remember) { public void setRememberCredentials(boolean remember) {
this.rememberUsername = remember; this.rememberCredentials = remember;
} }
/** . /** .
@ -84,8 +84,12 @@ public class AuthenticationSuccess extends SavedRequestAwareAuthenticationSucces
} }
private void remember(UserInfo user, HttpServletRequest hreq, HttpServletResponse hresp) { private void remember(UserInfo user, HttpServletRequest hreq, HttpServletResponse hresp) {
boolean remember = rememberUsername && "true".equals(hreq.getParameter("remember")); boolean remember = rememberCredentials && "true".equals(hreq.getParameter("remember"));
Cookie cookie = new Cookie("username", remember ? user.getUsername() : ""); addCookie(hresp, remember, "userAccount", user.getAccount());
}
private void addCookie(HttpServletResponse hresp, boolean remember, String name, String value) {
Cookie cookie = new Cookie(name, remember ? value : "");
cookie.setMaxAge(remember ? Integer.MAX_VALUE : 0); cookie.setMaxAge(remember ? Integer.MAX_VALUE : 0);
hresp.addCookie(cookie); hresp.addCookie(cookie);
} }

@ -4,7 +4,6 @@ import java.io.IOException;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession; import javax.servlet.http.HttpSession;
@ -24,6 +23,7 @@ import org.springframework.web.context.WebApplicationContext;
import cokr.xit.base.security.authentication.service.AuthenticationService; import cokr.xit.base.security.authentication.service.AuthenticationService;
import cokr.xit.foundation.Assert; import cokr.xit.foundation.Assert;
import cokr.xit.foundation.Log; import cokr.xit.foundation.Log;
import cokr.xit.foundation.web.Kookie;
/** /**
* @author mjkhan * @author mjkhan
@ -76,39 +76,43 @@ public class LogoutSuccess extends SimpleUrlLogoutSuccessHandler implements Appl
HttpSession session = hreq.getSession(false); HttpSession session = hreq.getSession(false);
if (session != null) if (session != null)
session.invalidate(); session.invalidate();
removeCookies(hreq, hresp);
new Kookie()
.set(hreq)
.set(hresp)
.remove();
hreq.logout(); hreq.logout();
hresp.setStatus(HttpServletResponse.SC_OK); hresp.setStatus(HttpServletResponse.SC_OK);
hresp.sendRedirect(getSuccessUrl(hreq.getContextPath())); hresp.sendRedirect(getSuccessUrl(hreq.getContextPath()));
} }
/** . /* .
* @param hreq 릿 * @param hreq 릿
* @param hresp 릿 * @param hresp 릿
*/
protected void removeCookies(HttpServletRequest hreq, HttpServletResponse hresp) { protected void removeCookies(HttpServletRequest hreq, HttpServletResponse hresp) {
Cookie[] cookies = hreq.getCookies(); Cookie[] cookies = hreq.getCookies();
if (cookies == null || cookies.length < 1) return; if (cookies == null || cookies.length < 1) return;
for (Cookie cookie: cookies) { for (Cookie cookie: cookies) {
removeCookie(cookie, "JSESSIONID", "username"); removeCookie(hresp, cookie, "JSESSIONID", "userAccount");
hresp.addCookie(cookie);
} }
} }*/
/** . /* .
* @param hresp 릿
* @param cookie * @param cookie
* @param cookieNames * @param cookieNames
*/ protected void removeCookie(HttpServletResponse hresp, Cookie cookie, String... cookieNames) {
protected void removeCookie(Cookie cookie, String... cookieNames) {
for (String name: cookieNames) { for (String name: cookieNames) {
if (!name.equals(cookie.getName())) continue; if (!name.equals(cookie.getName())) continue;
cookie.setMaxAge(0); cookie.setMaxAge(0);
cookie.setValue(""); cookie.setValue("");
hresp.addCookie(cookie);
} }
} }*/
@Override @Override
public void setApplicationContext(ApplicationContext actx) throws BeansException { public void setApplicationContext(ApplicationContext actx) throws BeansException {

@ -3,7 +3,7 @@ package cokr.xit.base.security.crypto;
import java.security.Key; import java.security.Key;
import java.security.SecureRandom; import java.security.SecureRandom;
import java.security.spec.KeySpec; import java.security.spec.KeySpec;
import java.util.Arrays; import java.util.List;
import javax.crypto.KeyGenerator; import javax.crypto.KeyGenerator;
import javax.crypto.SecretKeyFactory; import javax.crypto.SecretKeyFactory;
@ -30,7 +30,7 @@ public class KeyFactory extends AbstractComponent {
* @return KeyFactory * @return KeyFactory
*/ */
public KeyFactory setKeySize(int keySize) { public KeyFactory setKeySize(int keySize) {
if (!Arrays.asList(128, 192, 256).contains(keySize)) if (!List.of(128, 192, 256).contains(keySize))
throw new IllegalArgumentException("keySize must be either of 128, 192, 256"); throw new IllegalArgumentException("keySize must be either of 128, 192, 256");
this.keySize = keySize; this.keySize = keySize;

Loading…
Cancel
Save