Skip to content

Commit

Permalink
[feat] : 접근권한 제어
Browse files Browse the repository at this point in the history
  • Loading branch information
BlackBean99 committed Sep 4, 2023
1 parent 6368a59 commit 8cf2d65
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
.permitAll()
.mvcMatchers(HttpMethod.GET, "/api/v1/token")
.permitAll()
.mvcMatchers(HttpMethod.GET, "/api/v1/timetables")
.permitAll()
.mvcMatchers(HttpMethod.POST, "/api/v1/timetables")
.permitAll()
.mvcMatchers(HttpMethod.POST, "/api/v1/questions")
.permitAll()
.mvcMatchers(HttpMethod.POST, "/api/v1/applicants")
Expand All @@ -96,7 +100,7 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
@Bean
public RoleHierarchyImpl roleHierarchy() {
RoleHierarchyImpl roleHierarchy = new RoleHierarchyImpl();
roleHierarchy.setHierarchy("ROLE_PRESIDENT > ROLE_OPERATION > ROLE_TF > ROLE_SWAGGER");
roleHierarchy.setHierarchy("ROLE_PRESIDENT > ROLE_OPERATION > ROLE_TF > ROLE_SWAGGER > ROLE_GUEST");
return roleHierarchy;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
package com.econovation.recruit.utils;

import com.econovation.recruitdomain.domains.dto.InterviewerCreateDto;
import com.econovation.recruitdomain.domains.interviewer.domain.Interviewer;
import com.econovation.recruitdomain.domains.interviewer.domain.Role;
import com.econovation.recruitdomain.out.InterviewerRecordPort;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.sql.SQLException;
import java.util.List;
import java.util.stream.Collectors;
import javax.annotation.PostConstruct;
import javax.sql.DataSource;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.core.io.ClassPathResource;
import org.springframework.jdbc.datasource.init.ScriptUtils;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;

@Component
Expand All @@ -18,6 +26,14 @@
@ConditionalOnProperty(name = "data.init.disabled", havingValue = "false", matchIfMissing = true)
public class DataInit {
private final DataSource dataSource;
private final InterviewerRecordPort interviewerRecordPort;
private final PasswordEncoder passwordEncoder;

@Value("${data.init.admin.id}")
private String adminEmail;

@Value("${data.init.admin.password}")
private String adminPassword;

@PostConstruct
public void init() throws IOException, SQLException {
Expand All @@ -27,5 +43,14 @@ public void init() throws IOException, SQLException {
String sql = new String(resource.getInputStream().readAllBytes(), StandardCharsets.UTF_8);
log.info(sql);
ScriptUtils.executeSqlScript(dataSource.getConnection(), resource);
String encededPassword = passwordEncoder.encode(adminPassword);
Interviewer admin = Interviewer.builder()
.name("이서현")
.role(Role.ROLE_OPERATION)
.year(21)
.email(adminEmail)
.password(encededPassword)
.build();
interviewerRecordPort.save(admin);
}
}
3 changes: 3 additions & 0 deletions server/Recruit-Api/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ spring:
data:
init:
disabled: ${DATA_INIT_DISABLED:false}
admin:
id: ${ADMINISTRATOR_ID:admin}
password: ${ADMINISTRATOR_PASSWORD:password}
server:
port: ${SERVER_PORT:8080}
throttle:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@ public class RecruitStatic {
"/api-docs"
};
public static final String[] RolePattern = {
"ROLE_TF", "ROLE_PRESIDENT", "ROLE_OPERATION",
"ROLE_TF", "ROLE_PRESIDENT", "ROLE_OPERATION", "ROLE_SWAGGER"
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class Interviewer {

@PrePersist
public void prePersist() {
this.role = Role.ROLE_TF;
this.role = Role.ROLE_GUEST;
}

public void updateRole(Role role) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
public enum Role {
ROLE_PRESIDENT("PRESIDENT"),
ROLE_OPERATION("OPERATION"),
ROLE_TF("TF");
ROLE_TF("TF"),
ROLE_GUEST("GUEST"),
;
private final String role;

Role(String role) {
Expand All @@ -22,10 +24,8 @@ public static Role getByName(String name) {
for (Role os : Role.values()) {
if (os.getRole().equals(name)) {
return os;
} else {
throw InterviewerInvalidRoleException.EXCEPTION;
}
}
return null;
throw InterviewerInvalidRoleException.EXCEPTION;
}
}

0 comments on commit 8cf2d65

Please sign in to comment.