Example usage for org.springframework.security.core AuthenticationException getMessage

List of usage examples for org.springframework.security.core AuthenticationException getMessage

Introduction

In this page you can find the example usage for org.springframework.security.core AuthenticationException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:edu.uiowa.icts.authentication.AuthHandle.java

/** {@inheritDoc} */
@Override/*  ww w.  j a v  a 2  s  .c o  m*/
public void onAuthenticationFailure(HttpServletRequest req, HttpServletResponse res,
        AuthenticationException excep) throws IOException, ServletException {
    AuditLogger.info("NONE", req.getParameter("j_username"), "Error logging in from " + req.getRemoteHost(),
            excep.getMessage());
    req.getSession().setAttribute("SPRING_SECURITY_LAST_EXCEPTION", excep);
    redirectStrategy.sendRedirect(req, res, "/login.html?error=true");
}

From source file:eu.freme.broker.security.ManagementEndpointAuthenticationFilter.java

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    HttpServletRequest httpRequest = asHttp(request);
    HttpServletResponse httpResponse = asHttp(response);

    Optional<String> username = Optional.fromNullable(httpRequest.getHeader("X-Auth-Username"));
    Optional<String> password = Optional.fromNullable(httpRequest.getHeader("X-Auth-Password"));

    String resourcePath = new UrlPathHelper().getPathWithinApplication(httpRequest);

    try {/*from w w w.j  a va2  s . c  o  m*/
        if (postToManagementEndpoints(resourcePath)) {
            logger.debug("Trying to authenticate user {} for management endpoint by X-Auth-Username method",
                    username);
            processManagementEndpointUsernamePasswordAuthentication(username, password);
        }

        logger.debug("ManagementEndpointAuthenticationFilter is passing request down the filter chain");
        chain.doFilter(request, response);
    } catch (AuthenticationException authenticationException) {
        SecurityContextHolder.clearContext();
        httpResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED, authenticationException.getMessage());
    }
}

From source file:org.freakz.hokan_ng_springboot.bot.LoginScreen.java

private void login() {
    try {/* w  w w.  j av a2s .  c  o m*/
        loggedOutLabel.setVisible(false);

        String password = passwordField.getValue();
        passwordField.setValue("");

        final Authentication authentication = vaadinSecurity.login(userName.getValue(), password);
        eventBus.publish(this, new SuccessfulLoginEvent(getUI(), authentication));
    } catch (AuthenticationException ex) {
        userName.focus();
        userName.selectAll();
        loginFailedLabel.setValue(String.format("Login failed: %s", ex.getMessage()));
        loginFailedLabel.setVisible(true);
    } catch (Exception ex) {
        Notification.show("An unexpected error occurred", ex.getMessage(), Notification.Type.ERROR_MESSAGE);
        LoggerFactory.getLogger(getClass()).error("Unexpected error while logging in", ex);
    } finally {
        login.setEnabled(true);
    }
}

From source file:architecture.user.security.spring.authentication.ExtendedAuthenticationProvider.java

@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
    try {//from   ww w.j a va 2 s .  c  om
        return super.authenticate(authentication);
    } catch (AuthenticationException e) {
        if (log.isInfoEnabled())
            log.info(L10NUtils.format("005012", authentication != null ? authentication.getName() : "<unknown>",
                    e.getMessage()));
        if (log.isTraceEnabled())
            log.trace(L10NUtils.getMessage("005013"), e);
        throw e;
    } catch (RuntimeException e) {
        log.warn(L10NUtils.format("005014", authentication != null ? authentication.getName() : "<unknown>"),
                e);
        throw e;
    }
}

From source file:org.devgateway.toolkit.forms.wicket.SSAuthenticatedWebSession.java

@Override
public boolean authenticate(final String username, final String password) {
    boolean authenticated;
    try {//from   w  ww  .  j a v a  2 s .c  o m
        Authentication authentication = authenticationManager
                .authenticate(new UsernamePasswordAuthenticationToken(username, password));
        SecurityContextHolder.getContext().setAuthentication(authentication);
        // httpSession.setAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY,
        // SecurityContextHolder.getContext());
        authenticated = authentication.isAuthenticated();

        if (authenticated && rememberMeServices != null) {
            rememberMeServices.loginSuccess(
                    (HttpServletRequest) RequestCycle.get().getRequest().getContainerRequest(),
                    (HttpServletResponse) RequestCycle.get().getResponse().getContainerResponse(),
                    authentication);
        }

    } catch (AuthenticationException e) {
        this.setAe(e);
        log.warn("User '{}' failed to login. Reason: {}", username, e.getMessage());
        authenticated = false;
    }
    return authenticated;
}

From source file:cn.com.esrichina.gcloud.commons.web.resources.SystemResource.java

@ApiOperation(value = "?Token", notes = "TOKEN?", httpMethod = "POST", response = UserToken.class)
@RequestMapping(value = "/GenerateToken", method = RequestMethod.POST)
@ResponseBody//from   w  w  w  .  j ava2  s .c  o m
public GenericResponse<UserToken> generateToken(@RequestBody GenerateTokenReq req) throws GeneralException {
    Authentication authentication = getAuthentication(req.getUsername(), req.getPassword());
    try {
        Authentication auth = authenticationManager.authenticate(authentication);
        String token = UUID.randomUUID().toString();

        securityContext.cacheUserByToken(token, auth);

        UserToken userToken = new UserToken();
        userToken.setToken(token);
        return new GenericResponse<UserToken>(userToken);
    } catch (AuthenticationException ae) {
        return new GenericResponse<UserToken>(false, ae.getMessage());
    }
}

From source file:com.sentinel.rest.handlers.AuthFailureHandler.java

@Override
public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response,
        AuthenticationException exception) throws IOException, ServletException {
    LOG.trace("Method: onAuthenticationFailure called.");

    response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
    PrintWriter writer = response.getWriter();
    writer.write(exception.getMessage());
    writer.flush();/*from   w w w .j  a v  a2s .  c  om*/
    LOG.trace("Method: onAuthenticationFailure finished.");
}

From source file:com.rockagen.gnext.service.spring.security.extension.ExAuthenticationHandler.java

/**
 * Authentication failure handler//ww  w  . ja v a  2 s .  c o  m
 *
 * @param request  request
 * @param response response
 */
public void failureHandler(HttpServletRequest request, HttpServletResponse response) throws IOException {
    String uid = request.getParameter(username);
    try {
        failureRegister(uid, request);
    } catch (AuthenticationException e) {
        response.sendError(HttpServletResponse.SC_UNAUTHORIZED, e.getMessage());
    }
}

From source file:com.seyren.core.security.UnauthorizedEntryPoint.java

@Override
public void commence(HttpServletRequest request, HttpServletResponse response,
        AuthenticationException authException) throws IOException, ServletException {
    response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
    response.setContentType((MediaType.APPLICATION_JSON.toString()));
    response.setCharacterEncoding("UTF-8");
    response.getWriter().write(authException.getMessage());
}

From source file:org.vaadin.spring.samples.security.shared.LoginUI.java

private void login() {
    try {// w w  w.  ja  v  a2  s  .  c  om
        vaadinSecurity.login(userName.getValue(), passwordField.getValue(), rememberMe.getValue());
    } catch (AuthenticationException ex) {
        userName.focus();
        userName.selectAll();
        passwordField.setValue("");
        loginFailedLabel.setValue(String.format("Login failed: %s", ex.getMessage()));
        loginFailedLabel.setVisible(true);
        if (loggedOutLabel != null) {
            loggedOutLabel.setVisible(false);
        }
    } catch (Exception ex) {
        Notification.show("An unexpected error occurred", ex.getMessage(), Notification.Type.ERROR_MESSAGE);
        LoggerFactory.getLogger(getClass()).error("Unexpected error while logging in", ex);
    } finally {
        login.setEnabled(true);
    }
}