- 아래에 대하여 설명하시오.
- 인증
- 권한
- 인가
- 아래의 로그인 방법에 대하여 설명하시오.
- token 방식
- 쿠세-세션 방식
- 소셜 로그인
- 자바스크립트에서, 게시판 CRUD의 모듈화에 대하여 정리 하시오?
- 스프링 시큐리티 라이브러리 3개를 정리하시오.
- 스프링 시큐리티에서 정적 리소스를 셋팅하는 방법은?
- 스프링 시큐리티에서 테스트 유저를 생성하는 방법은?(인메모리 방식)
- 스프링 시큐리티에서 시큐리티 에서 권한을 설정 하는 방법은?
- 아래가 되도록 셋팅 하시오.
유저가 admin 이고 권한이 admin 인 사람만이 /company/list 가 나오도록 하시오.
board.js
/*
* boardService
* 모듈 구성하기
*
* 모듈 패턴은 쉽게 말해서 Java의 클래스처럼 JavaScript를 이용해서 메서드를 가지는 객체를 구성한다.
* 모듈 패턴은 JavaScript의 즉시 실행함수와 '{}'를 이용해서 객체를 구성한다.
*
*
* */
console.log("board Module..");
let boardService = (function() {
function boardList(callback) {
$.ajax({
type : "GET",
url : "/boards/list",
success : function(result) {
console.log(result);
if (callback) {
callback(result);
}
},
error : function(e) {
console.log(e);
}
});
}
function getBoard(id) {
$.ajax({
type : "GET",
url : "${pageContext.request.contextPath}/boards/" + id,
success : function(result) {
console.log(result);
},
error : function(e) {
console.log(e);
}
});
}
function deleteBoard(id){
$.ajax({
type:"DELETE",
url: "${pageContext.request.contextPath}/boards/" + id,
success: function(result){
console.log(result);
},
error: function(e){
console.log(e);
}
});
}
return {
list : boardList,
get : getBoard,
del : deleteBoard,
};
})();
board.js 파일을 포함시킨 파일
- 모듈화된 객체를 이용해 사용하려는 기능을 가진 함수를 호출하는 방식.
<script type="text/javascript" src="/js/board.js"></script>
<script type="text/javascript">
$(document).ready(function(){
function makeList(result) {
let htmls = "";
$("#list-table").html("");
$("<tr>" , {
html : "<td>" + "번호" + "</td>" + // 컬럼명들
"<td>" + "이름" + "</td>" +
"<td>" + "제목" + "</td>" +
"<td>" + "날짜" + "</td>" +
"<td>" + "히트" + "</td>"
}).appendTo("#list-table") // 이것을 테이블에 붙임
if(result.length < 1){
htmls.push("등록된 게시글 없습니다.");
}else{
$(result).each(function(){
htmls += '<tr>';
htmls += '<td>' + this.bid + '</td>';
htmls += '<td>' + this.bname + '</td>';
htmls += '<td>'
for(var i=0; i < this.bindent; i++) {
htmls += '-'
}
htmls += '<a href="${pageContext.request.contextPath}/content_view?bid=' + this.bid + '">' + this.btitle + '</a></td>';
htmls += '<td>'+ this.bdate + '</td>';
htmls += '<td>'+ this.bhit + '</td>';
htmls += '<td>'+ '<input id=' + this.bid + " type='button' class='btn_delete' value='삭제'>" + '</td>';
htmls += '</tr>';
}); //each end
}
htmls+='<tr>';
htmls+='<td colspan="5"> <a href="${pageContext.request.contextPath}/write_view">글작성</a> </td>';
htmls+='</tr>';
$("#list-table").append(htmls);
}
// 모듈에서 불러온 함수
boardService.list(makeList);
}
</script>
<!-- 스프링 시큐리티 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<!-- 스프링 부트에서는 jsp 태그를 지원 하지 않기 때문에 직접 입력 해야 함 -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-taglibs</artifactId>
</dependency>
import org.springframework.context.annotation.Configuration;
org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
@Configuration
@EnableWebSecurity // 스프링 시큐리티 필터가 스프링 필터체인에 등록됨.
public class SecurityConfig extends WebSecurityConfigurerAdapter{
}
@Override
public void configure(WebSecurity web) throws Exception {
// web.ignoring().requestMatchers(PathRequest.toStaticResources().atCommonLocations());
web.ignoring().antMatchers("/css/**", "/js/**", "/imgs/**", "/lib/**");
}
web.ignoring().antMatchers("/css/**", "/js/**", "/images/**", "/lib/**");

@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication()
.withUser("member").password("{noop}member").roles("USER").and()
.withUser("admin").password("{noop}admin").roles("ADMIN");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
//우선 CSRF설정을 해제한다.
//초기 개발시만 해주는게 좋다.
http.csrf().disable();
http.authorizeRequests()
.antMatchers("/member/**").hasAnyRole("ROLE_MEMBER")
.antMatchers("/admin/**").hasAnyRole("ROLE_ADMIN")
.antMatchers("/**").permitAll();
}
// 유저 admin 생성 및 권한 부여
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication()
.withUser("member").password("{noop}member").roles("USER").and()
.withUser("admin").password("{noop}admin").roles("ADMIN");
}
// 권한 설정하기
@Override
protected void configure(HttpSecurity http) throws Exception {
// 우선 CSRF설정을 해제한다.
// 초기 개발시만 해주는게 좋다.
http.csrf().disable();
// 권한 설정
http.authorizeRequests()
.antMatchers("/board/**").hasAnyRole("USER")
.antMatchers("/admin/**").hasAnyRole("ADMIN")
.antMatchers("/company/list").hasAnyRole("ADMIN")
.antMatchers("/**").permitAll();
// .antMatchers("/company/list").hasAnyRole("ADMIN") : 권한 설정할 때 사용하는 문구
http.formLogin(); // 스프링 시큐리티에 있는 기본 로그인 폼을 사용하겠다.
}