|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.zeevbelkin.web.filter.access.AjaxLoginPeer
public abstract class AjaxLoginPeer
This class is a helper that may be used to implement ajax login/logout procedures with DWR. To use this class a customer should derive a class from it that should be exposed with in allow in the dwr.xml configuration file.
<allow> <create creator="new" javascript="Authenticator"> <param name="class" value="com.myapp.Authenticator"/> </create> </allow>This derived class must override at least
assignCredentials
method. This method sets the user credentials if the authentication info
is correct. The method can also return some optional info to the javascript
caller. An example of such derived class you can see below (an actual
class ordinary checks the authentication info with a database).
public class Authenticator extends AjaxLoginPeer { protected Map assignCredentials( Map attributes, Yaaf.SessionSecurityInfo ssi, HttpServletRequest request, HttpServletResponse response ) { String login=(String)attributes.get("login"),password=(String)attributes.get("password"); if ("pupkin".equals(login)&&"stam".equals(password)) { ssi.setName("pupkin"); } return null; } }
Constructor Summary | |
---|---|
AjaxLoginPeer()
|
Method Summary | |
---|---|
protected abstract java.util.Map |
assignCredentials(java.util.Map attributes,
Yaaf.SessionSecurityInfo ssi,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Checks the user authentication info and assigns credentials in case of success. |
java.lang.String |
getName(javax.servlet.http.HttpServletRequest request)
Returns an authenticated user name if any. |
java.util.Map |
login(java.util.Map attributes,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Performs login. |
java.util.Map |
loginAndRemember(java.util.Map attributes,
int daysToKeepLogin,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
This function is just like login ,
but stores a user login in a cookie in a case of successful
authentication. |
void |
logout(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Performs logout. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public AjaxLoginPeer()
Method Detail |
---|
public java.lang.String getName(javax.servlet.http.HttpServletRequest request)
<script> Authenticator.getName( function(str) { if (str!=null) { $("ajaxLoginForm").style.display='none'; $("ajaxLogoutForm").style.display='block'; $("userNameLabel").innerText=str; } else { $("ajaxLoginForm").style.display='block'; $("ajaxLogoutForm").style.display='none'; } } ); $("loginError").style.display='none'; </script>
public void logout(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
<script type='text/javascript'> function doLogout() { Authenticator.logout( function() { $("ajaxLoginForm").style.display='block'; $("ajaxLogoutForm").style.display='none'; } ); } </script>
public java.util.Map login(java.util.Map attributes, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
<script> function doLogin() { Authenticator.login( { login: $("user_id").value, password: $("password").value },AndRemember function(hm) { // the hashap hm may content some optional // info that inform the JS-code how to act to reach sucessful // authentication (it is especially important to implement openid login) if (hm['name']!=null) { $("ajaxLoginForm").style.display='none'; $("ajaxLogoutForm").style.display='block'; $("userNameLabel").innerText=hm['name']; $("loginError").style.display='none'; } else { $("loginError").style.display='block'; } } ); } </script>
attributes
- various values required to check user identity, ordinaty,
them are a user name and a password.
public java.util.Map loginAndRemember(java.util.Map attributes, int daysToKeepLogin, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
login
,
but stores a user login in a cookie in a case of successful
authentication.
attributes
- various values required to check user identity, ordinaty,
them are a user name and a password.daysToKeepLogin
- time to keep a successful login in a cookie in days
protected abstract java.util.Map assignCredentials(java.util.Map attributes, Yaaf.SessionSecurityInfo ssi, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
request
- various values required to check user identity, ordinary,
them are a user name and a password.ssi
- Session Security Info object used to assign the credentials
in case of success
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |