Posts

Showing posts with the label spring-security

How to allow anonymous users to access a certain function only using spring security

How to allow anonymous users to access a certain function only using spring security I'm using spring security in my project. I have a condition where the anonymous users should be able to read from database whereas only authorized users to add/update/delete. How can we mention such situation in the security-config? .antMatchers("/user/**").permitAll() permit all requires to be authenticated but I want even none authenticated users to access via the GET method. @RequestMapping("/user") @PreAuthorize("hasAuthority('USER')") public List<UserAll> getAll() { return userService.getAll(); } And here how do I mention that this function should be accessed by anonymous users too? you can change to hasAnyRole('USER', 'ANONYMOUS') – fg78nc Jul 2 at 4:18 hasAnyR...

Spring boot security login verify failed

Spring boot security login verify failed I want to verify the user's identity when he or she send a localhost:8080/submit request, so I added the following to SecurityConfig class: localhost:8080/submit @Override protected void configure(HttpSecurity http) throws Exception { http .authorizeRequests() .antMatchers("/submit").access("hasRole('WORKER')") .antMatchers("/**").permitAll() .and() .formLogin() .loginPage("/login") .and() .logout() .logoutSuccessUrl("/") .and() .rememberMe() .tokenValiditySeconds(4838400) .key("workerKey"); } I wish the page could redirect to localhost:8080/login when I input localhost:8080/submit in the address field. My Worker entity has the role "WORKER": localhost:8080/login localhost:8080/submit @Override public Col...

Spring Boot 2 PreAuthentication using windows login username

Spring Boot 2 PreAuthentication using windows login username Once user logins to windows machine and access the website, the user should be able to access the site without login and the roles should be set from the database. I am using Spring boot 2, SpringSecurity and Postgres SQL. I have gone through few PreAuthentication posts but they are mainly for Site Minder authentication, but no information on applying the roles from the database. Any help would be highly appreciated. By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.