-
Notifications
You must be signed in to change notification settings - Fork 62
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 #164 from FederatedAI/develop-1.11.1
Develop 1.11.1
- Loading branch information
Showing
5 changed files
with
65 additions
and
4 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
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
43 changes: 43 additions & 0 deletions
43
src/main/java/com/webank/ai/fate/board/conf/WebsocketFilter.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,43 @@ | ||
package com.webank.ai.fate.board.conf; | ||
|
||
import com.alibaba.fastjson.JSON; | ||
import com.webank.ai.fate.board.global.ErrorCode; | ||
import com.webank.ai.fate.board.global.ResponseResult; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.springframework.core.annotation.Order; | ||
|
||
import javax.servlet.*; | ||
import javax.servlet.annotation.WebFilter; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import javax.servlet.http.HttpSession; | ||
import javax.websocket.server.HandshakeRequest; | ||
import java.io.IOException; | ||
|
||
@Slf4j | ||
@Order(1) | ||
@WebFilter(filterName = "websocketFilter", urlPatterns = {"/websocket/progress/*","/log/new/*"}) | ||
public class WebsocketFilter implements Filter { | ||
|
||
@Override | ||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) | ||
throws IOException, ServletException { | ||
HttpServletResponse resp = (HttpServletResponse) response; | ||
HttpServletRequest req = (HttpServletRequest) request; | ||
|
||
HttpSession session = req.getSession(false); | ||
if (session == null) { | ||
resp.getWriter().write(JSON.toJSONString(new ResponseResult<>(ErrorCode.LOGIN_ERROR))); | ||
return ; | ||
} | ||
Object user = session.getAttribute("USER"); | ||
if (user == null) { | ||
resp.getWriter().write(JSON.toJSONString(new ResponseResult<>(ErrorCode.LOGIN_ERROR))); | ||
return ; | ||
} | ||
|
||
chain.doFilter(request, response); | ||
} | ||
|
||
} |