Showing posts with label Spring. Show all posts
Showing posts with label Spring. Show all posts

Thursday, 31 July 2008

... migrating from ACEGI to Spring Security

this piece of work is done by now. Here are my experiences so far. In most cases one can take Spring Security and use it as given. There are plenty of providers and mechanisms, that are supported (like LDAP, JAAS, CAS, digest, form authentication etc.) and would fulfil one's needs in 90% of cases. When it gets tough? Like in our case, when you e.g. would like to use some custom security providers or load access definitions from a file, describing your access rules in some other way.
Back again to a normal case... The new feature presented in Spring Security is a new configuration syntax, which allows you to skip defining all the beans in a Spring manner. A minimal configuration looks like:
Code...

Looks fine doesn't it? Than you have to specify an authentication provider to map a user with a valid password to the roles. And that's it. So what is when you'd like to override some filter in the filter chain? Or to define a custom ports mapping for HTTP and HTTPS? Or would like to use a custom JSF login page? I'll tell you. You end very soon by good old ACEGI Security configuration syntax with beans.

There was one issues that posed special degree of difficulty: how do I configure a custom JSF login page using Spring Security authentication mechanism without having to reimplement the whole authentication logic? The solution is to use Spring Security j_spring_security_check.jsp as a filter process URL and correctly map the username and password fields to be forwarded as request parameters. It looks something like this:
Code...

It will only work in connection with the login JSF designed as follows:
Code...

and not to forget the navigation rule in the faces config:
Code...

and the last point - the JSF backing bean to map username and password input from the login page, which is defined as a managed bean in faces config:
Code...

The java class LoginView contains only getter and setter for username and password and an exception handler to forward a failed login message from JSF to Spring:
Code...


Another interesting topic is localization. How to get localized login error messages displayed if locale is managed in JSF. I'll write on it some other time...

Thursday, 10 July 2008

Still working on...

migrating to Spring Security in a JSF application. There seems to be a way. Going deep into Spring code and debug crazily helps to get understanding what's going on there. I'll post some more info, tricks and important details as soon as I have the complete solution. But I'm very optimistic now !

Sunday, 15 June 2008

Currently working on...

migrating our application framework from Acegi to Spring Security. It sounds like a pretty easy task. It is really so as long as you go along with the standard set of security features contained in Spring Security, which is very extensive. So that in 90% of cases you would take it out of the box, configure & use. But if you have some existing peculiarities in your software landscape, that you would like to integrate, that's where it gets tough.

We for example use a web service for user authentication and authorization and had to implement our specific provider to plug it into the framework. Moreover it surprised me that there is still no reasonable JSF support in Spring Security. My idea was to use it in a JSF application and possibly write no authentication specific code. What I was hoping on, was to supply my own WS authentication provider, configure the Spring and/or JSF beans and it should work. But the truth is, actually there is no way around as to use a backing bean with authentication logic. This solution is presented here in Java World Magazine. It is a good and working one, but I wish it were simplier.

What Spring guys actually promise and underline as a highlight of Spring Security comparing with Acegi is less configuration and easy understanding. As matter of fact the main issue here is interaction between Spring Security and JSF and a question how to configure it without need to write the whole authentication / authorization logic in Java, but just to get it configured somehow.

So should you've run into an appropriate solution, please be so kind and drop a line here ...