Esempio n. 1
0
        public AuthenticatedToken Authenticate()
        {
            try
            {
                ApplicationAuthenticationContext appContext = new ApplicationAuthenticationContext
                {
                    name = APPLICATION_NAME
                };

                // Provide the password associated with the application, as set-up in Crowd.
                PasswordCredential pwdApp = new PasswordCredential
                {
                    credential = APPLICATION_PWD
                };
                appContext.credential = pwdApp;

                // Authenticate the application (will fire a SOAPException if authentication fails).
                return(this._securityServer.authenticateApplication(appContext));
            }
            catch (SoapException soapException)
            {
                MessageBox.Show(soapException.Message, soapException.Detail.FirstChild.Name, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(null);
            }
        }
        private AuthenticatedToken GetAuthenticatedToken()
        {
            var passwordCredentials = new PasswordCredential {
                credential = _apiPassword
            };
            var appContext = new ApplicationAuthenticationContext
            {
                name       = _applicationName,
                credential = passwordCredentials
            };

            try
            {
                return(_securityServer.authenticateApplication(appContext));
            }
            catch (WebException e)
            {
                throw new AuthenticatedUserClientException("Unable to connect to the Crowd API.", e);
            }
            catch (SoapException e)
            {
                throw new AuthenticatedUserClientException("Unable to authenticate with the Crowd API.", e);
            }
        }
Esempio n. 3
0
        public bool Authenticate(string username,
                                 string password,
                                 out SOAPPrincipal principal)
        {
            bool authenticated = false;

            principal = null;

            ApplicationAuthenticationContext appContext = new ApplicationAuthenticationContext
            {
                name = APPLICATION_NAME
            };

            // Provide the password associated with the application, as set-up in Crowd.
            PasswordCredential pwdApp = new PasswordCredential
            {
                credential = APPLICATION_PWD
            };

            appContext.credential = pwdApp;

            try
            {
                // Authenticate the application (will fire a SOAPException if authentication fails).
                AuthenticatedToken appToken = _securityServer.authenticateApplication(appContext);

                if (appToken != null)
                {
                    // Set-up authentication context for the principal (user)
                    UserAuthenticationContext userContext = new UserAuthenticationContext
                    {
                        application = APPLICATION_NAME,
                        name        = username
                    };

                    // Provide the password for authenticating this principal (user)
                    PasswordCredential pwdPrincipal = new PasswordCredential
                    {
                        credential = password
                    };
                    userContext.credential = pwdPrincipal;

                    // Authenticate the principal (will fire a SOAPException if authentication fails).
                    string principalToken = _securityServer.authenticatePrincipal(appToken, userContext);

                    if (!string.IsNullOrEmpty(principalToken))
                    {
                        // Find some more details about this authentication user.
                        principal = _securityServer.findPrincipalByToken(appToken, principalToken);

                        authenticated = true;
                    }
                }
            }

            catch (SoapException soapException)
            {
                // Handle Authentication/SOAP Errors here...
                if (soapException.Detail.FirstChild.Name == "InvalidAuthenticationException")
                {
                    MessageBox.Show("Błędny login lub hasło", "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    // throw;
                }
                else
                {
                    MessageBox.Show(soapException.Message, soapException.Detail.FirstChild.Name, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                #region ExceptionInfo
                // Consult soapException.Detail.FirstChild.Name for further details:

                // This may be set to one of:
                //      RemoteException
                //      InvalidAuthenticationException
                //      InvalidAuthorizationTokenException
                //      InactiveAccountException
                //      InvalidTokenException
                #endregion
            }
            catch (Exception ex)
            {
                // Handle all other errors here...
                MessageBox.Show(ex.Message);
            }

            return(authenticated);
        }