DirectoryServicesCOMException when clear AD Property (CountryCode) - active-directory

I try clear COUNTRYCODE property for ActiveDirectory using NET (DirectoryEntry, PrincipalContext)
public const String COUNTRYCODE = "countryCode";
if (dEntry.Properties.Contains(property))
{
dEntry.Properties[property].Clear();
dEntry.CommitChanges();
dEntry.Close();
return;
}
The error:
System.DirectoryServices.DirectoryServicesCOMException
ExtendedError 8311
ExtendedMessage: 00002077: SvcErr: DSID-031903C9, problem 5003 (WILL_NOT_PERFORM), data 0
I try:
dEntry.Invoke("Remove", new object[] { property });
or
dEntry.Invoke("remove", new object[] { property });
I get the error:
System.Runtime.InteropServices.COMException: Nombre desconocido.
(0x80020006 (DISP_E_UNKNOWNNAME))

When you see WILL_NOT_PERFORM, it means you are trying to do something that is not allowed.
You cannot clear the countryCode attribute. It must have a value. You can set it to 0 if you'd like.

Related

How to SaveChanges in SQL Server?

I'm trying to add a controller for the ApplicationUser.cs so that when a admin is logged in, they have the ability to view, edit, delete any records from the dbo.AspNetUsers table however I think I'm doing it wrong. This run with Error "NullReferenceException: Object reference not set to an instance of an object."Any idea?
AdminController:
public AdminController (ApplicationDbContext application)
{
_application = application;
[HttpGet]
public IActionResult ActiveUser() { return View();}
[HttpPost]
public async Task<ActionResult> ActiveUser(ApplicationUser Model)
{
var active = await _application.Users.FindAsync(Model.Email);
Model.IsActive = true;
active.IsActive = (Model.IsActive==true);
await _application.SaveChangesAsync();
return View();
}
View : ` #model ApplicationUser
<input asp-for="IsActive" class="form-control" />
<span asp-validation-for="IsActive" class="text-danger"></span>
</div>
<button type="submit" class="btn btn-success">ok</button>`
You are actually never setting the IsActive on the user object. Note there is a difference between '=' and '=='.
Try this code:
ApplicationUser active = await _application.Users.FindAsync(Model.Email);
active.IsActive = true;
_application.Update(active);
await _application.SaveChangesAsync();
The error message indicates you are trying to access properties from a null reference. Based on the code provided, there are two probable causes:
The "await _application.Users.FindAsync(Model.Email);" is not finding the user and returning null, hence, when you try to do "active.IsActive = (Model.IsActive==true);" you get the exception.
The "Model" variable is not getting an instance and you are getting a null reference exception. You need to verify you are sending the payload in the "POST" and, also, decorate the "Model" parameter with "[FromBody]" attribute. See below:
[HttpPost]
public async Task<ActionResult> ActiveUser([FromBody]ApplicationUser Model)
{
// Always check the parameters....
if (Model == null)
{
return View();
}
var active = await _application.Users.FindAsync(Model.Email);
// Always verify if found...
if (active == null)
{
Response.StatusCode=404;
return View();
}
active.IsActive = (Model.IsActive==true);
await _application.SaveChangesAsync();
return View();
}
You need to assign value for Model.IsActive:
if (active.IsActive == false)
{
Model.IsActive = (active.IsActive == true);
}
_application.Update(active);
await _application.SaveChangesAsync();
return View();
Your code seems correct. But it seems that you need to pass model object to View. In your case it seems that your View will need object active to be passed.
Try return View(active); instead of return View().

Register custom ISpecimenBuilder only to a particular type

I have a custom specimen builder for AutoFixture that omits requests for anonymous values in properties based on the type of the property being requested.
public class PropertyTypeExclusion<T> : ISpecimenBuilder
{
public object Create(object request, ISpecimenContext context)
{
var propertyInfo = request as PropertyInfo;
if (propertyInfo?.PropertyType == typeof(T))
{
return new OmitSpecimen();
}
return new NoSpecimen();
}
}
I can add the customization to the fixture no problem, and it works as expected.
_fixture.Customizations.Add(new PropertyTypeExclusion<IdentityRef>());
Now I want this exclusion to be registered to requests for a specific type. Something like this:
_fixture.Customize<Release>(c => new PropertyTypeExclusion<IdentityRef>());
While the use of .Customize<Release> is valid, it has the same outcome as the call to .Customizations.Add.
Is there a way to register this ISpecimenBuilder only to a specific requested type?
If I understand you correctly, you'd like to be able to do smth like this:
fixture.Create<Release>(); // the `IdentityRef` prop is omitted
fixture.Create<SomeOtherType>(); // the `IdentityRef` prop is NOT omitted
Ok, let's look on this statement:
While the use of .Customize is valid, it has the same outcome as the call to .Customizations.Add
... meaning that even if you register the customization for the Release type only, the other types are impacted as well:
fixture.Customize<Release>(c => new PropertyTypeExclusion<IdentityRef>());
fixture.Create<Release>(); // the `IdentityRef` prop is omitted which is OK
fixture.Create<SomeOtherType>(); // the `IdentityRef` prop is also omitted but it MUST NOT
That sounds like a bug in AF to me and I'd address it here...
As a quick workaround to your issue, you can extend the customization to accept both class and property types to perform more precise filtering:
public class PropertyTypeExclusion<TType, TProp> : ISpecimenBuilder
{
public object Create(object request, ISpecimenContext context)
{
var propertyInfo = request as PropertyInfo;
if (propertyInfo?.PropertyType == typeof(TProp) &&
propertyInfo.DeclaringType == typeof(TType))
{
return new OmitSpecimen();
}
return new NoSpecimen();
}
}
Now:
fixture.Customizations.Add(new PropertyTypeExclusion<Release, IdentityRef>());
fixture.Create<Release>(); // the `IdentityRef` prop is omitted
fixture.Create<SomeOtherType>(); // the `IdentityRef` prop is NOT omitted
To fully re-use the existing AutoFixture's building blocks you could just create a specification:
public class PropertyOfTypeSpecification<TContainer, TProperty> : IRequestSpecification
{
public bool IsSatisfiedBy(object request)
{
return request is PropertyInfo propertyInfo
&& propertyInfo.PropertyType == typeof(TProperty)
&& propertyInfo.ReflectedType == typeof(TContainer);
}
}
Later you could customize your Fixture as following:
var fixture = new Fixture();
fixture.Customizations.Add(
new Omitter(
new PropertyOfTypeSpecification<Build, IdentityRef>()));

Not able to view custom data added (used Schema Extension) for a user

In the Azure AD, I have created a Native application and assigned users to it. I want to create an extension property using Microsoft Graph's SchemaExtension. I have written the code for the same and it does not throw any errors and the extension is also added(able to see the Id) through code. I then add the value of the custom property for a user under the application but am not able to view in the Azure portal or in the code when I do the below:
I have supplied the value for the custom property after updating the status of the schema extensions to "Available" but still not able to fetch the custom property value in code or in the UI. Please provide inputs if any.
Below is the code i am using:
var aap = new AzureAuthenticationProvider();
var graphserviceClient = new GraphServiceClient(aap);
IEnumerable<string> targetType = new string[] { "User" };
SchemaExtension extensionDefinition = new SchemaExtension
{
ODataType = "microsoft.graph.ComplexExtensionValue",
Id = $"crmCompanyId",
Description = "This extension is for company id",
Owner = "fac4cdd3-1015-4ed5-8a7b-6008095750e6",
Properties = new List<ExtensionSchemaProperty>()
{
new ExtensionSchemaProperty() { Name = "cid", Type = "String" }
},
Status = "InDevelopment",
TargetTypes = targetType
};
SchemaExtension schemaExtension = //code to add extensionDefinition
var updateSchemaExtension = new SchemaExtension
{
Status = "Available"
};
//update schema to available status
var updatedSchema = code to update extension
IDictionary<string, object> extensionInstance = new Dictionary<string,object>();
extensionInstance.Add(schemaExtension.Id, new
MyDBExtensionClass("testMyExtension"));
User updateUser = new User()
{
AdditionalData = extensionInstance
};
var updatedUser = await graphserviceClient.Users["9ca2bb42-a7f8-487c-
87a0 - 38513057886d"].Request().UpdateAsync(updateUser);//AzureADGraphUser3
- 9ca2bb42 - a7f8 - 487c - 87a0 - 38513057886d
await Task.Delay(10000);
Could you please review the code and let me know what I am missing...I have referred the comments at https://github.com/microsoftgraph/msgraph-sdk-dotnet/issues/151 enter code hereby Michael Maier. Let me know in case I need to provide any further info.
Thanks
I was finally able to view the property i had set once i found this link:https://github.com/microsoftgraph/msgraph-sdk-dotnet/issues/238
I queried the extension property on a user this way and was able to view the property value i set.

AngularJS $resource update/ PUT operation?

I'm confused as to how exactly to update a resource using $save. I've read the angular resource documentation and looked at other posts on stack overflow but I cannot seem to perform an update operation on an existing object.
For example, I have an event object and I want to update its name and location properties. I have the start of a function that correctly takes in the eventId of a singular event.
Here is the function so far:
eventService.updateEvent = function (eventId, eventName, eventLocation) {
// Defines the resource (WORKS)
var Event = $resource('/api/events/:id/', {id:'#_id'});
// Gets the event we're talking about (WORKS)
var event = Event.get({'id': eventId});
// TODO update event
};
How do i successfully update this resource?
Figured it out!
When I defined the resource, I defined the PUT operation as a custom method called 'update'.
I called get on that resource and looked up a particular object by ID.
Using a promise, I was able to update the resource using the 'update method' if the object was found, else throw an error.
eventService.updateEvent = function (eventId,eventName,eventLocation) {
// Define the event resource, adding an update method
var Event = $resource('/api/events/:id/', {id:'#_id'},
{
update:
{
method: 'PUT'
}
});
// Use get method to get the specific object by ID
// If object found, update. Else throw error
Event.get({'id': eventId}).$promise.then(function(res) {
// Success (object was found)
// Set event equal to the response
var e = res;
// Pass in the information that needs to be updated
e.name = eventName;
e.location = eventLocation;
// Update the resource using the custom method we created
Event.update(e)
}, function(errResponse) {
// Failure, throw error (object not found)
alert('event not found');
});
};

Flex 4.5.1 - Database access problem on mobile simulator

I am trying to connect to a SQLite database that's located in the assets folder of a project.
I wrote up a class, here is the part that is throwing an error:
public class Database
{
private var sqlConnection:SQLConnection;
public function connect(db:String):Object
{
var response:Object={status:false,message:''};
try
{
var dbFile:File=File.applicationDirectory.resolvePath(db);
sqlConnection.open(dbFile);
response.status=true;
response.message='';
}
catch(error:SQLError)
{
response.status=false
response.message=error.message;
}
return response;
}
}
I call that class in an MXML view component on the creationComplete handler:
private function init():void
{
var db:Database=new Database();
var connectResponse:Object=db.connect('assets/data.db');
if(connectResponse.status)
{
//getData() runs a simple select query and returns an array
acData=new ArrayCollection(db.getData());
}
else
{
//If the status is false I show a label control for debugging
labelError.text=connectResponse.message;
labelError.includeInLayout=true;
labelError.visible=true;
}
list.dataProvider=acData;
}
The error I get is something along the lines: TypeError: Error #1009: Cannot access a property or method of a null object reference..
I think you need to instantiate your sqlConnection before you use it:
sqlConnection = new SQLConnection();
sqlConnection.open(dbFile);

Resources