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

master
mjkhan21 1 year ago
parent 0cac241cfa
commit 78840279da

@ -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>
@ -210,8 +210,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>

@ -37,7 +37,7 @@ public class ApplicationContainer implements ApplicationContextAware {
private Date startupDate; private Date startupDate;
private boolean secured; private boolean secured;
private ApplicationContainer() { public ApplicationContainer() {
try { try {
init(); init();
} catch (Exception e) { } catch (Exception e) {

@ -11,8 +11,11 @@ public class User extends AbstractEntity implements Serializable {
private String private String
id, id,
account,
name, name,
password; password,
institute,
locked;
private boolean sealed; private boolean sealed;
/**User () . /**User () .
@ -25,22 +28,36 @@ public class User extends AbstractEntity implements Serializable {
return !UNKNOWN.equals(getId()); return !UNKNOWN.equals(getId());
} }
/** . /** .<br />
* @return * .
* @return
*/ */
public String getId() { public String getId() {
return id != null ? id : UNKNOWN; return id != null ? id : UNKNOWN;
} }
/** . /** .<br />
* @param id * .
* @param id
*/ */
public void setId(String id) { public void setId(String id) {
notSealed().id = id; notSealed().id = id;
} }
public String getUsername() { /** .<br />
return getId(); * {@link #getAccount() } .
* @return
*/
public String getAccount() {
return account != null ? account : UNKNOWN;
}
/** .<br />
* {@link #getAccount() } .
* @param account
*/
public void setAccount(String account) {
this.account = account;
} }
/** . /** .
@ -71,6 +88,34 @@ public class User extends AbstractEntity implements Serializable {
notSealed().password = password; notSealed().password = password;
} }
/** .
* @return
*/
public String getInstitute() {
return institute;
}
/** .
* @param insititute
*/
public void setInstitute(String insititute) {
this.institute = insititute;
}
/** .
* @return
*/
public String getLocked() {
return Assert.ifEmpty(locked, "N");
}
/** .
* @param locked
*/
public void setLocked(String locked) {
this.locked = locked;
}
private User seal() { private User seal() {
sealed = true; sealed = true;
return this; return this;

@ -4,8 +4,6 @@ import java.io.Serializable;
import java.util.Collections; import java.util.Collections;
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.Stream;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -18,7 +16,7 @@ public class UserInfo implements Serializable {
public static final String public static final String
NAME = "userInfoProvider", NAME = "userInfoProvider",
SEC_NAME = "securedUserInfoProvider"; SEC_NAME = "securedUserInfoProvider";
public static final List<String> ALL_ACTIONS = Stream.of("all-actions").collect(Collectors.toList()); public static final List<String> ALL_ACTIONS = List.of("all-actions");
/** . /** .
* @author mjkhan * @author mjkhan
@ -100,15 +98,15 @@ public class UserInfo implements Serializable {
return getUser().getId(); return getUser().getId();
} }
/** . public String getUsername() {
* @param id return getId();
*/
public void setId(String id) {
getUser().setId(id);
} }
public String getUsername() { /** .
return getUser().getUsername(); * @return
*/
public String getAccount() {
return getUser().getAccount();
} }
/** . /** .
@ -118,13 +116,6 @@ public class UserInfo implements Serializable {
return getUser().getName(); return getUser().getName();
} }
/** .
* @param name
*/
public void setName(String name) {
getUser().setName(name);
}
/** . /** .
* @return * @return
*/ */
@ -132,13 +123,6 @@ public class UserInfo implements Serializable {
return getUser().getPassword(); return getUser().getPassword();
} }
/** .
* @param password
*/
public void setPassword(String password) {
getUser().setPassword(password);
}
/** map . /** map .
* @return map * @return map
*/ */

@ -1,7 +1,9 @@
package cokr.xit.foundation.component; package cokr.xit.foundation.component;
import cokr.xit.foundation.ApplicationException; import cokr.xit.foundation.ApplicationException;
import cokr.xit.foundation.Assert;
import cokr.xit.foundation.UserInfo; import cokr.xit.foundation.UserInfo;
import cokr.xit.foundation.data.Convert;
import cokr.xit.foundation.data.DataObject; import cokr.xit.foundation.data.DataObject;
/** .<br /> /** .<br />
@ -80,9 +82,7 @@ import cokr.xit.foundation.data.DataObject;
* <delete>}</pre> * <delete>}</pre>
* @author mjkhan * @author mjkhan
*/ */
public interface AbstractMapper extends public interface AbstractMapper extends Assert.Support, Convert.Support {
cokr.xit.foundation.Assert.Support,
cokr.xit.foundation.data.Convert.Support {
/** . /** .
* @return * @return

@ -1,41 +0,0 @@
package cokr.xit.foundation.test;
import cokr.xit.foundation.component.AbstractDao;
/**JUnit SQL DAO.<br />
* .<br />
* TestDao test.xml.
* @author mjkhan
*/
//@Repository("testDao")
public class TestDao extends AbstractDao {
/** INSERT .
* @param sql INSERT SQL
* @return
*/
public int execInsert(String sql) {
return insert("test.insert", params().set("sql", sql));
}
/** UPDATE .
* @param sql UPDATE SQL
* @return
*/
public int execUpdate(String sql) {
return insert("test.update", params().set("sql", sql));
}
/** DELETE .
* @param sql DELETE SQL
* @return
*/
public int execDelete(String sql) {
return insert("test.delete", params().set("sql", sql));
}
/** SQL .
*/
public void commit() {
update("test.commit");
}
}

@ -48,6 +48,8 @@ public class AccessInitializer extends RequestInterceptor {
@Override @Override
public void postHandle(HttpServletRequest hreq, HttpServletResponse hresp, Object handler, ModelAndView mav) throws Exception { public void postHandle(HttpServletRequest hreq, HttpServletResponse hresp, Object handler, ModelAndView mav) throws Exception {
if (mav == null) return;
Map<String, Object> model = mav.getModel(); Map<String, Object> model = mav.getModel();
model.entrySet().stream() model.entrySet().stream()
.filter(entry -> entry.getValue() instanceof ServiceRequest) .filter(entry -> entry.getValue() instanceof ServiceRequest)

@ -4,6 +4,7 @@ import java.io.PrintWriter;
import java.io.StringWriter; import java.io.StringWriter;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ControllerAdvice;
@ -11,7 +12,6 @@ import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.ModelAndView;
import cokr.xit.foundation.Access;
import cokr.xit.foundation.ApplicationException; import cokr.xit.foundation.ApplicationException;
/** ModelAndView . /** ModelAndView .
@ -25,7 +25,17 @@ public class ExceptionController extends AbstractController {
* @return uri * @return uri
*/ */
protected String getAction(HttpServletRequest hreq) { protected String getAction(HttpServletRequest hreq) {
return (String)hreq.getAttribute("javax.servlet.forward.request_uri"); return currentAccess().getAction();
}
protected ModelAndView toErrorPage(HttpServletRequest hreq, Object status, String msgKey) {
return new ModelAndView("error/errorPage")
.addObject("json", ajaxRequest())
.addObject("path", getAction(hreq))
.addObject("failed", true)
.addObject("status", status)
.addObject("message", message(msgKey))
;
} }
/**pageNotFound ModelAndView . /**pageNotFound ModelAndView .
@ -34,11 +44,7 @@ public class ExceptionController extends AbstractController {
*/ */
@RequestMapping("/error/pageNotFound.do") @RequestMapping("/error/pageNotFound.do")
public ModelAndView pageNotFound(HttpServletRequest hreq) { public ModelAndView pageNotFound(HttpServletRequest hreq) {
return new ModelAndView(ajaxRequest() ? "jsonView" : "error/errorPage") return toErrorPage(hreq, 404, "pageNotFound");
.addObject("path", getAction(hreq))
.addObject("failed", true)
.addObject("status", 404)
.addObject("message", message("pageNotFound"));
} }
/** ModelAndView . /** ModelAndView .
@ -47,12 +53,7 @@ public class ExceptionController extends AbstractController {
*/ */
@RequestMapping("/error/sessionExpired.do") @RequestMapping("/error/sessionExpired.do")
public ModelAndView sessionExpired(HttpServletRequest hreq) { public ModelAndView sessionExpired(HttpServletRequest hreq) {
return new ModelAndView(ajaxRequest() ? "jsonView" : "error/errorPage") return toErrorPage(hreq, "sessionExpired", "sessionExpired");
.addObject("path", getAction(hreq))
.addObject("failed", true)
.addObject("status", "sessionExpired")
.addObject("message", message("sessionExpired"))
.addObject("home", true);
} }
/** ModelAndView . /** ModelAndView .
@ -61,12 +62,7 @@ public class ExceptionController extends AbstractController {
*/ */
@RequestMapping("/error/invalidSession.do") @RequestMapping("/error/invalidSession.do")
public ModelAndView invalidSession(HttpServletRequest hreq) { public ModelAndView invalidSession(HttpServletRequest hreq) {
return new ModelAndView(ajaxRequest() ? "jsonView" : "error/errorPage") return toErrorPage(hreq, "invalidSession", "invalidSession");
.addObject("path", getAction(hreq))
.addObject("failed", true)
.addObject("status", "invalidSession")
.addObject("message", message("invalidSession"))
.addObject("home", true);
} }
/** ModelAndView . /** ModelAndView .
@ -75,11 +71,17 @@ public class ExceptionController extends AbstractController {
*/ */
@RequestMapping("/error/accessDenied.do") @RequestMapping("/error/accessDenied.do")
public ModelAndView accessDenied(HttpServletRequest hreq) { public ModelAndView accessDenied(HttpServletRequest hreq) {
return new ModelAndView(ajaxRequest() ? "jsonView" : "error/errorPage") return toErrorPage(hreq, "accessDenied", "accessDenied");
.addObject("path", Access.current().getAction()) }
.addObject("failed", true)
.addObject("status", "accessDenied") public void accessDenied(HttpServletRequest hreq, HttpServletResponse hresp) {
.addObject("message", message("accessDenied")); try {
ModelAndView mav = toErrorPage(hreq, "accessDenied", "accessDenied");
mav.getModel().forEach(hreq::setAttribute);
hreq.getRequestDispatcher("/WEB-INF/jsp/" + mav.getViewName() + ".jsp").forward(hreq, hresp);
} catch (Exception e) {
throw runtimeException(e);
}
} }
/**ApplicationException ModelAndView . /**ApplicationException ModelAndView .
@ -100,18 +102,13 @@ public class ExceptionController extends AbstractController {
public ModelAndView onException(Throwable e) { public ModelAndView onException(Throwable e) {
Throwable cause = rootCause(e); Throwable cause = rootCause(e);
String action = currentAccess().getAction(), String description = cause != null ? ifEmpty(cause.getMessage(), () -> cause.getClass().getSimpleName()) : "";
description = cause.getClass().getSimpleName() + " from " + currentAccess(), String stacktrace = getStackTrace(cause);
stacktrace = getStackTrace(cause);
log().error(description); log().error(description);
log().error(stacktrace); log().error(stacktrace);
return new ModelAndView(ajaxRequest() || jsonResponse() ? "jsonView" : "error/errorPage") return toErrorPage(null, 500, "serverError")
.addObject("status", 500)
.addObject("failed", true)
.addObject("description", description) .addObject("description", description)
.addObject("path", action)
.addObject("message", cause.getMessage())
.addObject("stacktrace", stacktrace); .addObject("stacktrace", stacktrace);
} }

@ -0,0 +1,106 @@
package cokr.xit.foundation.web;
import java.util.List;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/** .
* <ul><li> {@link #get(String) }</li>
* <li> {@link #set(String, String) }</li>
* <li> {@link #remove(String...) }</li>
* </ul>
* @author mjkhan
*/
public class Kookie {
private HttpServletRequest hreq;
private HttpServletResponse hresp;
/**HttpServletRequest .
* @param hreq HttpServletRequest
* @return Kookie
*/
public Kookie set(HttpServletRequest hreq) {
this.hreq = hreq;
return this;
}
/**HttpServletResponse .
* @param hresp HttpServletResponse
* @return Kookie
*/
public Kookie set(HttpServletResponse hresp) {
this.hresp = hresp;
return this;
}
/** .
* <pre><code> String kookieValue = new Kookie()
* .set(hreq)
* .get("kookieName");</code></pre>
* @param name
* @return
*/
public String get(String name) {
Cookie[] cookies = hreq.getCookies();
if (cookies == null || cookies.length < 1) return "";
for (Cookie cookie: cookies) {
if (cookie.getName().equals(name))
return cookie.getValue();
}
return "";
}
/** .
* <pre><code> String kookieValue = new Kookie()
* .set(hresp)
* .set("kookieName", "kookieValue");</code></pre>
* @param name
* @param value
* @return Kookie
*/
public Kookie set(String name, String value) {
Cookie cookie = new Cookie(name, value);
cookie.setMaxAge(Integer.MAX_VALUE);
hresp.addCookie(cookie);
return this;
}
/** .<br />
* .
* <pre><code> String kookieValue = new Kookie()
* .set(hreq)
* .set(hresp)
* .remove("kookieName0", "kookieName1");</code></pre>
* @param names
* @return Kookie
*/
public Kookie remove(String... names) {
Cookie[] cookies = hreq.getCookies();
if (cookies == null || cookies.length < 1) return this;
List<String> cookieNames = List.of(names);
for (Cookie cookie: cookies) {
if (!cookieNames.isEmpty()
&& !cookieNames.contains(cookie.getName())) continue;
cookie.setValue("");
cookie.setMaxAge(0);
hresp.addCookie(cookie);
}
return this;
}
/** Kookie HttpServletRequest HttpServletResponse .<br />
* Kookie .
* @return Kookie
*/
public Kookie clear() {
hreq = null;
hresp = null;
return this;
}
}
Loading…
Cancel
Save