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.example.security.RestAuthenticationEntryPoint.java

@Override
public void commence(HttpServletRequest request, HttpServletResponse response,
        AuthenticationException authException) throws IOException {
    Logger.getLogger("org.example.security.RestAuthenticationEntryPoint")
            .info("Inside RestAuthenticationEntryPoint...");
    response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Unauthorized");
}

From source file:com.counter.counter.api.AuthenticationEntryPoint.java

@Override
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authEx)
        throws IOException, ServletException {
    response.addHeader("WWW-Authenticate", "Basic realm=" + getRealmName());
    response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
    PrintWriter writer = response.getWriter();
    writer.println("HTTP Status 401 - " + authEx.getMessage());
}

From source file:com.alliander.osgp.shared.security.UnauthorizedEntryPoint.java

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

    response.sendError(HttpServletResponse.SC_UNAUTHORIZED,
            "Unauthorized: Authentication token was either missing or invalid.");
}

From source file:com.lennonjesus.auth.security.handler.AjaxAuthenticationFailureHandler.java

@Override
public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response,
        AuthenticationException exception) throws IOException, ServletException {
    logger.debug("Authentication Failed");
    response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Authentication failed");
}

From source file:com.betfair.tornjak.monitor.overlay.AuthUtils.java

/**
 * Returns null if user is not authenticated or authorised, otherwise returns Auth object.
 * //from  w ww.j a  v  a 2 s  .  c o  m
 */
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.ebay.pulsar.analytics.security.spring.PlainTextBasicAuthenticationEntryPoint.java

@Override
public void commence(HttpServletRequest request, HttpServletResponse response,
        AuthenticationException authException) throws IOException, ServletException {
    response.addHeader("WWW-Authenticate", "Basic realm=\"" + getRealmName() + "\"");
    response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
    PrintWriter writer = response.getWriter();
    writer.println("HTTP Status " + HttpServletResponse.SC_UNAUTHORIZED + " - " + authException.getMessage());

}

From source file:waffle.spring.handlers.CustomAccessDeniedHandler.java

@Override
public void handle(final HttpServletRequest request, final HttpServletResponse response,
        final AccessDeniedException ex) throws IOException, ServletException {
    // here we can add custom headers or response status, data or redirect
    response.addHeader("Custom-header", "some value");
    response.sendError(HttpServletResponse.SC_UNAUTHORIZED);

}

From source file:com.seyren.core.security.UnauthorizedEntryPoint.java

@Override
public void commence(HttpServletRequest request, HttpServletResponse response,
        AuthenticationException authException) throws IOException, ServletException {
    response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
    response.setContentType((MediaType.APPLICATION_JSON.toString()));
    response.setCharacterEncoding("UTF-8");
    response.getWriter().write(authException.getMessage());
}

From source file:org.chtijbug.drools.platform.web.security.Http401UnauthorizedEntryPoint.java

@Override
public void commence(HttpServletRequest request, HttpServletResponse response,
        AuthenticationException authException) throws IOException, ServletException {
    response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
    response.getWriter().write("Need authentication");
}

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());
}