List of usage examples for javax.servlet.http HttpServletResponse SC_UNAUTHORIZED
int SC_UNAUTHORIZED
To view the source code for javax.servlet.http HttpServletResponse SC_UNAUTHORIZED.
Click Source Link
From source file:org.sharetask.web.authentication.Http401UnauthenticatedEntryPoint.java
/** * Always returns a 401 error code to the client. */// w w w.j ava 2 s .co m @Override public void commence(final HttpServletRequest request, final HttpServletResponse response, final AuthenticationException arg2) throws IOException, ServletException { log.debug("Pre-authenticated entry point called. Rejecting access"); final HttpServletResponse httpResponse = response; httpResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Unauthenticated request"); }
From source file:ro.allevo.fintpws.security.ApiAuthenticationEntryPoint.java
@Override public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException { response.addHeader("Access-Control-Allow-Origin", "null"); response.addHeader("WWW-Authenticate", "Basic realm=\"" + getRealmName() + "\""); response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); PrintWriter writer = response.getWriter(); writer.println(/*from w ww . j a va2 s . co m*/ "Here : HTTP Status " + HttpServletResponse.SC_UNAUTHORIZED + " - " + authException.getMessage()); }
From source file:io.getlime.security.powerauth.rest.api.spring.entrypoint.PowerAuthApiAuthenticationEntryPoint.java
@Override public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException { PowerAuthApiResponse<String> errorResponse = new PowerAuthApiResponse<>("ERROR", "Authentication failed"); response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); response.getOutputStream().println(new ObjectMapper().writeValueAsString(errorResponse)); response.getOutputStream().flush();//from ww w . j a v a2s.c om }
From source file:de.steilerdev.myVerein.server.security.rest.RestAuthenticationFailureHandler.java
@Override public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException { logger.warn("[{}] Authentication failed: {}", SecurityHelper.getClientIpAddr(request), exception.getMessage());//from ww w .ja v a2s . c om if (!response.isCommitted()) { response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Authentication failed: " + exception.getMessage()); } }
From source file:org.cloudfoundry.identity.uaa.error.JsonAwareAuthenticationEntryPointTests.java
@Test public void testCommenceWithJson() throws Exception { request.addHeader("Accept", MediaType.APPLICATION_JSON_VALUE); entryPoint.commence(request, response, new BadCredentialsException("Bad")); assertEquals(HttpServletResponse.SC_UNAUTHORIZED, response.getStatus()); assertEquals("{\"error\":\"Bad\"}", response.getContentAsString()); assertEquals(null, response.getErrorMessage()); }
From source file:com.iflytek.edu.cloud.frame.spring.OAuth2AuthenticationEntryPointExt.java
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException { if (authException.getCause() instanceof InvalidTokenException) { response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); MainError mainError = MainErrors.getError(MainErrorType.INVALID_ACCESS_TOKEN, (Locale) request.getAttribute("locale")); messageConverter.convertData(request, response, mainError); } else {/*w w w. j a v a 2 s.com*/ response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); doHandle(request, response, authException); } }
From source file:org.tec.security.spring.Http401AuthenticationEntryPoint.java
/** * {@inheritDoc}/* w ww .j a v a2 s .c o m*/ */ @Override() public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException { if (mLogger.isDebugEnabled()) { mLogger.debug("url requires authentication " + request.getRequestURL().toString()); } //send response code to trip error handler to prompt for login response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Authentication required"); }
From source file:com.erudika.para.security.SimpleAuthenticationEntryPoint.java
@Override public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException { if (isPreflight(request)) { response.setStatus(HttpServletResponse.SC_NO_CONTENT); } else if (isRestRequest(request)) { RestUtils.returnStatusResponse(response, HttpServletResponse.SC_UNAUTHORIZED, authException.getMessage()); } else {//from www . j a v a2s .co m super.commence(request, response, authException); } }
From source file:org.tec.webapp.web.controller.TestResponseController.java
/** * send 401 response code/* www . jav a 2s .c o m*/ * * @param response the http response * * @return empty model */ @RequestMapping(method = RequestMethod.GET) public ModelAndView unauth(HttpServletResponse response) { JSONModelAndView jmv = new JSONModelAndView(); try { if (mLogger.isDebugEnabled()) { mLogger.debug("sending error " + HttpServletResponse.SC_UNAUTHORIZED); } response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Authentication required"); } catch (Throwable e) { jmv.setError(new WebError("failed to set response", e)); } return jmv; }
From source file:com.econcept.init.AppAuthenticationEntryPoint.java
@Override public void commence(HttpServletRequest request, HttpServletResponse pResponse, AuthenticationException authException) throws IOException, ServletException { pResponse.addHeader("WWW-Authenticate", "xBasic realm=\"" + getRealmName() + "\""); pResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED, authException.getMessage()); }