[OCP 21 book] | [OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Manohar Parelly wrote:Hi,
Using window.name javascript property we can track tabs/windows in the same session. I successfully used window.name in my application to track & do necessary action when application is accessed from multiple tabs.
Implementation details to restrict multi tabs access:
On Login page submit, set the window.name property to some value. Pass the same value as a hidden variable to Login action.
With this we can always ensure that proper login attempt window will have a name associated with it.
You have to put a check in Login action. If the value is not there in the session, it means 1st time you are trying to login in the session. Put the value in the session. If value already exist in the session, it means you are trying to login from another tab in the same session.
if(sessionmap.get("WINDOW_NAME") == null){
sessionmap.put("WINDOW_NAME", windowName);
}else{
return "InvalidBrowserWindowError";
}
Assume user is already logged in from 1st tab. In my application, if I open another tab in IE (even another window in forefox) and copy & paste the URL from 1st tab... it automatically takes the user to same page as in 1st page. To restrict this access, I identified all entry points to different modules in my application, and put below logic in some required jsp files to throw error page.
<form name="invalidwindow" id="invalidwindow" action="<<some action>>" method="post">
</form>
<script language="JavaScript" type="text/javascript">
if(window.name == '' || window.name != <<some value>>'){
invokeInvalidBrowserWindow();
}
function invokeInvalidBrowserWindow(){
document.invalidwindow.submit();
}
</script>
Above logic is to restrict web application access from multiple tabs.
If you want to support multiple logins from same machine you can do like below:
IE --> login from one IE tab. Open a new IE window (File --> New Window). and login from new window.
Mozilla --> Install CookiePie add-on in your mizilla browser window. Enable CookiePie for each tab. CookiePie will ensure that a new session will be created for each tab.
Regards,
Manohar Parelly
Asheesh Mathurs wrote:Manohar,
This is a smart idea, is it possible to share the entire source code.
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Rob Spoor wrote:
Asheesh Mathurs wrote:Manohar,
This is a smart idea, is it possible to share the entire source code.
No; we are NotACodeMill.
Space pants. Tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|