How add dynamic user attribute value in keycloak with saml - saml-2.0

ENVIRONMENT:
Keycloack 3.2
Saml2.0
SITUATION:
I need to add user attributes value dynamically.
TASK:
I need name attribute for my user, which can fill dynamically from First Name and Last Name fields, which as I found in keycloack can be fullName property.
NOTE: Instead of fullName it can be firstName + lastName field in my case as well.
ACTION:
I added user property with name fullName under my Clients -> myCLient -> Mappers,
then added under my user Users -> myUser -> Attributes, attribute key name and attribute value ${fullName}.
RESULT:
As a result I got ${fullName} as a value instead of dynamic value from my predefined user property.
QUESTIONS:
Is it possible to do this kind of things what I need ?
If it's possible then, what are wrong in my steps here?

For users like me who looking for a solution of this problem with newest version of Keycloak, in keycloak 18.0 you can create a Mapper with the type Javascript Mapper with this code: user.getFirstName() + ' ' + user.getLastName().

As a solution, I found that under client in keylock we have builtin user properties.
Example X500 givenName, X500 surname can be added and can get in BE side as a part of SAML assertion attributes.

There is another solution if the user federation are LDAP or Active Directory
On the user federation you can use the full-name-ldap-mapper.
By default it uses cn, but you can change that.
Next in your client you would add a saml mapper.
{
"name": "fullName",
"protocol": "saml",
"protocolMapper": "saml-user-attribute-mapper",
"consentRequired": false,
"config": {
"attribute.nameformat": "Unspecified",
"user.attribute": "full name",
"friendly.name": "Full name",
"attribute.name": "displayName"
}
}
Remember the attribute.name is the property that the SP would use.
Also the nameformat has to be discussed with the SP.

Related

pyvmomi to retrieve custom attribute "owner" for all VMs

I'm trying (and failing) to figure out how to use pyvmomi to retrieve a custom attribute named "owner" for all VMs in a vCenter.
I use code like this to retrieve VM name, power state, and uuid:
summary = vm.summary
print(summary.config.name, " ", summary.runtime.powerState, " summary.config.uuid)
But, I cannot figure out how to retrieve the custom attribute named "owner" for all VMs in a vCenter.
Thanks in advance
CustomAttribute is stored separately in customValue field. Each customValue have its name and key, the "Owner" in your case is the name, you need to get its key first.
here is a sample:
conn=connect.SmartConnect(host='***', user='***', pwd='***', port=443)
content = conn.RetrieveContent()
cfm = content.customFieldsManager
required_field = ["Owner"]
my_customField = {}
for my_field in cfm.field:
if my_field.name in required_field:
my_customField[my_field.key]=my_field.name
The key and its display name is in my_customField dict, you can get customValue by it
for opts in vm.customValue:
if opts.key in my_customField:
output[my_customField[opts.key]]=opts.value
and in output dict you have what you want.

How to find the various fields of User object in DNN 7.2

I have a new user registration form. After creating the user, I want to provide various details like username, email, company name etc in the new user registration email to the administrator. After searching through various DNN community threads, I found out that these are configured in the GlobalResources.resx in App_GlobalResources folder. I can see two fields DisplayName, Email already being used. How can I get other fields like First Name, Last Name, City of the User Object?
<data name="EMAIL_USER_REGISTRATION_ADMINISTRATOR_BODY.Text"
xml:space="preserve">
<value>
Date: [Date:Current]
Display Name: [User:DisplayName]
Email: [User:Email]
</value>
</data>
You have to use a feature that is called Tokens. Read more here: https://www.dnnsoftware.com/wiki/tokens.
The first name and the last name are members of the user object, therefore you have to use [User:FirstName] and [User:LastName]. Other stuff (as the city) can be found in the Membership object, therefore it's [Membership:City].
I strongly recommend to create a resource file for your portal instead of changing the text in the GlobalResources.resx - this will be overwritten with the next update.

LDAP Filter, search contains (Active Directory)

I want find users from active directory where Objectsid = "x-xxx-xxxxxx-xxxxxxx-11060"
My search filter is :
(&(objectClass=user)(objectCategory=person)(Objectsid=*11060))
but no users are returned.
What is problem with my filter?
When I completely write Objectsid the user information return.
Even when change code to
(&(objectClass=user)(objectCategory=person)(Objectsid=*))
that should return all users, but no user are returned
LDAP is case-sensitive, and the proper spelling of that attribute you're trying to use is objectSid (not Objectsid) - so try this filter:
(&(objectClass=user)(objectCategory=person)(objectSid=*))

What is the variable that refers to the number of likes on sharepoint 2013?

I want to write a request on the search result request webpart. My request should enables me to retrieve all documents that have the biggest number of likes. There is no variable for the number of likes proposed on the drop list while writing a request , that why I decided to set a refinableInt00 variable and give it the value : LikesCount but it doesn't work? it means that LikesCount doesn't exist as a variable on sharepoint so what is the variable on sharepoint that would enable me to have the number of likes?
You can get the number of likes using the listitem property "Number of Likes"
This is a code from a Sample console application
using (SPSite site=new SPSite("your site URL"))
{
using (SPWeb web=site.OpenWeb())
{
SPList list = web.Lists["Your List Name"];
foreach (SPListItem item in list.Items)
{
//Print the number of likes
Console.WriteLine(item["Number of Likes"].ToString());
}
}
}
I know this is old but I had the same question. The problem is the LikesCount property does not default to Sortable. To fix this:
-Open up Central Administration
-Go to Search Service Application
-Click on Search Schema
-Locate the "LikesCount" property and click edit
-Scroll down to Sortable and change to Yes
-Run a full crawl on your content source
Ratings for list must be enable.
List -> List settings -> Rating settings ->
Allow items in this list to be rated?
yes ? no
and
Which voting/rating experience you would like to enable for this list?
Likes ? Star Ratings
After that you can access likes by "Number of Likes" field name "LikesCount".
"Number of Ratings" field name "RatingCount"

setWhatId in salesforce using email template

i have to send an email to a user in salesforce using email template.this template contain merge field type of custom object.
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setTargetObjectId(user.get(0).id);
mail.setTargetObjectId(user.get(0).Id)
mail.setTemplateId(specifier.get(0).Template_id__c);
mail.saveAsActivity = false;
mail.setWhatId(custom_object.Id);
i read in documentation
If you specify a contact for the targetObjectId field, you can specify a whatId as well. This helps to further ensure that merge fields in the template contain the correct data. The value must be one of the following types:
Account
Asset
Campaign
Case
Contract
Opportunity
Order
Product
Solution
Custom
but if we are sending email to a user not to contact then how to assign a custom object for merge field type in custom objects as in the above code
This is a GIGANTIC whole in their email methods, and one that has annoyed me for years. Particularly given workflow email alerts seem to have no problem sending an email template for a user. Alas, you can't use setWhatId() if your target is a user. But you can vote for them to add that functionality,
I've worked around this I typically create a contact with the same name and email as the user, use it to send the email, and then delete it. This works well, although dealing with validation rules on the contact object can be a challenge. See their dev boards for a full discussion.
You can get the template and replace the merge fields as follows:
EmailTemplate template = [SELECT Id, Subject, HtmlValue, Body FROM EmailTemplate WHERE Name = 'Case Update'];
Case modifiedCase = [SELECT Account.Id, Account.Name, Owner.FirstName, Owner.LastName, CaseNumber, Subject, LastModifiedBy.FirstName, LastModifiedBy.LastName from Case where Id=:modifiedCaseId];
String subject = template.Subject;
subject = subject.replace('{!Case.Account}', modifiedCase.Account.Name);
subject = subject.replace('{!Case.CaseNumber}', modifiedCase.CaseNumber);
subject = subject.replace('{!Case.Subject}', modifiedCase.Subject);
String htmlBody = template.HtmlValue;
htmlBody = htmlBody.replace('{!Case.Account}', modifiedCase.Account.Name);
htmlBody = htmlBody.replace('{!Case.OwnerFullName}', ownerFullName);
...
Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
email.setSubject(subject);
email.setHtmlBody(htmlBody);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});
As far as no new fields are added in the template this will work fine. The admin can mess with the format of the email without the need for code changes.
Not sure this is possible to do, but it depends on the relationship between your custom object and your users that will be receiving the merged emails. Do you have a 1-to-1 relationship between User and CustomObject? If so, perhaps adding a reference to the single custom object instance that each user object references and then adding custom formula fields on your user object with CustomObject__r.CustomField__c would do the trick.
In a custom formula field on your User object:
TEXT(CustomObject__r.CustomField__c)
Then your template could be changed into a User template and the merge fields would be the formula fields that actually pointed to your custom object instance. But if you have some other relationship like 1-to-many or many-to-many between User and CustomObject__c, I think you're out of luck.

Resources