public bool Evaluate(EvaluationContext context, ref object state)
        {
            object obj;

            if (!context.Properties.TryGetValue("Identities", out obj))
            {
                return(false);
            }

            IList <IIdentity> identities = obj as IList <IIdentity>;

            if (obj == null)
            {
                return(false);
            }

            // find the matching identity
            IIdentity clientIdentity = CollectionUtils.SelectFirst(identities,
                                                                   delegate(IIdentity i) { return(i.Name == _userName); });

            if (clientIdentity == null)
            {
                return(false);
            }

            // set the principal
            context.Properties["Principal"] = DefaultPrincipal.CreatePrincipal(clientIdentity, _sessionToken);

            return(true);
        }
Exemplo n.º 2
0
        private static LoginResult DoLogin(string userName, string password)
        {
            try
            {
                Platform.Log(LogLevel.Debug, "Attempting login...");

                var result = LoginResult.None;
                Platform.GetService(
                    delegate(IAuthenticationService service)
                {
                    var request = new InitiateSessionRequest(userName, ProductInformation.Component, Dns.GetHostName(), password)
                    {
                        GetAuthorizations = true
                    };
                    var response = service.InitiateSession(request);

                    if (response.SessionToken == null)
                    {
                        throw new Exception("Invalid session token returned from authentication service.");
                    }

                    // if the call succeeded, set a default principal object on this thread, containing
                    // the set of authority tokens for this user
                    Thread.CurrentPrincipal = DefaultPrincipal.CreatePrincipal(
                        new GenericIdentity(userName),
                        response.SessionToken,
                        response.AuthorityTokens);

                    result = new LoginResult(userName, response.SessionToken);
                });

                Platform.Log(LogLevel.Debug, "Login attempt was successful.");
                return(result);
            }
            catch (FaultException <UserAccessDeniedException> e)
            {
                Platform.Log(LogLevel.Debug, e.Detail, "Login attempt failed.");
                throw e.Detail;
            }
            catch (FaultException <PasswordExpiredException> e)
            {
                Platform.Log(LogLevel.Debug, e.Detail, "Login attempt failed.");
                throw e.Detail;
            }
        }
Exemplo n.º 3
0
 public AppContext()
 {
     User = new DefaultPrincipal(new DefaultIdentity());
 }