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: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?
}

From source file:ru.mystamps.web.support.spring.security.Http401UnauthorizedEntryPoint.java

/**
 * Always returns a 401 error code to the client.
 **//*from w w w . ja va2s .c  om*/
@Override
public void commence(HttpServletRequest req, HttpServletResponse resp, AuthenticationException ex)
        throws IOException {

    resp.sendError(HttpServletResponse.SC_UNAUTHORIZED);
}

From source file:fedora.server.security.servletfilters.FilterEnforceAuthn.java

@Override
public boolean doThisSubclass(ExtendedHttpServletRequest request, HttpServletResponse response)
        throws Throwable {
    String method = "doThisSubclass() ";
    if (log.isDebugEnabled()) {
        log.debug(enter(method));// w ww. j a  va2  s  .  co m
    }
    super.doThisSubclass(request, response);
    request.lockWrapper();

    boolean terminateServletFilterChain = request.getUserPrincipal() == null;
    if (terminateServletFilterChain) {
        if (log.isDebugEnabled()) {
            log.debug(format(method, "no principal found, sending 401"));
        }
        String realm = "fedora";
        String value = "BASIC realm=\"" + realm + "\"";
        String name = "WWW-Authenticate";
        int sc = HttpServletResponse.SC_UNAUTHORIZED;
        response.reset();
        //httpServletResponse.sendError(sc, "supply credentials"); //same as after
        if (response.containsHeader(name)) {
            response.setHeader(name, value);
        } else {
            response.addHeader(name, value);
        }
        try {
            response.sendError(sc, "supply credentials");
        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } //here, no bad auth msg at wget
        response.setContentType("text/plain");
        try {
            response.flushBuffer();
        } catch (IOException e) {
            showThrowable(e, log, "response flush error");
        }
    }
    return terminateServletFilterChain;
}

From source file:fr.mycellar.interfaces.web.security.RestAuthenticationEntryPoint.java

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

From source file:es.ucm.fdi.dalgs.rest.security.RestAuthenticationFailureHandler.java

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

From source file:com.hp.autonomy.frontend.find.idol.web.IdolGlobalExceptionHandler.java

@ExceptionHandler(AciErrorException.class)
@ResponseBody// w  w  w  . j  a  va2s  .c o m
public ErrorResponse authenticationFailedHandler(final AciErrorException exception,
        final HttpServletResponse response) {
    if (SECURITY_INFO_TOKEN_EXPIRED_ID.equals(exception.getErrorId())) {
        response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
        return new ErrorResponse("Security Info has expired");
    }

    response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    return handler(exception);
}

From source file:ru.codemine.ccms.api.security.ApiEntryPointHandler.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.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 . ja  v a2 s .com
    LOG.trace("Method: onAuthenticationFailure finished.");
}

From source file:com.poscoict.license.security.AjaxSessionTimeoutFilter.java

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    HttpServletRequest req = (HttpServletRequest) request;
    HttpServletResponse res = (HttpServletResponse) response;
    if (isAjaxRequest(req)) {
        try {/* w ww  .j  a v a2 s .  co  m*/
            String user = (String) req.getSession().getAttribute("USER_NO");
            if (user == null) {
                throw new AccessDeniedException(" ");
            } else {
                chain.doFilter(req, res);
            }
        } catch (AccessDeniedException e) {
            System.out.println(e.getMessage());
            res.sendError(HttpServletResponse.SC_FORBIDDEN);
        } catch (AuthenticationException e) {
            res.sendError(HttpServletResponse.SC_UNAUTHORIZED);
        }
    } else {
        chain.doFilter(req, res);
    }
}

From source file:net.maritimecloud.identityregistry.security.RestAuthenticationEntryPoint.java

@Override
public void commence(HttpServletRequest request, HttpServletResponse responce,
        AuthenticationException exception) throws IOException, ServletException {
    responce.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Unauthorized");

}