Example #1
0
        public async Task AuthenticateSamlUserAsync_SamlDisabled_AuthenticationException()
        {
            // Arrange

            // Act
            await _authenticationRepository.AuthenticateSamlUserAsync("fakeSamlResponce");

            // Assert
            // Exception
        }
Example #2
0
        public async Task <IHttpActionResult> PostSessionSingleSignOn([FromBody] string samlResponse, bool force = false)
        {
            try
            {
                var user = await _authenticationRepository.AuthenticateSamlUserAsync(samlResponse);

                return(await RequestSessionTokenAsync(user, force, true));
            }
            catch (FederatedAuthenticationException ex)
            {
                await _log.LogInformation(WebApiConfig.LogSourceSessions, $"{ex.Message}.{ex.InnerException?.Message ?? ""}");

                if (ex.ErrorCode == FederatedAuthenticationErrorCode.WrongFormat)
                {
                    throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.CreateHttpError(ErrorCodes.FederatedAuthenticationException)));
                }

                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.Unauthorized, ex.CreateHttpError(ErrorCodes.FederatedAuthenticationException)));
            }
            catch (AuthenticationException ex)
            {
                await _log.LogInformation(WebApiConfig.LogSourceSessions, ex.Message);

                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.Unauthorized, ex.CreateHttpError()));
            }
            catch (ApplicationException ex)
            {
                await _log.LogInformation(WebApiConfig.LogSourceSessions, ex.Message);

                return(Conflict());
            }
            catch (FormatException ex)
            {
                await _log.LogInformation(WebApiConfig.LogSourceSessions, ex.Message);

                return(BadRequest());
            }
            catch (Exception ex)
            {
                await _log.LogError(WebApiConfig.LogSourceSessions, ex);

                return(InternalServerError());
            }
        }