get user group description and name in liferay - java

I want to get the user group description as well the name of logged-in user in portlet.
I am able to get the logged-in user object using:
ThemeDisplay td = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
User user = td.getUser();
Please help me out with how to get the logged-in user's group.
These user groups are coming from ldap and mapped in liferay DB UserGroup.
Thanks in advance.

As you have the user object, you can get full name of user by using
user.getFullName()
for getting the user group description, call the following method, which will give you the list of Groups. which belongs to user.
List <Group> grpList = GroupLocalServiceUtil.getUserGroups(userId);
Iterate the list to get the groupId's. Pass group Id to following method.
Group grp = GroupLocalServiceUtil.getGroup(groupId)
You can get group Description using
String grpDisc = grp.getDescription();
Hope this is what you are looking for.

Related

VMM how to find or fetch VMM entity attribute mapping / attribute names

Starting point:
I have a WebSphere with federated security (there is an Active Directory behind it).
I am trying to fetch a VMM user uid by his/her email address, but I a don't know how it's VMM (schema) attributes are mapped to the AD (schema) attributes of the underlying Active Directory entity (person, organizationalPerson objectClass, mail attribute.
(By describing it in a different way: If one have a look at the WAS console, in the "Users and Groups" -> "Manage Users" there is a table where there is an E-Mail column, so it is somehow mapped.
But, by clicking on the ( "Global Security" -> "(federated repositories) configure button" -> (there is a table, you can select the)) LDAP1 row, and checking the table in "Federated repositories property names to LDAP attributes mapping", I don't find that the 'E-Mail' column how has been mapped to the AD attribute. Maybe there is an implicit mapping?)
So, the starting question is this:
How to find this on the WAS console? Or, maybe via wsadmin (scripts)?
So, because of this, I tried to move forward and now I would try to find it using the VMM API, but I don't find in the official documentation the answer to the second question:
Is it possible to fetch somehow the assigned / available attributes of an WebSphere VMM entity (Virtual member manager)?
There is a lot of examples about how to fetch the attributes when you know their name, but there is nothing about this...
Yes, I know that is is a bit XY problem, but please guide me a bit.
Many thanks in advance.
To provide some code sample too, I am trying to fetch the user's uid by using the following code:
public String testFetch(String email) throws Exception
{
String returnAttr = "uid";
// here in the search expression what should I wrire instead of the 'mail'?
String vmmSearchExpr = String.format("#xsi:type='PersonAccount' and mail='%s'", email);
DataObject root = SDOHelper.createRootDataObject();
DataObject searchCtrl = SDOHelper.createControlDataObject(root, null, SchemaConstants.DO_SEARCH_CONTROL);
searchCtrl.setString(SchemaConstants.PROP_SEARCH_EXPRESSION, vmmSearchExpr);
#SuppressWarnings("unchecked")
List<String> props = searchCtrl.getList(SchemaConstants.PROP_PROPERTIES);
props.add(returnAttr);
Service service = new LocalServiceProvider(null);
DataObject searchRoot = service.search(root);
String result = "";
List<?> entities = searchRoot.getList(SchemaConstants.DO_ENTITIES);
if (entities.size() > 1) throw new RuntimeException("multiple users for an identity:" + vmmSearchExpr);
if (entities.size() > 0)
{
DataObject objdo = (DataObject) entities.get(0);
result = objdo.getString(returnAttr);
}else{
log("Got empty list There is no result.");
}
return result;
}
A possible solution is to add a new federal repository supported property (Name: mail, Property name: mail, Entity types: PersonAccount):
After a WAS restart I was able to use the search expression
#xsi:type='PersonAccount' and mail='<email address>'
and the code above to fetch the corresponding uid to the given email address.
It seems there is some info in the c:\IBM\WebSphere\AppServer\etc\wim\setup\wimdbproperties.xml, as if the "ibm-primaryEmail" would be the property that contains the email address, albeit I was not able to find my uid when I specified this instead of the "mail" attribute name.

How to search users inside group in Keycloak?

Using Keycloak 11.0.3.
I trying to search users inside group using Keycloak API:
List<UserRepresentation> users = realmResource.users().search(username, firstname, lastname, email,
0, 100);
But when I try to get groups of found users I get null even if user have group:
List<String> groups = users.get(0).getGroups(); //It's null
So how to search users inside group?
To get the groups that a user belongs to try with the following:
realm.users().get(userId).groups();
Use the userID instead.
To get the users of a given group do the following:
realm.groups().group(groupId).members();

How can I change this filter from a specific AD Group to All AD Groups in the Organization?

This filterString gets all AD users from a specific AD group, I need to change this to get ALL users from ALL groups in my organization. I have read through dozens of similar questions and changed this string around several times and cannot find the solution.
String filterString = "(&(objectCategory=user)(memberOf=cn=" + this.ldapUserSearch + ",ou=Groups,OU=Organization,dc=organizationsoftware,dc=com))";
You can try the following filter, which includes an attribute presence clause:
(&(objectCategory=user)(memberOf=*))
This will return every user whose memberOf attribute is set to any value. This should have the effect of retrieving all users from all groups.

How to insert user current user details to another node in Firebase?

I am inserting a data in my Request Node in Firebase database in Android using this,
public void submitRequest(View v) {
Request myUserInsertObj = "Pending";
rootReference.child("Request").child("Pending").child(firebaseuser.getUid()).setValue
(myUserInsertObj);
}
This is my Request Class.
Public class Request{
public String request_status;
public Request(String request_status){
this.request_status = request_status;
}
Request()
}
I found in firebase documentation that I can use firebaseuser.getDisplayName to get the current logged in user's name. But where will the .getDisplayName get the user's name since I created my own login form and user registration in my app.
Question 2:
If I do this, is this possible? Because I want to put a name in requesting guest node so that when I retrieve it in my HTML web admin panel the data will be easier to read.
rootReference.child("Request")
.child("Pending")
.child(firebaseuser.getUid())
.setValue(myUserInsertObj + firebaseuser.getDisplayName);
If so what should I add in my Request Class?
Question 3.
How do I add timestamp I know timestamp is very important in data insertion on every system.
I found in firebase documentation that I can use firebaseuser.getDisplayName to get the current logged in user's name.
Yes, that correct. Calling getDisplayName() on a FirebaseUser object:
Returns the main display name of this user from the Firebase project's user database.
Regarding the second part of your question:
But where will the .getDisplayName get the user's name since I created my own log in form and user registration in my app.
As explained above, getDisplayName() is getting you the name that is coming from the authentication process. If you want to get the user name from your custom user object then you should first get the user object from the database and use it where it is needed.
Because I want to put a name in the request node so that when I retrieve it in my HTML web admin panel the data will be easier to read.
If you want to add the name in your node, you should pass the display name to the child() method and not to the setValue(). Your code should look like this:
rootReference.child("Request")
.child("Pending")
.child(firebaseuser.getUid() + "_" + firebaseuser.getDisplayName())
.setValue(myUserInsertObj);
This code will generate a child that might look like this:
Firebase-root
|
--- Request
|
--- Pending
|
--- SxbVg0...uobvk1_Theodore
|
--- //user details
DatabaseReference class has 4 overloaded setValue() methods but none of this methods allow you to pass an object along with a String as arguments.
Question 3. How do I add timestamp I know timestamp is very important in data insertion on every system.
This is how you add and get the timestamp that you were talking about.

How to add user login check in GenericDao.java in Ofbiz

I am Trying to achieve single DB and multiple organization (not Multi tenancy) in ofbiz, how do i get user login Id till GenericDAO and append it to the query.
Please Suggest if you have any other ideas except multi tenancy!
Thanks
EDIT:
if (!conditions.isEmpty()) {
whereString.append(prefix);
whereString.append(EntityCondition.makeCondition(conditions, EntityOperator.AND).makeWhereString(modelEntity, whereEntityConditionParams, this.datasource));
}
System.out.println("************ whereString ************ "+whereString+" ---- ");
return whereString;
In line number 841 in my ofbiz v13.07 GenericDAO.java, i can get to know the place where query string is getting created. i want to access the session here to get the company Id and so i append it to the where clause. to get relevant data.

Categories

Resources