Search in sources :

Example 61 with AuthenticationException

use of org.springframework.security.core.AuthenticationException in project spring-security by spring-projects.

the class HttpStatusServerEntryPointTests method setup.

@BeforeEach
public void setup() {
    this.request = MockServerHttpRequest.get("/").build();
    this.exchange = MockServerWebExchange.from(this.request);
    this.authException = new AuthenticationException("") {
    };
    this.entryPoint = new HttpStatusServerEntryPoint(HttpStatus.UNAUTHORIZED);
}
Also used : AuthenticationException(org.springframework.security.core.AuthenticationException) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 62 with AuthenticationException

use of org.springframework.security.core.AuthenticationException in project spring-security by spring-projects.

the class AuthenticationEventTests method testRejectsNullAuthentication.

@Test
public void testRejectsNullAuthentication() {
    AuthenticationException exception = new DisabledException("TEST");
    assertThatIllegalArgumentException().isThrownBy(() -> new AuthenticationFailureDisabledEvent(null, exception));
}
Also used : AuthenticationException(org.springframework.security.core.AuthenticationException) DisabledException(org.springframework.security.authentication.DisabledException) Test(org.junit.jupiter.api.Test)

Example 63 with AuthenticationException

use of org.springframework.security.core.AuthenticationException in project spring-security by spring-projects.

the class AuthenticationFilter method doFilterInternal.

@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
    if (!this.requestMatcher.matches(request)) {
        if (logger.isTraceEnabled()) {
            logger.trace("Did not match request to " + this.requestMatcher);
        }
        filterChain.doFilter(request, response);
        return;
    }
    try {
        Authentication authenticationResult = attemptAuthentication(request, response);
        if (authenticationResult == null) {
            filterChain.doFilter(request, response);
            return;
        }
        HttpSession session = request.getSession(false);
        if (session != null) {
            request.changeSessionId();
        }
        successfulAuthentication(request, response, filterChain, authenticationResult);
    } catch (AuthenticationException ex) {
        unsuccessfulAuthentication(request, response, ex);
    }
}
Also used : AuthenticationException(org.springframework.security.core.AuthenticationException) Authentication(org.springframework.security.core.Authentication) HttpSession(jakarta.servlet.http.HttpSession)

Example 64 with AuthenticationException

use of org.springframework.security.core.AuthenticationException in project dhis2-core by dhis2.

the class DhisApiTokenAuthenticationEntryPoint method commence.

@Override
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException {
    _commence(response);
    HandlerExceptionResolver handlerExceptionResolver;
    try {
        handlerExceptionResolver = (HandlerExceptionResolver) applicationContext.getBean("handlerExceptionResolver");
        handlerExceptionResolver.resolveException(request, response, null, authException);
    } catch (Exception e) {
        log.error("Could not find a HandlerExceptionResolver bean!");
    }
}
Also used : HandlerExceptionResolver(org.springframework.web.servlet.HandlerExceptionResolver) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) AuthenticationException(org.springframework.security.core.AuthenticationException)

Example 65 with AuthenticationException

use of org.springframework.security.core.AuthenticationException in project midpoint by Evolveum.

the class PageRegistrationConfirmation method init.

private void init(final PageParameters pageParameters) {
    PageParameters params = pageParameters;
    if (params == null) {
        params = getPageParameters();
    }
    OperationResult result = new OperationResult(OPERATION_FINISH_REGISTRATION);
    if (params == null) {
        LOGGER.error("Confirmation link is not valid. No credentials provided in it");
        String msg = createStringResource("PageSelfRegistration.invalid.registration.link").getString();
        getSession().error(createStringResource(msg));
        result.recordFatalError(msg);
        initLayout(result);
        return;
    }
    StringValue userNameValue = params.get(SchemaConstants.USER_ID);
    Validate.notEmpty(userNameValue.toString());
    StringValue tokenValue = params.get(SchemaConstants.TOKEN);
    Validate.notEmpty(tokenValue.toString());
    try {
        UserType user = checkUserCredentials(userNameValue.toString(), tokenValue.toString(), result);
        PrismObject<UserType> administrator = getAdministratorPrivileged(result);
        assignDefaultRoles(user.getOid(), administrator, result);
        result.computeStatus();
        if (result.getStatus() == OperationResultStatus.FATAL_ERROR) {
            LOGGER.error("Failed to assign default roles, {}", result.getMessage());
        } else {
            NonceType nonceClone = user.getCredentials().getNonce().clone();
            removeNonceAndSetLifecycleState(user.getOid(), nonceClone, administrator, result);
            assignAdditionalRoleIfPresent(user.getOid(), nonceClone, administrator, result);
            result.computeStatus();
        }
        initLayout(result);
    } catch (CommonException | AuthenticationException e) {
        result.computeStatus();
        initLayout(result);
    }
}
Also used : AuthenticationException(org.springframework.security.core.AuthenticationException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) CommonException(com.evolveum.midpoint.util.exception.CommonException) PageParameters(org.apache.wicket.request.mapper.parameter.PageParameters) StringValue(org.apache.wicket.util.string.StringValue)

Aggregations

AuthenticationException (org.springframework.security.core.AuthenticationException)156 Authentication (org.springframework.security.core.Authentication)78 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)42 BadCredentialsException (org.springframework.security.authentication.BadCredentialsException)28 HttpServletRequest (javax.servlet.http.HttpServletRequest)27 HttpServletResponse (javax.servlet.http.HttpServletResponse)25 Test (org.junit.Test)24 Test (org.junit.jupiter.api.Test)19 AuthenticationServiceException (org.springframework.security.authentication.AuthenticationServiceException)15 IOException (java.io.IOException)13 ServletException (javax.servlet.ServletException)12 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)11 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)10 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)9 AuthenticationManager (org.springframework.security.authentication.AuthenticationManager)8 GrantedAuthority (org.springframework.security.core.GrantedAuthority)8 Map (java.util.Map)7 MidPointPrincipal (com.evolveum.midpoint.security.api.MidPointPrincipal)6 HashMap (java.util.HashMap)6 InternalAuthenticationServiceException (org.springframework.security.authentication.InternalAuthenticationServiceException)6