|
432 | 432 | For more on ``HttpSecurity`` with Spring Security, see `its HttpSecurity documentation <http://docs.spring.io/spring-security/site/docs/current/reference/htmlsingle/#jc-httpsecurity>`_.
|
433 | 433 |
|
434 | 434 | We've added a new method to our ``HelloController``. It does not call out any other authorizaton requirements. As such,
|
435 |
| - anyone logged in will be able to access ``/me``. Furthermore, anyone NOT logged in trying to access ``/me`` will automatically |
| 435 | + anyone logged in will be able to access ``/userdetails``. Furthermore, anyone NOT logged in trying to access ``/userdetails`` will automatically |
436 | 436 | be redirected to the ``/login`` view.
|
437 | 437 |
|
438 | 438 | .. code-block:: java
|
|
442 | 442 | public class HelloController {
|
443 | 443 |
|
444 | 444 | ...
|
445 |
| - @RequestMapping("/me") |
446 |
| - String me() { |
447 |
| - return "me"; |
| 445 | + @RequestMapping("/userdetails") |
| 446 | + String userDetails() { |
| 447 | + return "userdetails"; |
448 | 448 | }
|
449 | 449 | ...
|
450 | 450 | }
|
451 | 451 |
|
452 |
| - Try it out. Launch the application as before, and then browse to: ``http://localhost:${port}/me``. You will be redirected to the ``/login`` |
453 |
| - and then after you login to a valid Stormpath Account, you will automatically be brought back to ``/me``. That's the Stormpath magic at work! |
| 452 | + Try it out. Launch the application as before, and then browse to: ``http://localhost:${port}/userdetails``. You will be redirected to the ``/login`` |
| 453 | + and then after you login to a valid Stormpath Account, you will automatically be brought back to ``/userdetails``. That's the Stormpath magic at work! |
454 | 454 |
|
455 | 455 | Now, we'll look at fine grained controls using Spring Security permissions connected to Stormpath custom data.
|
456 | 456 |
|
|
534 | 534 |
|
535 | 535 | This part of the tutorial exercises the Token Magement features using Spring Security Spring Boot WebMVC.
|
536 | 536 |
|
537 |
| - There's a simple `@RestController` called `MeController` that returns information about the authenticated account. |
| 537 | + There's a simple `@RestController` called `UserDetailsController` that returns information about the authenticated account. |
538 | 538 |
|
539 | 539 | .. code-block:: java
|
540 | 540 |
|
541 | 541 | @RestController
|
542 |
| - public class MeController { |
543 |
| - @RequestMapping(value="/me", produces = MediaType.APPLICATION_JSON_VALUE) |
| 542 | + public class UserDetailsController { |
| 543 | + @RequestMapping(value="/userdetails", produces = MediaType.APPLICATION_JSON_VALUE) |
544 | 544 | public AccountInfo info(HttpServletRequest req) {
|
545 | 545 | // must be logged in to get here per Spring Security config
|
546 | 546 | Account account = AccountResolver.INSTANCE.getAccount(req);
|
|
549 | 549 | }
|
550 | 550 | }
|
551 | 551 |
|
552 |
| - In order to hit the `/me` endpoint, we'll first, we'll get an `access_token` and a `refresh_token` by hitting the |
| 552 | + In order to hit the `/userdetails` endpoint, we'll first, we'll get an `access_token` and a `refresh_token` by hitting the |
553 | 553 | `/oauth/token` endpoint:
|
554 | 554 |
|
555 | 555 | .. code-block:: bash
|
|
577 | 577 |
|
578 | 578 | The response includes the tokens as well as information on their type (`Bearer` in this case) and when it expires.
|
579 | 579 |
|
580 |
| - We can now use the `access_token` to hit the `/me` endpoint: |
| 580 | + We can now use the `access_token` to hit the `/userdetails` endpoint: |
581 | 581 |
|
582 | 582 |
|
583 | 583 | .. code-block:: bash
|
584 | 584 |
|
585 | 585 | curl \
|
586 | 586 | -H "Authorization: Bearer eyJraWQiOiJSOTJTQkhKQzFVNERBSU1HUTNNSE9HVk1YIiwiYWxnIjoiSFMyNTYifQ.eyJqdGkiOiI2M1laa1FBNjRTdEdUQjFhVEhlNGdPIiwiaWF0IjoxNDU0NDM4MTQ3LCJpc3MiOiJodHRwczovL2FwaS5zdG9ybXBhdGguY29tL3YxL2FwcGxpY2F0aW9ucy82dkZUNEFSZldDbXVIVlY4Vmt0alRvIiwic3ViIjoiaHR0cHM6Ly9hcGkuc3Rvcm1wYXRoLmNvbS92MS9hY2NvdW50cy80V1NjTWJBbm8zVjk1aWlTc3dralBYIiwiZXhwIjoxNDU0NDQxNzQ3LCJydGkiOiI2M1laa01xMTlzYUhxTHZqSDFtbzRLIn0.-3NNpi7-DTvl2VNCfHHFNwWVikmeCyNPy6KEu--XYjk" \
|
587 |
| - http://localhost:${port}/me |
| 587 | + http://localhost:${port}/userdetails |
588 | 588 |
|
589 | 589 | You will get a response like this:
|
590 | 590 |
|
|
644 | 644 |
|
645 | 645 | curl \
|
646 | 646 | -H "Authorization: Bearer eyJraWQiOiJSOTJTQkhKQzFVNERBSU1HUTNNSE9HVk1YIiwiYWxnIjoiSFMyNTYifQ.eyJqdGkiOiI1eDlxbWlES2U0RmlFMU02alhLSDBMIiwiaWF0IjoxNDU0NDQ0MTU1LCJpc3MiOiJodHRwczovL2FwaS5zdG9ybXBhdGguY29tL3YxL2FwcGxpY2F0aW9ucy82dkZUNEFSZldDbXVIVlY4Vmt0alRvIiwic3ViIjoiaHR0cHM6Ly9hcGkuc3Rvcm1wYXRoLmNvbS92MS9hY2NvdW50cy80V1NjTWJBbm8zVjk1aWlTc3dralBYIiwiZXhwIjoxNDU0NDQ3NzU1LCJydGkiOiI2M1laa01xMTlzYUhxTHZqSDFtbzRLIn0.J2NR7MV3OoolYImfUNiu8SCDvaQdresHTnPHgL7mO1Q" \
|
647 |
| - http://localhost:${port}/me |
| 647 | + http://localhost:${port}/userdetails |
648 | 648 |
|
649 | 649 | Here's the response:
|
650 | 650 |
|
|
0 commit comments