ClearCanvas.Web.Enterprise.Authentication.LoginService.Login C# (CSharp) Method

Login() private method

private Login ( string userName, string password, string appName ) : ClearCanvas.Web.Enterprise.Authentication.SessionInfo
userName string
password string
appName string
return ClearCanvas.Web.Enterprise.Authentication.SessionInfo
		public SessionInfo Login(string userName, string password, string appName)
		{
			if (string.IsNullOrEmpty(userName))
				throw new ArgumentException(SR.UserIDIsEmpty);

			if (string.IsNullOrEmpty(password))
				throw new ArgumentException(SR.PasswordIsEmpty);

			Platform.CheckForEmptyString(password, "password");
			Platform.CheckForEmptyString(appName, "appName");

			SessionInfo session = null;

			Platform.GetService(
				delegate(IAuthenticationService service)
					{
						try
						{
							var request = new InitiateSessionRequest(userName, appName,
							                                         Dns.GetHostName(), password)
							              	{
							              		GetAuthorizations = true
							              	};

							InitiateSessionResponse response = service.InitiateSession(request);
							if (response != null)
							{
								var credentials = new LoginCredentials
								                  	{
								                  		UserName = userName,
								                  		DisplayName = response.DisplayName,
								                  		SessionToken = response.SessionToken,
								                  		Authorities = response.AuthorityTokens,
								                  		DataAccessAuthorityGroups = response.DataGroupOids,
								                  		EmailAddress = response.EmailAddress
								                  	};
								var user = new CustomPrincipal(new CustomIdentity(userName, response.DisplayName), credentials);
								Thread.CurrentPrincipal = user;

								session = new SessionInfo(user);
								session.User.WarningMessages = response.WarningMessages;

								SessionCache.Instance.AddSession(response.SessionToken.Id, session);

								LoginServiceAuditLog.AuditSuccess(userName, response.DisplayName, response.SessionToken.Id);
								Platform.Log(LogLevel.Info, "{0} has successfully logged in.", userName);
							}
						}
						catch (FaultException<PasswordExpiredException> ex)
						{
							throw ex.Detail;
						}
						catch (FaultException<UserAccessDeniedException> ex)
						{
							LoginServiceAuditLog.AuditFailure(userName);
								
							throw ex.Detail;
						}
						catch (FaultException<RequestValidationException> ex)
						{
							throw ex.Detail;
						}
					}
				);

			return session;
		}

Usage Example

Example #1
0
        /// <summary>
        /// Logs in and intializes the session using the given username and password.
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <param name="appName"></param>
        /// <param name="redirect"></param>
        public static SessionInfo InitializeSession(string username, string password, string appName, bool redirect)
        {
            using (LoginService service = new LoginService())
            {
                SessionInfo session = service.Login(username, password, appName);
                InitializeSession(session);
                Platform.Log(LogLevel.Info, "[{0}]: {1} has successfully logged in.", appName, username);

                if(redirect) HttpContext.Current.Response.Redirect(FormsAuthentication.GetRedirectUrl(username, false), false);
                return session;
            }
        }
All Usage Examples Of ClearCanvas.Web.Enterprise.Authentication.LoginService::Login