DefaultAuthenticationFailureHandler.java

  1. /*
  2.  * GovWay - A customizable API Gateway
  3.  * https://govway.org
  4.  *
  5.  * Copyright (c) 2005-2025 Link.it srl (https://link.it).
  6.  *
  7.  * This program is free software: you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License version 3, as published by
  9.  * the Free Software Foundation.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18.  *
  19.  */
  20. package org.openspcoop2.utils.service.authentication.handler.jaxrs;

  21. import java.io.IOException;
  22. import java.util.TimeZone;

  23. import javax.servlet.ServletException;
  24. import javax.servlet.http.HttpServletRequest;
  25. import javax.servlet.http.HttpServletResponse;
  26. import javax.ws.rs.core.Response;

  27. import org.openspcoop2.utils.service.authentication.entrypoint.jaxrs.AbstractBasicAuthenticationEntryPoint;
  28. import org.openspcoop2.utils.service.fault.jaxrs.FaultCode;
  29. import org.springframework.security.core.AuthenticationException;
  30. import org.springframework.security.web.authentication.AuthenticationFailureHandler;

  31. /**
  32.  * DefaultAuthenticationFailureHandler
  33.  *
  34.  * @author Giuliano Pintori (pintori@link.it)
  35.  * @author $Author$
  36.  * @version $Rev$, $Date$
  37.  */
  38. public class DefaultAuthenticationFailureHandler implements AuthenticationFailureHandler {

  39.     private TimeZone timeZone = TimeZone.getDefault();
  40.     private String timeZoneId = null;
  41.     public String getTimeZoneId() {
  42.         return this.timeZoneId;
  43.     }
  44.     public void setTimeZoneId(String timeZoneId) {
  45.         this.timeZoneId = timeZoneId;
  46.         this.timeZone = TimeZone.getTimeZone(timeZoneId);
  47.     }
  48.    
  49.     @Override
  50.     public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse res, AuthenticationException exception) throws IOException, ServletException {
  51.         AbstractBasicAuthenticationEntryPoint.fillResponse(res, getPayload(exception, res), this.timeZone);
  52.     }

  53.     public Response getPayload(AuthenticationException authException, HttpServletResponse httpResponse) {
  54.         return FaultCode.AUTORIZZAZIONE.toFaultResponse(authException);
  55.     }
  56. }