Asp.net MVC azure ad group identification - asp.net

I'm currently finishing my website in ASP.NET MVC with azure AD login.
For this website, some pages are only accessible by admins. For this, I made a new group that's named testAdmins and when I check if the user can access to a page, I use this :
ClaimsPrincipal principal = User as ClaimsPrincipal;
if (principal.Claims.Any(x => x.Type == "groups" && x.Value == "id of testAdmins")){ //code }
And it's working fine with my user witch is in this group.
But when I change the id of testAdmins with the value of the real group of admins (Admins) I'm going to use when the site will be deployed and witch I'm not in, the server is not showing anything for 40 sec and then I got this message :
An exception of type 'System.Web.HttpException' occurred in
System.Web.dll but was not handled in user code
Additional information: Unable to connect to SQL Server database.
Can someone explain me what's going on ?
Thanks in advance
PS : I made some more test... When my user is in the group it works fast but when it's not it takes 2 min and do the error message... if someone as no idea what is the problem, did anyone have a way to make different access from user wich are in a special group from Azure Active Directory ?

Provide the whole stacktrace and relevant source code line (the full stacktrace includes file names and line numbers!). The issue you are facing is very common for on-boarding developers (on-boarding to ASP.NET 4.0+).
Your project is based on the default project template for ASP.NET 4.0 (or later), which by default creates the website with "Local User Accounts". This template creates an Entity Framework db context and local models for the user authentication / authorization. This also creates some settings in your web.config to define connectin strings (or instruct the default one) for the EF.
On top of that template you added the neccessery Azure AD authentication details - either through the right click menu (Configure Azure AD Authentication - available in VS 2015) or manually by including a bunch of NuGet packages. Thus you (without knowing) created a nasty mix of FBA (Forms Based Authentication) - dictated by the local accounts, and OpenID Connect - dictated by Azure AD authentication.
The SQL Server error comes from that FBA (or local user accounts setting) config. And there is no easy way to remove it.
Because I see you are just playing around and testing out things, I would warmly recommend that you start over with a new project and be careful by your second step of the wizard (available in both VS 2013 and VS 2015) - Click on "change authentication" and chose "No authentication":
On this clean project, you can add your Azure AD authentication and everything will work and you will not see any SQL Server Errors (well it depends how you configure your Azure AD Auth - some of the wizzards - namely the one of Multi-tenant also creates EF context).

Related

Kusto.Explorer - Authentication Trouble

I'm having trouble adding a connection in the Kusto.Explorer desktop app 1.0.3.949. I can login via Web UI but in the desktop app it gives me this error:
This normally represents a permanent error, and retrying is unlikely to help.
Please provide the following information when contacting the Kusto team # https://aka.ms/kustosupport :
DataSource='https://m1explorer.westus.kusto.windows.net/v1/rest/mgmt',
DatabaseName='NetDefaultDB',
ClientRequestId='KD2RunCommand;5723fa83-9dd5-48fe-a1ee-5d4ddb7f9cd9',
ActivityId='74b41f5e-be7c-46be-88f5-dae1a6d35c30,
Timestamp='2020-08-02T18:48:13.6846740Z'.
In other applications such as the Kuskus VSCode extension or even the Web UI, the problem seems to be that it uses the "common" tenant/authority id as a default. Is there a way to specify the tenant id when adding the connection? It says you can import an .xml file but I'm not sure where or how this can be generated.
Thanks,
Steven
Please try approach described at:
https://learn.microsoft.com/en-us/azure/data-explorer/kusto/tools/kusto-explorer#control-the-user-identity-connecting-to-kustoexplorer
The default security model for new connections is AAD-Federated
security. Authentication is done through the Azure Active Directory
using the default AAD user experience.
If you need finer control over the authentication parameters, you can
expand the "Advanced: Connection Strings" edit box and provide a valid
Kusto connection string value.
For example, users with a presence in multiple AAD tenants sometimes
need to use a particular "projection" of their identities to a
specific AAD tenant. Do this by providing a connection string, such as
the one below (replace words IN CAPITALS with specific values):
Data Source=https://CLUSTER_NAME.kusto.windows.net;Initial Catalog=DATABASE_NAME;AAD Federated Security=True;Authority Id=AAD_TENANT_OF_CLUSTER;User=USER_DOMAIN

Oracle SOA taskflow deployed but not available in worklist

I have been working with Oracle SOA Suit 12c human task component. However, I have created a simple bpel processs that takes one input for human intervention and response required by the user assigned. The project deployed successfully to weblogic domain soa_server1. Now the web service is being tested by oracle em->soa_server->composite application. When the user login to worklist, the task is being populated but when he clicks on task, it shows a login form rathar than the huam task form(the jsf/jspx) page.
Additional Details
Weblogic Server 12c, SOA Quick Start 12c(12.2.2.1.0) installed and weblogic domain configured using database. JDeveloper version 12c.
Below is the screenshot of worklist
Can anyone please look in to this, what's the issue??
Issue was related to user assignment in Human Task dedinition.
Double click on human task in your composite.
Go to assignments(user assignment)
My mistake- I had set the owner as weblogic and trying to access the task in worklist with user 'level1'
SOLUTION THAT WORKED FOR ME
Either leave blank to owner text filed or specify all users whom task is being assigned or users who manually clam task.
I haven't tried but probably of you have hierarchy set for users then it might require only top level person to be specified in owner section.
I had a different issue the url in the humantask configuration was pointing to some random name and not the server host name changing that worked

How to use active Directory for ASP.Net 5 (MVC6) Intranet application

I am developing an intranet application and would like to use the existing organisations Active Directory for user authentication and policy based role authorisation.
Can someone point me in the right direction? I am getting a bit confused (well actually a lot confused).
Thankyou
Per Authentication and Autorization resources under http://docs.asp.net/en/latest/security/index.html
First start a new ASP.Net Web Application project, Pick the Web Application template then on the right pane press the "Change Authentication" button and pick "Windows Authentication".
You can now use [Authorize] on a class or method to check basic authentication vs active directory as of RC2 you can simply use the group names ala [Authorize(Roles=#"DOMAIN\GROUP")]
The now obsolete and cumbersome alternative (still works):
If you look at User.Claims you can see the groupsid keys exist for each of the user's groups. Building off that you can do something like [Authorize(Policy="FOOBAR")] and define it in your Startup.ConfigureServices method via
services.AddAuthorization(
o => o.AddPolicy(
"FOOBAR",
p => p.RequireClaim("http://schemas.microsoft.com/ws/2008/06/identity/claims/groupsid",
"ENTER GROUP SID")
));
Note that the second param to RequireClaim is a string array to allow for multiple groups.
Also note to figure out group ids via this command line magic dsquery group -name “ENTER GROUP NAME” | dsget group -sid

log4Net eventlog permissions issue using non-administrator account

This probably isnt an issue with SiteCore per se but I've included it for completeness. I have sitecore 6.3 running under IIS7 using a custom identity for the app pool. I cant get Sitecore to write its logging information (using the default log4net settings) to the eventlog. I've followed the advice here: http://logging.apache.org/log4net/release/faq.html#Why%20doesn%27t%20the%20EventLogAppender%20work? and although it works fine when I make the custom identity a member of the administrator's group I need to find a way to get it working in production without such a security hack.
The weird thing is that I have a MSI that installs it (running under an account which IS a member of the administrator's group) and creates the correct registry keys in the eventlog for me and yet despite that, I am still getting the following error when I run the application using the custom identity (without it being a member of administrators).
log4net:ERROR DOMConfigurator: Could not create Appender [EventLogAppender] of type [log4net.Appender.EventLogAppender]. Reported error follows.
System.Security.SecurityException: Requested registry access is not allowed.
at Microsoft.Win32.RegistryKey.OpenSubKey(String name, Boolean writable)
at System.Diagnostics.EventLog.GetEventLogRegKey(String machine, Boolean writable)
at System.Diagnostics.EventLog.FindSourceRegistration(String source, String machineName, Boolean readOnly)
at System.Diagnostics.EventLog.DeleteEventSource(String source, String machineName)
at log4net.Appender.EventLogAppender.ActivateOptions()
at log4net.Repository.Hierarchy.DOMHierarchyConfigurator.ParseAppender(XmlElement appenderElement)
The Zone of the assembly that failed was:
MyComputer
log4net:ERROR DOMConfigurator: Appender named [EventLogAppender] not found.
Thinking I could narrow it down to a registry permission issue I granted Everyone full permissions to the following registry key and subkeys but it didnt work either: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\eventlog
The custom identity is a member of the following groups:
Event Log Readers
IIS_USERS
Performance Monitor Users
I've also seen the following question which seems to ask the same thing. The Microsoft article seems to suggest it might be a problem with ACLs on an event log and gives examples on how you can change SSDLs but I'd rather avoid that if at all possible.
EDIT:
I have another server running where the log is being populated fine. The custom identity was a member of administrators so I revoked that and rebooted, trying to purposely break it but I cant. Config is identical on both boxes and same identity used to run the MSI which creates the registry keys. Have run procmon on both (after doing a IISReset and spinning up the app pool again) to examine registry activity. Strange thing is - on the box that works you get 477 name not found records for my event source in the wrong places (Application, and a different Custom EventLog "MyCompany"). No hits for the place where it is logging which is "MyCompany\MyCompany.SiteCore". Whilst on the box which is broken, it does appear to be requesting to read the right key (albeit only 6 times) but you then get the Log4Net registry access error.
As I understand it EventStores are stored in the registry, so you only need write permission to registry to create or delete an EventStore. This is usually only needed once and most applications create this as part of the install procedure so that the application does not need to be run as Administrator during normal execution.
However your error message (in the question) includes the method DeleteEventSource from which I would deduce/guess that the EventSource does exist but is wrong in some way. So perhaps this is currently registered as writing to the event log named MyCompany and you are now trying to change it to "MyCompany\MyCompany.SiteCore" which requires you to delete the old eventsource and create a new one.
So it sounds like your installation routine is creating a different EventSource from the one that your application is actually using.
If that doesn't help, then I would suggest enabling internal logging for Log4net (but obviously not to the eventlog) which will probably give you more information.
Giving full permission to the registry key is not enough.
According to Microsoft
To create an event source in Windows Vista and later or Windows Server 2003, you must have administrative privileges.
The reason for this requirement is that all event logs, including security, must be searched to determine whether the event source is unique. Starting with Windows Vista, users do not have permission to access the security log; therefore, a SecurityException is thrown.
Starting with Windows Vista, User Account Control (UAC) determines the privileges of a user. If you are a member of the Built-in Administrators group, you are assigned two run-time access tokens: a standard user access token and an administrator access token. By default, you are in the standard user role. To execute the code that accesses the security log, you must first elevate your privileges from standard user to administrator. You can do this when you start an application by right-clicking the application icon and indicating that you want to run as an administrator.
I think, contrary to the Apache documentation, log4net DOES need write access to the registry – or at least it does in my case. To prove this, I backed up the registry on the server where it wasnt working and granted IIS administrator privileges before spinning up sitecore. Sure enough it started logging away to the eventlog nicely and then when I exported the registry again to run a diff, there WAS a difference.
The value for the eventlogmessage file on my event source had been updated from:
C:\Windows\Microsoft.NET\Framework\v2.0.50727\EventLogMessages.dll
To
C:\Windows\Microsoft.NET\Framework64\v2.0.50727\EventLogMessages.dll
So I assumed that merely changing this value in the registry by hand would work.
But it didn’t.
So I ran procmon on the two servers I have: A=the working one, B=the failing one. Sure enough, on server B I have a line which says:
Operation: RegOpenKey, Path: HKLM\System\CurrentControlSet\Services\EventLog, Desired Access:Read/Write, Result: ACCESS DENIED.
I’ve traced through with Server A and in exactly the same place, the key is requested with Desired Access:Read.
Conclusion:
It seems unavoidable that I will need to grant my app pool identity administrator privileges in production for at least enough time to programatically do the necessary registry writes the first time from within log4net. I dont know why administrator; I have tried granting Full permissions to the entire eventlog node in the registry for my custom app to no avail. It seems to do something which I cannot identify or pin down. I will then revoke this privilege immediately after it starts to log and monitor whether subsequent installs knock out the functionality afterwards. (Hopefully not).
If anyone has any insight into this behaviour it would be greatly appreciated.

Windows authentication mode in ASP.NET uses the Active Directory group name (pre-Windows 2000)?

Here is the background. I had an .NET MVC v1.0 project that I was trying to secure it by using Windows authentication mode. So I set the web.config to:
<authentication mode="Windows" />
And then went into my controller and did the following:
[Authorize(Roles="IT")]
public class LicenseController : Controller
In AD we have a group called "IT" and I am many others are apart of this group. Once I had this in place I started a debug session and tried going to any of the actions in that controller and I was met with a 401. I search high and low looking for somewhere that I had screwed the pooch and couldn't find anything wrong. After a while of struggling I decided to try changing the "Authorize" to a specific user an see if that worked. So I changed it to the following:
[Authorize(Users="domain\\tnederveld")]
And low and behold that worked. So I went and added a different group that I was a member of and took out the users authorize statement and that worked. I started looking into the differences between the two AD groups and the only thing that was different was on the second group I tried the "Group name (pre-Windows 2000):" were the same. The "IT" groups "Group name (pre-Windows 2000):" was "IT Associates". So I tried changing the authorize statement to:
[Authorize(Roles="IT Associates")]
And it started working. I thought for sure this was an MVC issue, so to make sure I tried it on a regular Web Forms project and was meet with the same issue.
The real kicker is that when you use the UserPrincipal that is part of the System.DirectoryServices.AccountManagement it returns the group "IT" when using the .GetGroups() method.
Why is this is happening?
You need to keep apart the various names an entry in AD can have:
the name per se is typically the CN attribute - the Common Name. This is the "CN=xxx" part in your LDAP string. Here it's IT - and that's what System.DirectoryServices.AccountManagement will return - it's the "Active Directory"'s most common name
the "IT Associates" name is the pre-Windows 2000 or sAMAccountName - the thing Windows NT used to use before there was AD - a local user and/or group name (SAM = Security Account Management or something like that). The SAM Account Name needs to be unique per domain - even in a huge AD forest these days.
Unfortunately, lots of the Windows API calls are still based on that name - since they are (and need to be) backwards compatible with earlier Windows versions. The ASP.NET membership system uses those calls and thus will use your domain/tnederveld user name and IT Associates group - those are the SAM account names of your objects
Not sure if there's much you can do about it - just be aware that in a AD environment, any of your user or groups has a plethora of "names" - always be very clear about which one you're talking about!
For a detailed list of all AD attributes, see Richard Mueller's excellent web site with Active Directory reference material.

Resources