Hi,
I 'm creating a custom login page to access a site, for that how I can verify the user exists in a user group?
The Portal Development Guide has some example code that will help you do this. Starting in Chapter 14, you'll find details on autheticating users and finding the user groups. On page 267 you'll find a good synopsis of getting attributes of a user and then finding user groups. You can also see information here on how to add business logic to this process (for finding a specific group membership for example).
For example, you can get information about a user through the PortalContext object (in a java class) and use EntityType to get things like group membership. Here is an example class that gets the entity object "currentName" for a user.
public PortalURI execute(PortalContext portalContext) throws ActionException {
HttpServletRequest request = portalContext.getHttpServletRequest();
String name = (String) request.getSession().getAttribute("currentName");
request.setAttribute("currentName", name);
return null;
or in a script as: User user = portalContext.getCurrentUser(); to get the current logged on user.
once you have the user then you need to get the list of entities available to that user:
// get users entities
EntityType userType = currentUser.getEntityType();
// query the type to get the ID of the property
Set propertyIDs = userType.getPropertyIDs();
// get the value of this property
String firstName = (String)currentUser.getProperty("firstname");
// check the value of this property attribute
EntityProperty firstNameProperty = userType.getProperty("firstname");
boolean canSearch = firstNameProperty.isSearchable();
// Then you can use the Group Type to find all the groups for this user or to look for a specific group...
EntityType userGroupType = UserGroupManager.getInstance().getUserGroupEntityType(); try{ Set userGroups = currentUser.getParents(userGroupType, false);
}catch (EntityPersistenceException exception){
// Handle exception.
}
try{
boolean isMember = currentUser.hasParent(groupA, false);
Most of this is from the Dev Guide but I added some practical examples as well (since the dev guide tends to be a bit pedantic).
Hope this helps.
here's the link to the Portal Development Guide: http://knowledge.opentext.com/knowledge/cs.dll/overview/19322335
The JavaDocs show that UserGroup implements the interfaceParentEntity so no conversion should be necessary.
---Travis
com.epicentric.user Class UserGroup
java.lang.Object
|
+--com.epicentric.entity.implementations.generic.EntityWrapper
+--com.epicentric.entity.implementations.generic.ParentEntityWrapper
+--com.epicentric.entity.implementations.generic.ParentAndChildEntityWrapper
+--com.epicentric.user.UserGroup
All Implemented Interfaces:
com.epicentric.authorization.Permissionable,com.epicentric.authorization.Principal, ChildEntity,Entity,ParentEntity,com.epicentric.repository.RepositoryElement,com.epicentric.repository.ShareableRepositoryElement, UniquelyIdentifiable
From: eLink Entry:OpenText Portal Forum [mailto:vignetteportal@elinkkc.opentext.com] Sent: Wednesday, February 29, 2012 10:04 AMTo: eLink RecipientSubject: How to verify a user in a user group?
How to verify a user in a user group?
Posted by saravanan.arumugam@mbusa.com (Arumugam, Saravanan) On 02-29-2012 10:01
Thanks for that. I'm also following the development guide, but I need more details about these classes, like how to extract the user and usergroup details. Is there any documentation available for this?
For example, to check the user in a group you have mentioned
but the groupA has to be of type ParentEntity so how do I can convert a given usergroup to ParentEntity type? does casting will help?
Here is the sample code I'm following to verify the user with his logon and the user availability in a particular group. After getting the parents of the user how can I check the required group name is available in the Set,
UserManager userManager = UserManager.getInstance();
! User user = userManager.getUser(User.LOGON_PROPERTY_ID,"TESTUSER");
EntityType userGroupEntityType = UserGroupManager.getInstance().getUserGroupEntityType();
Set parents = user.getParents(userGroupEntityType, false);
}catch (EntityNotFoundException exception){
System.out.println(exception);
// Handle database error.
}catch(Exception e){
System.out.println(e);
thanks in advance.
[To post a comment, use the normal reply function]
Topic:
Forum:
OpenText Portal Forum
Content Server:
Knowledge Center