-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor PAT authentication by making it standalone
Signed-off-by: JohnNiang <[email protected]>
- Loading branch information
Showing
13 changed files
with
91 additions
and
284 deletions.
There are no files selected for viewing
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
70 changes: 0 additions & 70 deletions
70
...n/src/main/java/run/halo/app/security/authentication/jwt/JwtAuthenticationConfigurer.java
This file was deleted.
Oops, something went wrong.
37 changes: 0 additions & 37 deletions
37
.../src/main/java/run/halo/app/security/authentication/jwt/LoginAuthenticationConverter.java
This file was deleted.
Oops, something went wrong.
31 changes: 0 additions & 31 deletions
31
...main/java/run/halo/app/security/authentication/jwt/LoginAuthenticationFailureHandler.java
This file was deleted.
Oops, something went wrong.
19 changes: 0 additions & 19 deletions
19
...on/src/main/java/run/halo/app/security/authentication/jwt/LoginAuthenticationManager.java
This file was deleted.
Oops, something went wrong.
62 changes: 0 additions & 62 deletions
62
...main/java/run/halo/app/security/authentication/jwt/LoginAuthenticationSuccessHandler.java
This file was deleted.
Oops, something went wrong.
29 changes: 29 additions & 0 deletions
29
...on/src/main/java/run/halo/app/security/authentication/pat/PatAuthenticationConverter.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,29 @@ | ||
package run.halo.app.security.authentication.pat; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
import org.springframework.security.core.Authentication; | ||
import org.springframework.security.oauth2.server.resource.authentication.BearerTokenAuthenticationToken; | ||
import org.springframework.security.oauth2.server.resource.web.server.authentication.ServerBearerTokenAuthenticationConverter; | ||
import org.springframework.web.server.ServerWebExchange; | ||
import reactor.core.publisher.Mono; | ||
|
||
/** | ||
* PAT authentication converter. | ||
* | ||
* @author johnniang | ||
* @since 2.20.4 | ||
*/ | ||
class PatAuthenticationConverter extends ServerBearerTokenAuthenticationConverter { | ||
|
||
public static final String PAT_TOKEN_PREFIX = "pat_"; | ||
|
||
@Override | ||
public Mono<Authentication> convert(ServerWebExchange exchange) { | ||
return super.convert(exchange) | ||
.cast(BearerTokenAuthenticationToken.class) | ||
.map(BearerTokenAuthenticationToken::getToken) | ||
.filter(token -> StringUtils.startsWith(token, PAT_TOKEN_PREFIX)) | ||
.map(token -> StringUtils.removeStart(token, PAT_TOKEN_PREFIX)) | ||
.map(BearerTokenAuthenticationToken::new); | ||
} | ||
} |
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
Oops, something went wrong.