跨域 屮·

This commit is contained in:
wangliwen 2022-06-02 13:53:40 +08:00
parent 5a41ac20c7
commit 641e6ea2d8
2 changed files with 25 additions and 16 deletions

View File

@ -8,7 +8,6 @@ import com.yawei.pso.SSOResponse;
import com.yawei.pso.TicketManager; import com.yawei.pso.TicketManager;
import io.renren.common.constant.Constant; import io.renren.common.constant.Constant;
import io.renren.common.interceptor.YaweiSSOProperties; import io.renren.common.interceptor.YaweiSSOProperties;
import io.renren.common.utils.HttpContextUtils;
import io.renren.common.utils.Result; import io.renren.common.utils.Result;
import io.renren.modules.security.service.SysUserTokenService; import io.renren.modules.security.service.SysUserTokenService;
import io.renren.modules.security.user.SecurityUser; import io.renren.modules.security.user.SecurityUser;
@ -35,7 +34,6 @@ import java.util.Map;
/** /**
* oauth2过滤器 * oauth2过滤器
*
*/ */
@Component() @Component()
@Scope("prototype") @Scope("prototype")
@ -152,7 +150,7 @@ public class Oauth2Filter extends AuthenticatingFilter {
private void send401Error(HttpServletResponse response, String msg) throws IOException { private void send401Error(HttpServletResponse response, String msg) throws IOException {
response.setContentType("application/json;charset=utf-8"); response.setContentType("application/json;charset=utf-8");
response.setHeader("Access-Control-Allow-Credentials", "true"); response.setHeader("Access-Control-Allow-Credentials", "true");
response.setHeader("Access-Control-Allow-Origin", HttpContextUtils.getOrigin()); response.setHeader("Access-Control-Allow-Origin", "*");
response.setStatus(HttpStatus.SC_UNAUTHORIZED); response.setStatus(HttpStatus.SC_UNAUTHORIZED);
Result r = new Result().error(HttpStatus.SC_UNAUTHORIZED, msg); Result r = new Result().error(HttpStatus.SC_UNAUTHORIZED, msg);

View File

@ -4,7 +4,8 @@
* https://www.renren.io * https://www.renren.io
* <p> * <p>
* 版权所有侵权必究 * 版权所有侵权必究
*/package io.renren.websocket; */
package io.renren.websocket;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import io.renren.common.constant.Constant; import io.renren.common.constant.Constant;
@ -12,6 +13,8 @@ import io.renren.websocket.config.WebSocketConfig;
import io.renren.websocket.data.MessageData; import io.renren.websocket.data.MessageData;
import io.renren.websocket.data.WebSocketData; import io.renren.websocket.data.WebSocketData;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.websocket.*; import javax.websocket.*;
@ -23,12 +26,17 @@ import java.util.concurrent.ConcurrentHashMap;
/** /**
* WebSocket服务 * WebSocket服务
*
*/ */
@Slf4j @Slf4j
@Component @Component
@ServerEndpoint(value = "/websocket", configurator = WebSocketConfig.class) @ServerEndpoint(value = "/websocket", configurator = WebSocketConfig.class)
public class WebSocketServer { public class WebSocketServer {
private static Logger logger = LoggerFactory.getLogger(WebSocketServer.class);
public WebSocketServer() {
logger.info("-------------websocket----------------");
}
/** /**
* 客户端连接信息 * 客户端连接信息
*/ */
@ -61,6 +69,7 @@ public class WebSocketServer {
/** /**
* 发送信息 * 发送信息
*
* @param userIdList 用户ID列表 * @param userIdList 用户ID列表
* @param message 消息内容 * @param message 消息内容
*/ */
@ -70,6 +79,7 @@ public class WebSocketServer {
/** /**
* 发送信息 * 发送信息
*
* @param userId 用户ID * @param userId 用户ID
* @param message 消息内容 * @param message 消息内容
*/ */
@ -83,6 +93,7 @@ public class WebSocketServer {
/** /**
* 发送信息给全部用户 * 发送信息给全部用户
*
* @param message 消息内容 * @param message 消息内容
*/ */
public void sendMessageAll(MessageData<?> message) { public void sendMessageAll(MessageData<?> message) {