0

Hı guys.I need your help. I created a project which is called library in springboot.Right now,i want to create same project with jhipster.I can see jhipster home page.(http://localhost:8080 is running).Also, i have created a users entity with some fields.It can be seen in jhipster entity section or in my database.But i cannot reach rest methods by using postman or browser.I am gettting "Pre-authenticated entry point called. Rejecting access".Do you have any idea?

@RestController
@RequestMapping("/api")
public class UsersResource {

    public UsersResource() {
        System.out.println("3");
    }

    public static final Logger logger = LoggerFactory.getLogger(UsersResource.class);

    private static final String ENTITY_NAME = "users";

    @Autowired
    UsersService usersService;

    /**
     * POST  /users : Create a new users.
     *
     * @param users the users to create
     * @return the ResponseEntity with status 201 (Created) and with body the new users, or with status 400 (Bad Request) if the users has already an ID
     * @throws URISyntaxException if the Location URI syntax is incorrect
     */
     @PostMapping("/users/")
     @Timed
    public ResponseEntity < String > createUsers( @RequestBody Users users, UriComponentsBuilder ucBuilder)throws URISyntaxException {
        logger.debug("REST request to save Users : {}", users);
        if (users.getId() != null) {
            return ResponseEntity.badRequest().headers(HeaderUtil.createFailureAlert(ENTITY_NAME, "idexists", "A new users cannot already have an ID")).body(null);
        }
        usersService.saveUsers(users);

        HttpHeaders headers = new HttpHeaders();
        headers.setLocation(ucBuilder.path("/api/users/{id}").buildAndExpand(users.getUserId()).toUri());
        return new ResponseEntity < String > (headers, HttpStatus.CREATED);
    }

    /**
     * PUT  /users : Updates an existing users.
     *
     * @param users the users to update
     * @return the ResponseEntity with status 200 (OK) and with body the updated users,
     * or with status 400 (Bad Request) if the users is not valid,
     * or with status 500 (Internal Server Error) if the users couldn't be updated
     * @throws URISyntaxException if the Location URI syntax is incorrect
     */
     @RequestMapping(value = "/users/{id}", method = RequestMethod.PUT)
    public ResponseEntity <  ?  > updateUser( @PathVariable("id")long id,  @RequestBody Users user) {
        logger.info("Updating User with id {}", id);

        Users currentUser = usersService.findById(id);

        if (currentUser == null) {
            logger.error("Unable to update. User with id {} not found.", id);
            return new ResponseEntity(new CustomErrorType("Unable to upate. User with id " + id + " not found."),
                HttpStatus.NOT_FOUND);
        }

        currentUser.setName(user.getName());
        currentUser.setSurname(user.getSurname());
        currentUser.setEmail(user.getEmail());

        usersService.updateUsers(currentUser);
        return new ResponseEntity < Users > (currentUser, HttpStatus.OK);
    }

    /**
     * GET  /users : get all the users.
     *
     * @return the ResponseEntity with status 200 (OK) and the list of users in body
     */
     @RequestMapping(value = "/users/", method = RequestMethod.GET)
    public ResponseEntity < List < Users >> listAllUsers() {
        List < Users > users = usersService.findAllUsers();
        if (users.isEmpty()) {
            return new ResponseEntity(HttpStatus.NO_CONTENT);
            // You many decide to return HttpStatus.NOT_FOUND
        }
        return new ResponseEntity < List < Users >> (users, HttpStatus.OK);
    }

    /**
     * GET  /users/:id : get the "id" users.
     *
     * @param id the id of the users to retrieve
     * @return the ResponseEntity with status 200 (OK) and with body the users, or with status 404 (Not Found)
     */
     @RequestMapping(value = "/users/{id}", method = RequestMethod.GET)
    public ResponseEntity <  ?  > getUser( @PathVariable("id")long id) {
        logger.info("Fetching User with id {}", id);
        Users user = usersService.findById(id);
        if (user == null) {
            logger.error("User with id {} not found.", id);
            return new ResponseEntity(new CustomErrorType("User with id " + id
                     + " not found"), HttpStatus.NOT_FOUND);
        }
        return new ResponseEntity < Users > (user, HttpStatus.OK);
    }

    /**
     * DELETE  /users/:id : delete the "id" users.
     *
     * @param id the id of the users to delete
     * @return the ResponseEntity with status 200 (OK)
     */
     @RequestMapping(value = "/user/{id}", method = RequestMethod.DELETE)
    public ResponseEntity <  ?  > deleteUser( @PathVariable("id")long id) {
        logger.info("Fetching & Deleting User with id {}", id);

        Users user = usersService.findById(id);
        if (user == null) {
            logger.error("Unable to delete. User with id {} not found.", id);
            return new ResponseEntity(new CustomErrorType("Unable to delete. User with id " + id + " not found."),
                HttpStatus.NOT_FOUND);
        }
        usersService.deleteUsersById(id);
        return new ResponseEntity < Users > (HttpStatus.NO_CONTENT);
    }

     @RequestMapping(value = "/users/", method = RequestMethod.DELETE)
    public ResponseEntity < Users > deleteAllUsers() {
        logger.info("Deleting All Users");

        usersService.deleteAllUsers();
        return new ResponseEntity < Users > (HttpStatus.NO_CONTENT);
    }
}
Aritz
  • 30,971
  • 16
  • 136
  • 217
  • Have you tried [this](https://stackoverflow.com/a/34834735/1199132)? – Aritz Aug 29 '17 at 06:50
  • Right now.I can see rest results in browser but not postman.I use same URL.http://localhost:8080/api/user/1 like that –  Aug 29 '17 at 08:51
  • That's because your browser already has the required token stored as a cookie, so you're authorized. In postman, you firstly need to invoke the auth endpoint. – Aritz Aug 29 '17 at 09:02
  • how do i invoke the authenticate endpoint. I cannot use postman right now.I choose http authentication in the installation.I read some pages, maybe i should create a token but i could not create a token –  Aug 29 '17 at 12:34

0 Answers0