[jboss-svn-commits] JBL Code SVN: r9353 - in labs/jbosslabs/trunk/portal-extensions: forge-login and 5 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Mon Feb 5 18:20:56 EST 2007


Author: szimano
Date: 2007-02-05 18:20:55 -0500 (Mon, 05 Feb 2007)
New Revision: 9353

Added:
   labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-common/src/java/org/jboss/wiki/JBossPortalCredentials24.java
Modified:
   labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/org/jboss/forge/common/PermissionTools.java
   labs/jbosslabs/trunk/portal-extensions/forge-login/maven.xml
   labs/jbosslabs/trunk/portal-extensions/forge-login/src/java/org/jboss/labs/login/LabsLoginModule.java
   labs/jbosslabs/trunk/portal-extensions/jbosswiki/forge-wiki/src/web/WEB-INF/portlet-instances.xml
   labs/jbosslabs/trunk/portal-extensions/jbosswiki/forge-wiki/src/web/WEB-INF/portlet.xml
   labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-common/src/java/org/jboss/wiki/JBossPortalCredentials.java
   labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-test/.classpath
   labs/jbosslabs/trunk/portal-extensions/portal-default/src/web/WEB-INF/default-object.xml
Log:
JBoss wiki identity fixes and portal login fixes (partial)

Modified: labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/org/jboss/forge/common/PermissionTools.java
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/org/jboss/forge/common/PermissionTools.java	2007-02-05 21:24:22 UTC (rev 9352)
+++ labs/jbosslabs/trunk/portal-extensions/forge-common/src/java/org/jboss/forge/common/PermissionTools.java	2007-02-05 23:20:55 UTC (rev 9353)
@@ -1,6 +1,5 @@
 package org.jboss.forge.common;
 
-import org.jboss.portal.core.modules.ModuleConstants;
 import org.jboss.portal.identity.*;
 import org.jboss.shotoku.tools.Tools;
 import org.jboss.logging.Logger;
@@ -17,27 +16,10 @@
 public class PermissionTools {
     private static final Logger log = Logger.getLogger(PermissionTools.class);
 
-    private static IdentityServiceController isc;
-
-    private static IdentityServiceController getIsc() {
-        if (isc == null) {
-            try {
-                InitialContext initialContext = new InitialContext();
-                isc = (IdentityServiceController) initialContext
-                        .lookup("portal:service=Module,type=IdentityServiceController");
-            } catch (NamingException e) {
-                log.error("Exception while getting the role module", e);
-            }
-        }
-
-        return isc;
-    }
-
     public static MembershipModule getMembershipModule() {
         try {
-            return (MembershipModule) isc.getIdentityContext().getObject(
-                    IdentityContext.TYPE_MEMBERSHIP_MODULE);
-        } catch (IdentityException e) {
+            return (MembershipModule)new InitialContext().lookup("java:portal/MembershipModule");
+        } catch (NamingException e) {
             log.error(e);
             return null;
         }
@@ -45,9 +27,8 @@
 
     public static UserProfileModule getUserProfileModule() {
         try {
-            return (UserProfileModule) isc.getIdentityContext().getObject(
-                    IdentityContext.TYPE_USER_PROFILE_MODULE);
-        } catch (IdentityException e) {
+            return (UserProfileModule)new InitialContext().lookup("java:portal/UserProfileModule");
+        } catch (NamingException e) {
             log.error(e);
             return null;
         }

Modified: labs/jbosslabs/trunk/portal-extensions/forge-login/maven.xml
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/forge-login/maven.xml	2007-02-05 21:24:22 UTC (rev 9352)
+++ labs/jbosslabs/trunk/portal-extensions/forge-login/maven.xml	2007-02-05 23:20:55 UTC (rev 9353)
@@ -14,15 +14,15 @@
     </goal>
 	
     <goal name="build">
-    	<!--<attainGoal name="jar" />-->
+    	<attainGoal name="jar" />
     </goal>
     
     <goal name="deploy">
-	<!--<ant:copy todir="${local.deploy.dir}" flatten="true">
+	<ant:copy todir="${local.deploy.dir}" flatten="true">
 	    	<ant:fileset dir=".">
 				<ant:filename name="target/*.jar" />
 	    	</ant:fileset>
-	</ant:copy>-->
+	</ant:copy>
     </goal> 
     
 </project>

Modified: labs/jbosslabs/trunk/portal-extensions/forge-login/src/java/org/jboss/labs/login/LabsLoginModule.java
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/forge-login/src/java/org/jboss/labs/login/LabsLoginModule.java	2007-02-05 21:24:22 UTC (rev 9352)
+++ labs/jbosslabs/trunk/portal-extensions/forge-login/src/java/org/jboss/labs/login/LabsLoginModule.java	2007-02-05 23:20:55 UTC (rev 9353)
@@ -21,7 +21,6 @@
  */
 package org.jboss.labs.login;
 
-import java.security.MessageDigest;
 import java.security.Principal;
 import java.security.acl.Group;
 import java.sql.Connection;
@@ -43,14 +42,18 @@
 
 import org.jboss.forge.common.ForgeHelper;
 import org.jboss.forge.common.PermissionTools;
-import org.jboss.forge.common.propertypersistance.PropertyService;
-import org.jboss.forge.common.soa.LabsServices;
+import org.jboss.forge.common.ejb3.LabsServices;
+import org.jboss.forge.common.ejb3.PropertyService;
 import org.jboss.portal.common.transaction.Transactions;
-import org.jboss.portal.core.modules.ModuleConstants;
-import org.jboss.portal.core.modules.ModuleException;
-import org.jboss.portal.identity.*;
+import org.jboss.portal.identity.MembershipModule;
+import org.jboss.portal.identity.NoSuchUserException;
+import org.jboss.portal.identity.Role;
+import org.jboss.portal.identity.RoleModule;
+import org.jboss.portal.identity.User;
+import org.jboss.portal.identity.UserModule;
+import org.jboss.portal.identity.UserProfileModule;
+import org.jboss.security.SimpleGroup;
 import org.jboss.security.auth.spi.UsernamePasswordLoginModule;
-import org.jboss.security.SimpleGroup;
 
 /**
  * A login module that use hibernate as underlying operational environment
@@ -78,7 +81,11 @@
 
 	private static final String AUTLOGIN_PASSWORD = "Autologin:password";
 	
-
+	private UserModule userModule;
+	private RoleModule roleModule;
+	private UserProfileModule userProfileModule;
+	private MembershipModule membershipModule;
+	
 	public void initialize(Subject subject, CallbackHandler callbackHandler,
 			Map sharedState, Map options) {
 		super.initialize(subject, callbackHandler, sharedState, options);
@@ -89,6 +96,15 @@
 		havingRole = (String) options.get("havingRole");
 		jbossDB = (String) options.get("jbossdb");
 
+		try {
+			userModule = (UserModule)new InitialContext().lookup("java:portal/UserModule");
+			roleModule = (RoleModule)new InitialContext().lookup("java:portal/RoleModule");
+			userProfileModule = (UserProfileModule)new InitialContext().lookup("java:portal/UserProfileModule");
+			membershipModule = (MembershipModule)new InitialContext().lookup("java:portal/MembershipModule");
+		} catch (NamingException e) {
+			log.error(e);
+		}
+		
 		// Some info
 		log.trace("userModuleJNDIName = " + userModuleJNDIName);
 		log.trace("additionalRole = " + additionalRole);
@@ -96,18 +112,6 @@
 		log.trace("jbossdb = " + jbossDB);
 	}
 
-	private UserModule userModule;
-
-	private RoleModule roleModule;
-
-	protected UserModule getUserModule() throws NamingException {
-		if (userModule == null) {
-			userModule = (UserModule) new InitialContext()
-					.lookup(userModuleJNDIName);
-		}
-		return userModule;
-	}
-
 	protected boolean validatePassword(String inputPassword,
 			String expectedPassword) {
 		final String inPassword = inputPassword;
@@ -187,14 +191,6 @@
 		}
 	}
 
-	protected RoleModule getRoleModule() throws NamingException {
-		if (roleModule == null) {
-			roleModule = (RoleModule) new InitialContext()
-					.lookup(ModuleConstants.ROLEMODULE_JNDINAME);
-		}
-		return roleModule;
-	}
-
 	protected String getUsersPassword() throws LoginException {
 		return "";
 	}
@@ -279,13 +275,13 @@
 					// getUsername());
 
 					user = userModule.createUser(getUsername(), rs
-							.getString("pn_pass"), rs.getString("pn_email"));
-					user.setFakeEmail(rs.getString("pn_femail"));
-					user.setGivenName(rs.getString("pn_fname"));
-					user.setFamilyName(rs.getString("pn_lname"));
+							.getString("pn_pass"));
+					userProfileModule.setProperty(user, User.INFO_USER_EMAIL_REAL, rs.getString("pn_email"));
+					userProfileModule.setProperty(user, User.INFO_USER_EMAIL_FAKE, rs.getString("pn_femail"));
+					userProfileModule.setProperty(user, User.INFO_USER_NAME_GIVEN, rs.getString("pn_fname"));
+					userProfileModule.setProperty(user, User.INFO_USER_NAME_FAMILY, rs.getString("pn_lname"));
+					userProfileModule.setProperty(user, User.INFO_USER_ENABLED, true);
 
-					user.setEnabled(true);
-
 					log.info("User " + getUsername()
 							+ " added to Labs Database.");
 
@@ -297,7 +293,7 @@
 						Role role = roleModule.findRoleByName(defaultRole);
 						if (role != null) {
 							roleSet.add(role);
-							roleModule.setRoles(user, roleSet);
+							membershipModule.assignRoles(user, roleSet);
 						} else {
 							log
 									.error("The role you specified as default role does not exist, check your portlet configuration");
@@ -385,4 +381,12 @@
 		}
 	}
 
+	public RoleModule getRoleModule() {
+		return roleModule;
+	}
+
+	public UserModule getUserModule() {
+		return userModule;
+	}
+
 }

Modified: labs/jbosslabs/trunk/portal-extensions/jbosswiki/forge-wiki/src/web/WEB-INF/portlet-instances.xml
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/jbosswiki/forge-wiki/src/web/WEB-INF/portlet-instances.xml	2007-02-05 21:24:22 UTC (rev 9352)
+++ labs/jbosslabs/trunk/portal-extensions/jbosswiki/forge-wiki/src/web/WEB-INF/portlet-instances.xml	2007-02-05 23:20:55 UTC (rev 9353)
@@ -4,7 +4,7 @@
       <if-exists>overwrite</if-exists>
       <instance>
          <instance-id>WikiPortletInstance</instance-id>
-         <portlet-ref>wikiportlet.WikiPortlet</portlet-ref>
+         <portlet-ref>WikiPortlet</portlet-ref>
       </instance>
    </deployment>
 </deployments>
\ No newline at end of file

Modified: labs/jbosslabs/trunk/portal-extensions/jbosswiki/forge-wiki/src/web/WEB-INF/portlet.xml
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/jbosswiki/forge-wiki/src/web/WEB-INF/portlet.xml	2007-02-05 21:24:22 UTC (rev 9352)
+++ labs/jbosslabs/trunk/portal-extensions/jbosswiki/forge-wiki/src/web/WEB-INF/portlet.xml	2007-02-05 23:20:55 UTC (rev 9353)
@@ -3,6 +3,7 @@
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd /opt/SUNWps/dtd/portlet.xsd" version="1.0">      
    <portlet>
+   	  <description>Wiki portlet</description>
       <portlet-name>WikiPortlet</portlet-name>
       <init-param>
             <name>default-view</name>
@@ -24,4 +25,5 @@
          <title>Wiki Portlet</title>
       </portlet-info>
    </portlet>
+
 </portlet-app>

Modified: labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-common/src/java/org/jboss/wiki/JBossPortalCredentials.java
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-common/src/java/org/jboss/wiki/JBossPortalCredentials.java	2007-02-05 21:24:22 UTC (rev 9352)
+++ labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-common/src/java/org/jboss/wiki/JBossPortalCredentials.java	2007-02-05 23:20:55 UTC (rev 9353)
@@ -19,204 +19,144 @@
  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
+
 package org.jboss.wiki;
 
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
 import java.util.Set;
 import java.util.TreeSet;
 
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
-import javax.portlet.ActionRequest;
-import javax.portlet.RenderRequest;
-import javax.transaction.TransactionManager;
 
 import org.jboss.logging.Logger;
-import org.jboss.portal.common.transaction.TransactionException;
-import org.jboss.portal.common.transaction.TransactionManagerProvider;
-import org.jboss.portal.common.transaction.Transactions;
-import org.jboss.portal.core.modules.ModuleException;
-import org.jboss.portal.identity.IdentityContext;
 import org.jboss.portal.identity.IdentityException;
-import org.jboss.portal.identity.IdentityServiceController;
 import org.jboss.portal.identity.MembershipModule;
 import org.jboss.portal.identity.Role;
 import org.jboss.portal.identity.RoleModule;
 import org.jboss.portal.identity.User;
+import org.jboss.portal.identity.UserModule;
 import org.jboss.portal.identity.UserProfileModule;
 import org.jboss.portlet.JBossActionRequest;
 import org.jboss.portlet.JBossRenderRequest;
 
+/**
+ * JBossPortalCredentials.java
+ *
+ * @author <a href="mailto:tomasz.szymanski at jboss.com">Tomasz Szymanski</a>
+ */
+
 public class JBossPortalCredentials extends Credentials {
 
-	private final String adminRoleName = "Admin";
-
-	private String name = null;
-
-	private boolean logedIn = false;
-
-	private boolean isAdmin = false;
-
-	private Set<String> roles;
-
-	private Set<Role> allRoles;
-
-	private TransactionManager tm;
+	private UserModule userModule;
+	private RoleModule roleModule;
+	private MembershipModule membershipModule;
+	private UserProfileModule userProfileModule;
+	private User user;
 	
-	private String email;
-
-	private static final String roleModulesCtx = "java:portal/RoleModule";
-
-	private Logger log = Logger.getLogger(this.getClass());
-
-	private static IdentityServiceController isc;
+	private final static Logger log = Logger.getLogger(JBossPortalCredentials.class);
 	
-	public JBossPortalCredentials() throws NamingException {
-		InitialContext initialContext = new InitialContext();
-        isc = (IdentityServiceController) initialContext
-                .lookup("portal:service=Module,type=IdentityServiceController");
-	}
+	private static final String ADMIN_ROLE_NAME = "admin";
 
-	private Set<String> getRoleNames(User user) {
-        Set<String> ret = new TreeSet<String>();
-        try {
-            for (Object roleObj : getMembershipModule().getRoles(user)) {
-                ret.add(((Role) roleObj).getName());
-            }
-        } catch (IdentityException e) {
-            return ret;
-        }
-
-        return ret;
-    }
+	public JBossPortalCredentials () throws NamingException {
+		userModule = (UserModule)new InitialContext().lookup("java:portal/UserModule");
+		roleModule = (RoleModule)new InitialContext().lookup("java:portal/RoleModule");
+		membershipModule = (MembershipModule)new InitialContext().lookup("java:portal/MembershipModule");
+		userProfileModule = (UserProfileModule)new InitialContext().lookup("java:portal/UserProfileModule");
+	}
 	
-	private MembershipModule getMembershipModule() {
-        try {
-            return (MembershipModule) isc.getIdentityContext().getObject(
-                    IdentityContext.TYPE_MEMBERSHIP_MODULE);
-        } catch (IdentityException e) {
-            log.error(e);
-            return null;
-        }
-    }
-	
-	 private UserProfileModule getUserProfileModule() {
-	        try {
-	            return (UserProfileModule) isc.getIdentityContext().getObject(
-	                    IdentityContext.TYPE_USER_PROFILE_MODULE);
-	        } catch (IdentityException e) {
-	            log.error(e);
-	            return null;
-	        }
-	    }
-
-	
-	public void setParam(Object param) {
+	@Override
+	public Set<String> getAllRoles() {
+		Set<String> roles = new TreeSet<String>();
 		
-		InitialContext initialContext;
-		RoleModule roleModule = null;
-		
 		try {
-			initialContext = new InitialContext();
-			roleModule = (RoleModule) initialContext
-					.lookup(roleModulesCtx);
-
-		} catch (NamingException e) {
+			for (Object role : roleModule.findRoles()) {
+				roles.add(((Role)role).getName());
+			}
+		} catch (IdentityException e) {
 			log.error(e);
-			
-			// should throw an exception here
-			return;
+			return null;
 		}
 		
-		
-		if (param instanceof JBossActionRequest) {
-			JBossActionRequest jrReq = (JBossActionRequest) param;
+		return roles;
+	}
 
-			if (jrReq.getUser() != null) {
-				name = jrReq.getUser().getUserName();
-				logedIn = true;
-				isAdmin = getRoleNames(jrReq.getUser())
-						.contains(adminRoleName);
-				roles = getRoleNames(jrReq.getUser());
-				try {
-					email = getUserProfileModule().getProperty(jrReq.getUser(), User.INFO_USER_EMAIL_REAL).toString();
-				} catch (IllegalArgumentException e) {
-					log.error(e);
-				} catch (IdentityException e) {
-					log.error(e);
-				}
-				
-			}
-
-		} else if (param instanceof JBossRenderRequest) {
-			JBossRenderRequest jrReq = (JBossRenderRequest) param;
-
-			if (jrReq.getUser() != null) {
-				name = jrReq.getUser().getUserName();
-				logedIn = true;
-				isAdmin = getRoleNames(jrReq.getUser())
-						.contains(adminRoleName);
-				roles = getRoleNames(jrReq.getUser());
-				try {
-					email = getUserProfileModule().getProperty(jrReq.getUser(), User.INFO_USER_EMAIL_REAL).toString();
-				} catch (IllegalArgumentException e) {
-					log.error(e);
-				} catch (IdentityException e) {
-					log.error(e);
-				}
-			} else {
-				name = "Unknown";
-			}
-
-		} else {
-			log.error("You are not running JBoss Portal");
+	@Override
+	public String getEmail() {
+		if (user == null) {
+			return null;
 		}
 		
 		try {
-			allRoles = roleModule.findRoles();
+			return userProfileModule.getProperty(user, User.INFO_USER_EMAIL_REAL).toString();
 		} catch (IdentityException e) {
-			log.error("Couldn't get roles from portal", e);
+			log.error(e);
+			return null;
 		}
 	}
 
+	@Override
 	public String getName() {
-		return name;
+		if (user == null) {
+			return null;
+		}
+		
+		return user.getUserName();
 	}
 
+	@Override
 	public boolean isAdmin() {
-		return isAdmin;
+		if (user == null) {
+			return false;
+		}
+		
+		try {
+			return membershipModule.findRoleMembers(ADMIN_ROLE_NAME, 0, 1, user.getUserName()).size() == 1;
+		} catch (IdentityException e) {
+			log.error(e);
+			return false;
+		}
 	}
-	private static final String userModuleCtx = "java:portal/UserModule";
 
-
+	@Override
 	public boolean isLoggedIn() {
-		return logedIn;
+		return (user != null);
 	}
 
 	@Override
 	public boolean isUserInRole(String role) {
-		if (roles != null)
-			return roles.contains(role);
-		else
+		if (user == null) {
 			return false;
+		}
+		
+		try {
+			return membershipModule.findRoleMembers(role, 0, 1, user.getUserName()).size() == 1;
+		} catch (IdentityException e) {
+			log.error(e);
+			return false;
+		}
 	}
 
 	@Override
-	public Set<String> getAllRoles() {
-		Set<String> roleNames = new TreeSet<String>();
+	public void setParam(Object param) {
+		
+		if (param instanceof JBossActionRequest) {
+			JBossActionRequest jrReq = (JBossActionRequest) param;
 
-		for (Role role : allRoles) {
-			roleNames.add(role.getName());
-		}
+			if (jrReq.getUser() != null) {
+				user = jrReq.getUser();
+			}
 
-		return roleNames;
-	}
+		} else if (param instanceof JBossRenderRequest) {
+			JBossRenderRequest jrReq = (JBossRenderRequest) param;
 
-	@Override
-	public String getEmail() {
-		return email;
+			if (jrReq.getUser() != null) {
+				user = jrReq.getUser();
+			}
+
+		} else {
+			log.error("You are not running JBoss Portal");
+		}
+		
 	}
 
 }

Added: labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-common/src/java/org/jboss/wiki/JBossPortalCredentials24.java
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-common/src/java/org/jboss/wiki/JBossPortalCredentials24.java	                        (rev 0)
+++ labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-common/src/java/org/jboss/wiki/JBossPortalCredentials24.java	2007-02-05 23:20:55 UTC (rev 9353)
@@ -0,0 +1,222 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.wiki;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.TreeSet;
+
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.portlet.ActionRequest;
+import javax.portlet.RenderRequest;
+import javax.transaction.TransactionManager;
+
+import org.jboss.logging.Logger;
+import org.jboss.portal.common.transaction.TransactionException;
+import org.jboss.portal.common.transaction.TransactionManagerProvider;
+import org.jboss.portal.common.transaction.Transactions;
+import org.jboss.portal.core.modules.ModuleException;
+import org.jboss.portal.identity.IdentityContext;
+import org.jboss.portal.identity.IdentityException;
+import org.jboss.portal.identity.IdentityServiceController;
+import org.jboss.portal.identity.MembershipModule;
+import org.jboss.portal.identity.Role;
+import org.jboss.portal.identity.RoleModule;
+import org.jboss.portal.identity.User;
+import org.jboss.portal.identity.UserProfileModule;
+import org.jboss.portlet.JBossActionRequest;
+import org.jboss.portlet.JBossRenderRequest;
+
+public class JBossPortalCredentials24 extends Credentials {
+
+	private final String adminRoleName = "Admin";
+
+	private String name = null;
+
+	private boolean logedIn = false;
+
+	private boolean isAdmin = false;
+
+	private Set<String> roles;
+
+	private Set<Role> allRoles;
+
+	private TransactionManager tm;
+	
+	private String email;
+
+	private static final String roleModulesCtx = "java:portal/RoleModule";
+
+	private Logger log = Logger.getLogger(this.getClass());
+
+	private static IdentityServiceController isc;
+	
+	public JBossPortalCredentials24() throws NamingException {
+		InitialContext initialContext = new InitialContext();
+        isc = (IdentityServiceController) initialContext
+                .lookup("service=Module,type=IdentityServiceController");
+	}
+
+	private Set<String> getRoleNames(User user) {
+        Set<String> ret = new TreeSet<String>();
+        try {
+            for (Object roleObj : getMembershipModule().getRoles(user)) {
+                ret.add(((Role) roleObj).getName());
+            }
+        } catch (IdentityException e) {
+            return ret;
+        }
+
+        return ret;
+    }
+	
+	private MembershipModule getMembershipModule() {
+        try {
+            return (MembershipModule) isc.getIdentityContext().getObject(
+                    IdentityContext.TYPE_MEMBERSHIP_MODULE);
+        } catch (IdentityException e) {
+            log.error(e);
+            return null;
+        }
+    }
+	
+	 private UserProfileModule getUserProfileModule() {
+	        try {
+	            return (UserProfileModule) isc.getIdentityContext().getObject(
+	                    IdentityContext.TYPE_USER_PROFILE_MODULE);
+	        } catch (IdentityException e) {
+	            log.error(e);
+	            return null;
+	        }
+	    }
+
+	
+	public void setParam(Object param) {
+		
+		InitialContext initialContext;
+		RoleModule roleModule = null;
+		
+		try {
+			initialContext = new InitialContext();
+			roleModule = (RoleModule) initialContext
+					.lookup(roleModulesCtx);
+
+		} catch (NamingException e) {
+			log.error(e);
+			
+			// should throw an exception here
+			return;
+		}
+		
+		
+		if (param instanceof JBossActionRequest) {
+			JBossActionRequest jrReq = (JBossActionRequest) param;
+
+			if (jrReq.getUser() != null) {
+				name = jrReq.getUser().getUserName();
+				logedIn = true;
+				isAdmin = getRoleNames(jrReq.getUser())
+						.contains(adminRoleName);
+				roles = getRoleNames(jrReq.getUser());
+				try {
+					email = getUserProfileModule().getProperty(jrReq.getUser(), User.INFO_USER_EMAIL_REAL).toString();
+				} catch (IllegalArgumentException e) {
+					log.error(e);
+				} catch (IdentityException e) {
+					log.error(e);
+				}
+				
+			}
+
+		} else if (param instanceof JBossRenderRequest) {
+			JBossRenderRequest jrReq = (JBossRenderRequest) param;
+
+			if (jrReq.getUser() != null) {
+				name = jrReq.getUser().getUserName();
+				logedIn = true;
+				isAdmin = getRoleNames(jrReq.getUser())
+						.contains(adminRoleName);
+				roles = getRoleNames(jrReq.getUser());
+				try {
+					email = getUserProfileModule().getProperty(jrReq.getUser(), User.INFO_USER_EMAIL_REAL).toString();
+				} catch (IllegalArgumentException e) {
+					log.error(e);
+				} catch (IdentityException e) {
+					log.error(e);
+				}
+			} else {
+				name = "Unknown";
+			}
+
+		} else {
+			log.error("You are not running JBoss Portal");
+		}
+		
+		try {
+			allRoles = roleModule.findRoles();
+		} catch (IdentityException e) {
+			log.error("Couldn't get roles from portal", e);
+		}
+	}
+
+	public String getName() {
+		return name;
+	}
+
+	public boolean isAdmin() {
+		return isAdmin;
+	}
+	private static final String userModuleCtx = "java:portal/UserModule";
+
+
+	public boolean isLoggedIn() {
+		return logedIn;
+	}
+
+	@Override
+	public boolean isUserInRole(String role) {
+		if (roles != null)
+			return roles.contains(role);
+		else
+			return false;
+	}
+
+	@Override
+	public Set<String> getAllRoles() {
+		Set<String> roleNames = new TreeSet<String>();
+
+		for (Role role : allRoles) {
+			roleNames.add(role.getName());
+		}
+
+		return roleNames;
+	}
+
+	@Override
+	public String getEmail() {
+		return email;
+	}
+
+}

Modified: labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-test/.classpath
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-test/.classpath	2007-02-05 21:24:22 UTC (rev 9352)
+++ labs/jbosslabs/trunk/portal-extensions/jbosswiki/wiki-test/.classpath	2007-02-05 23:20:55 UTC (rev 9353)
@@ -1,29 +1,56 @@
 <?xml version="1.0" encoding="UTF-8"?>
+
 <classpath>
-	<classpathentry kind="src" path="src/java"/>
-	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
-	<classpathentry kind="var" path="MAVEN_REPO/log4j/jars/log4j-1.2.9.jar"/>
-	<classpathentry kind="var" path="MAVEN_REPO/aslibs/jars/javax.servlet.jar"/>
-	<classpathentry kind="var" path="MAVEN_REPO/aslibs/jars/javax.servlet.jsp.jar"/>
-	<classpathentry kind="var" path="MAVEN_REPO/junit/jars/junit-3.8.1.jar"/>
-	<classpathentry kind="var" path="MAVEN_REPO/jboss/jars/activation.jar"/>
-	<classpathentry kind="var" path="MAVEN_REPO/commons-fileupload/jars/commons-fileupload-1.0.jar"/>
-	<classpathentry kind="var" path="MAVEN_REPO/commons-configuration/jars/commons-configuration-1.1.jar"/>
-	<classpathentry kind="var" path="MAVEN_REPO/commons-lang/jars/commons-lang-2.1.jar"/>
-	<classpathentry kind="var" path="MAVEN_REPO/commons-collections/jars/commons-collections-3.1.jar"/>
-	<classpathentry kind="var" path="MAVEN_REPO/dom4j/jars/dom4j-1.6.jar"/>
-	<classpathentry kind="var" path="MAVEN_REPO/jdom/jars/jdom-1.0.jar"/>
-	<classpathentry kind="var" path="MAVEN_REPO/jboss/jars/jboss-ejb3x.jar"/>
-	<classpathentry kind="var" path="MAVEN_REPO/jboss/jars/jboss-ejb3.jar"/>
-	<classpathentry kind="var" path="MAVEN_REPO/portlet-api/jars/portlet-api-1.0.jar"/>
-	<classpathentry kind="var" path="MAVEN_REPO/jboss/jars/jboss-jmx.jar"/>
-	<classpathentry kind="var" path="MAVEN_REPO/jboss/jars/jboss-common.jar"/>
-	<classpathentry kind="var" path="MAVEN_REPO/jboss/jars/portal-common-lib.jar"/>
-	<classpathentry kind="var" path="MAVEN_REPO/jboss/jars/portal-core-lib.jar"/>
-	<classpathentry kind="var" path="MAVEN_REPO/jboss/jars/portal-portlet-lib.jar"/>
-	<classpathentry kind="var" path="MAVEN_REPO/jboss/jars/jbossall-client-3.2.3.jar"/>
-	<classpathentry kind="lib" path="/home/tomek/java/sandbox/portal-extensions/shotoku/shotoku-base/target/shotoku-base.jar"/>
-	<classpathentry kind="var" path="MAVEN_REPO/shotoku/jars/shotoku-aop.jar"/>
-	<classpathentry combineaccessrules="false" kind="src" path="/wiki-common"/>
-	<classpathentry kind="output" path="target/classes"/>
-</classpath>
+  <classpathentry excluding="" kind="src" path="src/java">
+  </classpathentry>
+  <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
+  </classpathentry>
+  <classpathentry kind="var" path="MAVEN_REPO/log4j/jars/log4j-1.2.9.jar">
+  </classpathentry>
+  <classpathentry kind="var" path="MAVEN_REPO/wiki-common/jars/wiki-common.jar">
+  </classpathentry>
+  <classpathentry kind="var" path="MAVEN_REPO/jboss/jars/javax.servlet.jar">
+  </classpathentry>
+  <classpathentry kind="var" path="MAVEN_REPO/jboss/jars/javax.servlet.jsp.jar">
+  </classpathentry>
+  <classpathentry kind="var" path="MAVEN_REPO/junit/jars/junit-3.8.1.jar">
+  </classpathentry>
+  <classpathentry kind="var" path="MAVEN_REPO/jboss/jars/activation.jar">
+  </classpathentry>
+  <classpathentry kind="var" path="MAVEN_REPO/commons-fileupload/jars/commons-fileupload-1.0.jar">
+  </classpathentry>
+  <classpathentry kind="var" path="MAVEN_REPO/commons-configuration/jars/commons-configuration-1.1.jar">
+  </classpathentry>
+  <classpathentry kind="var" path="MAVEN_REPO/commons-lang/jars/commons-lang-2.1.jar">
+  </classpathentry>
+  <classpathentry kind="var" path="MAVEN_REPO/commons-collections/jars/commons-collections-3.1.jar">
+  </classpathentry>
+  <classpathentry kind="var" path="MAVEN_REPO/dom4j/jars/dom4j-1.6.jar">
+  </classpathentry>
+  <classpathentry kind="var" path="MAVEN_REPO/jdom/jars/jdom-1.0.jar">
+  </classpathentry>
+  <classpathentry kind="var" path="MAVEN_REPO/jboss/jars/jboss-ejb3x.jar">
+  </classpathentry>
+  <classpathentry kind="var" path="MAVEN_REPO/jboss/jars/jboss-ejb3.jar">
+  </classpathentry>
+  <classpathentry kind="var" path="MAVEN_REPO/portlet-api/jars/portlet-api-1.0.jar">
+  </classpathentry>
+  <classpathentry kind="var" path="MAVEN_REPO/jboss/jars/jboss-jmx.jar">
+  </classpathentry>
+  <classpathentry kind="var" path="MAVEN_REPO/jboss/jars/jboss-common.jar">
+  </classpathentry>
+  <classpathentry kind="var" path="MAVEN_REPO/jboss/jars/portal-common-lib.jar">
+  </classpathentry>
+  <classpathentry kind="var" path="MAVEN_REPO/jboss/jars/portal-core-lib.jar">
+  </classpathentry>
+  <classpathentry kind="var" path="MAVEN_REPO/jboss/jars/portal-portlet-lib.jar">
+  </classpathentry>
+  <classpathentry kind="var" path="MAVEN_REPO/jboss/jars/jbossall-client-3.2.3.jar">
+  </classpathentry>
+  <classpathentry kind="lib" path="/home/tomek/java/sandbox/portal-extensions/shotoku/shotoku-base/target/shotoku-base.jar">
+  </classpathentry>
+  <classpathentry kind="var" path="MAVEN_REPO/shotoku/jars/shotoku-aop.jar">
+  </classpathentry>
+  <classpathentry kind="output" path="target/classes">
+  </classpathentry>
+</classpath>
\ No newline at end of file

Modified: labs/jbosslabs/trunk/portal-extensions/portal-default/src/web/WEB-INF/default-object.xml
===================================================================
--- labs/jbosslabs/trunk/portal-extensions/portal-default/src/web/WEB-INF/default-object.xml	2007-02-05 21:24:22 UTC (rev 9352)
+++ labs/jbosslabs/trunk/portal-extensions/portal-default/src/web/WEB-INF/default-object.xml	2007-02-05 23:20:55 UTC (rev 9353)
@@ -102,7 +102,7 @@
 
         </portal>
     </deployment>
-
+	
     <deployment>
         <if-exists>overwrite</if-exists>
         <parent-ref>default</parent-ref>
@@ -129,7 +129,61 @@
             </window>
         </page>
     </deployment>
+    
     <deployment>
+      <parent-ref/>
+      <if-exists>keep</if-exists>
+      <context>
+         <context-name>dashboard</context-name>
+         <properties>
+            <!--
+            | Set the layout for the default portal, see also portal-layouts.xml.
+            -->
+            <property>
+               <name>layout.id</name>
+               <value>generic</value>
+            </property>
+            <!--
+            | Set the theme for the default portal, see also portal-themes.xml.
+            -->
+            <property>
+               <name>theme.id</name>
+               <value>renaissance</value>
+            </property>
+            <!--
+            | Set the default render set name (used by the render tag in layouts), see also portal-renderSet.xml
+            -->
+            <property>
+               <name>theme.renderSetId</name>
+               <value>divRenderer</value>
+            </property>
+            <!--
+            | Set the default strategy name (used by the strategy interceptor), see also portal-strategies.xml
+            -->
+            <property>
+               <name>layout.strategyId</name>
+               <value>maximizedRegion</value>
+            </property>
+            <!--
+            | Set the dashboard property
+            -->
+            <property>
+               <name>dashboard</name>
+               <value>true</value>
+            </property>
+         </properties>
+<!--
+         <security-constraint>
+            <policy-permission>
+               <role-name>Authenticated</role-name>
+               <action-name>view</action-name>
+            </policy-permission>
+         </security-constraint>
+-->
+      </context>
+   </deployment>
+   
+    <deployment>
         <if-exists>overwrite</if-exists>
         <parent-ref>default</parent-ref>
         <!--  community page -->




More information about the jboss-svn-commits mailing list