跨域 屮·
This commit is contained in:
parent
5a41ac20c7
commit
641e6ea2d8
|
@ -8,7 +8,6 @@ import com.yawei.pso.SSOResponse;
|
|||
import com.yawei.pso.TicketManager;
|
||||
import io.renren.common.constant.Constant;
|
||||
import io.renren.common.interceptor.YaweiSSOProperties;
|
||||
import io.renren.common.utils.HttpContextUtils;
|
||||
import io.renren.common.utils.Result;
|
||||
import io.renren.modules.security.service.SysUserTokenService;
|
||||
import io.renren.modules.security.user.SecurityUser;
|
||||
|
@ -35,11 +34,10 @@ import java.util.Map;
|
|||
|
||||
/**
|
||||
* oauth2过滤器
|
||||
*
|
||||
*/
|
||||
@Component()
|
||||
@Scope("prototype")
|
||||
public class Oauth2Filter extends AuthenticatingFilter {
|
||||
public class Oauth2Filter extends AuthenticatingFilter {
|
||||
|
||||
@Autowired
|
||||
private YaweiSSOProperties yaweiSSOProperties;
|
||||
|
@ -55,7 +53,7 @@ public class Oauth2Filter extends AuthenticatingFilter {
|
|||
//获取请求token
|
||||
String token = getRequestToken((HttpServletRequest) request);
|
||||
|
||||
if(StringUtils.isBlank(token)){
|
||||
if (StringUtils.isBlank(token)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -152,7 +150,7 @@ public class Oauth2Filter extends AuthenticatingFilter {
|
|||
private void send401Error(HttpServletResponse response, String msg) throws IOException {
|
||||
response.setContentType("application/json;charset=utf-8");
|
||||
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);
|
||||
Result r = new Result().error(HttpStatus.SC_UNAUTHORIZED, msg);
|
||||
|
||||
|
@ -167,7 +165,7 @@ public class Oauth2Filter extends AuthenticatingFilter {
|
|||
/**
|
||||
* 获取请求的token
|
||||
*/
|
||||
private String getRequestToken(HttpServletRequest httpRequest){
|
||||
private String getRequestToken(HttpServletRequest httpRequest) {
|
||||
//从header中获取token
|
||||
String token = httpRequest.getHeader(Constant.TOKEN_HEADER);
|
||||
|
||||
|
@ -176,7 +174,7 @@ public class Oauth2Filter extends AuthenticatingFilter {
|
|||
}
|
||||
|
||||
//如果header中不存在token,则从参数中获取token
|
||||
if(StringUtils.isBlank(token)){
|
||||
if (StringUtils.isBlank(token)) {
|
||||
token = httpRequest.getParameter(Constant.TOKEN_HEADER);
|
||||
}
|
||||
|
||||
|
@ -200,7 +198,7 @@ public class Oauth2Filter extends AuthenticatingFilter {
|
|||
private boolean yaweiHandle(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
||||
// 获取当前请求的url
|
||||
String requestUri = request.getHeader("REQUESTURI");
|
||||
if (requestUri == null){
|
||||
if (requestUri == null) {
|
||||
requestUri = request.getRequestURI();
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,8 @@
|
|||
* https://www.renren.io
|
||||
* <p>
|
||||
* 版权所有,侵权必究!
|
||||
*/package io.renren.websocket;
|
||||
*/
|
||||
package io.renren.websocket;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
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.WebSocketData;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.websocket.*;
|
||||
|
@ -23,12 +26,17 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||
|
||||
/**
|
||||
* WebSocket服务
|
||||
*
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
@ServerEndpoint(value = "/websocket", configurator = WebSocketConfig.class)
|
||||
public class WebSocketServer {
|
||||
private static Logger logger = LoggerFactory.getLogger(WebSocketServer.class);
|
||||
|
||||
public WebSocketServer() {
|
||||
logger.info("-------------websocket----------------");
|
||||
}
|
||||
|
||||
/**
|
||||
* 客户端连接信息
|
||||
*/
|
||||
|
@ -56,13 +64,14 @@ public class WebSocketServer {
|
|||
|
||||
@OnMessage
|
||||
public void onMessage(Session session, String msg) {
|
||||
log.info("session id: " + session.getId()+", message:" + msg);
|
||||
log.info("session id: " + session.getId() + ", message:" + msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送信息
|
||||
* @param userIdList 用户ID列表
|
||||
* @param message 消息内容
|
||||
*
|
||||
* @param userIdList 用户ID列表
|
||||
* @param message 消息内容
|
||||
*/
|
||||
public void sendMessage(List<Long> userIdList, MessageData<?> message) {
|
||||
userIdList.forEach(userId -> sendMessage(userId, message));
|
||||
|
@ -70,8 +79,9 @@ public class WebSocketServer {
|
|||
|
||||
/**
|
||||
* 发送信息
|
||||
* @param userId 用户ID
|
||||
* @param message 消息内容
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @param message 消息内容
|
||||
*/
|
||||
public void sendMessage(Long userId, MessageData<?> message) {
|
||||
servers.values().forEach(info -> {
|
||||
|
@ -83,7 +93,8 @@ public class WebSocketServer {
|
|||
|
||||
/**
|
||||
* 发送信息给全部用户
|
||||
* @param message 消息内容
|
||||
*
|
||||
* @param message 消息内容
|
||||
*/
|
||||
public void sendMessageAll(MessageData<?> message) {
|
||||
servers.values().forEach(info -> sendMessage(info.getSession(), message));
|
||||
|
|
Loading…
Reference in New Issue