public InitiateSessionResponse InitiateSession(InitiateSessionRequest request) { bool ok = Membership.ValidateUser(request.UserName, request.Password); if (ok) { Guid tokenId = Guid.NewGuid(); var token = new SessionToken(tokenId.ToString(), Platform.Time + ServerPlatform.WebSessionTimeout); string[] authority = Roles.GetRolesForUser(request.UserName); string displayName = request.UserName; #if STANDALONE var list = new List <string>(); list.AddRange(authority); list.Add(Enterprise.Authentication.AuthorityTokens.Study.ViewImages); list.Add("Viewer/Visible"); list.Add("Viewer/Clinical"); authority = list.ToArray(); #endif var rsp = new InitiateSessionResponse(token, authority, new Guid[0], displayName, string.Empty); SessionTokenManager.Instance.AddSession(token); return(rsp); } throw new FaultException <UserAccessDeniedException>(new UserAccessDeniedException()); }
public InitiateSessionResponse InitiateSession(InitiateSessionRequest request) { bool ok = Membership.ValidateUser(request.UserName, request.Password); if (ok) { Guid tokenId = Guid.NewGuid(); var token = new SessionToken(tokenId.ToString(), Platform.Time + ServerPlatform.WebSessionTimeout); string[] authority = Roles.GetRolesForUser(request.UserName); string displayName = request.UserName; var rsp = new InitiateSessionResponse(token, authority, new Guid[0], displayName, string.Empty); SessionTokenManager.Instance.AddSession(token); return(rsp); } throw new FaultException <UserAccessDeniedException>(new UserAccessDeniedException()); }
private IPrincipal InitiateSession(string password) { IPrincipal principal = null; Platform.GetService <IAuthenticationService>( delegate(IAuthenticationService service) { // obtain session InitiateSessionResponse response = service.InitiateSession( new InitiateSessionRequest(_userName, _application, _hostName, password, true)); // create principal principal = DefaultPrincipal.CreatePrincipal( new GenericIdentity(_userName), response.SessionToken, response.AuthorityTokens); }); return(principal); }
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; // Note: need to insert into the cache before calling SessionInfo.Validate() SessionCache.Instance.AddSession(response.SessionToken.Id, session); session.Validate(); Platform.Log(LogLevel.Info, "{0} has successfully logged in.", userName); } } catch (FaultException <PasswordExpiredException> ex) { throw ex.Detail; } catch (FaultException <UserAccessDeniedException> ex) { throw ex.Detail; } catch (FaultException <RequestValidationException> ex) { throw ex.Detail; } } ); return(session); }