PluggableAuthenticator now has some sample-/base-authenticators
The newest version of the PluggableAuthenticator for JSR 196 now includes some authenticators to easily start off with:
- form-based authentication
- ticket-based authentication
- simple logout
- combination of multiple authenticators
Get it here!!
A little example? No problem!
This is how you could use all of the above, to achieve that a user can login with a ticket (or one time token, ott) or on a login-page with username and password.
It'll also let a user quit a session.
package name.aikesommer.Authenticator.Samples;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import name.aikesommer.Authenticator.AuthenticationRequest;
import name.aikesommer.Authenticator.DelegatingAuthenticator;
import name.aikesommer.Authenticator.FormAuthenticator;
import name.aikesommer.Authenticator.LogoutManager;
import name.aikesommer.Authenticator.PluggableAuthenticator;
import name.aikesommer.Authenticator.PluggableAuthenticator.AuthenticationManager;
import name.aikesommer.Authenticator.SimplePrincipal;
import name.aikesommer.Authenticator.TicketAuthenticator;
/**
* This is just a sample, make sure to actually check credentials and such!!
*
* @author Aike J Sommer
*/
public class FormAndTicketSample extends DelegatingAuthenticator {
@Override
protected Collection getAuthenticators(AuthenticationManager manager, AuthenticationRequest request) {
List result = new ArrayList();
/**
* Allow form-based logins.
*/
result.add(new FormAuthenticator() {
@Override
protected boolean checkCredentials(String username, String password) {
// check the credentials with some config-files, db-data
// or a realm in the app-server
// we just return true here, so everything will be accepted
return true;
}
@Override
protected SimplePrincipal loadPrincipal(String username) {
// load user-data from config-files, db or where ever you
// have it stored :-)
return new SimplePrincipal(username, "user");
}
});
/**
* Allow ticket-based logins.
*/
result.add(new TicketAuthenticator() {
@Override
protected boolean checkTicket(String ticket) {
// check the ticket, for example with some secret and a
// hash
// we just return true here, so everything will be accepted
return true;
}
@Override
protected SimplePrincipal loadPrincipal(String ticket) {
return new SimplePrincipal("guest", "guest");
}
});
/**
* Allow a user to "logout".
*/
result.add(new LogoutManager());
return result;
}
}
Hope this is easy to understand!!
:-)
- Awesome and legendary online pokertimer
- New releases for AuthenticRoast and ViewNControl
- New release of AuthenticRoast - Moved to Google code
- ViewNControl: VNC connections with pure HTML / JavaScript
- Make that mouse-pointer stay out of invisible areas
- RESTful web-services in Java using JAX-RS - Part 1: Getting up and running
- SumtnSumtn goes public :-)
- Problems with f:param inside h:outputLink
- Tomcat and UTF-8
- Multihead in KDE 4.2.2
Aike J Sommer