管理端口也添加获取应用authCode的方法
This commit is contained in:
@@ -34,6 +34,10 @@ abstract public class AdminAction extends Action {
|
|||||||
SECRET_KEY = secretKey;
|
SECRET_KEY = secretKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getSecretKey() {
|
||||||
|
return SECRET_KEY;
|
||||||
|
}
|
||||||
|
|
||||||
public static void setNoCheckTime(String noCheckTime) {
|
public static void setNoCheckTime(String noCheckTime) {
|
||||||
try {
|
try {
|
||||||
NO_CHECK_TIME = Boolean.parseBoolean(noCheckTime);
|
NO_CHECK_TIME = Boolean.parseBoolean(noCheckTime);
|
||||||
|
|||||||
+58
@@ -0,0 +1,58 @@
|
|||||||
|
package com.xiaoleilu.loServer.action.admin;
|
||||||
|
|
||||||
|
import cn.wildfirechat.common.APIPath;
|
||||||
|
import cn.wildfirechat.common.ErrorCode;
|
||||||
|
import cn.wildfirechat.pojos.InputApplicationGetUserInfo;
|
||||||
|
import cn.wildfirechat.pojos.OutputApplicationUserInfo;
|
||||||
|
import cn.wildfirechat.proto.ProtoConstants;
|
||||||
|
import cn.wildfirechat.proto.WFCMessage;
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.hazelcast.util.StringUtil;
|
||||||
|
import com.xiaoleilu.loServer.RestResult;
|
||||||
|
import com.xiaoleilu.loServer.annotation.HttpMethod;
|
||||||
|
import com.xiaoleilu.loServer.annotation.Route;
|
||||||
|
import com.xiaoleilu.loServer.handler.Request;
|
||||||
|
import com.xiaoleilu.loServer.handler.Response;
|
||||||
|
import io.netty.handler.codec.http.FullHttpRequest;
|
||||||
|
import io.netty.handler.codec.http.HttpResponseStatus;
|
||||||
|
|
||||||
|
@Route(APIPath.User_Application_Get_UserInfo)
|
||||||
|
@HttpMethod("POST")
|
||||||
|
public class ApplicationGetUserInfoAction extends AdminAction {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isTransactionAction() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean action(Request request, Response response) {
|
||||||
|
if (request.getNettyRequest() instanceof FullHttpRequest) {
|
||||||
|
InputApplicationGetUserInfo inputUserToken = getRequestBody(request.getNettyRequest(), InputApplicationGetUserInfo.class);
|
||||||
|
|
||||||
|
RestResult result;
|
||||||
|
if (inputUserToken == null || StringUtil.isNullOrEmpty(inputUserToken.getAuthCode())) {
|
||||||
|
result = RestResult.resultOf(ErrorCode.INVALID_PARAMETER);
|
||||||
|
} else {
|
||||||
|
String userId = messagesStore.verifyApplicationAuthCode(inputUserToken.getAuthCode(), "admin", ProtoConstants.ApplicationType.ApplicationType_Admin);
|
||||||
|
if(userId != null) {
|
||||||
|
OutputApplicationUserInfo outputVerifyApplicationUser = new OutputApplicationUserInfo();
|
||||||
|
outputVerifyApplicationUser.setUserId(userId);
|
||||||
|
WFCMessage.User user = messagesStore.getUserInfo(userId);
|
||||||
|
if(user != null) {
|
||||||
|
outputVerifyApplicationUser.setDisplayName(user.getDisplayName());
|
||||||
|
outputVerifyApplicationUser.setPortraitUrl(user.getPortrait());
|
||||||
|
}
|
||||||
|
result = RestResult.ok(outputVerifyApplicationUser);
|
||||||
|
} else {
|
||||||
|
result = RestResult.resultOf(ErrorCode.ERROR_CODE_TOKEN_ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
response.setStatus(HttpResponseStatus.OK);
|
||||||
|
response.setContent(new Gson().toJson(result));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -23,6 +23,7 @@ import com.google.gson.Gson;
|
|||||||
import com.google.protobuf.ByteString;
|
import com.google.protobuf.ByteString;
|
||||||
import com.hazelcast.core.*;
|
import com.hazelcast.core.*;
|
||||||
import com.hazelcast.util.StringUtil;
|
import com.hazelcast.util.StringUtil;
|
||||||
|
import com.xiaoleilu.loServer.action.admin.AdminAction;
|
||||||
import com.xiaoleilu.loServer.model.FriendData;
|
import com.xiaoleilu.loServer.model.FriendData;
|
||||||
import cn.wildfirechat.common.ErrorCode;
|
import cn.wildfirechat.common.ErrorCode;
|
||||||
import io.moquette.BrokerConstants;
|
import io.moquette.BrokerConstants;
|
||||||
@@ -3316,7 +3317,7 @@ public class MemoryMessagesStore implements IMessagesStore {
|
|||||||
@Override
|
@Override
|
||||||
public String getApplicationAuthCode(String fromUser, String applicationId, int type, String host) {
|
public String getApplicationAuthCode(String fromUser, String applicationId, int type, String host) {
|
||||||
String secret = null;
|
String secret = null;
|
||||||
if(type == 0) {
|
if(type == ProtoConstants.ApplicationType.ApplicationType_Robot) {
|
||||||
WFCMessage.Robot robotData = getRobot(applicationId);
|
WFCMessage.Robot robotData = getRobot(applicationId);
|
||||||
if(robotData != null && !StringUtil.isNullOrEmpty(robotData.getCallback()) && !StringUtil.isNullOrEmpty(robotData.getSecret())) {
|
if(robotData != null && !StringUtil.isNullOrEmpty(robotData.getCallback()) && !StringUtil.isNullOrEmpty(robotData.getSecret())) {
|
||||||
try {
|
try {
|
||||||
@@ -3340,7 +3341,7 @@ public class MemoryMessagesStore implements IMessagesStore {
|
|||||||
}
|
}
|
||||||
LOG.warn("get application auth code error, reason {}", errorReason);
|
LOG.warn("get application auth code error, reason {}", errorReason);
|
||||||
}
|
}
|
||||||
} else if(type == 1) {
|
} else if(type == ProtoConstants.ApplicationType.ApplicationType_Channel) {
|
||||||
WFCMessage.ChannelInfo channelData = getChannelInfo(applicationId);
|
WFCMessage.ChannelInfo channelData = getChannelInfo(applicationId);
|
||||||
if(channelData != null && !StringUtil.isNullOrEmpty(channelData.getCallback()) && !StringUtil.isNullOrEmpty(channelData.getSecret())) {
|
if(channelData != null && !StringUtil.isNullOrEmpty(channelData.getCallback()) && !StringUtil.isNullOrEmpty(channelData.getSecret())) {
|
||||||
try {
|
try {
|
||||||
@@ -3364,6 +3365,8 @@ public class MemoryMessagesStore implements IMessagesStore {
|
|||||||
}
|
}
|
||||||
LOG.warn("get application auth code error, reason {}", errorReason);
|
LOG.warn("get application auth code error, reason {}", errorReason);
|
||||||
}
|
}
|
||||||
|
} else if(type == ProtoConstants.ApplicationType.ApplicationType_Admin) {
|
||||||
|
secret = AdminAction.getSecretKey();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!StringUtil.isNullOrEmpty(secret)) {
|
if(!StringUtil.isNullOrEmpty(secret)) {
|
||||||
@@ -3378,16 +3381,18 @@ public class MemoryMessagesStore implements IMessagesStore {
|
|||||||
@Override
|
@Override
|
||||||
public String verifyApplicationAuthCode(String authCode, String applicationId, int type) {
|
public String verifyApplicationAuthCode(String authCode, String applicationId, int type) {
|
||||||
String secret = null;
|
String secret = null;
|
||||||
if(type == 0) {
|
if(type == ProtoConstants.ApplicationType.ApplicationType_Robot) {
|
||||||
WFCMessage.Robot robotData = getRobot(applicationId);
|
WFCMessage.Robot robotData = getRobot(applicationId);
|
||||||
if(robotData != null && !StringUtil.isNullOrEmpty(robotData.getCallback()) && !StringUtil.isNullOrEmpty(robotData.getSecret())) {
|
if(robotData != null && !StringUtil.isNullOrEmpty(robotData.getCallback()) && !StringUtil.isNullOrEmpty(robotData.getSecret())) {
|
||||||
secret = robotData.getSecret();
|
secret = robotData.getSecret();
|
||||||
}
|
}
|
||||||
} else if(type == 1) {
|
} else if(type == ProtoConstants.ApplicationType.ApplicationType_Channel) {
|
||||||
WFCMessage.ChannelInfo channelData = getChannelInfo(applicationId);
|
WFCMessage.ChannelInfo channelData = getChannelInfo(applicationId);
|
||||||
if(channelData != null && !StringUtil.isNullOrEmpty(channelData.getCallback()) && !StringUtil.isNullOrEmpty(channelData.getSecret())) {
|
if(channelData != null && !StringUtil.isNullOrEmpty(channelData.getCallback()) && !StringUtil.isNullOrEmpty(channelData.getSecret())) {
|
||||||
secret = channelData.getSecret();
|
secret = channelData.getSecret();
|
||||||
}
|
}
|
||||||
|
} else if(type == ProtoConstants.ApplicationType.ApplicationType_Admin) {
|
||||||
|
secret = AdminAction.getSecretKey();
|
||||||
}
|
}
|
||||||
|
|
||||||
secret = ensureSecretLength(secret);
|
secret = ensureSecretLength(secret);
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ public interface APIPath {
|
|||||||
String User_Kickoff_Client = "/admin/user/kickoff_client";
|
String User_Kickoff_Client = "/admin/user/kickoff_client";
|
||||||
String User_Online_Count = "/admin/user/online_count";
|
String User_Online_Count = "/admin/user/online_count";
|
||||||
String User_Online_List = "/admin/user/online_list";
|
String User_Online_List = "/admin/user/online_list";
|
||||||
|
String User_Application_Get_UserInfo = "/admin/user/app_get_user_info";
|
||||||
|
|
||||||
String Friend_Update_Status = "/admin/friend/status";
|
String Friend_Update_Status = "/admin/friend/status";
|
||||||
String Friend_Get_List = "/admin/friend/list";
|
String Friend_Get_List = "/admin/friend/list";
|
||||||
|
|||||||
@@ -233,6 +233,7 @@ public class ProtoConstants {
|
|||||||
public interface ApplicationType {
|
public interface ApplicationType {
|
||||||
int ApplicationType_Robot = 0;
|
int ApplicationType_Robot = 0;
|
||||||
int ApplicationType_Channel = 1;
|
int ApplicationType_Channel = 1;
|
||||||
|
int ApplicationType_Admin = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final int MESSAGE_CONTENT_TYPE_CREATE_GROUP = 104;
|
public static final int MESSAGE_CONTENT_TYPE_CREATE_GROUP = 104;
|
||||||
|
|||||||
@@ -136,4 +136,11 @@ public class UserAdmin {
|
|||||||
request.count = count;
|
request.count = count;
|
||||||
return AdminHttpUtils.httpJsonPost(APIPath.User_Online_List, request, GetOnlineUserResult.class);
|
return AdminHttpUtils.httpJsonPost(APIPath.User_Online_List, request, GetOnlineUserResult.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static IMResult<OutputApplicationUserInfo> applicationGetUserInfo(String authCode) throws Exception {
|
||||||
|
String path = APIPath.User_Application_Get_UserInfo;
|
||||||
|
InputApplicationGetUserInfo input = new InputApplicationGetUserInfo();
|
||||||
|
input.setAuthCode(authCode);
|
||||||
|
return AdminHttpUtils.httpJsonPost(path, input, OutputApplicationUserInfo.class);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user