Example usage for javax.servlet.http HttpServletResponse SC_FORBIDDEN

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

Introduction

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

Prototype

int SC_FORBIDDEN

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

Click Source Link

Document

Status code (403) indicating the server understood the request but refused to fulfill it.

Usage

From source file:com.sitewhere.security.LoginManager.java

/**
 * Get the currently logged in user from Spring Security.
 * //www  .j a  v  a2  s  .  c  o m
 * @return
 * @throws SiteWhereException
 */
public static IUser getCurrentlyLoggedInUser() throws SiteWhereException {
    Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    if (auth == null) {
        throw new SiteWhereSystemException(ErrorCode.NotLoggedIn, ErrorLevel.ERROR,
                HttpServletResponse.SC_FORBIDDEN);
    }
    if (!(auth instanceof SitewhereAuthentication)) {
        throw new SiteWhereException(
                "Authentication was not of expected type: " + SitewhereAuthentication.class.getName());
    }
    return (IUser) ((SitewhereAuthentication) auth).getPrincipal();
}

From source file:net.nan21.dnet.core.web.security.DefaultAccessDeniedHandler.java

@Override
public void handle(HttpServletRequest request, HttpServletResponse response,
        AccessDeniedException accessDeniedException) throws IOException, ServletException {

    response.sendError(HttpServletResponse.SC_FORBIDDEN, "Not authenticated");

}

From source file:net.nan21.dnet.core.web.security.DefaultNotAuthenticatedEntryPoint.java

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

    response.setStatus(HttpServletResponse.SC_FORBIDDEN);
    response.getWriter().write("Not authenticated");
    response.flushBuffer();/*  w  w w.  j  a  v  a  2  s.  c  o  m*/

}

From source file:cz.cas.lib.proarc.authentication.utils.AuthUtils.java

/**
 * Writes the authentication required status to the HTTP response.
 * @param response response//www  .j  av  a 2 s .c o  m
 * @throws IOException failure
 * @see #HEADER_AUTHENTICATE_TYPE
 * @see <a href='http://www.smartclient.com/smartgwt/javadoc/com/smartgwt/client/docs/Relogin.html'>SmartGWT Relogin</a>
 */
public static void setLoginRequiredResponse(HttpServletResponse response) throws IOException {
    response.setHeader(HEADER_AUTHENTICATE_TYPE, Authenticators.getInstance().getLoginType());
    response.setStatus(HttpServletResponse.SC_FORBIDDEN);
    response.setContentType(MediaType.TEXT_HTML);
    InputStream res = ProarcAuthFilter.class.getResourceAsStream("loginRequiredMarker.html");
    try {
        IOUtils.copy(res, response.getOutputStream());
        res.close();
    } finally {
        IOUtils.closeQuietly(res);
    }
}

From source file:gov.nih.nci.cabig.ctms.lookandfeel.AssetServlet.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    if (req.getPathInfo().contains("..")) {
        resp.sendError(HttpServletResponse.SC_FORBIDDEN, "Illegal path");
        return;//from  w w w . j  a v a2s . c o m
    }
    String resource = resourcePath(req.getPathInfo());
    String mimeType = contentType(req.getPathInfo());
    if (mimeType != null) {
        resp.setContentType(mimeType);
    }
    // TODO: this is primitive.  Should add content-length at least
    InputStream resStream = getClass().getResourceAsStream(resource);
    if (resStream == null) {
        resp.sendError(HttpServletResponse.SC_NOT_FOUND);
    } else {
        IOUtils.copy(resStream, resp.getOutputStream());
    }
}

From source file:com.hp.autonomy.frontend.configuration.authentication.XhrAccessDeniedHandler.java

@Override
public void handle(final HttpServletRequest request, final HttpServletResponse response,
        final AccessDeniedException e) throws IOException, ServletException {
    // if AJAX, add 403 to the response, otherwise redirect to the given page
    if ("XMLHttpRequest".equalsIgnoreCase(request.getHeader("X-Requested-With"))) {
        response.sendError(HttpServletResponse.SC_FORBIDDEN, "Blocked by " + this.getClass().getName());
    } else {/*w  w w .  j av a  2 s .c o m*/
        response.sendRedirect(request.getContextPath() + '/' + loginPage);
    }
}

From source file:net.shopxx.filter.AccessDeniedFilter.java

public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
        throws IOException, ServletException {
    HttpServletResponse response = (HttpServletResponse) servletResponse;
    response.addHeader(new String(Base64.decodeBase64("UG93ZXJlZEJ5"), "utf-8"),
            new String(Base64.decodeBase64("Y2hlbmd6aGFuZy5jbw=="), "utf-8"));
    response.sendError(HttpServletResponse.SC_FORBIDDEN, ERROR_MESSAGE);
}

From source file:net.shopxx.interceptor.ValidateInterceptor.java

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
        throws Exception {
    if (!isValid(request)) {
        String requestType = request.getHeader("X-Requested-With");
        if (StringUtils.equalsIgnoreCase(requestType, "XMLHttpRequest")) {
            response.addHeader("validateStatus", "accessDenied");
        }/*from   w ww. j  av a  2 s.  c  o  m*/
        response.sendError(HttpServletResponse.SC_FORBIDDEN, ERROR_MESSAGE);
        return false;
    }
    return true;
}

From source file:gov.nih.nci.cabig.ctms.lookandfeel.AssetServletTest.java

public void testRelativePathInfoForbidden() throws Exception {
    request.setPathInfo("../foo/Bar.class");
    servlet.service(request, response);/*from ww w  . j a v  a2 s  . com*/
    assertEquals(HttpServletResponse.SC_FORBIDDEN, response.getStatus());
    assertEquals("Illegal path", response.getErrorMessage());
}

From source file:com.cnd.greencube.web.base.filter.AccessDeniedFilter.java

public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
        throws IOException, ServletException {
    HttpServletResponse response = (HttpServletResponse) servletResponse;
    response.addHeader(new String(Base64.decodeBase64("UG93ZXJlZEJ5"), "utf-8"),
            new String(Base64.decodeBase64("VG9wIFRlYW0="), "utf-8"));
    response.sendError(HttpServletResponse.SC_FORBIDDEN, ERROR_MESSAGE);
}