Class DefaultAuthService
java.lang.Object
tech.riemann.nif.auth.service.HttpServletAuthService
tech.riemann.nif.auth.service.impl.DefaultAuthService
- All Implemented Interfaces:
AuthService
默认认证服务实现
继承自HttpServletAuthService,提供基于Spring Web上下文的默认实现
主要特点: 1. 通过RequestContextHolder获取HttpServletRequest和HttpServletResponse 2. 使用构造器注入所需的依赖(JWTEncoder、JWTDecoder、UserDetailService) 3. 适用于标准的Spring Boot Web应用
使用示例:
@Bean
public AuthService authService(JWTEncoder encoder, JWTDecoder decoder, UserDetailService userDetailService,
AuthAutoConfigurationProperties config) {
return new DefaultAuthService(encoder, decoder, userDetailService, config.isAllowQueryToken());
}
- Author:
- Kerbores(kerbores@riemann.tech)
-
Field Summary
Fields inherited from class HttpServletAuthService
TOKEN_EXPIRED -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected boolean是否允许从 URL 查询参数中获取 Token(H10)jakarta.servlet.http.HttpServletRequest获取HttpServletRequest对象jakarta.servlet.http.HttpServletResponse获取HttpServletResponse对象获取JWT解码器获取JWT编码器获取用户详情服务Methods inherited from class HttpServletAuthService
addCookie, authentication, authorizationHeaderKey, cookieSettings, login, logout, optionalUser, pass, refreshToken, refreshToken, refreshTokenKey, skip, subject, token, token, tokenKey, tokenOrRefreshToken, tryRefreshToken, userMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface AuthService
permissions, roles, userName
-
Constructor Details
-
DefaultAuthService
public DefaultAuthService()
-
-
Method Details
-
allowQueryToken
protected boolean allowQueryToken()是否允许从 URL 查询参数中获取 Token(H10)- Overrides:
allowQueryTokenin classHttpServletAuthService- Returns:
- 由配置
nif.auth.allow-query-token决定,默认 false(禁止)
-
getRequest
public jakarta.servlet.http.HttpServletRequest getRequest()获取HttpServletRequest对象通过Spring的RequestContextHolder获取当前请求上下文
- Specified by:
getRequestin classHttpServletAuthService- Returns:
- HttpServletRequest实例
-
getResponse
public jakarta.servlet.http.HttpServletResponse getResponse()获取HttpServletResponse对象通过Spring的RequestContextHolder获取当前响应上下文
- Specified by:
getResponsein classHttpServletAuthService- Returns:
- HttpServletResponse实例
-
userDetailService
获取用户详情服务- Specified by:
userDetailServicein classHttpServletAuthService- Returns:
- UserDetailService实例
-
jwtEncoder
获取JWT编码器- Specified by:
jwtEncoderin classHttpServletAuthService- Returns:
- JWTEncoder实例
-
jwtDecoder
获取JWT解码器- Specified by:
jwtDecoderin classHttpServletAuthService- Returns:
- JWTDecoder实例
-