private void CheckPermission() { UserAccessInfo userAccessInfo = WcfContext.Current.GetUserAccessInfo(); if (userAccessInfo == null) { throw new AuthenticationException("Not login or login timeout."); } this.CheckPermission(userAccessInfo, this.ApplicationCode, this.OperationCodes); }
private void CheckPermission(UserAccessInfo accessInfo, string applicationCode, string[] operationCodes) { if ((operationCodes != null) && (operationCodes.Length != 0)) { if (string.IsNullOrEmpty(applicationCode)) { throw new ArgumentIsNullOrEmptyException("Missing application code."); } List <RolePolicy> userRolePolicys = WcfContext.Current.GetUserAccessManager().GetUserRolePolicys(accessInfo.User.Id, applicationCode); if (!(((userRolePolicys != null) && (userRolePolicys.Count != 0)) && userRolePolicys.Any <RolePolicy>(t => (operationCodes.Contains <string>(t.OperationCode) && (t.State == 0))))) { throw new NoPermissionException("No Permission to operate."); } } }
private void CheckAccess(string value) { UserAccessManager userAccessManager = WcfContext.Current.GetUserAccessManager(); OperationKey operationKey = this.GetOperationKey(value); if (operationKey == null) { throw new ArgumentException("Invalid operation key."); } if (!userAccessManager.CheckAccess(operationKey.SessionId)) { throw new AuthenticationException("Not login or login timeout."); } User user = userAccessManager.GetUser(operationKey.SessionId, true); if (!this.IsUserActive(user)) { throw new AuthenticationException(string.Format("The user (Serial:{0}) is {1}.", user.Serial, user.Status)); } Organization org = userAccessManager.GetOrganization(operationKey.SessionId); if (!this.IsOrganizationActive(org)) { throw new AuthenticationException(string.Format("The organization (Name:{0}) is {1}.", org.Name, org.Status)); } UserAccess access = userAccessManager.FindUserAccessItem(operationKey.SessionId); if (access == null) { throw new AuthenticationException("Cannot find login session."); } userAccessManager.KeepAlive(operationKey.SessionId); UserAccessInfo info = new UserAccessInfo { Organization = org, User = user, UserAccess = access }; WcfContext.Current.Set("UserAccessInfo", info); WcfContext.Current.Set("OperationKey", operationKey); }