Many times we have created url for anonymous user but when authenticated users access anonymous url , portal session is completely lost.
Soluation
There is a configuration you can set to ensure that authenticated requests to /wps/portal get redirected to /wps/myportal.
http://publib.boulder.ibm.com/infocenter/wpdoc/v6r1/index.jsp?topic=/com.ibm.wp.ent.doc_v6101/admin/srvcfgref.html
Look for
uri.home.substitution = (false)
Determines whether a public URL should be translated to a protected URL if a user session exists
set this value true in WAS console
Restart server
Wednesday, November 11, 2009
Monday, November 9, 2009
Cookie from Portal 6.1 theme
Many times we are tried add cookies in response object in theme but response cookies overwritten by portal aggregation engine.
I have created cookies.jsp and it include in Default.jsp
I had used java script ways to add cookies. I had created a separate Cookie.jsp
Include Cookie.jsp in defualt.jsp at bottom
<%@ include file="./Cookie.jsp" %>
Retrieve cookies in jsp
String user_name=null;
Cookie cokkies[] = request.getCookies();
for(int i = 0 ; i < cokkies.length ; i++ ){
if(cokkies[i].getName().equalsIgnoreCase("user_name")){
user_name = cokkies[i].getValue();
}
Code in cookies.jsp
View source this page to get code
*********************code started******************************************
<%-- Licensed Materials - Property of IBM, 5724-E76, (C) Copyright IBM Corp. 2001, 2004, 2006 - All Rights reserved. --%>
<%@ page session="false"%>
<%@ taglib uri="http://www.ibm.com/xmlns/prod/websphere/portal/v6.0/portal-logic" prefix="portal-logic" %>
<%@ taglib uri="http://www.ibm.com/xmlns/prod/websphere/portal/v6.0/portal-core" prefix="portal-core" %>
*********************code end ******************************************
I have created cookies.jsp and it include in Default.jsp
I had used java script ways to add cookies. I had created a separate Cookie.jsp
Include Cookie.jsp in defualt.jsp at bottom
<%@ include file="./Cookie.jsp" %>
Retrieve cookies in jsp
String user_name=null;
Cookie cokkies[] = request.getCookies();
for(int i = 0 ; i < cokkies.length ; i++ ){
if(cokkies[i].getName().equalsIgnoreCase("user_name")){
user_name = cokkies[i].getValue();
}
Code in cookies.jsp
View source this page to get code
*********************code started******************************************
<%-- Licensed Materials - Property of IBM, 5724-E76, (C) Copyright IBM Corp. 2001, 2004, 2006 - All Rights reserved. --%>
<%@ page session="false"%>
<%@ taglib uri="http://www.ibm.com/xmlns/prod/websphere/portal/v6.0/portal-logic" prefix="portal-logic" %>
<%@ taglib uri="http://www.ibm.com/xmlns/prod/websphere/portal/v6.0/portal-core" prefix="portal-core" %>
*********************code end ******************************************
Thursday, November 5, 2009
Generate WebSphere Portal V6.1 LogOut url by API
There are different ways to generate logout url
First Simple : Using JSP code
1) Create the sample Portlet with below code in jsp file
<%@ taglib uri = "http://www.ibm.com/xmlns/prod/websphere/portal/v6.0/portal-navigation" prefix = "portal-navigation" %>
// Put below code in java script
// get var url = portal-navigation:url command="LogoutUser";
var url = ;
window.location= url ;
Make sure copy the tlds in Web-inf folder.
2) Put that Portlet in page and give it url mapping
3) Send redirect from your servlet code.
Second approach By API
Servlet code
package com.ibm.logoutsimple;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.ibm.portal.state.Constants;
import com.ibm.portal.state.StateManager;
import com.ibm.portal.state.accessors.StateAccessor;
import com.ibm.portal.state.accessors.StateAccessorFactory;
import com.ibm.portal.state.accessors.action.engine.logout.LogoutActionAccessorController;
import com.ibm.portal.state.accessors.action.engine.logout.LogoutActionAccessorFactory;
import com.ibm.portal.state.accessors.exceptions.StateNotInRequestException;
import com.ibm.portal.state.accessors.url.URLContext;
import com.ibm.wps.state.accessors.url.EngineUrlEx;
import com.ibm.wps.state.accessors.url.URLAccessorFactoryEx;
import com.ibm.wps.state.accessors.url.URLContextConstants;
import com.ibm.wps.state.utils.StateHelper;
public class MyServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
getLogOuturl(request, response);
super.doGet(request, response);
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
// TODO Auto-generated method stub
super.doPost(req, resp);
}
private URLContext getURLContext(URLContext urlcontext)
{
return URLContextConstants.FORCE_ABSOLUTE_URLS;
}
private void getLogOuturl( HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse){
try{
EngineUrlEx engineurlex;
StateManager statemanager = StateHelper.getStateManager();
StateAccessorFactory stateaccessorfactory = (StateAccessorFactory)statemanager.getAccessorFactory(com.ibm.portal.state.accessors.StateAccessorFactory.class);
StateAccessor stateaccessor = stateaccessorfactory.getStateAccessor();
Object obj = null;
try
{
obj = stateaccessor.getStateHolder(httpservletrequest);
System.out.println("1");
}
catch(StateNotInRequestException statenotinrequestexception)
{
System.out.println("2");
obj = statemanager.newState();
}
stateaccessor.dispose();
URLAccessorFactoryEx urlaccessorfactoryex = (URLAccessorFactoryEx)statemanager.getAccessorFactory(com.ibm.wps.state.accessors.url.URLAccessorFactoryEx.class);
engineurlex = urlaccessorfactoryex.newURL(httpservletrequest, httpservletresponse, ((com.ibm.portal.state.StateHolder) (obj)), getURLContext(null), Constants.EMPTY_COPY);
LogoutActionAccessorFactory logoutactionaccessorfactory = (LogoutActionAccessorFactory)statemanager.getAccessorFactory(com.ibm.portal.state.accessors.action.engine.logout.LogoutActionAccessorFactory.class);
LogoutActionAccessorController logoutactionaccessorcontroller = logoutactionaccessorfactory.newLogoutActionController(httpservletrequest, engineurlex.getState());
logoutactionaccessorcontroller.dispose();
String LogOuturl = engineurlex.toString();
// System.out.println(LogOuturl);
String contextpath="PA_LogOutSimple/";
LogOuturl = LogOuturl.replaceAll(contextpath, "");
System.out.println(LogOuturl);
httpservletresponse.sendRedirect(LogOuturl);
}catch (Exception e) {
e.printStackTrace();
}
}
}
First Simple : Using JSP code
1) Create the sample Portlet with below code in jsp file
<%@ taglib uri = "http://www.ibm.com/xmlns/prod/websphere/portal/v6.0/portal-navigation" prefix = "portal-navigation" %>
// Put below code in java script
// get var url = portal-navigation:url command="LogoutUser";
var url =
window.location= url ;
Make sure copy the tlds in Web-inf folder.
2) Put that Portlet in page and give it url mapping
3) Send redirect from your servlet code.
Second approach By API
Servlet code
package com.ibm.logoutsimple;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.ibm.portal.state.Constants;
import com.ibm.portal.state.StateManager;
import com.ibm.portal.state.accessors.StateAccessor;
import com.ibm.portal.state.accessors.StateAccessorFactory;
import com.ibm.portal.state.accessors.action.engine.logout.LogoutActionAccessorController;
import com.ibm.portal.state.accessors.action.engine.logout.LogoutActionAccessorFactory;
import com.ibm.portal.state.accessors.exceptions.StateNotInRequestException;
import com.ibm.portal.state.accessors.url.URLContext;
import com.ibm.wps.state.accessors.url.EngineUrlEx;
import com.ibm.wps.state.accessors.url.URLAccessorFactoryEx;
import com.ibm.wps.state.accessors.url.URLContextConstants;
import com.ibm.wps.state.utils.StateHelper;
public class MyServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
getLogOuturl(request, response);
super.doGet(request, response);
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
// TODO Auto-generated method stub
super.doPost(req, resp);
}
private URLContext getURLContext(URLContext urlcontext)
{
return URLContextConstants.FORCE_ABSOLUTE_URLS;
}
private void getLogOuturl( HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse){
try{
EngineUrlEx engineurlex;
StateManager statemanager = StateHelper.getStateManager();
StateAccessorFactory stateaccessorfactory = (StateAccessorFactory)statemanager.getAccessorFactory(com.ibm.portal.state.accessors.StateAccessorFactory.class);
StateAccessor stateaccessor = stateaccessorfactory.getStateAccessor();
Object obj = null;
try
{
obj = stateaccessor.getStateHolder(httpservletrequest);
System.out.println("1");
}
catch(StateNotInRequestException statenotinrequestexception)
{
System.out.println("2");
obj = statemanager.newState();
}
stateaccessor.dispose();
URLAccessorFactoryEx urlaccessorfactoryex = (URLAccessorFactoryEx)statemanager.getAccessorFactory(com.ibm.wps.state.accessors.url.URLAccessorFactoryEx.class);
engineurlex = urlaccessorfactoryex.newURL(httpservletrequest, httpservletresponse, ((com.ibm.portal.state.StateHolder) (obj)), getURLContext(null), Constants.EMPTY_COPY);
LogoutActionAccessorFactory logoutactionaccessorfactory = (LogoutActionAccessorFactory)statemanager.getAccessorFactory(com.ibm.portal.state.accessors.action.engine.logout.LogoutActionAccessorFactory.class);
LogoutActionAccessorController logoutactionaccessorcontroller = logoutactionaccessorfactory.newLogoutActionController(httpservletrequest, engineurlex.getState());
logoutactionaccessorcontroller.dispose();
String LogOuturl = engineurlex.toString();
// System.out.println(LogOuturl);
String contextpath="PA_LogOutSimple/";
LogOuturl = LogOuturl.replaceAll(contextpath, "");
System.out.println(LogOuturl);
httpservletresponse.sendRedirect(LogOuturl);
}catch (Exception e) {
e.printStackTrace();
}
}
}
Tuesday, November 3, 2009
How to get LogOut url from IBM WebSphere Portlet V6.1
Here the sample code to get LogOut url from Portlet/Servlet.
Import the following classes
import com.ibm.portal.state.Constants;
import com.ibm.portal.state.StateManager;
import com.ibm.portal.state.accessors.StateAccessor;
import com.ibm.portal.state.accessors.StateAccessorFactory;
import com.ibm.portal.state.accessors.action.engine.logout.LogoutActionAccessorController;
import com.ibm.portal.state.accessors.action.engine.logout.LogoutActionAccessorFactory;
import com.ibm.portal.state.accessors.exceptions.StateNotInRequestException;
import com.ibm.portal.state.accessors.url.URLContext;
import com.ibm.wps.state.accessors.url.EngineUrlEx;
import com.ibm.wps.state.accessors.url.URLAccessorFactoryEx;
import com.ibm.wps.state.accessors.url.URLContextConstants;
import com.ibm.wps.state.utils.StateHelper;
Called below method from Portlet
private void getLogOuturl( HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse){
try{
EngineUrlEx engineurlex;
StateManager statemanager = StateHelper.getStateManager();
StateAccessorFactory stateaccessorfactory = (StateAccessorFactory)statemanager.getAccessorFactory(com.ibm.portal.state.accessors.StateAccessorFactory.class);
StateAccessor stateaccessor = stateaccessorfactory.getStateAccessor();
Object obj = null;
try
{
obj = stateaccessor.getStateHolder(httpservletrequest);
}
catch(StateNotInRequestException statenotinrequestexception)
{
obj = statemanager.newState();
}
stateaccessor.dispose();
URLAccessorFactoryEx urlaccessorfactoryex = (URLAccessorFactoryEx)statemanager.getAccessorFactory(com.ibm.wps.state.accessors.url.URLAccessorFactoryEx.class);
engineurlex = urlaccessorfactoryex.newURL(httpservletrequest, httpservletresponse, ((com.ibm.portal.state.StateHolder) (obj)), getURLContext(null), Constants.EMPTY_COPY);
LogoutActionAccessorFactory logoutactionaccessorfactory = (LogoutActionAccessorFactory)statemanager.getAccessorFactory(com.ibm.portal.state.accessors.action.engine.logout.LogoutActionAccessorFactory.class);
LogoutActionAccessorController logoutactionaccessorcontroller = logoutactionaccessorfactory.newLogoutActionController(httpservletrequest, engineurlex.getState());
logoutactionaccessorcontroller.dispose();
System.out.println(engineurlex.toString());
String LogOuturl = engineurlex.toString();
}catch (Exception e) {
e.printStackTrace();
}
}
private URLContext getURLContext(URLContext urlcontext)
{
return URLContextConstants.FORCE_ABSOLUTE_URLS;
}
Import the following classes
import com.ibm.portal.state.Constants;
import com.ibm.portal.state.StateManager;
import com.ibm.portal.state.accessors.StateAccessor;
import com.ibm.portal.state.accessors.StateAccessorFactory;
import com.ibm.portal.state.accessors.action.engine.logout.LogoutActionAccessorController;
import com.ibm.portal.state.accessors.action.engine.logout.LogoutActionAccessorFactory;
import com.ibm.portal.state.accessors.exceptions.StateNotInRequestException;
import com.ibm.portal.state.accessors.url.URLContext;
import com.ibm.wps.state.accessors.url.EngineUrlEx;
import com.ibm.wps.state.accessors.url.URLAccessorFactoryEx;
import com.ibm.wps.state.accessors.url.URLContextConstants;
import com.ibm.wps.state.utils.StateHelper;
Called below method from Portlet
private void getLogOuturl( HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse){
try{
EngineUrlEx engineurlex;
StateManager statemanager = StateHelper.getStateManager();
StateAccessorFactory stateaccessorfactory = (StateAccessorFactory)statemanager.getAccessorFactory(com.ibm.portal.state.accessors.StateAccessorFactory.class);
StateAccessor stateaccessor = stateaccessorfactory.getStateAccessor();
Object obj = null;
try
{
obj = stateaccessor.getStateHolder(httpservletrequest);
}
catch(StateNotInRequestException statenotinrequestexception)
{
obj = statemanager.newState();
}
stateaccessor.dispose();
URLAccessorFactoryEx urlaccessorfactoryex = (URLAccessorFactoryEx)statemanager.getAccessorFactory(com.ibm.wps.state.accessors.url.URLAccessorFactoryEx.class);
engineurlex = urlaccessorfactoryex.newURL(httpservletrequest, httpservletresponse, ((com.ibm.portal.state.StateHolder) (obj)), getURLContext(null), Constants.EMPTY_COPY);
LogoutActionAccessorFactory logoutactionaccessorfactory = (LogoutActionAccessorFactory)statemanager.getAccessorFactory(com.ibm.portal.state.accessors.action.engine.logout.LogoutActionAccessorFactory.class);
LogoutActionAccessorController logoutactionaccessorcontroller = logoutactionaccessorfactory.newLogoutActionController(httpservletrequest, engineurlex.getState());
logoutactionaccessorcontroller.dispose();
System.out.println(engineurlex.toString());
String LogOuturl = engineurlex.toString();
}catch (Exception e) {
e.printStackTrace();
}
}
private URLContext getURLContext(URLContext urlcontext)
{
return URLContextConstants.FORCE_ABSOLUTE_URLS;
}
Subscribe to:
Posts (Atom)