spring-security

403 forbidden when I try to post to my spring api?

爷,独闯天下 提交于 2021-01-20 18:14:59
问题 Using postman, I can get a list of users with a get request to: http://localhost:8080/users . But when I send a post request to the same address, I get a 403 error. @RestController public class UserResource { @Autowired private UserRepository userRepository; @GetMapping("/users") public List<User> retrievaAllUsers() { return userRepository.findAll(); } @PostMapping("/users") public ResponseEntity<Object> createUser(@RequestBody User user) { User savedUser = userRepository.save(user); URI

ResponseEntityExceptionHandler is not getting called when exception occurs

坚强是说给别人听的谎言 提交于 2021-01-18 05:19:48
问题 I am new to spring. I am developing a REST api with spring webmvc. For Error Handling I got this link http://docs.spring.io/spring/docs/3.2.x/spring-framework-reference/html/mvc.html#mvc-ann-rest-spring-mvc-exceptions I have tried to use ResponseEntityExceptionHandler in my project . but whenever my controller throws exception it never reaches to this ResponseEntityExceptionHandler. Following are my code snippet Controller @Controller @RequestMapping("/hello") public class HelloController {

ResponseEntityExceptionHandler is not getting called when exception occurs

那年仲夏 提交于 2021-01-18 05:19:17
问题 I am new to spring. I am developing a REST api with spring webmvc. For Error Handling I got this link http://docs.spring.io/spring/docs/3.2.x/spring-framework-reference/html/mvc.html#mvc-ann-rest-spring-mvc-exceptions I have tried to use ResponseEntityExceptionHandler in my project . but whenever my controller throws exception it never reaches to this ResponseEntityExceptionHandler. Following are my code snippet Controller @Controller @RequestMapping("/hello") public class HelloController {

Spring Security with session get online users returns empty

佐手、 提交于 2021-01-11 02:59:19
问题 There are multiple versions of the same questions around and none seem to address the issue. I would like to get online users from spring security. I understand we need to Autowire SessionRegistry and use it. But still, it doesn't work. Here is the code. Not sure whether it is due to custom Username, password authentication or due to custom password encoder or something else. Everything seems to be correct. Even getting the current logged in user's data works fine but not logged in user list.

Spring Security with session get online users returns empty

倖福魔咒の 提交于 2021-01-11 02:58:26
问题 There are multiple versions of the same questions around and none seem to address the issue. I would like to get online users from spring security. I understand we need to Autowire SessionRegistry and use it. But still, it doesn't work. Here is the code. Not sure whether it is due to custom Username, password authentication or due to custom password encoder or something else. Everything seems to be correct. Even getting the current logged in user's data works fine but not logged in user list.

Accessing JWT Token from a Spring Boot Rest Controller

爷,独闯天下 提交于 2021-01-03 07:10:45
问题 I am implementing a REST API with Spring Boot and I am securing it with JWT and Oauth 2. I have no problems with authentication and producing an access token. When a user makes a request I want to access its JWT token from the controller. @RequestMapping(value = "/users", method = RequestMethod.GET) public List<AppUser> getUsers(OAuth2Authentication auth) { logger.info("CREDENTIALS:" + auth.getCredentials().toString()); logger.info("PRINCIPAL:" + auth.getPrincipal().toString()); logger.info(

Accessing JWT Token from a Spring Boot Rest Controller

亡梦爱人 提交于 2021-01-03 07:07:31
问题 I am implementing a REST API with Spring Boot and I am securing it with JWT and Oauth 2. I have no problems with authentication and producing an access token. When a user makes a request I want to access its JWT token from the controller. @RequestMapping(value = "/users", method = RequestMethod.GET) public List<AppUser> getUsers(OAuth2Authentication auth) { logger.info("CREDENTIALS:" + auth.getCredentials().toString()); logger.info("PRINCIPAL:" + auth.getPrincipal().toString()); logger.info(

Accessing JWT Token from a Spring Boot Rest Controller

匆匆过客 提交于 2021-01-03 07:06:47
问题 I am implementing a REST API with Spring Boot and I am securing it with JWT and Oauth 2. I have no problems with authentication and producing an access token. When a user makes a request I want to access its JWT token from the controller. @RequestMapping(value = "/users", method = RequestMethod.GET) public List<AppUser> getUsers(OAuth2Authentication auth) { logger.info("CREDENTIALS:" + auth.getCredentials().toString()); logger.info("PRINCIPAL:" + auth.getPrincipal().toString()); logger.info(

How to disable security on management port in Spring Boot 2

我只是一个虾纸丫 提交于 2020-12-30 07:51:27
问题 I have the /actuator/ Endpoints (in my case manage ) on Port 6565. Is it possible to disable Security in Spring Boot 2 only for a specific port? At the moment I can only exclude certain paths from security. That would be insecure if I now run Enpoints under the main application port 1337 under /manage/. In the past we used management.security.enabled: false or was that path related too? @Configuration @EnableWebSecurity public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

What does Cookie CsrfTokenRepository.withHttpOnlyFalse () do and when to use it?

瘦欲@ 提交于 2020-12-19 04:17:05
问题 I am trying to learn Spring Security right now and I have seen many different examples using this. I know what CSRF is and that Spring Security enables it by default. The thing that I am curious about to know is this kind of customization. .csrf().csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse()) .and() .authorizeRequests(request -> { request .antMatchers("/login").permitAll() .anyRequest() ....more code What kind of customization does .csrf().csrfTokenRepository