public void LoginTestMethod1() { Configuration.Configure(); AccountBussiness accountBussines = new AccountBussiness(); SignInMessage msg = new SignInMessage(); msg.UserName = "******"; RSAEncryptionCreator encryption = new RSAEncryptionCreator(); msg.Password = encryption.PublicEncryption("123"); msg.ClientId = "1"; var result = accountBussines.Authenticate(msg); Assert.AreNotEqual(result.HasError, true); Assert.AreNotEqual(result.IdentityToken.Signature, string.Empty); TokenValidator validator = new TokenValidator(); var tokenValidation = validator.ValiateIdentityToken(result.IdentityToken); var strToken = result.IdentityToken.ToString(); IdentityToken cToken = new IdentityToken(strToken); var strCtoken = cToken.ToString(); Assert.AreEqual(strToken, strCtoken); Assert.AreEqual(tokenValidation.IsError, true); }
public SecurityResourceDtoContainer MenuList(Common.Message.AuthorizationRequest request) { SecurityResourceDtoContainer container = new SecurityResourceDtoContainer(); TokenValidator tokenValidator = new TokenValidator(); PermissionTDataAccess permissionDa = new PermissionTDataAccess(); var validationResult = tokenValidator.ValiateIdentityToken(request.IdentityToken); if (validationResult.IsError) { container.Response.AddBusinessException(validationResult.Error, Framework.Common.Service.Message.BusinessExceptionEnum.Validation); return(container); } else { ResourceTDataAccess resource = new ResourceTDataAccess(); int userId = 0; int.TryParse(request.IdentityToken.SubjectId, out userId); var menuItemList = resource.GetMenuAccessList(request.AppDomainId, userId); // container.SecurityResourceDtoList.AddRange(menuItemList); foreach (var item in menuItemList) { permissionDa.AddResources(item, container.SecurityResourceDtoList); } // container.SecurityResourceDtoList.AddRange(submenuList); } return(container); }
public Common.Message.AuthorizationResult CheckAccess(Common.Message.AuthorizationRequest request) { AuthorizationResult result = new AuthorizationResult(); TokenValidator tokenValidator = new TokenValidator(); var validationResult = tokenValidator.ValiateIdentityToken(request.IdentityToken); if (validationResult.IsError) { result.ErrorMessage = validationResult.Error; return(result); } AccessTokenGenerator generator = new AccessTokenGenerator(); var accessToken = generator.GenerateToken(request.IdentityToken, request.Resource); result.AccessToken = accessToken; return(result); }
public IdentityToken ExpireToken(IdentityToken token) { SessionBussiness sessionBs = new SessionBussiness(); TokenValidator tokenValidator = new TokenValidator(); var validationResult = tokenValidator.ValiateIdentityToken(token); if (validationResult.IsError) { return(token); } if (token.HasLogin) { sessionBs.ExpireSession(token.SessionId); token.HasLogin = false; TokenSigner.SignIdentityToken(token); } return(token); }
public SecurityResourceDtoContainer AccessList(Common.Message.AuthorizationRequest request) { SecurityResourceDtoContainer container = new SecurityResourceDtoContainer(); TokenValidator tokenValidator = new TokenValidator(); var validationResult = tokenValidator.ValiateIdentityToken(request.IdentityToken); if (validationResult.IsError) { container.Response.AddBusinessException(validationResult.Error, Framework.Common.Service.Message.BusinessExceptionEnum.Validation); return(container); } else { ResourceTDataAccess resource = new ResourceTDataAccess(); int userId = 0; int.TryParse(request.IdentityToken.SubjectId, out userId); var resourceList = resource.GetResourceAccessList(request.ResourceTypeId, request.AppDomainId, userId); container.SecurityResourceDtoList.AddRange(resourceList); } return(container); }
public Common.Message.TokenValidationResult ValidateIdentityToken(Common.Message.IdentityToken token) { TokenValidator validator = new TokenValidator(); return(validator.ValiateIdentityToken(token)); }