Example #1
0
        public JsonResult Get(string token, int id)
        {
            if (_auth.Authenticate(token, id) == null && !_auth.IsSuperUser(token))
            {
                throw new TedExeption(ExceptionCodes.Authentication);
            }

            return(Json(new
            {
                success = true,
                data = _repo.GetOne(id)
            }));
        }
Example #2
0
        public JsonResult GetAll(string token)
        {
            var user = _auth.Authenticate(token);

            if (user == null)
            {
                throw new TedExeption(ExceptionCodes.Authentication);
            }

            return(Json(new
            {
                success = true,
                data = _repo.GetAllForUser(user)
            }));
        }
Example #3
0
        /// <summary>
        /// Authenticates a request looking for the <code>delegation</code>
        /// query-string parameter and verifying it is a valid token.
        /// </summary>
        /// <remarks>
        /// Authenticates a request looking for the <code>delegation</code>
        /// query-string parameter and verifying it is a valid token. If there is not
        /// <code>delegation</code> query-string parameter, it delegates the
        /// authentication to the
        /// <see cref="Org.Apache.Hadoop.Security.Authentication.Server.KerberosAuthenticationHandler
        ///     "/>
        /// unless it is
        /// disabled.
        /// </remarks>
        /// <param name="request">the HTTP client request.</param>
        /// <param name="response">the HTTP client response.</param>
        /// <returns>the authentication token for the authenticated request.</returns>
        /// <exception cref="System.IO.IOException">thrown if an IO error occurred.</exception>
        /// <exception cref="Org.Apache.Hadoop.Security.Authentication.Client.AuthenticationException
        ///     ">thrown if the authentication failed.</exception>
        public override AuthenticationToken Authenticate(HttpServletRequest request, HttpServletResponse
                                                         response)
        {
            AuthenticationToken token;
            string delegationParam = GetDelegationToken(request);

            if (delegationParam != null)
            {
                try
                {
                    Org.Apache.Hadoop.Security.Token.Token <AbstractDelegationTokenIdentifier> dt = new
                                                                                                    Org.Apache.Hadoop.Security.Token.Token();
                    dt.DecodeFromUrlString(delegationParam);
                    UserGroupInformation ugi = tokenManager.VerifyToken(dt);
                    string shortName         = ugi.GetShortUserName();
                    // creating a ephemeral token
                    token = new AuthenticationToken(shortName, ugi.GetUserName(), GetType());
                    token.SetExpires(0);
                    request.SetAttribute(DelegationTokenUgiAttribute, ugi);
                }
                catch (Exception ex)
                {
                    token = null;
                    HttpExceptionUtils.CreateServletExceptionResponse(response, HttpServletResponse.ScForbidden
                                                                      , new AuthenticationException(ex));
                }
            }
            else
            {
                token = authHandler.Authenticate(request, response);
            }
            return(token);
        }
Example #4
0
        public async Task Authenticate_CorrectCredentials_ShouldReturnAJwtToken()
        {
            User returningUser = new()
            {
                Email    = "*****@*****.**",
                Password = BCrypt.Net.BCrypt.HashPassword("This Is The Password")
            };

            _userRepository.GetByEmail(Arg.Any <string>()).Returns(returningUser);

            var token = await _authenticationHandler.Authenticate(new AuthenticationRequest { Email = returningUser.Email, Password = "******" });

            token.Should().NotBeEmpty();
        }
    }
Example #5
0
        public ActionResult <AuthResponseModel> Login([FromBody] AuthRequestModel authRequestModel)
        {
            if (ModelState.IsValid)
            {
                var token = AuthenticationHandler.Authenticate(authRequestModel.Username, authRequestModel.Password);

                var authResponseModel = new AuthResponseModel()
                {
                    token = token
                };
                return(Ok(authResponseModel));
            }
            else
            {
                return(BadRequest());
            }
        }
Example #6
0
        public void CreateTable(string token, string table, [FromBody] dynamic value)
        {
            var user = _auth.Authenticate(token);

            _repo.CreateTable(user, table, value["columns"], value["masterTableId"]?.Value);
        }