parent
8edd0ca663
commit
a94405afa1
@ -0,0 +1,117 @@
|
||||
package au.com.royalpay.payment.manage.appclient.extend;
|
||||
|
||||
import au.com.royalpay.payment.manage.mappers.client.AuthHistoryMapper;
|
||||
import au.com.royalpay.payment.tools.device.entity.DeviceInfo;
|
||||
import au.com.royalpay.payment.tools.device.support.DeviceRegister;
|
||||
import au.com.royalpay.payment.tools.exceptions.ForbiddenException;
|
||||
import au.com.royalpay.payment.tools.merchants.core.MerchantInfoProvider;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* Create by davep at 2019-09-19 12:07
|
||||
*/
|
||||
@Service
|
||||
public class GatewayOAuthRegister implements DeviceRegister {
|
||||
public static final String CLIENT_TYPE = "oauthclient";
|
||||
private MerchantInfoProvider provider;
|
||||
private AuthHistoryMapper authHistoryMapper;
|
||||
private StringRedisTemplate redisTemplate;
|
||||
private String prefix;
|
||||
|
||||
public GatewayOAuthRegister(MerchantInfoProvider provider, AuthHistoryMapper authHistoryMapper,
|
||||
StringRedisTemplate redisTemplate, @Value("${app.redis.prefix}") String prefix) {
|
||||
this.provider = provider;
|
||||
this.authHistoryMapper = authHistoryMapper;
|
||||
this.redisTemplate = redisTemplate;
|
||||
this.prefix = prefix;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDevType() {
|
||||
return CLIENT_TYPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject register(String encrypted, int type) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DeviceInfo checkDeviceRequest(HttpServletRequest request) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject fillDeviceInfo(HttpServletRequest request, String devId, String devType, String accountId) {
|
||||
JSONObject auth = findAuthDetail(devId);
|
||||
int clientId = auth.getIntValue("client_id");
|
||||
JSONObject client = provider.getClientInfo(clientId);
|
||||
auth.put("client_moniker", client.getString("client_moniker"));
|
||||
auth.put("client", client);
|
||||
|
||||
return auth;
|
||||
}
|
||||
|
||||
private JSONObject findAuthDetail(String authId) {
|
||||
String authStr = redisTemplate.boundValueOps(authDetailCacheKey(authId)).get();
|
||||
if (authStr == null) {
|
||||
JSONObject authObj = authHistoryMapper.find(authId);
|
||||
if (authObj == null || !authObj.getBooleanValue("is_valid")) {
|
||||
throw new ForbiddenException("Auth Expired");
|
||||
}
|
||||
JSONObject auth = new JSONObject();
|
||||
auth.put("dev_id", authId);
|
||||
auth.put("client_type", CLIENT_TYPE);
|
||||
auth.put("appid", authObj.getString("appid"));
|
||||
int clientId = authObj.getIntValue("client_id");
|
||||
auth.put("client_id", clientId);
|
||||
auth.put("auth_time", authObj.getDate("auth_time"));
|
||||
auth.put("account_id", authObj.getString("account_id"));
|
||||
auth.put("authorize_ip", authObj.getString("authorize_ip"));
|
||||
auth.put("scope", authObj.getString("scope"));
|
||||
auth.put("grant_scene", authObj.getString("grant_scene"));
|
||||
|
||||
return auth;
|
||||
}
|
||||
return JSON.parseObject(authStr);
|
||||
}
|
||||
|
||||
private String authDetailCacheKey(String authId) {
|
||||
return prefix + ":oauth:auth_detail_cache:" + authId;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public JSONObject checkManageDeviceSign(HttpServletRequest request, String sign, String deviceId, String devVersion) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean includeDevId() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void signout(JSONObject device) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void manageSignout(JSONObject device) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkClient(Integer clientId) {
|
||||
JSONObject client = provider.getClientInfo(clientId);
|
||||
if (client == null || !client.getBooleanValue("is_valid")) {
|
||||
throw new ForbiddenException("Client Not Exists");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package au.com.royalpay.payment.manage.mappers.client;
|
||||
|
||||
import cn.yixblog.support.mybatis.autosql.annotations.AutoMapper;
|
||||
import cn.yixblog.support.mybatis.autosql.annotations.AutoSql;
|
||||
import cn.yixblog.support.mybatis.autosql.annotations.SqlType;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/**
|
||||
* Create by davep at 2019-08-16 15:05
|
||||
*/
|
||||
@AutoMapper(tablename = "log_client_app_authentication", pkName = "auth_id")
|
||||
public interface AuthHistoryMapper {
|
||||
|
||||
|
||||
@AutoSql(type = SqlType.SELECT)
|
||||
JSONObject find(@Param("auth_id") String authId);
|
||||
|
||||
}
|
Loading…
Reference in new issue