本文整理汇总了C#中DataService.CreateAuthenticator方法的典型用法代码示例。如果您正苦于以下问题:C# DataService.CreateAuthenticator方法的具体用法?C# DataService.CreateAuthenticator怎么用?C# DataService.CreateAuthenticator使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataService
的用法示例。
在下文中一共展示了DataService.CreateAuthenticator方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
IRepositoryFactory repositoryFactory = RepositoryFactory.Instance;
ISymmetricAlgorithmProvider symmetricAlgorithmProvider = SymmetricAlgorithmProvider.Instance;
using (var traceManager = new TraceManager("trace.txt"))
{
using (var dbContext = new KerberosStorageContext())
{
using (var unitOfWork = new UnitOfWork(dbContext, repositoryFactory))
{
var users =
unitOfWork.Repository<User, int>()
.Query()
.Filter(p => p.Email.Equals("[email protected]", StringComparison.OrdinalIgnoreCase))
.Get();
var user = users.FirstOrDefault();
if (user != null)
{
IAuthenticationService authenticationService = new AuthenticationService(
unitOfWork,
symmetricAlgorithmProvider,
traceManager);
var authenticationRequest = new AuthenticationRequest
{
ServerId = "authentication server",
TimeStamp = DateTime.Now,
UserId = user.Email
};
traceManager.Trace("Authentication Request Sent", authenticationRequest);
IAuthenticationReply authenticationReply = authenticationService.Authenticate(authenticationRequest);
traceManager.Trace("TGS encrypted received", Tuple.Create(authenticationReply.TgsBytes, authenticationReply.TgtBytes));
ITgsToken tgsToken = authenticationService.DecryptReply(user.Email, authenticationReply);
traceManager.Trace("TGS decrypted: ", tgsToken);
IAuthorizationService authorizationService = new AuthorizationService(
unitOfWork,
symmetricAlgorithmProvider,
traceManager);
byte[] authenticator = authorizationService.CreateAuthenticator(user.Email, tgsToken.SessionKey);
traceManager.Trace("Auth authenticator encrypted", authenticator);
var authorizationRequest = new AuthorizationRequest
{
AutheticatorBytes = authenticator,
TgtBytes = authenticationReply.TgtBytes
};
IAuthorizationReply authorizationReply = authorizationService.Authorize(authorizationRequest);
traceManager.Trace("Authorization reply received", Tuple.Create(authorizationReply.ServiceTicket, authorizationReply.ServiceToken));
IServiceToken serviceToken = authorizationService.DecryptReply(user.Email, authorizationReply, tgsToken.SessionKey);
traceManager.Trace("Service token decrypted", serviceToken);
IDataService dataService = new DataService(unitOfWork, symmetricAlgorithmProvider, traceManager);
authenticator = dataService.CreateAuthenticator(user.Email, serviceToken.SessionKey);
var dataServiceRequest = new DataServiceRequest
{
Authenticator = authenticator,
ServiceTicket = authorizationReply.ServiceTicket
};
traceManager.Trace("Data service request sent", dataServiceRequest);
IDataServiceReply dataServiceReply = dataService.GetAccess(dataServiceRequest);
ITimeStampContainer timeStampContainer = dataService.DecryptReply(user.Email, dataServiceReply, serviceToken.SessionKey);
if (Math.Abs((DateTime.UtcNow - new DateTime(timeStampContainer.TimeStamp, DateTimeKind.Utc)).Ticks) < new TimeSpan(1, 0, 0).Ticks)
{
traceManager.Trace("The operation has been completed successfully.");
}
}
}
}
}
}