2018-07-04 16:43:46 +02:00
|
|
|
package sonia.scm.security;
|
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
2018-09-12 12:24:57 +02:00
|
|
|
import static sonia.scm.api.v2.resources.ScmPathInfo.REST_API_PATH;
|
|
|
|
|
|
2018-07-04 16:43:46 +02:00
|
|
|
/**
|
|
|
|
|
* Created by masuewer on 04.07.18.
|
|
|
|
|
*/
|
|
|
|
|
public final class SecurityRequests {
|
|
|
|
|
|
2018-09-12 12:24:57 +02:00
|
|
|
private static final Pattern URI_LOGIN_PATTERN = Pattern.compile(REST_API_PATH + "(?:/v2)?/auth/access_token");
|
2018-09-28 14:40:26 +02:00
|
|
|
private static final Pattern URI_INDEX_PATTERN = Pattern.compile(REST_API_PATH + "/v2/?");
|
2018-07-04 16:43:46 +02:00
|
|
|
|
|
|
|
|
private SecurityRequests() {}
|
|
|
|
|
|
|
|
|
|
public static boolean isAuthenticationRequest(HttpServletRequest request) {
|
|
|
|
|
String uri = request.getRequestURI().substring(request.getContextPath().length());
|
|
|
|
|
return isAuthenticationRequest(uri);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static boolean isAuthenticationRequest(String uri) {
|
|
|
|
|
return URI_LOGIN_PATTERN.matcher(uri).matches();
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-28 14:40:26 +02:00
|
|
|
public static boolean isIndexRequest(HttpServletRequest request) {
|
|
|
|
|
String uri = request.getRequestURI().substring(request.getContextPath().length());
|
|
|
|
|
return isAuthenticationRequest(uri);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static boolean isIndexRequest(String uri) {
|
|
|
|
|
return URI_INDEX_PATTERN.matcher(uri).matches();
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-04 16:43:46 +02:00
|
|
|
}
|