-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Eseguita integrazione lavoro sulla console angular nel processo di compilazione della console. Eseguiti test di login tramite oauth2 con la configurazione della sicurezza da file esterni.
- Loading branch information
Showing
13 changed files
with
202 additions
and
19 deletions.
There are no files selected for viewing
119 changes: 119 additions & 0 deletions
119
...ay/rs/v1/authentication/oauth2/server/entrypoint/BearerTokenAuthenticationEntryPoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
package it.govpay.rs.v1.authentication.oauth2.server.entrypoint; | ||
|
||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
import java.util.TimeZone; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
import org.openspcoop2.generic_project.exception.ServiceException; | ||
import org.openspcoop2.utils.Utilities; | ||
import org.openspcoop2.utils.service.authentication.entrypoint.jaxrs.AbstractBasicAuthenticationEntryPoint; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.security.core.AuthenticationException; | ||
import org.springframework.security.oauth2.core.OAuth2AuthenticationException; | ||
import org.springframework.security.oauth2.core.OAuth2Error; | ||
import org.springframework.security.oauth2.server.resource.BearerTokenError; | ||
import org.springframework.security.web.AuthenticationEntryPoint; | ||
import org.springframework.util.StringUtils; | ||
|
||
import it.govpay.rs.v1.exception.CodiceEccezione; | ||
|
||
|
||
/** | ||
* Un {@link AuthenticationEntryPoint} estende l'implementazione {@link org.springframework.security.oauth2.server.resource.web.BearerTokenAuthenticationEntryPoint} | ||
* per includere una risposta nel formato GovPay nei casi non gestiti dalla procedura originale. | ||
* | ||
* @author Giuliano Pintori | ||
*/ | ||
public class BearerTokenAuthenticationEntryPoint implements AuthenticationEntryPoint { | ||
|
||
private TimeZone timeZone = TimeZone.getDefault(); | ||
private String timeZoneId = null; | ||
public String getTimeZoneId() { | ||
return this.timeZoneId; | ||
} | ||
public void setTimeZoneId(String timeZoneId) { | ||
this.timeZoneId = timeZoneId; | ||
this.timeZone = TimeZone.getTimeZone(timeZoneId); | ||
} | ||
|
||
private String realmName; | ||
|
||
/** | ||
* Collect error details from the provided parameters and format according to RFC | ||
* 6750, specifically {@code error}, {@code error_description}, {@code error_uri}, and | ||
* {@code scope}. | ||
* @param request that resulted in an <code>AuthenticationException</code> | ||
* @param response so that the user agent can begin authentication | ||
* @param authException that caused the invocation | ||
*/ | ||
@Override | ||
public void commence(HttpServletRequest request, HttpServletResponse response, | ||
AuthenticationException authException) { | ||
HttpStatus status = HttpStatus.UNAUTHORIZED; | ||
Map<String, String> parameters = new LinkedHashMap<>(); | ||
if (this.realmName != null) { | ||
parameters.put("realm", this.realmName); | ||
} | ||
if (authException instanceof OAuth2AuthenticationException) { | ||
OAuth2Error error = ((OAuth2AuthenticationException) authException).getError(); | ||
parameters.put("error", error.getErrorCode()); | ||
if (StringUtils.hasText(error.getDescription())) { | ||
parameters.put("error_description", error.getDescription()); | ||
} | ||
if (StringUtils.hasText(error.getUri())) { | ||
parameters.put("error_uri", error.getUri()); | ||
} | ||
if (error instanceof BearerTokenError) { | ||
BearerTokenError bearerTokenError = (BearerTokenError) error; | ||
if (StringUtils.hasText(bearerTokenError.getScope())) { | ||
parameters.put("scope", bearerTokenError.getScope()); | ||
} | ||
status = ((BearerTokenError) error).getHttpStatus(); | ||
} | ||
|
||
String wwwAuthenticate = computeWWWAuthenticateHeaderValue(parameters); | ||
response.addHeader(HttpHeaders.WWW_AUTHENTICATE, wwwAuthenticate); | ||
response.setStatus(status.value()); | ||
return; | ||
} | ||
|
||
// altre eccezioni | ||
if(Utilities.existsInnerException(authException, ServiceException.class)) { | ||
AbstractBasicAuthenticationEntryPoint.fillResponse(response, CodiceEccezione.ERRORE_INTERNO.toFaultResponse(authException), this.timeZone); | ||
return; | ||
} | ||
|
||
AbstractBasicAuthenticationEntryPoint.fillResponse(response, CodiceEccezione.AUTENTICAZIONE.toFaultResponse(authException), this.timeZone); | ||
} | ||
|
||
/** | ||
* Set the default realm name to use in the bearer token error response | ||
* @param realmName | ||
*/ | ||
public void setRealmName(String realmName) { | ||
this.realmName = realmName; | ||
} | ||
|
||
private static String computeWWWAuthenticateHeaderValue(Map<String, String> parameters) { | ||
StringBuilder wwwAuthenticate = new StringBuilder(); | ||
wwwAuthenticate.append("Bearer"); | ||
if (!parameters.isEmpty()) { | ||
wwwAuthenticate.append(" "); | ||
int i = 0; | ||
for (Map.Entry<String, String> entry : parameters.entrySet()) { | ||
wwwAuthenticate.append(entry.getKey()).append("=\"").append(entry.getValue()).append("\""); | ||
if (i != parameters.size() - 1) { | ||
wwwAuthenticate.append(", "); | ||
} | ||
i++; | ||
} | ||
} | ||
return wwwAuthenticate.toString(); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
wars/web-console/src/main/java/it/govpay/web/console/filter/Html5RoutingFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package it.govpay.web.console.filter; | ||
|
||
import java.io.IOException; | ||
|
||
import javax.servlet.Filter; | ||
import javax.servlet.FilterChain; | ||
import javax.servlet.FilterConfig; | ||
import javax.servlet.ServletException; | ||
import javax.servlet.ServletRequest; | ||
import javax.servlet.ServletResponse; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
public class Html5RoutingFilter implements Filter { | ||
|
||
@Override | ||
public void init(FilterConfig filterConfig) throws ServletException { | ||
// Inizializzazione del filtro (se necessario) | ||
} | ||
|
||
@Override | ||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { | ||
HttpServletRequest httpRequest = (HttpServletRequest) request; | ||
HttpServletResponse httpResponse = (HttpServletResponse) response; | ||
|
||
// Verifica se la richiesta è per un file o una directory esistente | ||
String path = httpRequest.getRequestURI().substring(httpRequest.getContextPath().length()); | ||
String queryString = httpRequest.getQueryString(); | ||
if (!path.contains(".")) { | ||
// Se la richiesta non contiene un'estensione, reindirizza al percorso HTML5 compatibile con l'app Angular | ||
String redirectPath = httpRequest.getContextPath() + "/#" + path; | ||
if (queryString != null && !queryString.isEmpty()) { | ||
redirectPath += "?" + queryString; // Aggiungi la query string al percorso di reindirizzamento | ||
} | ||
httpResponse.sendRedirect(redirectPath); | ||
} else { | ||
// Altrimenti, continua il normale flusso di richiesta | ||
chain.doFilter(request, response); | ||
} | ||
} | ||
|
||
@Override | ||
public void destroy() { | ||
// Operazioni di chiusura (se necessario) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
<!doctype html><html lang="en"><head><meta charset="utf-8"><title></title><base href="${it.govpay.backoffice.gui.baseUrl}"><meta http-equiv="X-UA-Compatible" content="IE=Edge"/><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" type="image/x-icon" href="favicon.ico"><style>.web-init{border:4px solid #f3f3f3;border-top:4px solid #06f;border-radius:50%;width:40px;height:40px;animation:spin 2s linear infinite;position:fixed;top:calc(50% - 20px);left:calc(50% - 20px)}@keyframes spin{0%{transform:rotate(0deg)}100%{transform:rotate(360deg)}}</style><script src="assets/Config.govpay"></script><link href="styles.bundle.css" rel="stylesheet"/></head><body><link-root><div class="web-init"></div></link-root><script type="text/javascript" src="inline.bundle.js"></script><script type="text/javascript" src="polyfills.bundle.js"></script><script type="text/javascript" src="scripts.bundle.js"></script><script type="text/javascript" src="vendor.bundle.js"></script><script type="text/javascript" src="main.bundle.js"></script></body></html> | ||
<!doctype html><html lang="en"><head><meta charset="utf-8"><title></title><base href="${it.govpay.backoffice.gui.baseUrl}"><meta http-equiv="X-UA-Compatible" content="IE=Edge"/><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" type="image/x-icon" href="favicon.ico"><style>.web-init{border:4px solid #f3f3f3;border-top:4px solid #06f;border-radius:50%;width:40px;height:40px;animation:spin 2s linear infinite;position:fixed;top:calc(50% - 20px);left:calc(50% - 20px)}@keyframes spin{0%{transform:rotate(0deg)}100%{transform:rotate(360deg)}}</style><script src="assets/Config.js"></script><link href="styles.bundle.css" rel="stylesheet"/></head><body><link-root><div class="web-init"></div></link-root><script type="text/javascript" src="inline.bundle.js"></script><script type="text/javascript" src="polyfills.bundle.js"></script><script type="text/javascript" src="scripts.bundle.js"></script><script type="text/javascript" src="vendor.bundle.js"></script><script type="text/javascript" src="main.bundle.js"></script></body></html> |