ip隔离-整理oauth/ticket
This commit is contained in:
@@ -31,10 +31,7 @@ public class LoginRecordService {
|
||||
|
||||
public int countLoginRecordToday(Long uid) {
|
||||
Date date = new Date();
|
||||
AccountLoginRecordExample example = new AccountLoginRecordExample();
|
||||
example.createCriteria().andUidEqualTo(uid)
|
||||
.andCreateTimeBetween(DateTimeUtil.getBeginTimeOfDay(date), DateTimeUtil.getEndTimeOfDay(date));
|
||||
return accountLoginRecordMapper.countByExample(example);
|
||||
return countLoginRecordBetweenQueryTime(uid, DateTimeUtil.getBeginTimeOfDay(date), DateTimeUtil.getEndTimeOfDay(date));
|
||||
}
|
||||
|
||||
public int countLoginRecordBetweenQueryTime(Long uid, Date startTime, Date endTime) {
|
||||
|
@@ -39,6 +39,8 @@ public class ApplicationConstant {
|
||||
public static final String CLIENT = "client";
|
||||
|
||||
public static final String H5 = "h5";
|
||||
public static final String MCC = "mcc";
|
||||
public static final String LANG = "lang";
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -21,6 +21,8 @@ public class DeviceInfo {
|
||||
private String androidId;
|
||||
private String client;
|
||||
private String adid;
|
||||
private String mcc;
|
||||
private String lang;
|
||||
|
||||
public String getClient() {
|
||||
return client;
|
||||
@@ -158,6 +160,22 @@ public class DeviceInfo {
|
||||
this.adid = adid;
|
||||
}
|
||||
|
||||
public String getMcc() {
|
||||
return mcc;
|
||||
}
|
||||
|
||||
public void setMcc(String mcc) {
|
||||
this.mcc = mcc;
|
||||
}
|
||||
|
||||
public String getLang() {
|
||||
return lang;
|
||||
}
|
||||
|
||||
public void setLang(String lang) {
|
||||
this.lang = lang;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DeviceInfo{" +
|
||||
|
@@ -1958,6 +1958,8 @@ public class Constant {
|
||||
|
||||
public static final String GUILD_JOIN_HIDE_LIST = "guild_join_hide_list";
|
||||
|
||||
public static final String MAINLAND_IP_IOS_INTERVAL_HOUR = "1";
|
||||
|
||||
}
|
||||
|
||||
public static class ActiveMq {
|
||||
|
@@ -765,6 +765,9 @@ public class UsersService extends BaseService {
|
||||
}
|
||||
if (StringUtils.isNotBlank(account.getRegisterIp())) {
|
||||
users.setRegion(regionService.getCountry(account.getRegisterIp()));
|
||||
users.setLastLoginTime(new Date());
|
||||
users.setLastLoginIp(account.getRegisterIp());
|
||||
users.setLastLoginRegion(regionService.getRegion(account.getRegisterIp()));
|
||||
}
|
||||
hasRegPacket = checkHasInviteRegisterPacket(users.getShareUid(), deviceInfo);
|
||||
users.setErbanNo(account.getErbanNo());
|
||||
|
@@ -43,6 +43,8 @@ public class BaseController {
|
||||
deviceInfo.setOs(request.getParameter(ApplicationConstant.PublicParameters.OS));
|
||||
deviceInfo.setOsVersion(request.getParameter(ApplicationConstant.PublicParameters.OS_VERSION));
|
||||
deviceInfo.setClient(request.getHeader(ApplicationConstant.PublicParameters.CLIENT));
|
||||
deviceInfo.setMcc(request.getHeader(ApplicationConstant.PublicParameters.MCC));
|
||||
deviceInfo.setLang(request.getHeader(ApplicationConstant.PublicParameters.LANG));
|
||||
return deviceInfo;
|
||||
}
|
||||
|
||||
|
@@ -1,60 +0,0 @@
|
||||
package com.accompany.oauth2.vo;
|
||||
|
||||
import com.accompany.oauth2.ticket.Ticket;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class TicketRes{
|
||||
private String issue_type;
|
||||
private List<TicketVo> tickets;
|
||||
private String accid;
|
||||
private Long uid;
|
||||
private String netEaseToken;
|
||||
|
||||
public String getIssue_type() {
|
||||
return issue_type;
|
||||
}
|
||||
|
||||
public String getAccid() {
|
||||
return accid;
|
||||
}
|
||||
|
||||
public Long getUid() {
|
||||
return uid;
|
||||
}
|
||||
|
||||
public String getNetEaseToken() {
|
||||
return netEaseToken;
|
||||
}
|
||||
|
||||
public void setIssue_type(String issue_type) {
|
||||
this.issue_type = issue_type;
|
||||
}
|
||||
|
||||
public List<TicketVo> getTickets() {
|
||||
return tickets;
|
||||
}
|
||||
|
||||
public void setAccid(String accid) {
|
||||
this.accid = accid;
|
||||
}
|
||||
|
||||
public void setUid(Long uid) {
|
||||
this.uid = uid;
|
||||
}
|
||||
|
||||
public void setNetEaseToken(String netEaseToken) {
|
||||
this.netEaseToken = netEaseToken;
|
||||
}
|
||||
|
||||
public void setTickets(List<Ticket> tickets){
|
||||
if(tickets == null){
|
||||
return;
|
||||
}
|
||||
this.tickets = new ArrayList<TicketVo>();
|
||||
for(Ticket ticket : tickets){
|
||||
this.tickets.add(new TicketVo(ticket));
|
||||
}
|
||||
}
|
||||
}
|
@@ -15,6 +15,7 @@ import com.accompany.oauth2.constant.LoginTypeEnum;
|
||||
import com.accompany.oauth2.model.AccountDetails;
|
||||
import com.accompany.oauth2.mq.RocketMQService;
|
||||
import com.accompany.oauth2.service.MyUserDetailsService;
|
||||
import com.accompany.oauth2.vo.TicketVo;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.google.common.collect.Maps;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@@ -102,8 +103,9 @@ public class TicketServices implements InitializingBean{
|
||||
throw new InvalidTokenException("Access token expired: " + accessTokenValue);
|
||||
}
|
||||
|
||||
String uid = accountDetails.getAccount().getUid().toString();
|
||||
String realAccessToken = ticketStore.readAccessToken(uid);
|
||||
Long uid = accountDetails.getAccount().getUid();
|
||||
String uidStr = uid.toString();
|
||||
String realAccessToken = ticketStore.readAccessToken(uidStr);
|
||||
logger.info("issueTicket. uid:{},realAccessToken:{},accessTokenValue:{}", uid, realAccessToken, accessTokenValue);
|
||||
if(StringUtils.isEmpty(realAccessToken)){
|
||||
throw new InvalidTokenException("accessTokenCache null: " + accessTokenValue);
|
||||
@@ -112,15 +114,18 @@ public class TicketServices implements InitializingBean{
|
||||
throw new InvalidTokenException("acessToken error...please relogin now. " + accessTokenValue);
|
||||
}
|
||||
|
||||
Map<String,Object> maps= Maps.newHashMap();
|
||||
List<Ticket> tickets = new ArrayList();
|
||||
DefaultTicket ticket = new DefaultTicket(UUID.randomUUID().toString());
|
||||
ticket.setAccessToken(accessToken);
|
||||
ticket.setExpiresIn(ticketValidityMillSeconds);
|
||||
tickets.add(ticketEnhancer != null? ticketEnhancer.enhance(ticket,authentication,accountDetails): ticket);
|
||||
ticketStore.storeTicket(tickets.get(0), authentication, accountDetails);
|
||||
DefaultTicket defaultTicket = new DefaultTicket(UUID.randomUUID().toString());
|
||||
defaultTicket.setAccessToken(accessToken);
|
||||
defaultTicket.setExpiresIn(ticketValidityMillSeconds);
|
||||
|
||||
List<TicketVo> tickets = new ArrayList<>();
|
||||
Ticket newTicket = ticketEnhancer.enhance(defaultTicket,authentication,accountDetails);
|
||||
ticketStore.storeTicket(newTicket, authentication, accountDetails);
|
||||
tickets.add(new TicketVo(newTicket));
|
||||
|
||||
Map<String,Object> maps = Maps.newHashMap();
|
||||
maps.put("tickets",tickets);
|
||||
maps.put("uid", accountDetails.getAccount().getUid());
|
||||
maps.put("uid", uid);
|
||||
return maps;
|
||||
}
|
||||
|
||||
|
@@ -2,12 +2,12 @@ package com.accompany.oauth2.controller;
|
||||
|
||||
import com.accompany.common.device.DeviceInfo;
|
||||
import com.accompany.common.result.BusiResult;
|
||||
import com.accompany.common.status.BusiStatus;
|
||||
import com.accompany.common.utils.IPUtils;
|
||||
import com.accompany.oauth2.common.BaseController;
|
||||
import com.accompany.oauth2.exception.UnsupportedIssueTypeException;
|
||||
import com.accompany.oauth2.ticket.Ticket;
|
||||
import com.accompany.oauth2.ticket.TicketServices;
|
||||
import com.accompany.oauth2.vo.TicketRes;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.oauth2.common.exceptions.InvalidTokenException;
|
||||
@@ -33,35 +33,31 @@ public class TicketController extends BaseController {
|
||||
private TicketServices ticketServices;
|
||||
|
||||
@RequestMapping("/ticket")
|
||||
public Object issueTicket(@RequestParam("issue_type") String type, @RequestParam("access_token") String token,
|
||||
public BusiResult<Map<String, Object>> issueTicket(@RequestParam("issue_type") String type, @RequestParam("access_token") String token,
|
||||
HttpServletRequest request, HttpServletResponse response,
|
||||
DeviceInfo deviceInfo) {
|
||||
log.info("oauth/ticket=" + token + ".........");
|
||||
try {
|
||||
if (Ticket.ONCE_TYPE.equals(type) || Ticket.MULTI_TYPE.equals(type)) {
|
||||
Map<String, Object> ticketsMap = ticketServices.issueTicket(token);
|
||||
TicketRes ticketRes = new TicketRes();
|
||||
ticketRes.setIssue_type(type);
|
||||
ticketRes.setTickets((List<Ticket>) ticketsMap.get("tickets"));
|
||||
ticketRes.setAccid((String) ticketsMap.get("accid"));
|
||||
ticketRes.setNetEaseToken((String) ticketsMap.get("netEaseToken"));
|
||||
ticketRes.setUid((Long) ticketsMap.get("uid"));
|
||||
String ipAddress = IPUtils.getRealIpAddress(request);
|
||||
ticketServices.saveLoginRecord((Long) ticketsMap.get("uid"), ipAddress, deviceInfo);
|
||||
return new BusiResult<>(ticketRes);
|
||||
if (!Ticket.ONCE_TYPE.equals(type) && !Ticket.MULTI_TYPE.equals(type)) {
|
||||
throw new UnsupportedIssueTypeException("unsupported ticket issue type");
|
||||
}
|
||||
throw new UnsupportedIssueTypeException("unsupported ticket issue type");
|
||||
|
||||
Map<String, Object> result = ticketServices.issueTicket(token);
|
||||
|
||||
String ipAddress = IPUtils.getRealIpAddress(request);
|
||||
ticketServices.saveLoginRecord((Long) result.get("uid"), ipAddress, deviceInfo);
|
||||
|
||||
result.put("issue_type", type);
|
||||
return new BusiResult<>(result);
|
||||
|
||||
} catch (InvalidTokenException e) {
|
||||
log.error("issueTicket InvalidTokenException, issue_type=" + type + ", access_token=" + token, e);
|
||||
response.setStatus(401);
|
||||
return e;
|
||||
return new BusiResult<>(BusiStatus.NOAUTHORITY);
|
||||
} catch (UnsupportedIssueTypeException e1) {
|
||||
log.error("issueTicket UnsupportedIssueTypeException, issue_type=" + type + ", access_token=" + token, e1);
|
||||
response.setStatus(400);
|
||||
return e1;
|
||||
} catch (Exception ex) {
|
||||
log.error("issueTicket Exception, issue_type=" + type + ", access_token=" + token, ex);
|
||||
return ex;
|
||||
return new BusiResult<>(BusiStatus.NOAUTHORITY);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user