BAIS 권한 서비스를 Spring Java로 전환 #2

Open
forge-bot wants to merge 4 commits from forge/BAIS-E2E-MIG-001-attempt-1 into main
4 changed files with 72 additions and 0 deletions

View file

@ -0,0 +1,3 @@
# BAIS-E2E-MIG-001-attempt-1
Forge 이슈 작업 브랜치 `forge/BAIS-E2E-MIG-001-attempt-1`.

41
pom.xml Normal file
View file

@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>bais-authorization-service</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
</plugin>
</plugins>
</build>
</project>

View file

@ -0,0 +1,11 @@
package com.example.authorization;
import org.springframework.stereotype.Service;
@Service
public class AuthorizationService {
public boolean hasAccess(String userRole, String resource) {
// 간단한 권한 확인 로직
return "ADMIN".equals(userRole) || "USER".equals(userRole) && "RESOURCE".equals(resource);
}
}

View file

@ -0,0 +1,17 @@
package com.example.authorization;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
class AuthorizationServiceTest {
private final AuthorizationService authorizationService = new AuthorizationService();
@Test
void testHasAccess() {
assertTrue(authorizationService.hasAccess("ADMIN", "RESOURCE"));
assertTrue(authorizationService.hasAccess("USER", "RESOURCE"));
assertFalse(authorizationService.hasAccess("USER", "OTHER_RESOURCE"));
assertFalse(authorizationService.hasAccess("GUEST", "RESOURCE"));
}
}