public AuthenticationModel GetSecurityModel() { IOptionsPlayIdentity identity = SessionHelper.GetIdentity(); if (identity == null) { return(null); } AuthenticationModel authenticationModel = new AuthenticationModel(); authenticationModel.Role = identity.Role; authenticationModel.Permissions = identity.Permissions.ToArray(); OptionsPlayFCUserIdentity fcUserIdentity = identity as OptionsPlayFCUserIdentity; if (fcUserIdentity != null) { authenticationModel.AccountNumber = fcUserIdentity.CustomerAccountCode; authenticationModel.AccountId = fcUserIdentity.AccountId; authenticationModel.UserName = fcUserIdentity.TradeAccountName; } //OptionsPlayWebUserIdentity webUserIdentity = identity as OptionsPlayWebUserIdentity; //if (webUserIdentity != null) //{ // authenticationModel.UserName = webUserIdentity.DisplayName; //} return(authenticationModel); }
public override void OnAuthorization(System.Web.Http.Controllers.HttpActionContext actionContext) { HttpContext context = HttpContext.Current; if (context == null || context.User == null) { throw new AuthorizeException(ErrorCode.AuthenticationInvalidHttpContext); } if (context.User.Identity.IsAuthenticated) { IOptionsPlayIdentity optionsPlayIdentity = context.User.Identity as IOptionsPlayIdentity; if (optionsPlayIdentity == null) { throw new AuthorizeException(ErrorCode.AuthenticationIncorrectIdentity); } if (_permissions.Length > 0 && !_permissions.Any(item => optionsPlayIdentity.Permissions.Contains(item))) { throw new AuthorizeException( ErrorCode.AuthenticationMethodAccessNotEnabled, optionsPlayIdentity.UserId.ToString(CultureInfo.InvariantCulture), string.Join(", ", _permissions.Select(item => item.ToString()))); } } else if (!_permissions.Contains(PermissionCollection.NotAuthenticatedAccessOnly)) { throw new AuthorizeException(ErrorCode.AuthenticationOnlyAuthenticatedAccess); } }
protected bool AreUserAndFunctionIsValid() { IOptionsPlayIdentity identity = FCIdentity; bool result; if (FCIdentity == null) { result = false; } else { List <string> connections = UserToConnectionMapper.GetConnectionIdsByUser(identity.UserId); result = connections != null; } return(result); }
protected override bool UserAuthorized(IPrincipal user) { if (user != null && user.Identity.IsAuthenticated) { IOptionsPlayIdentity identity = (IOptionsPlayIdentity)user.Identity; if (_permissions.Length > 0 && !_permissions.All(m => identity.Permissions.Contains(m))) { return(false); } } else if (!_permissions.Contains(PermissionCollection.NotAuthenticatedAccessOnly)) { return(false); } return(true); }
public static IOptionsPlayIdentity GetIdentity() { IOptionsPlayIdentity optionsPlayIdentity = HttpContext.Current.User.Identity as IOptionsPlayIdentity; return(optionsPlayIdentity); }