[jboss-user] [JBoss Portal] - Re: Redirect portal
alessio.papi
do-not-reply at jboss.com
Wed Feb 11 04:52:56 EST 2009
Hi,
my idea (implemented in my project) was to extend DefaultPortalCommandFactory and SignOutURLFactory to change the page/URL to redirect to role default page. The two factoris replace the standard factories CommandFactory and SignOutURLFactory.
For example, the redirect to home factory is something like this :
public class RedirectHomeFactory extends DefaultPortalCommandFactory {
/** Log */
private static final Log LOG = LogFactory.getLog(RedirectHomeFactory.class);
/** Slash */
private static final String SLASH = "/";
/** Mapping */
private Properties mapping;
/**
* Get mapping
* @return Mapping
*/
public Properties getMapping() {
return mapping;
}
/**
* Set mapping
* @param mapping Mapping
*/
public void setMapping(Properties mapping) {
this.mapping = mapping;
}
/**
* {@inheritDoc}
*/
@Override
public ControllerCommand doMapping(ControllerContext context, ServerInvocation serverInvocation, String host, String contextPath, String requestPath) {
// Command
ControllerCommand command = null;
// Get http request and check roles
HttpServletRequest request = serverInvocation.getServerContext().getClientRequest();
// Redirect only if portal is not specified
if (requestPath != null && (requestPath.trim().length() == 0 || requestPath.trim().equals(SLASH))) {
// Flag
boolean found = false;
// Role
String role = null;
// Get roles
Enumeration enumeration = mapping.keys();
while (!found && enumeration.hasMoreElements()) {
// Get role
role = (String) enumeration.nextElement();
// Check role
if (request.isUserInRole(role)) {
// Get portal and page of role
String[] portalAndPage = mapping.getProperty(role).split(SLASH);
if (portalAndPage == null || portalAndPage.length < 2) {
throw new IllegalStateException("Wrong portal/page for role " + role);
}
// Get portal
Portal portal = getContainer().getContext().getPortal(portalAndPage[0]);
if (portal == null) {
throw new IllegalStateException("Default portal does not exist");
}
// Get default page
Page page = portal.getPage(portalAndPage[1]);
if (page == null) {
throw new IllegalStateException("Default page does not exist");
}
// Log
LOG.debug("Redirect to " + portal.getName() + " " + page.getName());
command = new ViewPageCommand(page.getId());
found = true;
}
}
if (!found) {
// Log
LOG.debug("Default redirect, no mapped role");
// Default command
command = super.doMapping(context, serverInvocation, host, contextPath, requestPath);
}
} else {
// Log
LOG.debug("Default redirect");
// Default command
command = super.doMapping(context, serverInvocation, host, contextPath, requestPath);
}
return command;
}
}
and the mbean that replace the standard portal mbean :
<!-- Redirect to user home -->
<mbean code="com.yourcompany.RedirectHomeFactory"
name="portal:commandFactory=RedirectHome" xmbean-dd=""
xmbean-code="org.jboss.portal.jems.as.system.JBossServiceModelMBean">
role=portal/default
<depends optional-attribute-name="NextFactory" proxy-type="attribute">portal:commandFactory=Delegating
<depends optional-attribute-name="Container" proxy-type="attribute">portal:container=PortalObject
you have to change the portal mbean controller properties :
<!--
<depends
optional-attribute-name="CommandFactory"
proxy-type="attribute">portal:commandFactory=DefaultPortal
-->
<depends
optional-attribute-name="CommandFactory"
proxy-type="attribute">portal:commandFactory=RedirectHome
For the signout the code is the same :
public class SignOutFactory extends SignOutURLFactory {
/** Log */
private static final Log LOG = LogFactory.getLog(SignOutFactory.class);
/** Location */
private static final String LOCATION = "location";
/** Mapping */
private Properties mapping;
/**
* Get mapping
* @return Mapping
*/
public Properties getMapping() {
return mapping;
}
/**
* Set mapping
* @param mapping Mapping
*/
public void setMapping(Properties mapping) {
this.mapping = mapping;
}
/**
* {@inheritDoc}
*/
@Override
public ServerURL doMapping(ControllerContext context, ServerInvocation serverInvocation, ControllerCommand controllerCommand) {
// URL
ServerURL serverURL = super.doMapping(context, serverInvocation, controllerCommand);
if (serverURL != null) {
// Get http request and check roles
HttpServletRequest request = serverInvocation.getServerContext().getClientRequest();
// Flag
boolean found = false;
// Role
String role = null;
// Get roles
Enumeration enumeration = mapping.keys();
while (!found && enumeration.hasMoreElements()) {
// Get role
role = (String) enumeration.nextElement();
// Check role
if (request.isUserInRole(role)) {
// Get location for role
try {
serverURL.setParameterValue(LOCATION, URLEncoder.encode(mapping.getProperty(role), "UTF-8"));
} catch (UnsupportedEncodingException encEx) {
LOG.error("Unsupported encoding " + encEx);
}
found = true;
}
}
}
return serverURL;
}
}
the mbean :
<!-- Redirect to user login -->
<mbean code="yourcompany.SignOutFactory"
name="portal:urlFactory=SignOut" xmbean-dd=""
xmbean-code="org.jboss.portal.jems.as.system.JBossServiceModelMBean">
role=portal/YourPortal
/signout
<depends optional-attribute-name="Factory" proxy-type="attribute">portal:urlFactory=Delegating
and comment out the portal signout mbean :
<!--
<mbean
code="org.jboss.portal.core.controller.command.mapper.SignOutURLFactory"
name="portal:urlFactory=SignOut"
xmbean-dd=""
xmbean-code="org.jboss.portal.jems.as.system.JBossServiceModelMBean">
/signout
<depends
optional-attribute-name="Factory"
proxy-type="attribute">portal:urlFactory=Delegating
-->
This solution redirects to default role portal only if the user doesn't specify the complete URL, to prevent users to go to another portal you have to add security-constraint into your portal-object.xml file.
HTH
Alessio
(Sorry for poor English...)
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4208933#4208933
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4208933
More information about the jboss-user
mailing list