Skip to content

Commit

Permalink
Merge pull request #1 from arichika/develop
Browse files Browse the repository at this point in the history
public beta
  • Loading branch information
arichika committed Aug 14, 2014
2 parents 5343ec3 + ae0fad0 commit 871593f
Show file tree
Hide file tree
Showing 13 changed files with 81 additions and 52 deletions.
37 changes: 36 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,39 @@
AspNet.Identity.Oracle
======================

AspNet.Identity.Oracle for ASP.NET Identity 2.0 with ODP.NET
AspNet.Identity.Oracle for ASP.NET Identity 2.0 with ODP.NET
forked from AspNet.Identity.MySQL provided at codeplex.

https://aspnet.codeplex.com/SourceControl/latest#Samples/Identity/AspNet.Identity.MySQL/AspNet.Identity.MySQL.csproj

How To Use
==========
(from ReadMe.txt)

This is an example to implement a OracleDatabase store for ASP.NET Identity 2.0

Steps to run project

- Open project in VS with Update 2 or later installed
- Build project to restore packages and build project
- In the solution, add a new one ASP.NET project with MVC and Individual Authentication
- Uninstall Microsoft.AspNet.Identity.EntityFramework package from the web application
- Update connection string to use the OracleDatabase database as needed
- In the IdentityModel.cs, let ApplicationUser class extend from Identity user in AspNet.Identity.Oracle
- ApplicationDbContext extend from OracleDatabase and the contructor take a single parameter with the connectionstring name
- In the ApplicationManager.Create method, replace instantiating UserManager as shown below

var manager = new ApplicationUserManager(new UserStore<ApplicationUser>(context.Get<ApplicationDbContext>() as OracleDatabase));

See Also
========

AspNet.Identity.MySQL(CodePlex)
https://aspnet.codeplex.com/SourceControl/latest#Samples/Identity/AspNet.Identity.MySQL/AspNet.Identity.MySQL.csproj

Implementing a Custom MySQL ASP.NET Identity Storage Provider
http://www.asp.net/identity/overview/extensibility/implementing-a-custom-mysql-aspnet-identity-storage-provider

Announcing RTM of ASP.NET Identity 2.0.0
http://blogs.msdn.com/b/webdev/archive/2014/03/20/test-announcing-rtm-of-asp-net-identity-2-0-0.aspx
//
2 changes: 1 addition & 1 deletion Src/AspNet.Identity.Oracle/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("3BDA7D00-695F-4B52-A835-FEAA2581D21C")]
[assembly: Guid("7403FCE0-1BCC-4DB6-8241-5D8A4FC0FDA1")]

// Version information for an assembly consists of the following four values:
//
Expand Down
4 changes: 2 additions & 2 deletions Src/AspNet.Identity.Oracle/Readme.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
This is an example to implement a OracleDatabase store for ASP.NET Identity updated to use ASP.NET Identity 2.0
This is an example to implement a OracleDatabase store for ASP.NET Identity 2.0

Steps to run project

- Open project in VS with Update 2 installed
- Open project in VS with Update 2 or later installed
- Build project to restore packages and build project
- In the solution, add a new one ASP.NET project with MVC and Individual Authentication
- Uninstall Microsoft.AspNet.Identity.EntityFramework package from the web application
Expand Down
4 changes: 2 additions & 2 deletions Src/AspNet.Identity.Oracle/RoleStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@ public Task<TRole> FindByIdAsync(string roleId)
{
var result = roleTable.GetRoleById(roleId) as TRole;

return Task.FromResult<TRole>(result);
return Task.FromResult(result);
}

public Task<TRole> FindByNameAsync(string roleName)
{
var result = roleTable.GetRoleByName(roleName) as TRole;

return Task.FromResult<TRole>(result);
return Task.FromResult(result);
}

public Task UpdateAsync(TRole role)
Expand Down
13 changes: 6 additions & 7 deletions Src/AspNet.Identity.Oracle/RoleTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public RoleTable(OracleDatabase database)
/// <returns></returns>
public int Delete(string roleId)
{
const string commandText = @"DELETE FROM ROLES WHERE ID = :ID";
const string commandText = @"DELETE FROM ANID2ROLES WHERE ID = :ID";
var parameters = new List<OracleParameter>
{
new OracleParameter {ParameterName = "ID", Value = roleId, OracleDbType = OracleDbType.Varchar2 },
Expand All @@ -43,7 +43,7 @@ public int Delete(string roleId)
/// <returns></returns>
public int Insert(IdentityRole role)
{
const string commandText = @"INSERT INTO ROLES (ID, NAME) VALUES (:ID, :NAME)";
const string commandText = @"INSERT INTO ANID2ROLES (ID, NAME) VALUES (:ID, :NAME)";
var parameters = new List<OracleParameter>
{
new OracleParameter {ParameterName = "ID", Value = role.Id, OracleDbType = OracleDbType.Varchar2 },
Expand All @@ -60,7 +60,7 @@ public int Insert(IdentityRole role)
/// <returns>Role name</returns>
public string GetRoleName(string roleId)
{
const string commandText = @"SELECT NAME FROM ROLES WHERE ID = :ID";
const string commandText = @"SELECT NAME FROM ANID2ROLES WHERE ID = :ID";
var parameters = new List<OracleParameter>
{
new OracleParameter {ParameterName = "ID", Value = roleId, OracleDbType = OracleDbType.Varchar2 },
Expand All @@ -76,15 +76,14 @@ public string GetRoleName(string roleId)
/// <returns>Role's Id</returns>
public string GetRoleId(string roleName)
{
string roleId = null;
const string commandText = @"SELECT ID FROM ROLES WHERE NAME = :NAME";
const string commandText = @"SELECT ID FROM ANID2ROLES WHERE NAME = :NAME";
var parameters = new List<OracleParameter>
{
new OracleParameter {ParameterName = "NAME", Value = roleName, OracleDbType = OracleDbType.Varchar2 },
};

var result = _database.QueryValue(commandText, parameters);
return result != null ? Convert.ToString(result) : roleId;
return result != null ? Convert.ToString(result) : null;
}

/// <summary>
Expand Down Expand Up @@ -126,7 +125,7 @@ public IdentityRole GetRoleByName(string roleName)

public int Update(IdentityRole role)
{
const string commandText = @"UPDATE ROLES SET NAME = :NAME WHERE ID = :ID";
const string commandText = @"UPDATE ANID2ROLES SET NAME = :NAME WHERE ID = :ID";
var parameters = new List<OracleParameter>
{
new OracleParameter {ParameterName = "ID", Value = role.Id, OracleDbType = OracleDbType.Varchar2 },
Expand Down
8 changes: 1 addition & 7 deletions Src/AspNet.Identity.Oracle/ToDecimalExtentions.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AspNet.Identity.Oracle
namespace AspNet.Identity.Oracle
{
public static class OracleBoolDecimalExtentions
{
Expand Down
10 changes: 5 additions & 5 deletions Src/AspNet.Identity.Oracle/UserClaimsTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public UserClaimsTable(OracleDatabase database)
public ClaimsIdentity FindByUserId(string userId)
{
var claims = new ClaimsIdentity();
const string commandText = @"SELECT * FROM USERCLAIMS WHERE USERID = :USERID";
const string commandText = @"SELECT * FROM ANID2USERCLAIMS WHERE USERID = :USERID";
var parameters = new List<OracleParameter>
{
new OracleParameter{ ParameterName = "USERID", Value = userId, OracleDbType = OracleDbType.Varchar2 },
Expand All @@ -51,7 +51,7 @@ public ClaimsIdentity FindByUserId(string userId)
/// <returns></returns>
public int Delete(string userId)
{
const string commandText = @"DELETE FROM USERCLAIMS WHERE USERID = :USERID";
const string commandText = @"DELETE FROM ANID2USERCLAIMS WHERE USERID = :USERID";
var parameters = new List<OracleParameter>
{
new OracleParameter{ ParameterName = "USERID", Value = userId, OracleDbType = OracleDbType.Varchar2 },
Expand All @@ -63,12 +63,12 @@ public int Delete(string userId)
/// <summary>
/// Inserts a new claim in UserClaims table
/// </summary>
/// <param name="userClaim">User's claim to be added</param>
/// <param name="claim">User's claim to be added</param>
/// <param name="userId">User's id</param>
/// <returns></returns>
public int Insert(Claim claim, string userId)
{
const string commandText = @"INSERT INTO USERCLAIMS (CLAIMVALUE, CLAIMTYPE, USERID) VALUES (:VALUE, :TYPE, :USERID)";
const string commandText = @"INSERT INTO ANID2USERCLAIMS (CLAIMVALUE, CLAIMTYPE, USERID) VALUES (:VALUE, :TYPE, :USERID)";
var parameters = new List<OracleParameter>
{
new OracleParameter{ ParameterName = "USERID", Value = userId, OracleDbType = OracleDbType.Varchar2 },
Expand All @@ -87,7 +87,7 @@ public int Insert(Claim claim, string userId)
/// <returns></returns>
public int Delete(IdentityUser user, Claim claim)
{
const string commandText = @"DELETE FROM USERCLAIMS WHERE USERID = :USERID AND @CLAIMVALUE = :VALUE AND CLAIMTYPE = :TYPE";
const string commandText = @"DELETE FROM ANID2USERCLAIMS WHERE USERID = :USERID AND @CLAIMVALUE = :VALUE AND CLAIMTYPE = :TYPE";
var parameters = new List<OracleParameter>
{
new OracleParameter{ ParameterName = "USERID", Value = user.Id, OracleDbType = OracleDbType.Varchar2 },
Expand Down
10 changes: 5 additions & 5 deletions Src/AspNet.Identity.Oracle/UserLoginsTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public UserLoginsTable(OracleDatabase database)
/// <returns></returns>
public int Delete(IdentityUser user, UserLoginInfo login)
{
const string commandText = @"DELETE FROM USERLOGINS WHERE USERID = :USERID AND LOGINPROVIDER = :LOGINPROVIDER AND PROVIDERKEY = :PROVIDERKEY";
const string commandText = @"DELETE FROM ANID2USERLOGINS WHERE USERID = :USERID AND LOGINPROVIDER = :LOGINPROVIDER AND PROVIDERKEY = :PROVIDERKEY";
var parameters = new List<OracleParameter>
{
new OracleParameter{ ParameterName = "USERID", Value = user.Id, OracleDbType = OracleDbType.Varchar2 },
Expand All @@ -47,7 +47,7 @@ public int Delete(IdentityUser user, UserLoginInfo login)
/// <returns></returns>
public int Delete(string userId)
{
const string commandText = @"DELETE FROM USERLOGINS WHERE USERID = :USERID";
const string commandText = @"DELETE FROM ANID2USERLOGINS WHERE USERID = :USERID";
var parameters = new List<OracleParameter>
{
new OracleParameter{ ParameterName = "USERID", Value = userId, OracleDbType = OracleDbType.Varchar2 },
Expand All @@ -64,7 +64,7 @@ public int Delete(string userId)
/// <returns></returns>
public int Insert(IdentityUser user, UserLoginInfo login)
{
const string commandText = @"INSERT INTO USERLOGINS (LOGINPROVIDER, PROVIDERKEY, USERID) VALUES (:LOGINPROVIDER, :PROVIDERKEY, :USERID)";
const string commandText = @"INSERT INTO ANID2USERLOGINS (LOGINPROVIDER, PROVIDERKEY, USERID) VALUES (:LOGINPROVIDER, :PROVIDERKEY, :USERID)";
var parameters = new List<OracleParameter>
{
new OracleParameter{ ParameterName = "USERID", Value = user.Id, OracleDbType = OracleDbType.Varchar2 },
Expand All @@ -82,7 +82,7 @@ public int Insert(IdentityUser user, UserLoginInfo login)
/// <returns></returns>
public string FindUserIdByLogin(UserLoginInfo login)
{
const string commandText = @"SELECT USERID FROM USERLOGINS WHERE LOGINPROVIDER = :LOGINPROVIDER AND PROVIDERKEY = :PROVIDERKEY";
const string commandText = @"SELECT USERID FROM ANID2USERLOGINS WHERE LOGINPROVIDER = :LOGINPROVIDER AND PROVIDERKEY = :PROVIDERKEY";
var parameters = new List<OracleParameter>
{
new OracleParameter{ ParameterName = "LOGINPROVIDER", Value = login.LoginProvider, OracleDbType = OracleDbType.Varchar2 },
Expand All @@ -99,7 +99,7 @@ public string FindUserIdByLogin(UserLoginInfo login)
/// <returns></returns>
public List<UserLoginInfo> FindByUserId(string userId)
{
const string commandText = @"SELECT * FROM USERLOGINS WHERE USERID = :USERID";
const string commandText = @"SELECT * FROM ANID2USERLOGINS WHERE USERID = :USERID";
var parameters = new List<OracleParameter>
{
new OracleParameter{ ParameterName = "USERID", Value = userId, OracleDbType = OracleDbType.Varchar2 },
Expand Down
6 changes: 3 additions & 3 deletions Src/AspNet.Identity.Oracle/UserRoleTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public UserRolesTable(OracleDatabase database)
/// <returns></returns>
public List<string> FindByUserId(string userId)
{
const string commandText = @"SELECT ROLES.NAME FROM USERROLES, ROLES WHERE USERROLES.USERID = :USERID AND USERROLES.ROLEID = ROLES.ID";
const string commandText = @"SELECT NAME FROM ANID2USERROLES, ANID2ROLES WHERE USERID = :USERID AND ANID2USERROLES.ROLEID = ANID2ROLES.ID";
var parameters = new List<OracleParameter>
{
new OracleParameter{ ParameterName = "USERID", Value = userId, OracleDbType = OracleDbType.Varchar2 }
Expand All @@ -45,7 +45,7 @@ public List<string> FindByUserId(string userId)
/// <returns></returns>
public int Delete(string userId)
{
const string commandText = @"DELETE FROM USERROLES WHERE USERID = :USERID";
const string commandText = @"DELETE FROM ANID2USERROLES WHERE USERID = :USERID";
var parameters = new List<OracleParameter>
{
new OracleParameter{ ParameterName = "USERID", Value = userId, OracleDbType = OracleDbType.Varchar2 }
Expand All @@ -62,7 +62,7 @@ public int Delete(string userId)
/// <returns></returns>
public int Insert(IdentityUser user, string roleId)
{
const string commandText = @"INSERT INTO USERROLES (USERID, ROLEID) VALUES (:USERID, :ROLEID)";
const string commandText = @"INSERT INTO ANID2USERROLES (USERID, ROLEID) VALUES (:USERID, :ROLEID)";
var parameters = new List<OracleParameter>
{
new OracleParameter{ ParameterName = "USERID", Value = user.Id, OracleDbType = OracleDbType.Varchar2},
Expand Down
26 changes: 13 additions & 13 deletions Src/AspNet.Identity.Oracle/UserStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ public Task<TUser> FindByIdAsync(string userId)
throw new ArgumentException("Null or empty argument: userId");
}

var result = userTable.GetUserById(userId) as TUser;
var result = userTable.GetUserById(userId);

return Task.FromResult<TUser>(result ?? null);
return Task.FromResult(result);
}

/// <summary>
Expand All @@ -108,12 +108,12 @@ public Task<TUser> FindByNameAsync(string userName)
throw new ArgumentException("Null or empty argument: userName");
}

var result = userTable.GetUserByName(userName) as List<TUser>;
var result = userTable.GetUserByName(userName);

// Should I throw if > 1 user?
if (result != null && result.Count == 1)
{
return Task.FromResult<TUser>(result[0]);
return Task.FromResult(result[0]);
}

return Task.FromResult<TUser>(null);
Expand Down Expand Up @@ -240,9 +240,9 @@ public Task<TUser> FindAsync(UserLoginInfo login)
var userId = userLoginsTable.FindUserIdByLogin(login);
if (userId == null) return Task.FromResult<TUser>(null);

var user = userTable.GetUserById(userId) as TUser;
var user = userTable.GetUserById(userId);

return Task.FromResult<TUser>(user ?? null);
return Task.FromResult(user);
}

/// <summary>
Expand All @@ -259,7 +259,7 @@ public Task<IList<UserLoginInfo>> GetLoginsAsync(TUser user)

var logins = userLoginsTable.FindByUserId(user.Id);

return Task.FromResult<IList<UserLoginInfo>>(logins ?? null);
return Task.FromResult<IList<UserLoginInfo>>(logins);
}

/// <summary>
Expand Down Expand Up @@ -357,11 +357,11 @@ public Task<bool> IsInRoleAsync(TUser user, string role)
{
if (roles != null && roles.Contains(role))
{
return Task.FromResult<bool>(true);
return Task.FromResult(true);
}
}

return Task.FromResult<bool>(false);
return Task.FromResult(false);
}

/// <summary>
Expand Down Expand Up @@ -399,7 +399,7 @@ public Task<string> GetPasswordHashAsync(TUser user)
{
var passwordHash = userTable.GetPasswordHash(user.Id);

return Task.FromResult<string>(passwordHash);
return Task.FromResult(passwordHash);
}

/// <summary>
Expand All @@ -411,7 +411,7 @@ public Task<bool> HasPasswordAsync(TUser user)
{
var hasPassword = !string.IsNullOrEmpty(userTable.GetPasswordHash(user.Id));

return Task.FromResult<bool>(Boolean.Parse(hasPassword.ToString()));
return Task.FromResult(Boolean.Parse(hasPassword.ToString()));
}

/// <summary>
Expand Down Expand Up @@ -513,8 +513,8 @@ public Task<TUser> FindByEmailAsync(string email)
throw new ArgumentNullException("email");
}

var result = userTable.GetUserByEmail(email) as TUser;
return Task.FromResult<TUser>(result ?? null);
var result = userTable.GetUserByEmail(email).FirstOrDefault();
return Task.FromResult(result);
}

/// <summary>
Expand Down
6 changes: 3 additions & 3 deletions Src/AspNet.Identity.Oracle/UserTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ public string GetUserId(string userName)
/// <returns></returns>
public TUser GetUserById(string userId)
{
TUser user = null;
TUser user;
const string commandText = @"SELECT * FROM ANID2USERS WHERE ID = :USERID";
var parameters = new List<OracleParameter>
{
new OracleParameter{ ParameterName = "USERID", Value = userId, OracleDbType = OracleDbType.Varchar2 }
};

var rows = _database.Query(commandText, parameters);
if (rows == null || rows.Count != 1) return user;
if (rows == null || rows.Count != 1) return null;

var row = rows[0];
user = (TUser)Activator.CreateInstance(typeof(TUser));
Expand Down Expand Up @@ -177,7 +177,7 @@ public string GetSecurityStamp(string userId)
new OracleParameter{ ParameterName = "USERID", Value = userId, OracleDbType = OracleDbType.Varchar2 }
};

return _database.GetStrValue(commandText, parameters);;
return _database.GetStrValue(commandText, parameters);
}

/// <summary>
Expand Down
3 changes: 3 additions & 0 deletions Src/SampleWebSite/SampleWebSite.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@
<Content Include="fonts\glyphicons-halflings-regular.ttf" />
<Content Include="fonts\glyphicons-halflings-regular.eot" />
<Content Include="packages.config" />
<Content Include="MyConnectionStrings.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<None Include="Web.Debug.config">
<DependentUpon>Web.config</DependentUpon>
</None>
Expand Down
4 changes: 1 addition & 3 deletions Src/SampleWebSite/Web.config
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
http://go.microsoft.com/fwlink/?LinkId=169433 を参照してください
-->
<configuration>
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=127.0.0.1)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=DB)));User Id=scott;Password=tiger;" />
</connectionStrings>
<connectionStrings configSource="MyConnectionStrings.config"/>
<appSettings>
<add key="owin:AppStartup" value="IdentitySample.Startup,SampleWebSite" />
<add key="webpages:Version" value="3.0.0.0" />
Expand Down

0 comments on commit 871593f

Please sign in to comment.