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.betfair.tornjak.monitor.overlay.AuthUtils.java

/**
 * Returns null if user is not authenticated or authorised, otherwise returns Auth object.
 * /*from ww w. j a va 2  s.  com*/
 */
public static Auth checkAuthorised(final HttpServletRequest request, HttpServletResponse response,
        ServletContext servletContext) throws IOException {

    RolePerms rolePerms = getOrCreateRolePerms(servletContext);

    Auth auth = new Auth(new Auth.Validator() {

        @Override
        public boolean isUserInRole(String role) {
            return request.isUserInRole(role);
        }

        @Override
        public boolean isAuthenticated() {
            return request.getUserPrincipal() != null;
        }
    }, rolePerms);

    switch (auth.check()) {
    case UNAUTHORISED:
        response.sendError(HttpServletResponse.SC_UNAUTHORIZED);
        return null;
    case FORBIDDEN:
        response.sendError(HttpServletResponse.SC_FORBIDDEN);
        return null;
    default:
        return auth;
    }
}

From source file:com.thinkberg.moxo.dav.HeadHandler.java

public void service(HttpServletRequest request, HttpServletResponse response) throws IOException {
    FileObject object = getResourceManager().getFileObject(request.getPathInfo());

    if (object.exists()) {
        if (FileType.FOLDER.equals(object.getType())) {
            response.sendError(HttpServletResponse.SC_FORBIDDEN);
        } else {/*from w w w  .  j  ava  2  s. c  om*/
            setHeader(response, object.getContent());
        }
    } else {
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
    }
}

From source file:com.sammyun.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("U2hvcHh4Lm5ldA=="), "utf-8"));
    response.sendError(HttpServletResponse.SC_FORBIDDEN, ERROR_MESSAGE);
}

From source file:net.incrementalism.tooter.ProfileServlet.java

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    User currentUser = getCurrentUser(request);
    if (currentUser == null) {
        response.sendError(HttpServletResponse.SC_FORBIDDEN);
        return;//from w  w w .j av  a 2  s.c o  m
    }

    if (request.getParameter("toot") != null) {
        String tootText = request.getParameter("tootText");
        if (isBlank(tootText)) {
            request.setAttribute("error", "'Toot' must not be empty.");
        } else {
            toot(currentUser, tootText);
        }
    } else if (request.getParameter("follow") != null) {
        String followUserName = request.getParameter("followUserName");
        if (isBlank(followUserName)) {
            request.setAttribute("error", "'Follow' must not be empty.");
        } else {
            try {
                addFollower(followUserName, currentUser.getUserName());
            } catch (UserNotFoundException e) {
                request.setAttribute("error", "User '" + e.getUserName() + "' does not exist.");
            }
        }
    }
    displayProfile(currentUser, request, response);
}

From source file:com.mirth.connect.server.servlets.UsageServlet.java

public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    try {//  www .j  a  v a2 s.  c  om
        if (!isUserLoggedIn(request)) {
            response.sendError(HttpServletResponse.SC_FORBIDDEN);
        } else {
            PrintWriter out = response.getWriter();
            ObjectXMLSerializer serializer = ObjectXMLSerializer.getInstance();
            Operation operation = Operations.getOperation(request.getParameter("op"));
            UsageController usageController = ControllerFactory.getFactory().createUsageController();

            if (operation.equals(Operations.USAGE_DATA_GET)) {
                response.setContentType(TEXT_PLAIN);
                if (isUserAuthorized(request, null)) {
                    serializer.serialize(usageController.createUsageStats(true), out);
                } else {
                    response.sendError(HttpServletResponse.SC_UNAUTHORIZED);
                }
            }
        }
    } catch (RuntimeIOException rio) {
        logger.debug(rio);
    } catch (Throwable t) {
        logger.debug(ExceptionUtils.getStackTrace(t));
        throw new ServletException(t);
    }
}

From source file:com.thinkberg.webdav.HeadHandler.java

public void service(HttpServletRequest request, HttpServletResponse response) throws IOException {
    FileObject object = VFSBackend.resolveFile(request.getPathInfo());

    if (object.exists()) {
        if (FileType.FOLDER.equals(object.getType())) {
            response.sendError(HttpServletResponse.SC_FORBIDDEN);
        } else {//from  w  w w. j  a va  2s.c o m
            setHeader(response, object.getContent());
        }
    } else {
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
    }
}

From source file:com.sg.rest.security.components.SgAccessDeniedHandler.java

@Override
public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException e)
        throws IOException, ServletException {
    response.setStatus(HttpServletResponse.SC_FORBIDDEN);

    AccessDenied dto = new AccessDenied();
    LOGGER.error("Authorization failed " + dto.getEventRef().getId() + ": ", e);

    response.setContentType(CustomMediaTypes.APPLICATION_JSON_UTF8.getMediatype().toString());
    jacksonObjectMapper.writeValue(response.getWriter(), dto);
}

From source file:com.dp2345.filter.AccessDeniedFilter.java

public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
        throws IOException, ServletException {
    HttpServletResponse response = (HttpServletResponse) servletResponse;
    // PoweredBy   dp2345.com
    response.addHeader(new String(base64.decode("UG93ZXJlZEJ5"), "utf-8"),
            new String(base64.decode("ZHAyMzQ1LmNvbQ=="), "utf-8"));
    response.sendError(HttpServletResponse.SC_FORBIDDEN, ERROR_MESSAGE);
}

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  a  2s  .  c  o  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:com.thinkberg.moxo.dav.GetHandler.java

public void service(HttpServletRequest request, HttpServletResponse response) throws IOException {
    FileObject object = getResourceManager().getFileObject(request.getPathInfo());

    if (object.exists()) {
        if (FileType.FOLDER.equals(object.getType())) {
            response.sendError(HttpServletResponse.SC_FORBIDDEN);
            return;
        }/*from  w  w  w. j a  va 2 s  .co  m*/

        setHeader(response, object.getContent());

        InputStream is = object.getContent().getInputStream();
        OutputStream os = response.getOutputStream();
        Util.copyStream(is, os);
        is.close();
    } else {
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
    }
}