Exemple #1
0
        /// <summary>
        /// Make a generic Endpoint visit
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="visit"></param>
        /// <returns>Activity</returns>
        protected void AuthenticateEndpointActivity(AuthEndpointVisit visit, ActivityType activityType,
                                                    NodeMethod method, out NodeVisit nodeVisit,
                                                    out string userToken, out Activity activity)
        {
            if (visit == null)
            {
                throw new ArgumentNullException("visit");
            }

            activity = new Activity(method, null, null, activityType, null, visit.IP, "Visit from endpoint version {0} for method {1}.",
                                    visit.Version, method.ToString());

            UserAccount userAccount = AccountManager.GetByName(visit.Credentials.UserName);

            if ((userAccount != null) && !userAccount.IsActive)
            {
                var message = string.Format("The user account \"{0}\" is not active on this node.",
                                            visit.Credentials.UserName);
                activity.AppendFormat(message);
                throw new ArgumentException(message);
            }

            activity.AppendFormat("Attempting to authenticate {0} from IP {1} using {2}.",
                                  visit.Credentials.UserName, visit.IP, visit.AuthMethod);

            // Get a token or fail trying
            userToken = AuthProvider.AuthenticateUser(visit.Credentials, visit.IP,
                                                      visit.AuthMethod);

            activity.AppendFormat("Successfully authenticated {0} with user token {1}.",
                                  visit.Credentials.UserName, userToken);

            //Always returns an account
            bool wasCreated;

            userAccount =
                AccountManager.GetOrCreate(visit.Credentials.UserName, true, out wasCreated);

            //Update the activity to created by the current user
            activity.ModifiedById = userAccount.Id;

            IDictionary <string, string> flowsIdToNameMap = _flowManager.GetAllFlowsIdToNameMap();

            nodeVisit = new NodeVisit(userAccount, visit.IP, flowsIdToNameMap);

            if (wasCreated)
            {
                activity.AppendFormat("Successfully created local user account for {0}.",
                                      visit.Credentials.UserName);
            }
            else
            {
                activity.AppendFormat("Successfully got local user account for {0}.",
                                      visit.Credentials.UserName);
            }
        }
Exemple #2
0
        /// <summary>
        /// Get Auth rewquest Visit
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <param name="domain"></param>
        /// <param name="method"></param>
        /// <returns></returns>
        public AuthEndpointVisit GetVisit(string username, string password, string domain, string method)
        {
            LOG.Debug(string.Format(
                          "Visit from (username: {0} password: *********** domain: {1} method: {2}",
                          username, domain, method));

            AuthEndpointVisit visit = GetVisit <AuthEndpointVisit>();

            visit.AuthMethod  = method;
            visit.Credentials = new AuthenticationCredentials(username, password, domain);

            LOG.Debug("Visit: " + visit);
            return(visit);
        }
 public virtual void ValidateVisitIsAuthenticated(NamedOrAuthEndpointVisit visit)
 {
     if (string.IsNullOrEmpty(visit.Token))
     {
         AuthEndpointVisit authEndpointVisit = new AuthEndpointVisit(visit);
         try
         {
             visit.Token = Authenticate(authEndpointVisit);
         }
         catch (Exception ex)
         {
             throw new AuthenticationException("Authentication failed.", ex);
         }
     }
 }
        /// <summary>
        /// Authenticate
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public string Authenticate(AuthEndpointVisit request)
        {
            //Create a visit from the request
            Activity activity = null;

            try
            {
                NodeVisit nodeVisit;
                string    token;
                AuthenticateEndpointActivity(request, ActivityType.Audit, NodeMethod.Authenticate,
                                             out nodeVisit, out token, out activity);

                return(token);
            }
            catch (Exception ex)
            {
                if (activity != null)
                {
                    activity.Append(ExceptionUtils.GetDeepExceptionMessage(ex));
                    activity.Type = ActivityType.Error;
                }
                if (ex is InvalidCredentialException)
                {
                    throw FaultProvider.GetFault(EndpointVersionType.EN20, ENExceptionCodeType.E_InvalidCredential,
                                                 ex.Message);
                }
                else
                {
                    throw FaultProvider.GetFault(request.Version, ex);
                }
            }
            finally
            {
                if (activity != null)
                {
                    ActivityManager.Log(activity);
                }
            }
        }
Exemple #5
0
        /// <summary>
        /// Authenticate
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="credential"></param>
        /// <param name="authenticationMethod"></param>
        /// <returns></returns>
        string INetworkNodeBinding.Authenticate(string userId, string credential, string authenticationMethod)
        {
            Init();
            LOG.Debug("Authenticate");

            #region Validate

            if (string.IsNullOrEmpty(userId) ||
                string.IsNullOrEmpty(credential))
            {
                throw _service11Provider.FaultProvider.GetFault(EndpointVersionType.EN11, ENExceptionCodeType.E_InvalidParameter,
                                                                "NULL Authenticate argument");
            }

            #endregion

            try
            {
                LOG.Debug("Getting visit");
                AuthEndpointVisit visit = _service11Provider.VisitProvider.GetVisit(userId,
                                                                                    credential,
                                                                                    null,
                                                                                    authenticationMethod);

                LOG.Debug("Authenticating using visit: " + visit);
                string token = _service11Provider.SecurityService.Authenticate(visit);

                LOG.Debug("Token: " + token);
                return(token);
            }
            catch (Exception ex)
            {
                LOG.Error("Error while authenticating", ex);
                throw _service11Provider.FaultProvider.GetFault(EndpointVersionType.EN11, ex);
            }
        }