-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from IoTeaTime/feature/41-kan-96-security-cont…
…ext-anotation feat: Security Context에서 로그인한 회원의 ID 정보 조회 구현, Swagger Authorization 헤더 추가
- Loading branch information
Showing
6 changed files
with
78 additions
and
17 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
src/main/java/org/ioteatime/meonghanyangserver/common/utils/LoginMember.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package org.ioteatime.meonghanyangserver.common.utils; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
|
||
@Target(ElementType.PARAMETER) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@AuthenticationPrincipal(expression = "id == null ? 0L : id") | ||
public @interface LoginMember {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,13 @@ | |
import io.swagger.v3.oas.annotations.OpenAPIDefinition; | ||
import io.swagger.v3.oas.annotations.info.Contact; | ||
import io.swagger.v3.oas.annotations.info.Info; | ||
import io.swagger.v3.oas.models.Components; | ||
import io.swagger.v3.oas.models.OpenAPI; | ||
import io.swagger.v3.oas.models.security.SecurityRequirement; | ||
import io.swagger.v3.oas.models.security.SecurityScheme; | ||
import io.swagger.v3.oas.models.servers.Server; | ||
import java.util.List; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@OpenAPIDefinition( | ||
|
@@ -13,4 +20,48 @@ | |
version = "v1", | ||
contact = @Contact(name = "서유진", email = "[email protected]"))) | ||
@Configuration | ||
public class OpenApiConfig {} | ||
public class OpenApiConfig { | ||
@Bean | ||
public OpenAPI openAPI() { | ||
SecurityScheme apiKey = | ||
new SecurityScheme() | ||
.type(SecurityScheme.Type.APIKEY) | ||
.in(SecurityScheme.In.HEADER) | ||
.name("Authorization"); | ||
|
||
SecurityRequirement securityRequirement = new SecurityRequirement().addList("Bearer Token"); | ||
|
||
Server productionServer = new Server(); | ||
productionServer.setDescription("Production Server"); | ||
productionServer.setUrl("https://my-server-name.com"); | ||
|
||
Server localServer = new Server(); | ||
localServer.setDescription("Local Server"); | ||
localServer.setUrl("http://localhost:8080"); | ||
|
||
return new OpenAPI() | ||
.addSecurityItem(getSecurityRequirement()) | ||
.components(getAuthComponent()) | ||
.servers(List.of(productionServer, localServer)) | ||
.components(new Components().addSecuritySchemes("Bearer Token", apiKey)) | ||
.addSecurityItem(securityRequirement); | ||
} | ||
|
||
private SecurityRequirement getSecurityRequirement() { | ||
String jwt = "JWT"; | ||
return new SecurityRequirement().addList(jwt); | ||
} | ||
|
||
private Components getAuthComponent() { | ||
return new Components() | ||
.addSecuritySchemes( | ||
"JWT", | ||
new SecurityScheme() | ||
.name("JWT") | ||
.type(SecurityScheme.Type.HTTP) | ||
.scheme("bearer") | ||
.bearerFormat("JWT") | ||
.in(SecurityScheme.In.HEADER) | ||
.name("Authorization")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters