private Connection GetDispatcherForRequest(ServerRequestInfo request, AnyCredential credential) { Connection dispatcher = null; string busId = credential.Bus; string loginId = credential.Login; if (Context.OnCallDispatch != null) { dispatcher = Context.OnCallDispatch(Context, busId, loginId, GetObjectUriForObjectKey( request.object_id), request.operation); } if (dispatcher == null) { dispatcher = Context.GetDefaultConnection(); } if ((dispatcher != null) && (!busId.Equals(dispatcher.BusId))) { // se a conexão retornada não pertence ao barramento esperado Logger.Error( String.Format( "A conexão retornada pela callback OnCallDispatch não pertence ao barramento da requisição sendo atendida.")); throw new NO_PERMISSION(UnknownBusCode.ConstVal, CompletionStatus.Completed_No); } return(dispatcher); }
/// <inheritdoc /> public void receive_request_service_contexts(ServerRequestInfo ri) { string interceptedOperation = ri.operation; Logger.Info(String.Format( "A operação '{0}' foi interceptada no servidor.", interceptedOperation)); bool legacyContext; ServiceContext serviceContext = GetContextFromRequestInfo(ri, true, out legacyContext); AnyCredential anyCredential = new AnyCredential(serviceContext, legacyContext); Logger.Debug( String.Format("A operação '{0}' possui credencial. É legada? {1}.", interceptedOperation, anyCredential.Legacy)); ConnectionImpl conn = null; try { conn = GetDispatcherForRequest(ri, anyCredential) as ConnectionImpl; if (conn == null) { Logger.Error( "Sem conexão ao barramento, impossível receber a chamada remota."); throw new NO_PERMISSION(UnknownBusCode.ConstVal, CompletionStatus.Completed_No); } if ((!conn.Legacy) && (anyCredential.Legacy)) { Logger.Error( String.Format( "Chamada negada devido a suporte legado inativo: login {0} operação {1} requestId {2}", anyCredential.Login, interceptedOperation, ri.request_id)); throw new NO_PERMISSION(NoCredentialCode.ConstVal, CompletionStatus.Completed_No); } Context.SetCurrentConnection(conn, ri); conn.ReceiveRequest(ri, anyCredential); } catch (InvalidSlot e) { Logger.Fatal("Falha ao inserir a credencial em seu slot.", e); throw; } finally { if (conn != null) { ri.set_slot(ReceivingConnectionSlotId, conn); } } }
/// <inheritdoc /> public void send_exception(ServerRequestInfo ri) { // esse tratamento precisa ser feito aqui (não é possível na receive_request) por causa de bugs do IIOP.net, descritos em OPENBUS-1677. String interceptedOperation = ri.operation; Logger.Info(String.Format( "O lançamento de uma exceção para a operação '{0}' foi interceptado no servidor.", interceptedOperation), (Exception)ri.sending_exception); NO_PERMISSION ex = ri.sending_exception as NO_PERMISSION; if (ex == null) { return; } if (ex.Minor == InvalidCredentialCode.ConstVal) { try { // pela implementação do IIOP.Net, o ServerRequestInfo da send_exception é // diferente do existente na receive_request. Assim, não podemos passar a // credencial por um slot e então precisamos fazer o unmarshal novamente. ConnectionImpl conn = ri.get_slot(ReceivingConnectionSlotId) as ConnectionImpl; if (conn == null) { Logger.Error( "Sem conexão ao barramento, impossível enviar exceção à chamada remota."); throw new NO_PERMISSION(UnverifiedLoginCode.ConstVal, CompletionStatus.Completed_No); } bool legacyContext; ServiceContext serviceContext = GetContextFromRequestInfo(ri, conn.Legacy, out legacyContext); // credencial é inválida AnyCredential anyCredential = new AnyCredential(serviceContext, legacyContext); Logger.Debug(String.Format( "A operação '{0}' para a qual será lançada a exceção possui credencial. Legada? {1}.", interceptedOperation, anyCredential.Legacy)); conn.SendException(ri, anyCredential); } catch (InvalidSlot e) { Logger.Fatal( "Falha ao acessar o slot da conexão de recebimento para enviar uma exceção.", e); throw; } } }