-
Notifications
You must be signed in to change notification settings - Fork 15.1k
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 #6878 from EightMonth/springboot3_sas
修复访问仪表盘401问题
- Loading branch information
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
jeecg-boot/jeecg-boot-base-core/src/main/java/org/jeecg/config/security/CopyTokenFilter.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,36 @@ | ||
package org.jeecg.config.security; | ||
|
||
import io.undertow.servlet.spec.HttpServletRequestImpl; | ||
import io.undertow.util.HttpString; | ||
import jakarta.servlet.FilterChain; | ||
import jakarta.servlet.ServletException; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import org.springframework.core.annotation.Order; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.util.StringUtils; | ||
import org.springframework.web.filter.OncePerRequestFilter; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* 复制仪盘表请求query体携带的token | ||
* @author eightmonth | ||
* @date 2024/7/3 14:04 | ||
*/ | ||
@Component | ||
@Order(value = Integer.MIN_VALUE) | ||
public class CopyTokenFilter extends OncePerRequestFilter { | ||
@Override | ||
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { | ||
// 以下为undertow定制代码,如切换其它servlet容器,需要同步更换 | ||
HttpServletRequestImpl undertowRequest = (HttpServletRequestImpl) request; | ||
String bearerToken = request.getParameter("token"); | ||
if (StringUtils.hasText(bearerToken)) { | ||
undertowRequest.getExchange().getRequestHeaders().add(new HttpString("Authorization"), "bearer " + bearerToken); | ||
} | ||
filterChain.doFilter(undertowRequest, response); | ||
} | ||
|
||
|
||
} |