Exemple #1
0
        /// <summary>
        /// Displays the dialog.
        /// </summary>
        public UserIdentity ShowDialog(IUserIdentity identity, string caption)
        {
            if (!String.IsNullOrEmpty(caption))
            {
                this.Text = caption;
            }

            if (identity != null)
            {
                UserNameIdentityToken token = identity.GetIdentityToken() as UserNameIdentityToken;

                if (token != null)
                {
                    UserNameTB.Text = token.UserName;
                    PasswordTB.Text = token.DecryptedPassword;
                }
            }

            if (ShowDialog() != DialogResult.OK)
            {
                return(null);
            }

            return(new UserIdentity(UserNameTB.Text, PasswordTB.Text));
        }
        /// <summary>
        /// Displays the dialog.
        /// </summary>
        public UserIdentity ShowDialog(IUserIdentity identity, string caption)
        {
            if (!String.IsNullOrEmpty(caption))
            {
                this.Text = caption;
            }

            if (identity != null)
            {
                UserNameIdentityToken token = identity.GetIdentityToken() as UserNameIdentityToken;

                if (token != null)
                {
                    UserNameTB.Text = token.UserName;
                    PasswordTB.Text = token.DecryptedPassword;
                }
            }

            if (ShowDialog() != DialogResult.OK)
            {
                return null;
            }

            return new UserIdentity(UserNameTB.Text, PasswordTB.Text);
        }
Exemple #3
0
        /// <summary>
        /// Returns a localized client for the specified locale id.
        /// </summary>
        /// <param name="identity">The identity.</param>
        /// <param name="localeId">The locales id.</param>
        /// <returns>A localized client.</returns>
        public ComClient GetLocalizedClient(IUserIdentity identity, int localeId)
        {
            // check if a logon is required.
            string userName = null;

            if (identity != null && identity.TokenType == UserTokenType.UserName)
            {
                userName = (identity.GetIdentityToken() as UserNameIdentityToken).UserName;
            }

            if (String.IsNullOrEmpty(userName) && localeId == ComUtils.LOCALE_SYSTEM_DEFAULT)
            {
                Utils.Trace("COM Client Selected: DEFAULT (no match for locale)");
                return(DefaultClient);
            }

            // create the key.
            StringBuilder buffer = new StringBuilder();

            buffer.Append(localeId);

            if (!String.IsNullOrEmpty(userName))
            {
                buffer.Append(':');
                buffer.Append(userName);
            }

            string key = buffer.ToString();

            if (m_localizedClients == null)
            {
                m_localizedClients = new Dictionary <string, ComClient>();
            }

            ComClient client = null;

            if (!m_localizedClients.TryGetValue(key, out client))
            {
                client              = CreateClient();
                client.Key          = key;
                client.LocaleId     = localeId;
                client.UserIdentity = identity;
                client.CreateInstance();
                m_localizedClients[key] = client;
            }

            // Utils.Trace("COM Client Seleted: {0}", key);
            return(client);
        }
        /// <summary>
        /// Sets the current user identity.
        /// </summary>
        public void SetUserIdentity(IUserIdentity identity)
        {
            string methodName = "IOPCSecurityPrivate.Logon";

            try
            {
                IOPCSecurityPrivate server = BeginComCall <IOPCSecurityPrivate>(methodName, true);

                if (server != null)
                {
                    int bAvailable = 0;
                    server.IsAvailablePriv(out bAvailable);

                    if (bAvailable != 0)
                    {
                        bool logoff = true;

                        if (identity != null && identity.TokenType == UserTokenType.UserName)
                        {
                            UserNameIdentityToken identityToken = identity.GetIdentityToken() as UserNameIdentityToken;

                            if (identityToken != null)
                            {
                                server.Logon(identityToken.UserName, identityToken.Password.ToString());
                                logoff = false;
                            }
                        }

                        if (logoff)
                        {
                            server.Logoff();
                        }
                    }
                }
            }
            catch (Exception e)
            {
                ComCallError(methodName, e);
            }
            finally
            {
                EndComCall(methodName);
            }
        }
        /// <summary>
        /// Updates the local displayed in the control.
        /// </summary>
        private void UpdateUserIdentity(Session session)
        {
            UserNameTB.Text = null;
            PasswordTB.Text = null;

            // get the current identity.
            IUserIdentity identity = session.Identity;

            if (identity != null && identity.TokenType == UserTokenType.UserName)
            {
                UserNameIdentityToken token = identity.GetIdentityToken() as UserNameIdentityToken;

                if (token != null)
                {
                    UserNameTB.Text = token.UserName;
                    PasswordTB.Text = token.DecryptedPassword;
                }
            }
        }
Exemple #6
0
        private IUserIdentity ValidateJwt(JwtEndpointParameters parameters, string jwt)
        {
            IUserIdentity identity = null;

            try
            {
                identity = JwtUtils.ValidateToken(new Uri(parameters.AuthorityUrl), Configuration.ApplicationUri, jwt);
            }
            catch (Exception)
            {
                identity = JwtUtils.ValidateToken(new Uri(parameters.AuthorityUrl), Namespaces.OAuth2SiteResourceUri, jwt);
            }

            string scopes = String.Empty;

            IssuedIdentityToken jwtToken = identity.GetIdentityToken() as IssuedIdentityToken;

            if (jwtToken != null)
            {
                // find the subject of the SAML assertion.
                JwtSecurityToken token = new JwtSecurityToken(new UTF8Encoding(false).GetChars(jwtToken.DecryptedTokenData).ToString());
                foreach (var claim in token.Claims)
                {
                    switch (claim.Type)
                    {
                    case "scope": { scopes += claim.Value.ToString(); break; }
                    }
                }
            }

            if (scopes.Contains("gdsadmin"))
            {
                return(new RoleBasedIdentity(identity, GdsRole.GdsAdmin));
            }

            if (scopes.Contains("appadmin"))
            {
                return(new RoleBasedIdentity(identity, GdsRole.ApplicationAdmin));
            }

            return(new RoleBasedIdentity(identity, GdsRole.ApplicationUser));
        }
Exemple #7
0
 public UserIdentityToken GetIdentityToken()
 {
     return(m_identity.GetIdentityToken());
 }
Exemple #8
0
        /// <summary>
        /// Returns a localized client for the specified locale id.
        /// </summary>
        /// <param name="identity">The identity.</param>
        /// <param name="localeId">The locales id.</param>
        /// <returns>A localized client.</returns>
        public ComClient GetLocalizedClient(IUserIdentity identity, int localeId)
        {
            // check if a logon is required.
            string userName = null;

            if (identity != null && identity.TokenType == UserTokenType.UserName)
            {
                userName = (identity.GetIdentityToken() as UserNameIdentityToken).UserName;
            }

            if (String.IsNullOrEmpty(userName) && localeId == ComUtils.LOCALE_SYSTEM_DEFAULT)
            {
                Utils.Trace("COM Client Selected: DEFAULT (no match for locale)");
                return DefaultClient;
            }

            // create the key.
            StringBuilder buffer = new StringBuilder();
            buffer.Append(localeId);
            
            if (!String.IsNullOrEmpty(userName))
            {
                buffer.Append(':');
                buffer.Append(userName);
            }

            string key = buffer.ToString();

            if (m_localizedClients == null)
            {
                m_localizedClients = new Dictionary<string, ComClient>();
            }

            ComClient client = null;

            if (!m_localizedClients.TryGetValue(key, out client))
            {
                client = CreateClient();
                client.Key = key;
                client.LocaleId = localeId;
                client.UserIdentity = identity;
                client.CreateInstance();
                m_localizedClients[key] = client;
            }

            // Utils.Trace("COM Client Seleted: {0}", key);
            return client;
        }
 /// <summary>
 /// Convert user identity to service model
 /// </summary>
 /// <param name="identity"></param>
 /// <returns></returns>
 public static CredentialModel ToServiceModel(this IUserIdentity identity) =>
 ToServiceModel(identity?.GetIdentityToken());
        /// <summary>
        /// Sets the current user identity.
        /// </summary>
        public void SetUserIdentity(IUserIdentity identity)
        {
            string methodName = "IOPCSecurityPrivate.Logon";

            try
            {
                IOPCSecurityPrivate server = BeginComCall<IOPCSecurityPrivate>(methodName, true);

                if (server != null)
                {
                    int bAvailable = 0;
                    server.IsAvailablePriv(out bAvailable);

                    if (bAvailable != 0)
                    {
                        bool logoff = true;

                        if (identity != null && identity.TokenType == UserTokenType.UserName)
                        {
                            UserNameIdentityToken identityToken = identity.GetIdentityToken() as UserNameIdentityToken;

                            if (identityToken != null)
                            {
                                server.Logon(identityToken.UserName, identityToken.Password.ToString());
                                logoff = false;
                            }
                        }

                        if (logoff)
                        {
                            server.Logoff();
                        }
                    }
                }
            }
            catch (Exception e)
            {
                ComCallError(methodName, e);
            }
            finally
            {
                EndComCall(methodName);
            }
        }
 /// <summary>
 /// Convert user identity to service model
 /// </summary>
 /// <param name="identity"></param>
 /// <param name="serializer"></param>
 /// <returns></returns>
 public static CredentialModel ToServiceModel(this IUserIdentity identity, IJsonSerializer serializer)
 {
     return(ToServiceModel(identity?.GetIdentityToken(), serializer));
 }