Exemplo n.º 1
0
        private GetRPTResponse GetRPTResponse(UmaRpGetRptParams getRptParams, CommandClient oxdcommand)
        {
            var cmdGetRPT = new Command {
                CommandType = CommandType.uma_rp_get_rpt, CommandParams = getRptParams
            };
            string commandResponse = oxdcommand.send(cmdGetRPT);
            var    response        = JsonConvert.DeserializeObject <GetRPTResponse>(commandResponse);

            Logger.Info(string.Format("Got response status as {0} and RPT is {1}", response.Status, response.Data.Rpt));
            return(response);
        }
Exemplo n.º 2
0
        public ActionResult ObtainRpt()
        {
            var getRptParams = new UmaRpGetRptParams();
            var getRptClient = new UmaRpGetRptClient();

            string ticket = "";

            if (Session["uma_ticket"] != null)
            {
                ticket = Session["uma_ticket"].ToString();
            }

            //prepare input params for Protect Resource
            getRptParams.OxdId  = oxd_id;
            getRptParams.ticket = ticket;


            var getRptResponse = new GetRPTResponse();

            //For OXD Local
            if (OXDType == "local")
            {
                //Get protection access token
                getRptParams.ProtectionAccessToken = GetProtectionAccessToken(oxdHost, oxdPort);
                //Get RPT
                getRptResponse = getRptClient.GetRPT(oxdHost, oxdPort, getRptParams);
            }

            //For OXD Web
            if (OXDType == "web")
            {
                //Get protection access token
                getRptParams.ProtectionAccessToken = GetProtectionAccessToken(httpresturl);
                //Get RPT
                getRptResponse = getRptClient.GetRPT(httpresturl, getRptParams);
            }

            //process response
            if (getRptResponse.Status.ToLower().Equals("ok"))
            {
                Session["rpt"] = getRptResponse.Data.Rpt;
                return(Json(new { Response = JsonConvert.SerializeObject(getRptResponse.Data) }));
            }

            throw new Exception("Obtaining RPT is not successful. Check OXD Server log for error details.");
        }
Exemplo n.º 3
0
        /// <summary>
        /// Gets RPT token from UMA RP
        /// </summary>
        /// <param name="host">Oxd Host</param>
        /// <param name="port">Oxd Port</param>
        /// <param name="getRptParams">Input params for Get RPT command</param>
        /// <returns></returns>
        public GetRPTResponse GetRPT(string host, int port, UmaRpGetRptParams getRptParams)
        {
            Logger.Info("Verifying input parameters.");
            if (string.IsNullOrEmpty(host))
            {
                throw new ArgumentNullException("Oxd Host should not be NULL.");
            }

            if (port <= 0)
            {
                throw new ArgumentNullException("Oxd Port should be a valid port number.");
            }

            if (getRptParams == null)
            {
                throw new ArgumentNullException("The get RPT command params should not be NULL.");
            }

            if (string.IsNullOrEmpty(getRptParams.OxdId))
            {
                throw new MissingFieldException("Oxd ID is required for getting RPT from UMA RP.");
            }

            try
            {
                Logger.Info("Preparing and sending command.");
                var cmdGetRPT = new Command {
                    CommandType = CommandType.uma_rp_get_rpt, CommandParams = getRptParams
                };
                var    commandClient   = new CommandClient(host, port);
                string commandResponse = commandClient.send(cmdGetRPT);

                var response = JsonConvert.DeserializeObject <GetRPTResponse>(commandResponse);
                Logger.Info(string.Format("Got response status as {0} and RPT is {1}", response.Status, response.Data.Rpt));

                return(response);
            }
            catch (Exception ex)
            {
                Logger.Log(NLog.LogLevel.Error, ex, "Exception when getting RPT token.");
                return(null);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Gets RPT token from UMA RP
        /// </summary>
        /// <param name="oxdweburl">oxdweburl</param>
        /// <param name="getRptParams">Input params for Get RPT command</param>
        /// <returns></returns>
        public GetRPTResponse GetRPT(string oxdweburl, UmaRpGetRptParams getRptParams)
        {
            if (getRptParams == null)
            {
                throw new ArgumentNullException("The get RPT command params should not be NULL.");
            }

            if (string.IsNullOrEmpty(getRptParams.OxdId))
            {
                throw new MissingFieldException("Oxd ID is required for getting RPT from UMA RP.");
            }

            try
            {
                var commandClient = new CommandClient(oxdweburl);
                return(GetRPTResponse(getRptParams, commandClient));
            }
            catch (Exception ex)
            {
                Logger.Log(NLog.LogLevel.Error, ex, "Exception when getting RPT token.");
                return(null);
            }
        }