diff --git a/App.config b/App.config index 561d23e..00877b2 100644 --- a/App.config +++ b/App.config @@ -3,7 +3,8 @@ - + + diff --git a/Authorization/Authorizations.cs b/Authorization/Authorizations.cs index 6e36f68..48ae09d 100644 --- a/Authorization/Authorizations.cs +++ b/Authorization/Authorizations.cs @@ -1,6 +1,8 @@ -using System; +using MarketData.DataAccess; +using MarketData.Extensions; +using MarketData.MarketDataModel.User; +using System; using System.Collections.Generic; -using System.Linq; using System.Text; namespace MarketDataServer.Authorization @@ -8,15 +10,14 @@ namespace MarketDataServer.Authorization public class Authorizations { private Dictionary authorizationDictionary = null; - private List validUsers = null; private static Authorizations authorizations = null; private bool isEnabled=true; + private Authorizations() { - validUsers = new List(); authorizationDictionary=new Dictionary(); - validUsers.Add("sean"); } + public static Authorizations GetInstance() { lock (typeof(Authorizations)) @@ -25,11 +26,13 @@ namespace MarketDataServer.Authorization } return authorizations; } + public bool IsEnabled { get{return isEnabled;} set{isEnabled=value;} } + public bool IsAuthorized(String token) { lock (this) @@ -38,6 +41,7 @@ namespace MarketDataServer.Authorization return authorizationDictionary.ContainsKey(token); } } + public String GetAuthenticationToken() { lock (this) @@ -47,13 +51,24 @@ namespace MarketDataServer.Authorization return token; } } - public bool IsValidUser(String user) + + public bool IsValidUser(String username,String password) { lock (this) { - return validUsers.Any(x => x.Equals(user)); + if(!UserDA.UserExists(username))return false; + Console.WriteLine(String.Format("[{0:G}][User {1} exists.]",DateTime.Now ,username)); + User user = UserDA.GetUser(username); + if(null == user) + { + Console.WriteLine(String.Format("[{0:G}][User {1} validation failed.]",DateTime.Now ,username)); + return false; + } + Console.WriteLine(String.Format("[{0:G}][User {1} is validated.]",DateTime.Now ,username)); + return user.Verify(password); } } + public static String Xor(String input, int magic) { StringBuilder sb = new StringBuilder(); diff --git a/Controllers/LoginController.cs b/Controllers/LoginController.cs index 6610b27..7a202e1 100644 --- a/Controllers/LoginController.cs +++ b/Controllers/LoginController.cs @@ -6,13 +6,15 @@ namespace MarketDataServer.Controllers { public class AuthorizationController : ApiController { - public String GetToken(String user) + + public String GetToken(String user, String password) { Console.WriteLine(String.Format("[{0:G}][AuthorizationController::Authorize]",DateTime.Now)); if(null==user)return null; user=Authorizations.Xor(user,5); + password=Authorizations.Xor(password,5); Console.WriteLine(String.Format("[{0:G}][Login requested for user '{1}']",DateTime.Now, user)); - if(!Authorizations.GetInstance().IsValidUser(user)) + if(!Authorizations.GetInstance().IsValidUser(user, password)) { Console.WriteLine(String.Format("[{0:G}][User '{1}' is not authorized]", DateTime.Now,user)); return null; @@ -20,7 +22,6 @@ namespace MarketDataServer.Controllers String accessToken= Authorizations.GetInstance().GetAuthenticationToken(); Console.WriteLine(String.Format("[{0:G}][Access token granted for user {1} : {2}]",DateTime.Now ,user, accessToken)); return accessToken; - } } } diff --git a/Controllers/PortfolioController.cs b/Controllers/PortfolioController.cs index 734da9e..52703c6 100644 --- a/Controllers/PortfolioController.cs +++ b/Controllers/PortfolioController.cs @@ -1,8 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Web.Http; using MarketData.MarketDataModel; using MarketData.DataAccess; @@ -32,19 +29,22 @@ namespace MarketDataServer.Controllers positionsWithDescription.Add(new PositionWithDescription(position,companyProfile.CompanyName, companyProfile.Description)); } return positionsWithDescription; - } + } + public IEnumerable GetAccounts(String token) { Console.WriteLine(String.Format("[{0:G}][PortfolioController::GetAccounts]",DateTime.Now)); if (!Authorizations.GetInstance().IsAuthorized(token)) return null; return PortfolioDA.GetAccounts(); } + public IEnumerable GetAccountsWithOpenTrades(String token) { Console.WriteLine(String.Format("[{0:G}][PortfolioController::GetAccountsWithOpenTrades]", DateTime.Now)); if (!Authorizations.GetInstance().IsAuthorized(token)) return null; return PortfolioDA.GetAccountsWithOpenTrades(); } + public StopLimit GetStopLimit(String token,String symbol) { Console.WriteLine(String.Format("[{0:G}][PortfolioController::GetStopLimit]",DateTime.Now)); @@ -52,6 +52,7 @@ namespace MarketDataServer.Controllers StopLimit stopLimit=PortfolioDA.GetStopLimit(symbol); return stopLimit; } + public PortfolioTradesWithParityPrice GetPortfolioTradesWithParityPrice(String token, String symbol) { Console.WriteLine(String.Format("[{0:G}][PortfolioController::GetPortfolioTradesWithParityPrice]", DateTime.Now)); diff --git a/bin/Debug/Axiom.Core.dll b/bin/Debug/Axiom.Core.dll index 1ee64dd..eef8393 100644 Binary files a/bin/Debug/Axiom.Core.dll and b/bin/Debug/Axiom.Core.dll differ diff --git a/bin/Debug/Axiom.Core.pdb b/bin/Debug/Axiom.Core.pdb index a83cdcd..18e21b9 100644 Binary files a/bin/Debug/Axiom.Core.pdb and b/bin/Debug/Axiom.Core.pdb differ diff --git a/bin/Debug/MarketDataLib.dll b/bin/Debug/MarketDataLib.dll index c0a67d9..0aaa4a6 100644 Binary files a/bin/Debug/MarketDataLib.dll and b/bin/Debug/MarketDataLib.dll differ diff --git a/bin/Debug/MarketDataLib.pdb b/bin/Debug/MarketDataLib.pdb index e229eaf..3631c24 100644 Binary files a/bin/Debug/MarketDataLib.pdb and b/bin/Debug/MarketDataLib.pdb differ diff --git a/bin/Debug/MarketDataServer.exe b/bin/Debug/MarketDataServer.exe index 07240b7..2d7d1b8 100644 Binary files a/bin/Debug/MarketDataServer.exe and b/bin/Debug/MarketDataServer.exe differ diff --git a/bin/Debug/MarketDataServer.exe.config b/bin/Debug/MarketDataServer.exe.config index d653a50..2ea1661 100644 --- a/bin/Debug/MarketDataServer.exe.config +++ b/bin/Debug/MarketDataServer.exe.config @@ -3,6 +3,7 @@ + diff --git a/bin/Debug/MarketDataServer.pdb b/bin/Debug/MarketDataServer.pdb index 056f3f0..6425a92 100644 Binary files a/bin/Debug/MarketDataServer.pdb and b/bin/Debug/MarketDataServer.pdb differ diff --git a/obj/Debug/MarketDataServer.exe b/obj/Debug/MarketDataServer.exe index 07240b7..2d7d1b8 100644 Binary files a/obj/Debug/MarketDataServer.exe and b/obj/Debug/MarketDataServer.exe differ diff --git a/obj/Debug/MarketDataServer.pdb b/obj/Debug/MarketDataServer.pdb index 056f3f0..6425a92 100644 Binary files a/obj/Debug/MarketDataServer.pdb and b/obj/Debug/MarketDataServer.pdb differ