I am new to spring-security (Java) and I am looking for a good and simple example of:
How to use spring security for login and logout
Make sure that the session exists on every page and if not redirect to the login again
How get access to the current User Session
My project is currently working with spring MVC, and hibernate.
I have built the loginAPI + loginDAO, I need now to combine the security and make some of the pages secured.
I searched for tutorials, but a lot of them are very complicated.
Spring Security Configuration is using Builder Pattern and based on the authenticate method, some of the methods won't be available later on. For example, auth. userDetailsService() returns the instance of UserDetailsService and then we can't have any other options, such as we can't set DataSource after it.
The first way to check for user roles in Java is to use the @PreAuthorize annotation provided by Spring Security. This annotation can be applied to a class or method, and it accepts a single string value that represents a SpEL expression. Before we can use this annotation, we must first enable global method security.
As of Spring Security version 5.7. 1, the default username is user and the password is randomly generated and displayed in the console (e.g. 8e557245-73e2-4286-969a-ff57fe326336 ).
Well.
This is I think by far is the best i have seen so far!
http://krams915.blogspot.com/2010/12/spring-security-mvc-integration_18.html
You can look for a Single-Sign-On(e.g CAS) implementation in Spring Security. It'll serve your purpose completely.
Check Out :-
http://static.springsource.org/spring-security/site/docs/3.0.x/reference/cas.html
https://wiki.jasig.org/display/CASC/Using+the+CAS+Client+3.1+with+Spring+Security
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With