JNDI Help regarding group group membership in Active Directory - jndi

I am trying to add a group to a different group in Active Directory using a JNDI program. On doing so, I get the following error
[LDAP: error code 53 - 00002142:
SvcErr: DSID-031A0FC0, problem 5003
(WILL_NOT_PERFORM), data 0
The code snippet I am using is below
Setting Group Attributes
Attributes attrs = new BasicAttributes(true);
attrs.put("objectClass","group")
attrs.put("description","A test group");
Adding group to different group
try{
ModificationItem member[] = new ModificationItem[1];
member[0]= new ModificationItem(DirContext.ADD_ATTRIBUTE, new BasicAttribute("member", groupDN));
ctx.modifyAttributes(grpDN,member);
System.out.println("Added group to group: " + grpDN);
}catch (NamingException e) {
System.err.println("Problem adding group to group: " + e);
}
I am able to add User to groups using almost the same type of code (below).
Setting User Attributes
// Create attributes to be associated with the new user
Attributes attrs = new BasicAttributes(true);
attrs.put("objectClass","user");
attrs.put("samAccountName","Perry");
attrs.put("cn","Perry");
attrs.put("givenName","Perry");
attrs.put("sn","Perry");
attrs.put("displayName","Perry Peterson");
attrs.put("description","Research Engineer");
int UF_ACCOUNTDISABLE = 0x0002;
int UF_PASSWD_NOTREQD = 0x0020;
int UF_PASSWD_CANT_CHANGE = 0x0040;
int UF_NORMAL_ACCOUNT = 0x0200;
int UF_DONT_EXPIRE_PASSWD = 0x10000;
int UF_PASSWORD_EXPIRED = 0x800000;
attrs.put("userAccountControl",Integer.toString(UF_NORMAL_ACCOUNT + UF_PASSWD_NOTREQD + UF_PASSWORD_EXPIRED+ UF_ACCOUNTDISABLE));
Adding User to Groups
try{
ModificationItem member[] = new ModificationItem[1];
member[0]= new ModificationItem(DirContext.ADD_ATTRIBUTE, new BasicAttribute("member", userDN));
ctx.modifyAttributes(groupDN,member);
System.out.println("Added user to group: " + groupName);
}catch (NamingException e){
System.err.println("Problem adding user to group: " + e);
}
Does any one has idea about what I am doing wrong here or is there any attribute that has to be set for groups also as in the case of Users. I have a SSL connection between my JNDI client and the server and I am able to successfully reset User password (that will not be possible if SSL is not there)
I suspect this is happening because the group I have created earlier are not created properly
Regards
Perry

This is happening as the Groups are created as Security Groups by default and it is not possible to add Groups to Groups (in case of Security Groups)
If you want to have nested groups, create groups as universal distribution and then only you will be able to add groups to groups
This behavior is for Active Directory. I am not aware of Other directories.

Related

How fetch image from database using Stream Classic?

I successful Adding image in SQL database using Stream class in that code
Public CN As New ADODB.Connection
Public Emp As New ADODB.Recordset
Public ST As New ADODB.Stream
Emp.Open("Employees", CN, ADODB.CursorTypeEnum.adOpenDynamic, ADODB.LockTypeEnum.adLockOptimistic)
Emp.AddNew()
ST.Open()
ST.Type = ADODB.StreamTypeEnum.adTypeBinary
ST.LoadFromFile(OpenFileDialog1.FileName)
Emp(19).Value = ST.Read
Emp.Update()
ST.Close()
Emp.Close()
this operation is successful but when I retrieve the database using this Code:
Emp.Open("Select * From Employees Where UserName = '" + TXTSearch.Text + "'", CN)
ST.Open()
ST.Type = ADODB.StreamTypeEnum.adTypeBinary
ST.Write(Emp.Fields(19).Value)
ST.SaveToFile("\temp", ADODB.SaveOptionsEnum.adSaveCreateOverWrite)
PICEmployee.Image = Image.FromFile("\temp")
ST.Close()
Emp.Close()
I have a button to show the database grid and it confirm the picture is loaded
but when I tried to fetch the data it stopped in that line
ST.SaveToFile("\temp", ADODB.SaveOptionsEnum.adSaveCreateOverWrite)
says Failed to Write I changed the Path got same error, I open the VB as Administrator got same error.
Tip: I didn't send All my Codes in case if something missing but everything about Stream is here
I like to have simple solution I'm still beginner and Need all Help you can give to me, Thanks

Can't preserve document core metadata (Created By, Modified By) when I import documents to SharePoint Document Library

I'm currently building a tool to migrate from a document management system to use SharePoint Online. The main challenge I'm facing is to preserve the details of document authors and creating time. I have checked bunch of of code online but I didn't get success with any of them.
Here are the approaches I used
SharePoint Rest API
Microsoft Graph API
CSOM (using console application)
Here is the code I have so far in CSOM but I'm still not able to update the Author field
li["Title"] = "Update from CSOM";
li["Created"] = DateTime.Now.AddYears(-5);
li["Author"] = author.Id;
li.UpdateOverwriteVersion();
clientContext.ExecuteQuery();
Any idea for how to do this, or if there is any other approach to achieve my goal?
The code works when I did test in my environment.
using (ClientContext context = new ClientContext("https://xxx.sharepoint.com/sites/lee"))
{
string s = "password";
SecureString passWord = new SecureString();
foreach (var c in s)
passWord.AppendChar(c);
context.Credentials = new SharePointOnlineCredentials("admin#xxx.onmicrosoft.com", passWord);
var author = context.Web.EnsureUser("Lee#xxx.onmicrosoft.com");
context.Load(author);
context.ExecuteQuery();
var _List = context.Web.Lists.GetByTitle("List1");
var li = _List.GetItemById(1);
li["Title"] = "Update from CSOM";
li["Created"] = DateTime.Now.AddYears(-5);
li["Author"] = author.Id;
li.UpdateOverwriteVersion();
context.ExecuteQuery();
}
You will need to update the Author and Editor fields at the same time in order to update the CreatedBy field. If you wish to update additional fields at the same time you can. Using SystemUpdate() does not update the Modified date whereas Update() does update the Modified date. See abbreviated sample below.
FieldUserValue userValue = new FieldUserValue();
User newUser = cc.Web.EnsureUser("newAuthor#xxx.onmicrosoft.com");
cc.Load(newUser);
cc.ExecuteQuery();
userValue.LookupId = newUser.Id;
item["Author"] = userValue;
item["Editor"] = userValue;
item.SystemUpdate();
cc.ExecuteQuery();

How to populate autocopmlete box with Active Directory emails?

I'm looking for the way to get list of the emails and groups of emails from the active directory. The list will be used to populate autocomplete textbox, the same as in Outlook.
Have any of you done something like that in the past using Asp.Net MVC?
I made this in a project some time ago and here are few steps I think you need to take:
Create a directory entry for your domain
Create a directory searcher and initialize it with a filter
Create a search collection searching with previous filter
Iterate your search collection
Get your properties for current iteration
Get your email from property collection
Code example:
DirectoryEntry dir = new DirectoryEntry("LDAP://" + YourDomain, LoginUsername, LoginPassword);
DirectorySearcher search = new DirectorySearcher(dir);
search.Filter = "(&(objectClass=user)(objectCategory=person))";
SearchResultCollection searchResultCollection = search.FindAll();
if (searchResultCollection != null)
{
for (int i = 0; i < searchResultCollection.Count; i++)
{
SearchResult crt= searchResultCollection[i];
PropertyCollection properties= crt.GetDirectoryEntry().Properties;
// get email from properties["email"].Value
}
}
Some useful links: first , second , third

Creating Remarketing list with tracking code already on website

I am trying to use the Remarketing feature for the first time. I have got the Remarketing code from Adwords and placed it on the website.
Looking through the examples; i have garnered the below flow.
With #2 i can associate one of my Userlist with a predefined Adgroup to be shown during Remarketing. My question is how do i link the tracker ID that i have received (looks like var google_conversion_id = 9925XXXXX) with the code below? where is this linking done? UserListConversionTypes and BasicUserList both have ID's; am i supposed to set any of those or this is done automatically?
Any pointers/help will be appreciated.
Please also let me know if you fine any issue with the code below.
set up remarketing using the AdWords API in two steps:
Create a remarketing list.
Create a CriterionUserList to tie your list to an AdGroup.
1.Create a remarketing list
Creating a remarketing list involves the creation of two separate entities: the RemarketingList itself and its associated UserListConversionTypes also known as remarketing tags.
The following code shows how to create a remarketing list.
AdWordsServices adWordsServices, AdWordsSession session) throws Exception {
// Get the UserListService.
AdwordsUserListServiceInterface userListService =
adWordsServices.get(session, AdwordsUserListServiceInterface.class);
// Get the ConversionTrackerService.
ConversionTrackerServiceInterface conversionTrackerService =
adWordsServices.get(session, ConversionTrackerServiceInterface.class);
UserListConversionType conversionType = new UserListConversionType();
conversionType.setName("Mars cruise customers #" + System.currentTimeMillis());
// Create remarketing user list.
RemarketingUserList userList = new RemarketingUserList();
userList.setName("Mars cruise customers #" + System.currentTimeMillis());
userList.setDescription("A list of mars cruise customers in the last year");
userList.setMembershipLifeSpan(365L);
userList.setConversionTypes(new UserListConversionType[] {conversionType});
// Create operations.
UserListOperation operation = new UserListOperation();
operation.setOperand(userList);
operation.setOperator(Operator.ADD);
UserListOperation[] operations = new UserListOperation[] {operation};
// Add user list.
userList = userListService.mutate(operations).getValue()[0];
2.Tie a remarketing list to an AdGroup
A new type of criteria object called CriterionUserList is now part of v201008. Through this type of criteria you are able to tie a UserList to an AdGroup. As with other types of
criteria, this type is also managed through the AdGroupCriterionService. The following code shows you how to create a CriterionUserList and tie it to an existing AdGroup.
// Create user list criterion.
CriterionUserList userListCriterion = new CriterionUserList();
userListCriterion.setUserListId(userListId);
// Create biddable ad group criterion.
BiddableAdGroupCriterion biddableCriterion = new BiddableAdGroupCriterion();
biddableCriterion.setAdGroupId(adGroupId);
biddableCriterion.setCriterion(userListCriterion);
// Create operation.
AdGroupCriterionOperation operation = new AdGroupCriterionOperation();
operation.setOperand(biddableCriterion);
operation.setOperator(Operator.ADD);
AdGroupCriterionOperation[] operations = new AdGroupCriterionOperation[] {operation};
// Add keywords.
AdGroupCriterionReturnValue result = adGroupCriterionService.mutate(operations);
Thanks,
-Devraj
Those two examples from Google pretty much cover how it's set up
The linking is done behind the scenes by Google - they match the ID in YOUR remarketing tag (which is usually specific to one AdWords account) with your remarketing lists (which are again at account level).
You can have many remarketing lists with varying criteria (visited certain URLs on your site, converted, etc. & combinations thereof) and link one of those lists to your campaign or adgroup.
I'd maybe suggest doing this through the AdWords web user interface first time so you understand the process you are automating with the API
You can get all existing conversion trackers as below.
ConversionTracker theConversionTracker = null;
Selector conversionTrackerSelector = new Selector();
conversionTrackerSelector.fields = new string[] { "Id", "Name" };
ConversionTrackerPage conversionTrackerPage = new ConversionTrackerPage();
try
{
ConversionTrackerService conversionTrackerService = (ConversionTrackerService)adWordsUser.GetService(AdWordsService.v201502.ConversionTrackerService);
conversionTrackerPage = conversionTrackerService.get(conversionTrackerSelector);
if (conversionTrackerPage != null && conversionTrackerPage.entries != null && conversionTrackerPage.entries.Length > 0)
{
//iterate over conversionTrackerPage.entries and write down the Id of the convertion tracker you need
}
}
catch (Exception ex)
{
}
Then you can use the Id when creating the conversion type
UserListConversionType conversionType = new UserListConversionType();
conversionType.name = "My conversion type name";
conversionType.id = 19XXXXXXXXL; // The Id you wrote down.

Wix: Save values from ListBox to config file

I have an installer with ListBox and Add/Remove buttons on one of dialogs.
Items to ListBox adds and removes thru my CAs.
Microsoft.Deployment.WindowsInstaller.View listBoxView = session.Database.OpenView("select * from ListBox where Property = '" + listBoxProperty + "'");
listBoxView.Execute(null);
int count = 0;
while (listBoxView.Fetch() != null)
count++;
Record newListBoxRecord = new Record(4);
newListBoxRecord[1] = listBoxProperty;
newListBoxRecord[2] = ++count;
newListBoxRecord[3] = listItemValue;
newListBoxRecord[4] = listItemValue;
ICollection<ValidationErrorInfo> errors = listBoxView.ValidateNew(newListBoxRecord);
if (errors == null)
listBoxView.Modify(ViewModifyMode.InsertTemporary, newListBoxRecord);
The items adds and removes successfully, but later I need to store them in application config file. Deffered action doesn't have access to Installer Database, so I used Immediate action after InstallFinalize. But when I read ListBox table it is empty. I supose it happens because of InsertTemporary modify mode. Insert mode gives me "Function failed during execution. Database: Table(s) Update failed." error.
When you leave this wizard page, save the list to a property, with a separator character.
Deferred actions have access to a special property CustomActionData, so that you can write them to config file during install phase.
Using immediate action after InstallFinalize has a downside that you can't write to protected system areas, like Program Files. Only deferred actions can be run elevated.

Resources