Example usage for javax.servlet.http HttpServletResponse SC_UNAUTHORIZED

List of usage examples for javax.servlet.http HttpServletResponse SC_UNAUTHORIZED

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletResponse SC_UNAUTHORIZED.

Prototype

int SC_UNAUTHORIZED

To view the source code for javax.servlet.http HttpServletResponse SC_UNAUTHORIZED.

Click Source Link

Document

Status code (401) indicating that the request requires HTTP authentication.

Usage

From source file:RestrictUserIP.java

public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    PrintWriter out;/*from   w ww  .j a  va2 s .  c  om*/
    /**
     * Status code (401) indicating that the request requires HTTP
     * authentication.
     */
    if (req.getRemoteAddr().equals("142.3.28.87")) {
        resp.sendError(HttpServletResponse.SC_UNAUTHORIZED);
    }
    resp.setContentType("text/html");
    out = resp.getWriter();
    out.println("<HTML>");
    out.println("<BODY>");
    out.println("<H1>");
    out.println("Hello!");
    out.println("<BR>");
    out.println("Your IP Address: " + req.getRemoteAddr());
    out.println("</H1>");
    out.println("</body>");
    out.println("</html>");
    out.close();
}

From source file:cz.sohlich.workstack.api.SecurityResource.java

@RequestMapping(value = "/login")
public void login(HttpServletResponse response) {
    log.info("Redirected to login via REST");
    response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
}

From source file:com.mycompany.springrest.token.RestAuthenticationEntryPoint.java

@Override
public void commence(HttpServletRequest request, HttpServletResponse response,
        AuthenticationException authException) throws IOException {

    response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Unauthorized");
}

From source file:com.mycompany.licit.custom.RESTAuthenticationEntryPoint.java

@Override
public void commence(HttpServletRequest hsr, HttpServletResponse hsr1, AuthenticationException ae)
        throws IOException, ServletException {
    hsr1.sendError(HttpServletResponse.SC_UNAUTHORIZED);
}

From source file:com.tamnd2.basicwebapp.security.EntryPointUnauthorizeHandler.java

@Override
public void commence(HttpServletRequest hsr, HttpServletResponse hsr1, AuthenticationException ae)
        throws IOException, ServletException {
    hsr1.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Access Denied");
}

From source file:com.tamnd.app.config.security.EntryPointUnauthorizeHandler.java

@Override
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException ex)
        throws IOException, ServletException {
    response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Access Denied");
}

From source file:Core.Security.CustomEntryPoint.java

public void commence(final HttpServletRequest request, final HttpServletResponse response,
        final AuthenticationException authException) throws IOException, ServletException {
    //Authentication failed, send error response.
    response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
    response.addHeader("WWW-Authenticate", "Basic realm=" + getRealmName() + "");
    PrintWriter writer = response.getWriter();
    writer.println("HTTP Status 401 : " + authException.getMessage());
}

From source file:com.jevontech.wabl.security.EntryPointUnauthorizedHandler.java

@Override
public void commence(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse,
        AuthenticationException e) throws IOException, ServletException {
    httpServletResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Access Denied");
}

From source file:com.tamnd2.basicwebapp.security.AuthFailure.java

@Override
public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response,
        AuthenticationException exception) throws IOException, ServletException {
    response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
}

From source file:cz.muni.fi.dndtroopsweb.controllers.BasicController.java

/**
 * just for testing purposes/*w w  w .  j av  a2  s.c om*/
 * @param request
 * @param response
 * @return 
 */
@RequestMapping(value = "/logout", method = RequestMethod.GET)
public String logoutPage(HttpServletRequest request, HttpServletResponse response) {
    request.setAttribute("authenticatedUser", null);
    response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
    return "home";
}