views:

106

answers:

2

I have a MVC application that I am now trying to add authentication and authorization to.

I want to allow users to get to the site and be automatically authenticated. So I set authentication mode="Windows" in the web.config, and enabled NTLM in the project options. The site now shows my domain name in the top right when I run it, but when I hit a action than needs DB access, it tells me access is denied for my user-name?

What step am I missing?

A: 

This is the subtle difference between authentication and authorization.

Authentication is the act of identifying who the user is (And you've done this bit) Authorisation is the act of determining who is allowed to do what (You need to apply the appropriate access permissions to the database, for each of your users/roles)

The subject of database access permissions is a little to complicated for sensible coverage on this forum, so i suggest that you do a bit of research via Google, etc

belugabob
The problem is that until I added the windows authentication I could get access to the database as myself (I assume that is what the build-in development server runs as by default)
My Other Me
Is there no way to have the Authentication happen via windows integration and then have the authorization happen separately?
My Other Me
Well, that's just the point. Authentication and Authorization are separate steps, but they're still quite closely related. Authorisation needs to know who it is that's being authorised, and it does this with the help of the Authentication layer.If you don't want/need the database access to be dependent on the current user (i.e. behaviour for all users is the same), then you could use the 'Anonymous access' settings in IIS (I'm assuming that you're using IIS)
belugabob
+1  A: 

This is not necessarily an IIS or Windows Authentication issue. I would assume that your connection string looks something like this

Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;

Now that you are using Windows authentication, the Domain\username is being passed to SQL to authenticate to the database. If you do not have the entire domain (or at least the subset logging into your application) as valid users in SQL, then you will get an unauthorized exception. You will need to a) pass a username/password to SQL in the conneciton string as below or b) add the users of your application to the security users of the database or c) use the impersonate attribute in the web.config file to impersonate a user that has access to both the application files on the web server and the database

SQL connection string with username/password

Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;
Tommy