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:net.cristcost.study.services.ServiceTestUtil.java

private static SecurityContext authenticate(PrintWriter writer, HttpServletRequest request,
        AuthenticationManager authenticationManager) {

    SecurityContext initialContext = SecurityContextHolder.getContext();

    if (request.getParameter("user") != null) {

        UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken(
                request.getParameter("user"), request.getParameter("pass"));
        try {/*  w ww.j a  v a 2  s. com*/
            Authentication authentication = authenticationManager.authenticate(authRequest);
            SecurityContextHolder.setContext(SecurityContextHolder.createEmptyContext());
            SecurityContextHolder.getContext().setAuthentication(authentication);
            writer.println("Authenticating user: " + request.getParameter("user"));
        } catch (AuthenticationException e) {
            writer.println("! Error while Authenticating: " + e.getMessage());
        }
        writer.println();
    }

    return initialContext;
}

From source file:com.sshdemo.common.security.manage.web.user.InitPasswordAction.java

public String execute() {

    if (!password.equals(passwordAgain)) {
        this.addActionError("??");
        return ERROR;
    }/*from  ww w  .j a  va  2 s.c o m*/

    try {
        userService.initPassword(username, password);
        addActionMessage("??");
        return SUCCESS;
    } catch (AuthenticationException e) {
        addActionError(e.getMessage());
        return ERROR;
    }
}

From source file:com.sshdemo.common.security.manage.web.account.PasswordAction.java

@Override
public String execute() {
    if (!againPassword.equals(password)) {
        addActionError("??");
        return ERROR;
    }//from w w  w.j  a va2s  .c o  m
    try {
        fac.changePassword(oldPassword, password);
        addActionMessage("??");
        return SUCCESS;
    } catch (AuthenticationException e) {
        addActionError(e.getMessage());
        return ERROR;
    }
}

From source file:com.company.project.web.controller.service.HttpAuthenticationEntryPoint.java

@Override
public void commence(HttpServletRequest request, HttpServletResponse response,
        AuthenticationException authException) throws IOException {
    response.sendError(HttpServletResponse.SC_UNAUTHORIZED, authException.getMessage());
}

From source file:com.companyname.LoginTest.java

@Test
public void authenticateUserTest() {
    logger.info("running test to authenticate a user ");
    try {/*  w w w.  j a va  2s  . co m*/
        Authentication request = new UsernamePasswordAuthenticationToken("toy", "toy");
        Authentication result = provider.authenticate(request);

        //SecurityContextHolder.getContext().setAuthentication(result);
        //SecurityContextHolder.getContext().getAuthentication()

        logger.info("Successfully authenticated. Security context contains: " + result);

        assertThat(result, IsNull.notNullValue());

    } catch (AuthenticationException e) {
        System.out.println("Authentication Test failed: " + e.getMessage());
    }
}

From source file:de.knightsoftnet.validators.server.security.HttpAuthenticationEntryPoint.java

@Override
public void commence(final HttpServletRequest prequest, final HttpServletResponse presponse,
        final AuthenticationException pauthException) throws IOException {
    presponse.sendError(HttpServletResponse.SC_UNAUTHORIZED, pauthException.getMessage());
}

From source file:io.github.autsia.crowly.controllers.rest.AuthenticationController.java

@RequestMapping(value = "/login", method = RequestMethod.POST)
public ResponseEntity<String> login(@RequestBody CrowlyUser user, HttpServletResponse response) {
    try {/*w w  w. j a  v a 2 s .c  om*/
        Authentication request = new UsernamePasswordAuthenticationToken(user.getEmail(), user.getPassword());
        Authentication result = authenticationManager.authenticate(request);
        SecurityContextHolder.getContext().setAuthentication(result);
        return new ResponseEntity<>(HttpStatus.OK);
    } catch (AuthenticationException e) {
        logger.warn("Failed login attempt for username: " + e.getMessage());
        return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
    }
}

From source file:com.oneops.security.APIAuthenticationEntryPoint.java

@Override
public void commence(HttpServletRequest request, HttpServletResponse response,
        AuthenticationException exception) throws IOException, ServletException {
    logger.error("Exception serving request" + exception.getMessage());
    CmsBaseException ce = new CmsBaseException(CmsError.RUNTIME_EXCEPTION, exception.getMessage());
    ErrorResponse error = new ErrorResponse(HttpStatus.UNAUTHORIZED.value(), HttpStatus.UNAUTHORIZED.value(),
            exception.getMessage());//from w ww . j  av a2 s  .c o  m
    response.setStatus(error.getCode());
    response.getWriter().write(gson.toJson(error));
}

From source file:ch.wisv.areafiftylan.security.RESTAuthenticationEntryPoint.java

@Override
public void commence(HttpServletRequest request, HttpServletResponse response,
        AuthenticationException authException) throws IOException, ServletException {
    response.sendError(HttpServletResponse.SC_UNAUTHORIZED, authException.getMessage());
}

From source file:org.apigw.authserver.shibboleth.ShibbolethSamlEntryPoint.java

@Override
public void commence(HttpServletRequest request, HttpServletResponse response,
        AuthenticationException authException) throws IOException, ServletException {
    response.sendError(HttpServletResponse.SC_UNAUTHORIZED, authException.getMessage()); //TODO: make something better?
}