[jboss-user] [JBoss Portal] - How to get user role in custom login ?

liutaiyo do-not-reply at jboss.com
Thu Mar 29 23:57:38 EDT 2007


I configured the portal login using DatabaseServerLoginModule

And I want to get the user role at 
jboss-portal.sar\portal-core.war\WEB-INF\jsp\loginindex.jsp 

Below is the code adding to the index.jsp to retrieve the user role.

But i can't get the user role which only create in our custom database. 
It only work on default portal user (user / admin)

How can i get the role name of the login user?

<%


	try{
	Context initContext = new InitialContext();
	RoleModule role = (RoleModule)initContext.lookup("java:/portal/RoleModule");
	UserModule user = (UserModule)initContext.lookup("java:/portal/UserModule");
	String username = request.getRemoteUser();
	if(username != null){
	if(role != null){
		
%>
		HAS ROLE <%= username  %> ROLE COUNT = <%=role.getRolesCount() %>
<%
		
	
		User u = null;
		if(user != null){
			//u = user.findUserByUserName(username);


		}else{

%>
			NO USER OBJECT		

<%
			u = new UserImpl(username);
		}
		if(u != null){
			Set s = role.getRoles(u);
			Iterator i = s.iterator();
			while(i.hasNext()){
				Role r = (Role)i.next();
%>
				AA <%= r.getName() %>
<%

	
			}
		}
%>
		HAS ROLE
<%
	}else{
%>
		NO ROLE
<%
	}
	}
	}catch(Exception e){
		e.printStackTrace();
%>
		System Exception

<%		
	}
%>

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4033001#4033001

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4033001



More information about the jboss-user mailing list