Java tutorial
/** * Copyright 2014 Telefonica Investigacin y Desarrollo, S.A.U <br> * This file is part of FI-WARE project. * <p> * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with * the License. * </p> * <p> * You may obtain a copy of the License at:<br> * <br> * http://www.apache.org/licenses/LICENSE-2.0 * </p> * <p> * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * </p> * <p> * See the License for the specific language governing permissions and limitations under the License. * </p> * <p> * For those usages not covered by the Apache version 2.0 License please contact with opensource@tid.es * </p> */ package com.telefonica.euro_iaas.paasmanager.rest.auth; import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.springframework.security.authentication.InsufficientAuthenticationException; import org.springframework.security.core.AuthenticationException; import org.springframework.security.web.AuthenticationEntryPoint; /** * The Class RestAuthenticationEntryPoint. * * @author dbermejo */ public class RestAuthenticationEntryPoint implements AuthenticationEntryPoint { /** * (non-Javadoc). * * @see org.springframework.security.web.AuthenticationEntryPoint#commence(javax.servlet.http.HttpServletRequest, * javax.servlet.http.HttpServletResponse, * org.springframework.security.core.AuthenticationException) */ public final void commence(final HttpServletRequest request, final HttpServletResponse response, final AuthenticationException authException) throws IOException, ServletException { // if (authException instanceof AuthenticationServiceException) { // LOG.error(authException); // response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, // authException.getMessage()); // } if (authException instanceof InsufficientAuthenticationException) { response.sendError(HttpServletResponse.SC_FORBIDDEN, "Forbidden"); } else { response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Unauthorized"); } } }