001package votorola.a.web.wic.authen; // Copyright 2012, Michael Allan. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Votorola Software"), to deal in the Votorola Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicence, and/or sell copies of the Votorola Software, and to permit persons to whom the Votorola Software is furnished to do so, subject to the following conditions: The preceding copyright notice and this permission notice shall be included in all copies or substantial portions of the Votorola Software. THE VOTOROLA SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE VOTOROLA SOFTWARE OR THE USE OR OTHER DEALINGS IN THE VOTOROLA SOFTWARE. 002 003import org.apache.wicket.Page; 004import org.apache.wicket.request.mapper.parameter.PageParameters; 005import votorola.a.web.wic.*; 006import votorola.g.lang.*; 007import votorola.g.web.wic.*; 008 009 010/** A facility to verify the identity of a user. 011 */ 012public @ThreadSafe abstract class Authenticator 013{ 014 015 016 // /** A user identifier that might be that of the persistently authenticated user, or 017 // * null if well-formed persistence data cannot be retrieved from the request cookies. 018 // * The persistence data are not authenticated. 019 // */ 020 // abstract IDPair apparentlyPersistedUser( HttpServletRequest reqHS ); 021 022 023 024 /** Removes "returnClass" from pP and returns the class it specifies. 025 */ 026 static Class<? extends Page> extractReturnClass( final PageParameters pP ) 027 { 028 try 029 { 030 final String s = PageParametersX.getStringRequired( pP, "returnClass" ); 031 pP.remove( "returnClass" ); 032 return Class.forName(s).asSubclass( Page.class ); 033 } 034 catch( ClassNotFoundException x ) { throw new RuntimeException( x ); } 035 } 036 037 038 039 /** The class of login page for this authenticator. 040 */ 041 public abstract Class<? extends VPageHTML> loginPageClass(); 042 043 044 045 /** Ensures that the user is logged out. 046 */ 047 public abstract void logOut(); 048 049 050 051 /** Constructs a login page that redirects to a newly constructed, bookmarkable, 052 * return page if authentication succeeds. If the return page is a {@linkplain 053 * votorola.a.voter.VoterPage voter page} without a specified voter, then pP is 054 * altered to specify the newly authenticated user. 055 * 056 * @param pP The type and parameters of the return page to construct after the 057 * login attempt. Parameter "returnClass" specifies the page type, while the 058 * remainder of pP is passed to the page instance. 059 */ 060 public abstract VPageHTML newLoginPage( PageParameters pP ); 061 062 063 064 /** The email address to automatically login for each session, as defined by the 065 * system property "votorola.a.web.wic.authen.Authenticator.PRELOGIN_EMAIL", or null 066 * if there is none. This is intended for testing in private deployments. 067 */ 068 public static final String PRELOGIN_EMAIL = 069 System.getProperty( "votorola.a.web.wic.authen.Authenticator.PRELOGIN_EMAIL" ); 070 071 072}