in my company, we're using MS Outlook and Skype. In both applications, I can click on several user to get information about them like the first name, the last name, availability, email adress or the information of WindowsIdentification.Name (i think, this is called the Live ID).
It looks like in the picutrue. I just erased personal information from the picture.
Is there a possibility to request this information of any user by their first and last name?
What I'm searching for is the function:
/*This function exists*/
System.Security.Principal.WindowsIdentity.GetCurrent().Name;
But I don't want to know my own LiveID but the ID from some other user. So, I need something like:
/*This function does not exists*/
string UID = System.Security.Principal.WindowsIdentity.GetByName("Max Mustermann").Name;
Console.WriteLine(UID) /*prints DomainName/UserID*/
Is something like that available in .NET?
You can use the DirectorySeacher class to do this.
For example:
DirectorySearcher searcher1 = new DirectorySearcher(entry);
searcher1.Filter = string.Format("(&(objectCategory=person)(objectClass=user)(givenname={0})(sn={1}))", aName, aSName);
SearchResultCollection results1;
results1 = searcher1.FindAll();
Related
i try to limit the list activity to a specific user but i always get the same results. i've tried users email address and the user id from the user list api function, both are not working.
i found a an open issue here, without an answer: https://code.google.com/p/google-apps-script-issues/issues/detail?can=2&start=0&num=100&q=&colspec=Stars%20Opened%20ID%20Type%20Status%20Summary%20Component%20Owner&groupby=&sort=&id=4974
my code:
ActivitiesResource.ListRequest listRequest = service.Activities.List();
listRequest.Source = "drive.google.com";
listRequest.DriveAncestorId = "root";
listRequest.UserId = "users email or Id";
listRequest.PageSize = 10;
IList<Activity> activities = listRequest.Execute().Activities;
additional info - i'm using a service account to authenticate
thanks
It is currently not possible to filter by user ID. Don't want to get into too many details, but the userId field has a different purpose that was never fully realized. Right now it's effectively ignored.
I'm working on a project where the client wants to restrict some content to only Active Directory users . Is there any way to identify that a SPUser is an AD user short of parsing the username string for the domain (or something along those lines). Something like SPUser.IsADUser would be awesome.
Edit
This seems to work, but I'm not sure if this is reliable enough? For this use case, identifying that a user is a windows user is enough (there are no local system accounts)
SPUser user = SPContext.Current.Web.CurrentUser;
string userName = user.LoginName.Substring(user.LoginName.IndexOf('|') + 1);
SPPrincipalInfo info = SPUtility.ResolveWindowsPrincipal(SPContext.Current.Site.WebApplication, userName, SPPrincipalType.User, false);
if(info != null){
//THIS IS A WINDOWS ACCOUNT
}
In my experience it is much better to use audiences for this purpose. You then can easily trim any web part using "Audience" property. You can read about audiences here. Of course it will only work if you have user profile synchronization configured.
In Google.Apis.Drive.v2.Data.File class it just provides name of the last modifying user. How to obtain full info of the user (like email, user id etc.)?
var service = new DriveService(auth);
Google.Apis.Drive.v2.Data.File file = service.Files.Get("fileid").Fetch();
file.LastModifyingUserName;// = "User Name" //How to get email id of this user?
In an organization there can be more than one person with the same first and last name. It is user id which differentiates. So I need email ID.
E.g Allan Donald => allan1#corp.com
Allan Donald => allan2#corp.com
This is very much possible.
I figured out how to do it in the Java API. It's far from elegant, but it works.
File file; // start with your file
User user = file.getLastModifyingUser();
Permission permission = service.permissions().get(file.getId(), user.getPermissionId()).execute();
String email = permission.getEmailAddress();
You can also use the RevisionList interface to get all the modifying users.
I am writing a small app that integrates with AD and will be listing users and allowing members of the site to edit certain fields of the users. These fields will be, first name, last name, display name and email.
When I run the following code I get an exception that says
The server is unwilling to process the request.
Please note that result is not null and contains the correct active directory user that I want to edit. Also note that result is of type SearchResult. Also note that the user I am using to connect to AD is the Administrative user.
DirectoryEntry entryToUpdate = result.GetDirectoryEntry();
entryToUpdate.Properties["cn"].Value = user.Name;
entryToUpdate.Properties["mail"].Value = user.Email;
entryToUpdate.Properties["sn"].Value = user.Surname;
entryToUpdate.Properties["displayName"].Value = user.DisplayName;
string username = user.Email.Substring(0, user.Email.IndexOf("#"));
entryToUpdate.Properties["sAMAccountName"].Value = username;
entryToUpdate.CommitChanges();
Any Ideas?
I believe
entryToUpdate.Properties["cn"].Value = user.Name;
is your Problem. Use givenName as first Name. "cn" is managed by the System.
Also:
If using Exchange, the Mail attribute is managed by it.
Consider the ramifications of modifing samAccountName. Users may not know how to log in, seperate Systems with pseudo SSO may not recognize them, the Login Name does not match the local Profile Name, etc.
I've been recommended to use System.DirectoryServices.Protocols to be able to support connecting to LDAP servers other than Active Directoy here.
Unfortunately, I have not been able to search the directory properly. I'd like to be able to get a certain attribute for a user (e.g. mail). This is easily done in System.DirectoryServices namespace by using DirectorySearcher class. How can I achieve the same in System.DirectoryServices.Protocols namespace. Here's what I have so far:
var domainParts = domain.Split('.');
string targetOu = string.Format("cn=builtin,dc={0},dc={1}", domainParts[0], domainParts[1]);
string ldapSearchFilter = string.Format("(&(ObjectClass={0})(sAMAccountName={1}))", "person", username);
// establish a connection to the directory
LdapConnection connection = new LdapConnection(
new LdapDirectoryIdentifier(domain),
new NetworkCredential() { UserName = username,
Password = "MyPassword" });
SearchRequest searchRequest = new SearchRequest(
targetOu, ldapSearchFilter, SearchScope.OneLevel, new[] {"mail"});
This code raises exception of type DirectoryOperationException with message The object does not exist.
I suspect there's something wrong with my targetOu and ldapSearchFilter variables.
Thanks.
I suspect the main problem might be: samAccountName is a strictly Windows-only attribute that other LDAP servers won't know about.
So if you're going against a non-Active Directory LDAP, you should use something else for searching - e.g. sn (for surname or last name), givenName (first name), possibly displayName.
Another interesting option might be to use ANR (ambiguous name resolution) searches - see this page on SelfADSI roughly in the middle, where ANR is explained.
With ANR, you would write your query like this:
string ldapSearchFilter =
string.Format("(&(ObjectCategory={0})(anr={1}))", "person", username);
I also changed ObjectClass to ObjectCategory for two reasons:
ObjectCategory is single-valued, e.g. only contains a single value (ObjectClass is multi-valued)
ObjectCategory is typically indexed, and thus searches are typically a lot faster using ObjectCategory
Does this return the results you're looking for?