123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- using System;
- using System.Collections.Generic;
- using JsonRpcLite.Network;
- using JsonRpcLite.Services;
- using JsonRpcLite.Utilities;
- using Newtonsoft.Json;
- using WingInterfaceLibrary.Enum;
- using WingInterfaceLibrary.Interface;
- using WingInterfaceLibrary.Request.Authentication;
- using WingServerCommon.Log;
- using WingServerCommon.Service;
- namespace WingCloudServer.Plugin
- {
- public interface ITokenVerifyPlugin : IJsonRpcHttpServerEnginePlugin
- {
- }
- public class TokenVerifyPlugin : JsonRpcService, ITokenVerifyPlugin
- {
- protected IAuthenticationService _authenticationService;
- public override void Load(JsonRpcClientPool jsonRpcClientPool)
- {
- base.Load(jsonRpcClientPool);
- _authenticationService = GetProxy<IAuthenticationService>();
- }
- /// <summary>
- /// 不需要token验证的接口列表
- /// </summary>
- /// <value></value>
- public static List<string> NotValidationRequiredList = new List<string>
- {
- "IConnectService/ConnectAsync",
- "IEmailService/SendEmailAsync",
- "ILoginService/CommonLoginAsync",
- "ILoginService/CheckLoginTypeAsync",
- "ILoginService/CommonSignUpAsync",
- "ILoginService/CheckSMSVerificationCodeAsync",
- "ILoginService/SendSMSVerificationCodeAsync",
- "ILoginService/SendEmailVerificationCodeAsync",
- "ILoginService/CheckEmailVerificationCodeAsync",
- "ILoginService/RetrievePasswordByPhoneAsync",
- "ILoginService/RetrievePasswordByEmailAsync",
- "ILoginService/VerifyAccountAsync",
- "IManagementService/AdminLogin",
- "IManagementService/FindReportPreviewUrlAsync",
- "IManagementService/FindReportShareConentAsync",
- "IManagementService/FindRelatedDeviceCodesAsync",
- "IManagementService/AddReportTemplateAsync",
- "IManagementService/UpdateReportTemplateAsync",
- "IManagementService/RemoveReportTemplateAsync",
- "IManagementService/GetReportTemplateAsync",
- "IManagementService/GetShareExamUrlAsync",
- "IRemedicalService/GetReportElementByLanguageAsync",
- "IRemedicalService/PushFinshExamNotificationToClientAsync",
- "INotificationService/SendMessageAsync",
- "INotificationService/PostMessageAsync",
- "IRegionService/GetRegionsAsync",
- "IReportService/FindShareContentAsync",
- "ISMSService/SendMessageAsync",
- "ISMSService/CheckVerificationCodeAsync",
- "ISMSService/GeneralMessageAsync",
- "IStorageService/UploadFileAsync",
- "IVinnoServerService/UpdateServerInfoAsync",
- "IVinnoServerService/GetServerInfoListAsync",
- "IVinnoServerService/EchoAsync",
- "IVinnoServerService/UpdateServerIPListAsync",
- "IAIDiagnosisService/DiagnosisImageAsync",
- "IReportService/CreateReportTemplatePreviewAsync",
- "IWingRtcService/GetRoomIdAsync",
- "IWingRtcService/GenerateRoomUrlAsync",
- "IWingRtcService/GetRtcSettingAsync",
- "IWingRtcService/GetUserSignAsync",
- "ILiveConsultationService/SyncServerMessageAsync",
- };
- public PluginProcessResult PreProcess(IJsonRpcHttpContext context, byte[] requestData)
- {
- var dataLength = (int)context.GetRequestContentLength();
- var requests = JsonRpcCodec.DecodeRequestsAsync(requestData, new System.Threading.CancellationToken(), dataLength).Result;
- var apiName = $"{context.GetRequestPath().Trim('/')}/{requests[0].Method.Trim('/')}";
- if (context.GetRequestPath() != "/IAuthenticationService" && context.GetRequestPath() != "/IMasterInteractionCenterService" && !NotValidationRequiredList.Contains(apiName)&&!context.GetRequestPath().Contains("IDynamicSlaveService") )
- {
- var tokenRequest = new ValidateTokenRequest();
- try
- {
- tokenRequest = JsonConvert.DeserializeObject<List<ValidateTokenRequest>>(requests[0].Params.Value.ToString().Replace("\r", "").Replace("\n", "").Replace("\t", ""))[0];
- }
- catch (Exception)
- {
- try
- {
- tokenRequest = JsonConvert.DeserializeObject<ValidateTokenRequest>(requests[0].Params.Value.ToString().Replace("\r", "").Replace("\n", "").Replace("\t", ""));
- }
- catch (Exception ex)
- {
- Logger.WriteLineError($"TokenVerifyPlugin err{ex.ToString()},{JsonConvert.SerializeObject(requests)}");
- }
- }
- var result = _authenticationService.ValidateTokenAsync(tokenRequest).Result;
- if (result.Code != CustomerRpcCode.Ok)
- {
- ThrowRpcException((int)result.Code, "Permission validation error");
- }
- }
- return new PluginProcessResult(requestData, false);
- }
- public PluginProcessResult PostProcess(IJsonRpcHttpContext context, byte[] responseData)
- {
- return new PluginProcessResult(responseData, false);
- }
- }
- }
|