Ejemplo n.º 1
0
        public static void DeleteExtentrixWindowsCredentials(Page page, LogLocationEnum LogLocation, SPUser user)
        {
            try
            {
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    using (SPSite site = new SPSite(SPContext.Current.Site.ID))
                    {
                        using (SPWeb web = site.OpenWeb())
                        {
                            SPServiceContext context = SPServiceContext.GetContext(SPServiceApplicationProxyGroup.Default, SPSiteSubscriptionIdentifier.Default);

                            SecureStoreServiceProxy ssp = new SecureStoreServiceProxy();
                            ISecureStore iss            = ssp.GetSecureStore(context);

                            SPContext.Current.Web.AllowUnsafeUpdates = true;
                            //SPUtility.ValidateFormDigest();

                            iss.DeleteUserCredentials(Constants.TargetAppID, GetSSClaim(user));
                            SPContext.Current.Web.AllowUnsafeUpdates = false;
                        }
                    }
                });
            }
            catch (SecureStoreServiceCredentialsNotFoundException ex)
            {
                Logger.Default.Error(LogLocation, ex.Message, ex);
            }
            catch (Exception ex)
            {
                Logger.Default.Info(LogLocation, "SecureStore: Exception delete Windows Credentials");
                Logger.Default.Error(LogLocation, ex.Message, ex);
            }
        }
Ejemplo n.º 2
0
        public static Credentials GetExtentrixWindowsCredentials(Page page, LogLocationEnum LogLocation, SPUser user)
        {
            WindowsCredentials extentrixCredentials = null;

            SecureStoreCredentialCollection ssCreds = null;
            SPServiceContext context = SPServiceContext.GetContext(SPServiceApplicationProxyGroup.Default, SPSiteSubscriptionIdentifier.Default);

            SecureStoreServiceProxy ssp = new SecureStoreServiceProxy();
            ISecureStore            iss = ssp.GetSecureStore(context);

            try
            {
                ssCreds = iss.GetCredentials(Constants.TargetAppID);

                if (ssCreds != null && ssCreds.Count() > 0)
                {
                    extentrixCredentials = new WindowsCredentials();
                    IList <TargetApplicationField> applicationFields = GetTargetApplicationFields(Constants.TargetAppID);

                    foreach (TargetApplicationField taf in applicationFields)
                    {
                        switch (taf.Name)
                        {
                        case "Windows User Name":
                            extentrixCredentials.UserName =
                                ReadSecureString(ssCreds[applicationFields.IndexOf(taf)].Credential);
                            break;

                        case "Windows Password":
                            extentrixCredentials.Password =
                                ReadSecureString(ssCreds[applicationFields.IndexOf(taf)].Credential);
                            break;

                        case "Domain":
                            extentrixCredentials.Domain =
                                ReadSecureString(ssCreds[applicationFields.IndexOf(taf)].Credential);
                            break;
                        }
                    }
                }
            }
            catch (SecureStoreServiceCredentialsNotFoundException ex)
            {
                Logger.Default.Error(LogLocation, ex.Message, ex);
            }
            catch (Exception ex)
            {
                Logger.Default.Info(LogLocation, "SecureStore: Exception getting Windows Credentials");
                Logger.Default.Error(LogLocation, ex.Message, ex);
            }

            return(extentrixCredentials);
        }
Ejemplo n.º 3
0
        public static void SetExtentrixWindowsCredentials(LogLocationEnum LogLocation, SPUser user, WindowsCredentials extentrixCredentials)
        {
            try
            {
                IList <TargetApplicationField> applicationFields = GetTargetApplicationFields(Constants.TargetAppID);
                IList <ISecureStoreCredential> creds             = new List <ISecureStoreCredential>(applicationFields.Count);

                using (SecureStoreCredentialCollection credentials = new SecureStoreCredentialCollection(creds))
                {
                    foreach (TargetApplicationField taf in applicationFields)
                    {
                        switch (taf.Name)
                        {
                        case "Windows User Name":
                            creds.Add(new SecureStoreCredential(MakeSecureString(extentrixCredentials.UserName),
                                                                SecureStoreCredentialType.WindowsUserName));
                            break;

                        case "Windows Password":
                            creds.Add(new SecureStoreCredential(MakeSecureString(extentrixCredentials.Password),
                                                                SecureStoreCredentialType.WindowsPassword));
                            break;

                        case "Domain":
                            creds.Add(new SecureStoreCredential(MakeSecureString(extentrixCredentials.Domain)
                                                                , SecureStoreCredentialType.Generic));
                            break;
                        }
                    }

                    SPSecurity.RunWithElevatedPrivileges(delegate()
                    {
                        using (SPSite site = new SPSite(SPContext.Current.Site.ID))
                        {
                            using (SPWeb web = site.OpenWeb())
                            {
                                SPServiceContext context    = SPServiceContext.GetContext(SPServiceApplicationProxyGroup.Default, SPSiteSubscriptionIdentifier.Default);
                                SecureStoreServiceProxy ssp = new SecureStoreServiceProxy();
                                ISecureStore iss            = ssp.GetSecureStore(context);

                                iss.SetUserCredentials(Constants.TargetAppID, GetSSClaim(user), credentials);
                            }
                        }
                    });
                }
            }
            catch (Exception ex)
            {
                Logger.Default.Info(LogLocation, "SecureStore: Exception setting windows credentials");
                Logger.Default.Error(LogLocation, ex.Message, ex);
            }
        }
Ejemplo n.º 4
0
        public void Info(LogLocationEnum location, string message)
        {
            if (!WSConstants.LOGINFO)
            {
                //return;
            }
            switch (location)
            {
            case LogLocationEnum.Default:
                SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory("Extentrix", TraceSeverity.Monitorable, EventSeverity.Information), TraceSeverity.Monitorable, message);
                break;

            case LogLocationEnum.Text:
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    _log.Info(message);
                });
                break;

            case LogLocationEnum.EventViewer:
                try
                {
                    SPSecurity.RunWithElevatedPrivileges(delegate()
                    {
                        string source = "Extentrix Web Interface for SharePoint";
                        string log    = "EXTWISP";

                        if (!EventLog.SourceExists(source))
                        {
                            EventLog.CreateEventSource(source, log);
                        }

                        EventLog aLog = new EventLog(log);
                        aLog.Source   = source;
                        aLog.Log      = log;
                        aLog.WriteEntry(source + ": " + message, EventLogEntryType.Information);
                        aLog.Close();
                    });
                }
                catch (Exception e)
                {
                    SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory("Extentrix", TraceSeverity.Unexpected, EventSeverity.Error), TraceSeverity.Unexpected, e.Message, e.StackTrace);
                }
                break;

            default:
                SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory("Extentrix", TraceSeverity.Monitorable, EventSeverity.Information), TraceSeverity.Monitorable, message);
                break;
            }
        }