Example #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @POST @Path("/{username}/password") public javax.ws.rs.core.Response setPassword(@PathParam("username") String username, @Context HttpServletRequest req, String payload)
        public virtual Response SetPassword(string username, HttpServletRequest req, string payload)
        {
            Principal principal = req.UserPrincipal;

            if (principal == null || !principal.Name.Equals(username))
            {
                return(_output.notFound());
            }

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.Map<String, Object> deserialized;
            IDictionary <string, object> deserialized;

            try
            {
                deserialized = _input.readMap(payload);
            }
            catch (BadInputException e)
            {
                return(_output.response(BAD_REQUEST, new ExceptionRepresentation(new Neo4jError(Org.Neo4j.Kernel.Api.Exceptions.Status_Request.InvalidFormat, e.Message))));
            }

            object o = deserialized[PASSWORD];

            if (o == null)
            {
                return(_output.response(UNPROCESSABLE, new ExceptionRepresentation(new Neo4jError(Org.Neo4j.Kernel.Api.Exceptions.Status_Request.InvalidFormat, string.Format("Required parameter '{0}' is missing.", PASSWORD)))));
            }
            if (!(o is string))
            {
                return(_output.response(UNPROCESSABLE, new ExceptionRepresentation(new Neo4jError(Org.Neo4j.Kernel.Api.Exceptions.Status_Request.InvalidFormat, string.Format("Expected '{0}' to be a string.", PASSWORD)))));
            }
            string newPassword = ( string )o;

            try
            {
                LoginContext loginContext = getLoginContextFromUserPrincipal(principal);
                if (loginContext == null)
                {
                    return(_output.notFound());
                }
                else
                {
                    UserManager userManager = _userManagerSupplier.getUserManager(loginContext.Subject(), false);
                    userManager.SetUserPassword(username, UTF8.encode(newPassword), false);
                }
            }
            catch (IOException e)
            {
                return(_output.serverErrorWithoutLegacyStacktrace(e));
            }
            catch (InvalidArgumentsException e)
            {
                return(_output.response(UNPROCESSABLE, new ExceptionRepresentation(new Neo4jError(e.Status(), e.Message))));
            }
            return(_output.ok());
        }