forked from TencentBlueKing/bk-ci
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat:oauth2 增加密码模式 TencentBlueKing#10663
- Loading branch information
Showing
18 changed files
with
126 additions
and
145 deletions.
There are no files selected for viewing
13 changes: 3 additions & 10 deletions
13
...re/auth/api-auth/src/main/kotlin/com/tencent/devops/auth/pojo/Oauth2AccessTokenRequest.kt
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 |
---|---|---|
@@ -1,17 +1,10 @@ | ||
package com.tencent.devops.auth.pojo | ||
|
||
import com.tencent.devops.auth.pojo.enum.Oauth2GrantType | ||
import io.swagger.v3.oas.annotations.media.Schema | ||
|
||
@Schema(title = "oauth2获取token请求报文体") | ||
data class Oauth2AccessTokenRequest( | ||
open class Oauth2AccessTokenRequest( | ||
@get:Schema(title = "授权类型", required = true) | ||
val grantType: String, | ||
@get:Schema(title = "授权码,用于授权码模式", required = false) | ||
val code: String? = null, | ||
@get:Schema(title = "refreshToken,用于刷新授权码模式", required = false) | ||
val refreshToken: String? = null, | ||
@get:Schema(title = "账号名称,用于密码模式", required = false) | ||
val userName: String? = null, | ||
@get:Schema(title = "密码,用于密码模式", required = false) | ||
val passWord: String? = null | ||
open val grantType: Oauth2GrantType | ||
) |
12 changes: 12 additions & 0 deletions
12
...h/api-auth/src/main/kotlin/com/tencent/devops/auth/pojo/Oauth2AuthorizationCodeRequest.kt
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 com.tencent.devops.auth.pojo | ||
|
||
import com.tencent.devops.auth.pojo.enum.Oauth2GrantType | ||
import io.swagger.v3.oas.annotations.media.Schema | ||
|
||
@Schema(title = "授权码模式获取token请求报文体") | ||
data class Oauth2AuthorizationCodeRequest( | ||
@get:Schema(title = "授权类型", required = true) | ||
override val grantType: Oauth2GrantType, | ||
@get:Schema(title = "授权码,用于授权码模式", required = false) | ||
val code: String | ||
) : Oauth2AccessTokenRequest(grantType) |
14 changes: 14 additions & 0 deletions
14
.../core/auth/api-auth/src/main/kotlin/com/tencent/devops/auth/pojo/Oauth2PassWordRequest.kt
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,14 @@ | ||
package com.tencent.devops.auth.pojo | ||
|
||
import com.tencent.devops.auth.pojo.enum.Oauth2GrantType | ||
import io.swagger.v3.oas.annotations.media.Schema | ||
|
||
@Schema(title = "密码模式获取token请求报文体") | ||
data class Oauth2PassWordRequest( | ||
@get:Schema(title = "授权类型", required = true) | ||
override val grantType: Oauth2GrantType, | ||
@get:Schema(title = "账号名称,用于密码模式", required = false) | ||
val userName: String? = null, | ||
@get:Schema(title = "密码,用于密码模式", required = false) | ||
val passWord: String? = null | ||
) : Oauth2AccessTokenRequest(grantType) |
12 changes: 12 additions & 0 deletions
12
...e/auth/api-auth/src/main/kotlin/com/tencent/devops/auth/pojo/Oauth2RefreshTokenRequest.kt
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 com.tencent.devops.auth.pojo | ||
|
||
import com.tencent.devops.auth.pojo.enum.Oauth2GrantType | ||
import io.swagger.v3.oas.annotations.media.Schema | ||
|
||
@Schema(title = "客户端模式获取token请求报文体") | ||
data class Oauth2RefreshTokenRequest( | ||
@get:Schema(title = "授权类型", required = true) | ||
override val grantType: Oauth2GrantType, | ||
@get:Schema(title = "刷新码,用于刷新授权码模式", required = false) | ||
val refreshToken: String | ||
) : Oauth2AccessTokenRequest(grantType) |
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
47 changes: 0 additions & 47 deletions
47
...core/auth/biz-auth/src/main/kotlin/com/tencent/devops/auth/service/oauth2/Oauth2Config.kt
This file was deleted.
Oops, something went wrong.
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
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
23 changes: 0 additions & 23 deletions
23
...uth/src/main/kotlin/com/tencent/devops/auth/service/oauth2/grant/CompositeTokenGranter.kt
This file was deleted.
Oops, something went wrong.
21 changes: 21 additions & 0 deletions
21
...src/main/kotlin/com/tencent/devops/auth/service/oauth2/grant/Oauth2TokenGranterFactory.kt
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,21 @@ | ||
package com.tencent.devops.auth.service.oauth2.grant | ||
|
||
import com.tencent.devops.auth.constant.AuthMessageCode | ||
import com.tencent.devops.auth.pojo.enum.Oauth2GrantType | ||
import com.tencent.devops.common.api.exception.ErrorCodeException | ||
import com.tencent.devops.common.service.utils.SpringContextUtil | ||
|
||
object Oauth2TokenGranterFactory { | ||
fun getTokenGranter(grantType: Oauth2GrantType): TokenGranter<*> { | ||
val tokenGranters = SpringContextUtil.getBeansWithClass(TokenGranter::class.java) | ||
for (tokenGranter in tokenGranters) { | ||
if (grantType == tokenGranter.type()) { | ||
return tokenGranter | ||
} | ||
} | ||
throw ErrorCodeException( | ||
errorCode = AuthMessageCode.INVALID_AUTHORIZATION_TYPE, | ||
defaultMessage = "The client does not support $grantType type" | ||
) | ||
} | ||
} |
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
Oops, something went wrong.