JAAS for human beings

Other users have provide some very useful links above so I am not going to bother with links. I have done a similar research in JAAS for web application and has ran into a “mind roadblock” until I finally realize JAAS is a framework tackling security at a different “layer” then web applications in the … Read more

How To Inject AuthenticationManager using Java Configuration in a Custom Filter

Override method authenticationManagerBean in WebSecurityConfigurerAdapter to expose the AuthenticationManager built using configure(AuthenticationManagerBuilder) as a Spring bean: For example: @Bean(name = BeanIds.AUTHENTICATION_MANAGER) @Override public AuthenticationManager authenticationManagerBean() throws Exception { return super.authenticationManagerBean(); }

How to secure REST API with Spring Boot and Spring Security?

Token based authentication – users will provide its credentials and get unique and time limited access token. I would like to manage token creation, checking validity, expiration in my own implementation. Actually, use Filter for token Auth – best way in this case Eventually, you can create CRUD via Spring Data for managing Token’s properties … Read more

How do I get the Session Object in Spring?

Your friend here is org.springframework.web.context.request.RequestContextHolder // example usage public static HttpSession session() { ServletRequestAttributes attr = (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes(); return attr.getRequest().getSession(true); // true == allow create } This will be populated by the standard spring mvc dispatch servlet, but if you are using a different web framework you have add org.springframework.web.filter.RequestContextFilter as a filter in your … Read more

Serving static web resources in Spring Boot & Spring Security application

There are a couple of things to be aware of: The Ant matchers match against the request path and not the path of the resource on the filesystem. Resources placed in src/main/resources/public will be served from the root of your application. For example src/main/resources/public/hello.jpg would be served from http://localhost:8080/hello.jpg This is why your current matcher … Read more

Spring Security configuration: HTTP 403 error

The issue is likely due to CSRF protection. If users will not be using your application in a web browser, then it is safe to disable CSRF protection. Otherwise you should ensure to include the CSRF token in the request. To disable CSRF protection you can use the following: @Configuration @EnableWebSecurity public class WebSecurityConfig extends … Read more

Invalid CSRF Token ‘null’ was found on the request parameter ‘_csrf’ or header ‘X-CSRF-TOKEN’

It looks like the CSRF (Cross Site Request Forgery) protection in your Spring application is enabled. Actually it is enabled by default. According to spring.io: When should you use CSRF protection? Our recommendation is to use CSRF protection for any request that could be processed by a browser by normal users. If you are only … Read more

How to create custom methods for use in spring security expression language annotations

None of the mentioned techniques will work anymore. It seems as though Spring has gone through great lengths to prevent users from overriding the SecurityExpressionRoot. EDIT 11/19/14 Setup Spring to use security annotations: <beans … xmlns:sec=”http://www.springframework.org/schema/security” … > … <sec:global-method-security pre-post-annotations=”enabled” /> Create a bean like this: @Component(“mySecurityService”) public class MySecurityService { public boolean hasPermission(String … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)