Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
proxy-manager-backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
aolda
proxy-manager-backend
Commits
7320a6e1
Commit
7320a6e1
authored
3 months ago
by
천 진강
Browse files
Options
Downloads
Patches
Plain Diff
fix: project token으로 project role 확인하도록 수정
parent
caac306f
Branches
Branches containing commit
No related tags found
3 merge requests
!15
Feat/certificate
,
!6
Feat/forwarding 포트포워딩 CRUD
,
!5
Feat/auth 어드민 권한 확인 로직, 개인 토큰 사용하도록 변경
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/com/aolda/itda/service/AuthService.java
+51
-1
51 additions, 1 deletion
src/main/java/com/aolda/itda/service/AuthService.java
with
51 additions
and
1 deletion
src/main/java/com/aolda/itda/service/AuthService.java
+
51
−
1
View file @
7320a6e1
...
@@ -15,6 +15,7 @@ import org.springframework.beans.factory.annotation.Value;
...
@@ -15,6 +15,7 @@ import org.springframework.beans.factory.annotation.Value;
import
org.springframework.http.*
;
import
org.springframework.http.*
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.web.client.HttpClientErrorException
;
import
org.springframework.web.client.HttpClientErrorException
;
import
org.springframework.web.client.RestClientException
;
import
org.springframework.web.client.RestTemplate
;
import
org.springframework.web.client.RestTemplate
;
import
java.util.*
;
import
java.util.*
;
...
@@ -133,11 +134,59 @@ public class AuthService {
...
@@ -133,11 +134,59 @@ public class AuthService {
return
token
;
return
token
;
}
}
private
String
getProjectToken
(
String
unscopedToken
,
String
projectId
)
{
String
url
=
keystone
+
"/auth/tokens"
;
HttpHeaders
headers
=
new
HttpHeaders
();
headers
.
setContentType
(
MediaType
.
APPLICATION_JSON
);
String
requestBody
=
"{\n"
+
" \"auth\": {\n"
+
" \"identity\": {\n"
+
" \"methods\": [\n"
+
" \"token\"\n"
+
" ],\n"
+
" \"token\": {\n"
+
" \"id\": \""
+
unscopedToken
+
"\"\n"
+
" }\n"
+
" },\n"
+
" \"scope\": {\n"
+
" \"project\": {\n"
+
" \"id\": \""
+
projectId
+
"\"\n"
+
" }\n"
+
" }\n"
+
" }\n"
+
"}"
;
HttpEntity
<
String
>
requestEntity
;
ResponseEntity
<
Map
>
res
;
try
{
requestEntity
=
new
HttpEntity
<>(
requestBody
,
headers
);
res
=
restTemplate
.
postForEntity
(
url
,
requestEntity
,
Map
.
class
);
}
catch
(
HttpClientErrorException
.
Forbidden
e
)
{
return
unscopedToken
;
}
catch
(
RuntimeException
e
)
{
e
.
printStackTrace
();
throw
new
CustomException
(
ErrorCode
.
INVALID_TOKEN
);
}
Map
<
String
,
Object
>
resToken
=
(
Map
<
String
,
Object
>)
res
.
getBody
().
get
(
"token"
);
Map
<
String
,
Object
>
resUser
=
(
Map
<
String
,
Object
>)
resToken
.
get
(
"user"
);
String
userId
=
(
String
)
resUser
.
get
(
"id"
);
String
token
=
res
.
getHeaders
().
getFirst
(
"X-Subject-Token"
);
return
token
;
}
// 특정 사용자의 특정 프로젝트 내 최고 권한 반환
// 특정 사용자의 특정 프로젝트 내 최고 권한 반환
public
Map
<
String
,
String
>
getBestRoleWithinProject
(
String
token
,
String
projectId
)
throws
JsonProcessingException
{
public
Map
<
String
,
String
>
getBestRoleWithinProject
(
String
token
,
String
projectId
)
throws
JsonProcessingException
{
return
getBestRoleWithinProject
(
Map
.
of
(
return
getBestRoleWithinProject
(
Map
.
of
(
"id"
,
validateTokenAndGetUserId
(
token
),
"id"
,
validateTokenAndGetUserId
(
token
),
"token"
,
token
),
"token"
,
getProjectToken
(
token
,
projectId
)
),
projectId
);
projectId
);
}
}
...
@@ -224,6 +273,7 @@ public class AuthService {
...
@@ -224,6 +273,7 @@ public class AuthService {
try
{
try
{
res
=
restTemplate
.
exchange
(
url
,
HttpMethod
.
GET
,
requestEntity
,
String
.
class
);
res
=
restTemplate
.
exchange
(
url
,
HttpMethod
.
GET
,
requestEntity
,
String
.
class
);
}
catch
(
HttpClientErrorException
.
NotFound
e
)
{
}
catch
(
HttpClientErrorException
.
NotFound
e
)
{
System
.
out
.
println
(
"validate"
);
throw
new
CustomException
(
ErrorCode
.
INVALID_TOKEN
);
throw
new
CustomException
(
ErrorCode
.
INVALID_TOKEN
);
}
}
return
objectMapper
.
readTree
(
res
.
getBody
()).
path
(
"token"
).
path
(
"user"
).
path
(
"id"
).
asText
();
return
objectMapper
.
readTree
(
res
.
getBody
()).
path
(
"token"
).
path
(
"user"
).
path
(
"id"
).
asText
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment