코드관리 작업중.

master
강석 최 2021-11-30 19:05:43 +09:00
parent 2ceb8059dd
commit 35a0a27254
20 changed files with 272 additions and 86 deletions

View File

@ -24,6 +24,7 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.springframework.boot:spring-boot-starter-web'
developmentOnly 'org.springframework.boot:spring-boot-devtools' developmentOnly 'org.springframework.boot:spring-boot-devtools'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter:2.1.4'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation group: 'nz.net.ultraq.thymeleaf', name: 'thymeleaf-layout-dialect', version: '2.5.3' implementation group: 'nz.net.ultraq.thymeleaf', name: 'thymeleaf-layout-dialect', version: '2.5.3'

View File

@ -1,9 +1,7 @@
package com.dbnt.kcgfilemanager; package com.dbnt.kcgfilemanager;
import com.dbnt.kcgfilemanager.userInfo.UserInfo; import com.dbnt.kcgfilemanager.model.UserInfo;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
@ -20,12 +18,12 @@ public class BaseController {
if(((UserInfo)((UsernamePasswordAuthenticationToken) principal).getPrincipal()).getUserRole().indexOf("ADMIN")>0){ if(((UserInfo)((UsernamePasswordAuthenticationToken) principal).getPrincipal()).getUserRole().indexOf("ADMIN")>0){
return "redirect:/admin/main"; return "redirect:/admin/main";
}else{ }else{
return "redirect:/main"; return "redirect:/user/main";
} }
} }
} }
@GetMapping("/main") @GetMapping("/user/main")
public String main() { public String main() {
return "main"; return "main";
} }

View File

@ -1,6 +1,6 @@
package com.dbnt.kcgfilemanager.config; package com.dbnt.kcgfilemanager.config;
import com.dbnt.kcgfilemanager.userInfo.service.UserInfoService; import com.dbnt.kcgfilemanager.service.UserInfoService;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
@ -27,16 +27,15 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override @Override
public void configure(WebSecurity web) throws Exception { public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers("/css/**", "/img/**", "/js/**", "/lib/**", "/vendor/**"); web.ignoring().antMatchers("/css/**", "/img/**", "/js/**", "/vendor/**");
} }
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests() // 페이지 권한 설정 http.authorizeRequests() // 페이지 권한 설정
.antMatchers("/info").hasRole("MEMBER") // MEMBER, ADMIN만 접근 허용 .antMatchers("/board/**").hasRole("MEMBER") // MEMBER, ADMIN만 접근 허용
.antMatchers("/admin").hasRole("ADMIN") // ADMIN만 접근 허용 .antMatchers("/admin/**").hasRole("ADMIN") // ADMIN만 접근 허용
.antMatchers("/**").permitAll() // 그외 모든 경로에 대해서는 권한 없이 접근 허용 .antMatchers("/user/login").permitAll() // 로그인 페이지는 권한 없이 접근 허용
// .anyRequest().authenticated() // 나머지 요청들은 권한의 종류에 상관 없이 권한이 있어야 접근 가능
.and() // 로그인 설정 .and() // 로그인 설정
.formLogin() .loginPage("/user/login") // Custom login form 사용 .formLogin() .loginPage("/user/login") // Custom login form 사용
.failureUrl("/login-error") // 로그인 실패 시 이동 .failureUrl("/login-error") // 로그인 실패 시 이동

View File

@ -1,48 +0,0 @@
package com.dbnt.kcgfilemanager.config;
import lombok.RequiredArgsConstructor;
import nz.net.ultraq.thymeleaf.LayoutDialect;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.thymeleaf.extras.springsecurity5.dialect.SpringSecurityDialect;
import org.thymeleaf.spring5.SpringTemplateEngine;
import org.thymeleaf.spring5.templateresolver.SpringResourceTemplateResolver;
import org.thymeleaf.spring5.view.ThymeleafViewResolver;
@Configuration
@RequiredArgsConstructor
public class ThymeleafViewResolverConfig {
private final ApplicationContext applicationContext;
@Bean
public SpringResourceTemplateResolver templateResolver(){
SpringResourceTemplateResolver templateResolver = new SpringResourceTemplateResolver();
templateResolver.setApplicationContext(this.applicationContext);
templateResolver.setPrefix("classpath:templates/");
templateResolver.setSuffix(".html");
templateResolver.setTemplateMode("HTML5");
templateResolver.setCacheable(false);
return templateResolver;
}
@Bean
public SpringTemplateEngine templateEngine() {
SpringTemplateEngine templateEngine = new SpringTemplateEngine();
templateEngine.setTemplateResolver(templateResolver());
templateEngine.addDialect(new SpringSecurityDialect());
templateEngine.addDialect(new LayoutDialect());
return templateEngine;
}
@Bean
public ThymeleafViewResolver viewResolver() {
ThymeleafViewResolver viewResolver = new ThymeleafViewResolver();
viewResolver.setTemplateEngine(templateEngine());
viewResolver.setCharacterEncoding("UTF-8");
viewResolver.setOrder(0);
return viewResolver;
}
}

View File

@ -1,7 +1,7 @@
package com.dbnt.kcgfilemanager.userInfo.controller; package com.dbnt.kcgfilemanager.controller;
import com.dbnt.kcgfilemanager.userInfo.UserInfo; import com.dbnt.kcgfilemanager.model.UserInfo;
import com.dbnt.kcgfilemanager.userInfo.service.UserInfoService; import com.dbnt.kcgfilemanager.service.UserInfoService;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
@ -11,6 +11,7 @@ import org.springframework.web.bind.annotation.PostMapping;
@Controller @Controller
@RequiredArgsConstructor @RequiredArgsConstructor
public class UserInfoController { public class UserInfoController {
private final UserInfoService userInfoService; private final UserInfoService userInfoService;
/** * 로그인 페이지 이동 * @return */ /** * 로그인 페이지 이동 * @return */

View File

@ -1,19 +1,21 @@
package com.dbnt.kcgfilemanager.adminMenu.controller; package com.dbnt.kcgfilemanager.controller;
import com.dbnt.kcgfilemanager.userInfo.UserInfo; import com.dbnt.kcgfilemanager.model.CommonCode;
import com.dbnt.kcgfilemanager.userInfo.service.UserInfoService; import com.dbnt.kcgfilemanager.service.CommonCodeService;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import java.util.List;
@Controller @Controller
@RequiredArgsConstructor @RequiredArgsConstructor
@RequestMapping("/admin") @RequestMapping("/admin")
public class adminController { public class adminController {
private final CommonCodeService commonCodeService;
/** * 회원가입 페이지 이동 * @return */ /** * 회원가입 페이지 이동 * @return */
@GetMapping("/signup") @GetMapping("/signup")
@ -38,7 +40,9 @@ public class adminController {
} }
@GetMapping("/codeMgt") @GetMapping("/codeMgt")
public String codeMgt() { public ModelAndView codeMgt(CommonCode commonCode) {
return "admin/codeMgt"; ModelAndView mav = new ModelAndView("admin/codeMgt");
mav.addObject("categoryList", commonCodeService.selectCommonCodeToCategory(commonCode));
return mav;
} }
} }

View File

@ -0,0 +1,12 @@
package com.dbnt.kcgfilemanager.mapper;
import com.dbnt.kcgfilemanager.model.CommonCode;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
@Mapper
public interface CommonCodeMapper {
List<CommonCode> selectCommonCodeToCategory(CommonCode commonCode);
}

View File

@ -0,0 +1,12 @@
package com.dbnt.kcgfilemanager.model;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
@Getter
@Setter
@NoArgsConstructor
public class BaseModel {
}

View File

@ -0,0 +1,26 @@
package com.dbnt.kcgfilemanager.model;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import javax.persistence.*;
@Getter
@Setter
@NoArgsConstructor
@Entity
@Table(name = "COMMON_CODE")
public class CommonCode {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "CODE_SQ")
private Integer codeSq;
@Column(name = "CATEGORY")
private String category;
@Column(name = "VALUE")
private String value;
@Column(name = "DESCRIPTION")
private String description;
}

View File

@ -1,4 +1,4 @@
package com.dbnt.kcgfilemanager.userInfo; package com.dbnt.kcgfilemanager.model;
import lombok.*; import lombok.*;
import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.GrantedAuthority;

View File

@ -0,0 +1,9 @@
package com.dbnt.kcgfilemanager.repository;
import com.dbnt.kcgfilemanager.model.CommonCode;
import org.springframework.data.jpa.repository.JpaRepository;
public interface CommonCodeRepository extends JpaRepository<CommonCode, Integer> {
}

View File

@ -1,6 +1,6 @@
package com.dbnt.kcgfilemanager.userInfo.repository; package com.dbnt.kcgfilemanager.repository;
import com.dbnt.kcgfilemanager.userInfo.UserInfo; import com.dbnt.kcgfilemanager.model.UserInfo;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import java.util.Optional; import java.util.Optional;

View File

@ -0,0 +1,26 @@
package com.dbnt.kcgfilemanager.service;
import com.dbnt.kcgfilemanager.mapper.CommonCodeMapper;
import com.dbnt.kcgfilemanager.model.CommonCode;
import com.dbnt.kcgfilemanager.model.UserInfo;
import com.dbnt.kcgfilemanager.repository.UserInfoRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.password.Pbkdf2PasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@Service
@RequiredArgsConstructor
public class CommonCodeService {
private final CommonCodeMapper commonCodeMapper;
public List<CommonCode> selectCommonCodeToCategory(CommonCode commonCode) {
return commonCodeMapper.selectCommonCodeToCategory(commonCode);
}
}

View File

@ -1,9 +1,8 @@
package com.dbnt.kcgfilemanager.userInfo.service; package com.dbnt.kcgfilemanager.service;
import com.dbnt.kcgfilemanager.userInfo.UserInfo; import com.dbnt.kcgfilemanager.model.UserInfo;
import com.dbnt.kcgfilemanager.userInfo.repository.UserInfoRepository; import com.dbnt.kcgfilemanager.repository.UserInfoRepository;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException; import org.springframework.security.core.userdetails.UsernameNotFoundException;
@ -11,11 +10,10 @@ import org.springframework.security.crypto.password.Pbkdf2PasswordEncoder;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
@Service @Service
@RequiredArgsConstructor @RequiredArgsConstructor
public class UserInfoService implements UserDetailsService { public class UserInfoService implements UserDetailsService {
private final UserInfoRepository userInfoRepository; private final UserInfoRepository userInfoRepository;
@Transactional @Transactional

View File

@ -1,8 +1,24 @@
spring.devtools.livereload.enabled=true
spring.jpa.show-sql=true #thymeleaf
spring.jpa.generate-ddl=false spring.thymeleaf.prefix=classpath:templates/
spring.thymeleaf.check-template-location=true
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=HTML5
spring.thymeleaf.cache=false
#mariaDB
spring.datasource.driverClassName=net.sf.log4jdbc.sql.jdbcapi.DriverSpy spring.datasource.driverClassName=net.sf.log4jdbc.sql.jdbcapi.DriverSpy
spring.datasource.url=jdbc:log4jdbc:mariadb://106.247.244.146:57306/kcg_fm?characterEncoding=UTF-8&serverTimezone=UTC spring.datasource.url=jdbc:log4jdbc:mariadb://106.247.244.146:57306/kcg_fm?characterEncoding=UTF-8&serverTimezone=UTC
spring.datasource.username=root spring.datasource.username=root
spring.datasource.password=dbnt0928 spring.datasource.password=dbnt0928
#jpa
spring.jpa.show-sql=true
spring.jpa.generate-ddl=false
# MyBatis
mybatis.mapper-locations: mybatisMapper/**/*.xml
mybatis.configuration.map-underscore-to-camel-case=true
mybatis.type-aliases-package=com.dbnt.kcgfilemanager.model
logging.level.com.atoz_develop.mybatissample.repository=TRACE

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.dbnt.kcgfilemanager.mapper.CommonCodeMapper">
<select id="selectCommonCodeToCategory" resultType="CommonCode" parameterType="CommonCode">
SELECT DISTINCT
CATEGORY
FROM COMMON_CODE
WHERE IS_DELETED &lt;> 'Y'
</select>
</mapper>

File diff suppressed because one or more lines are too long

View File

@ -4,7 +4,118 @@
xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity5" xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity5"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorate="~{layout/layout}"> layout:decorate="~{layout/layout}">
<div layout:fragment="content"> <div layout:fragment="content">
<h1>codeMgt Page.</h1> <main>
<h4>코드 관리</h4>
<div class="row mx-0">
<div class="col-6 card text-center">
<div class="card-body">
<div class="row justify-content-start">
<div class="col-5">
<table class="table table-striped">
<thead>
<tr>
<th></th>
<th>분류</th>
</tr>
</thead>
<tbody th:if="${categoryList.size()==0}">
<tr>
<td colspan="2">검색된 분류가 없습니다.</td>
</tr>
</tbody>
<tbody th:if="${categoryList.size()>0}">
<tr th:each="commonCode:${categoryList}">
<td>
<input type="checkbox">
</td>
<td>${commonCode.category}</td>
</tr>
</tbody>
</table>
</div> </div>
<div class="col-7">
<table class="table table-striped">
<thead>
<tr>
<th></th>
<th></th>
<th>설명</th>
</tr>
</thead>
<tbody>
<tr>
<td colspan="3">분류를 선택해주세요.</td>
</tr>
<!--<tr>
<td>
<input type="checkbox">
</td>
<td>
asdf
</td>
<td>
zxcv
</td>
</tr>-->
</tbody>
</table>
</div>
</div>
</div>
<div class="card-footer row justify-content-end">
<div class="col-auto">
<input type="button" class="btn btn-primary" value="추가" data-bs-toggle="modal" data-bs-target="#addCommonCodeModal">
<input type="button" class="btn btn-danger" value="삭제">
</div>
</div>
</div>
</div>
</main>
<div class="modal fade" id="addCommonCodeModal" tabindex="-1" aria-labelledby="addCommonCodeModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="addCommonCodeModalLabel">코드 추가</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<div class="mb-3 row">
<input type="hidden" name="category">
<label class="col-sm-2 col-form-label">분류</label>
<div class="col-sm-5">
<select class="form-select" id="categorySelector" th:attrappend="${categoryList.size()==0?'disabled=':''}">
<option th:each="commonCode:${categoryList}" th:value="${commonCode.category}" th:text="${commonCode.category}"></option>
</select>
</div>
<div class="col-sm-5" style="display: none;">
<input type="text" id="categoryInput" class="form-control">
</div>
<div class="col-sm-auto">
<input type="checkbox" id="categoryCheckBox">
<label for="categoryCheckBox">직접입력</label>
</div>
</div>
<div class="mb-3 row">
<label for="value" class="col-sm-2 col-form-label"></label>
<div class="col-sm-5">
<input type="text" class="form-control" id="value">
</div>
</div>
<div class="mb-3 row">
<label for="description" class="col-sm-2 col-form-label">설명</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="description">
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save</button>
</div>
</div>
</div>
</div>
</div>
</html> </html>

View File

@ -8,14 +8,19 @@
<title>해양경찰청 파일관리 시스템</title> <title>해양경찰청 파일관리 시스템</title>
<!-- 공통으로 쓰이는 css파일을넣는다.--> <!-- 공통으로 쓰이는 css파일을넣는다.-->
<!--bootstrap--> <!--bootstrap-->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css"> <!--<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.7.1/font/bootstrap-icons.css"> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.7.1/font/bootstrap-icons.css">-->
<link rel="stylesheet" th:href="@{/vendor/bootstrap-5.1.3-dist/css/bootstrap.min.css}">
<link rel="stylesheet" th:href="@{/img/bootstrap-icons-1.7.1/bootstrap-icons.scss}">
<!-- 컨텐츠페이지의 CSS 영역이 들어감 --> <!-- 컨텐츠페이지의 CSS 영역이 들어감 -->
<th:block layout:fragment="css"></th:block> <th:block layout:fragment="css"></th:block>
<!-- 공통으로 쓰이는 js파일을넣는다.--> <!-- 공통으로 쓰이는 js파일을넣는다.-->
<!--bootstrap--> <!--bootstrap-->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script> <!--<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>-->
<script type="text/javascript" th:src="@{/vendor/bootstrap-5.1.3-dist/js/bootstrap.bundle.min.js}"></script>
<!--jquery-->
<script type="text/javascript" th:src="@{/vendor/jquery-3.6.0/jquery-3.6.0.min.js}"></script>
<!-- 컨텐츠페이지의 스크립트 영역이 들어감 --> <!-- 컨텐츠페이지의 스크립트 영역이 들어감 -->
<th:block layout:fragment="script"></th:block> <th:block layout:fragment="script"></th:block>
</head> </head>

View File

@ -24,7 +24,7 @@
<!-- 로그인 시 아이디의 name 애트리뷰트 값은 username --> <!-- 로그인 시 아이디의 name 애트리뷰트 값은 username -->
<!-- 파라미터명을 변경하고 싶을 경우 config class formlogin()에서 .usernameParameter("") 명시 --> <!-- 파라미터명을 변경하고 싶을 경우 config class formlogin()에서 .usernameParameter("") 명시 -->
<img class="mb-4" src="/docs/5.1/assets/brand/bootstrap-logo.svg" alt="" width="72" height="57"> <!--<img class="mb-4" th:src="@{/img/}" alt="" width="72" height="57">-->
<h1 class="h3 mb-3 fw-normal">Please sign in</h1> <h1 class="h3 mb-3 fw-normal">Please sign in</h1>
<div class="form-floating"> <div class="form-floating">
<input type="text" class="form-control" id="username" name="username" placeholder="아이디"> <input type="text" class="form-control" id="username" name="username" placeholder="아이디">