mirror of https://github.com/halo-dev/halo
Provide an authentication enabled option
parent
0add4107ef
commit
35a2ddf546
|
@ -82,6 +82,9 @@ public class HaloConfiguration {
|
||||||
ObjectMapper objectMapper,
|
ObjectMapper objectMapper,
|
||||||
StringCacheStore cacheStore) {
|
StringCacheStore cacheStore) {
|
||||||
AdminAuthenticationFilter adminFilter = new AdminAuthenticationFilter(cacheStore, "/admin/api/login");
|
AdminAuthenticationFilter adminFilter = new AdminAuthenticationFilter(cacheStore, "/admin/api/login");
|
||||||
|
// Set auth enabled
|
||||||
|
adminFilter.setAuthEnabled(haloProperties.getAuthEnabled());
|
||||||
|
|
||||||
// Set failure handler
|
// Set failure handler
|
||||||
adminFilter.setFailureHandler(new AdminAuthenticationFailureHandler(haloProperties.getProductionEnv(), objectMapper));
|
adminFilter.setFailureHandler(new AdminAuthenticationFailureHandler(haloProperties.getProductionEnv(), objectMapper));
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,11 @@ public class HaloProperties {
|
||||||
*/
|
*/
|
||||||
private Boolean productionEnv = true;
|
private Boolean productionEnv = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Authentication enabled
|
||||||
|
*/
|
||||||
|
private Boolean authEnabled = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Work directory.
|
* Work directory.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -50,6 +50,11 @@ public class AdminAuthenticationFilter extends OncePerRequestFilter {
|
||||||
|
|
||||||
private AuthenticationFailureHandler failureHandler;
|
private AuthenticationFailureHandler failureHandler;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Authentication enabled.
|
||||||
|
*/
|
||||||
|
private boolean authEnabled = true;
|
||||||
|
|
||||||
private final StringCacheStore cacheStore;
|
private final StringCacheStore cacheStore;
|
||||||
|
|
||||||
private final Collection<String> excludeUrlPatterns;
|
private final Collection<String> excludeUrlPatterns;
|
||||||
|
@ -64,6 +69,13 @@ public class AdminAuthenticationFilter extends OncePerRequestFilter {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
|
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
|
||||||
|
|
||||||
|
if (!authEnabled) {
|
||||||
|
// If authentication disabled
|
||||||
|
filterChain.doFilter(request, response);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Get token from request
|
// Get token from request
|
||||||
String token = getTokenFromRequest(request);
|
String token = getTokenFromRequest(request);
|
||||||
|
|
||||||
|
@ -112,6 +124,10 @@ public class AdminAuthenticationFilter extends OncePerRequestFilter {
|
||||||
this.failureHandler = failureHandler;
|
this.failureHandler = failureHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setAuthEnabled(boolean authEnabled) {
|
||||||
|
this.authEnabled = authEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets token from request.
|
* Gets token from request.
|
||||||
*
|
*
|
||||||
|
|
|
@ -54,3 +54,4 @@ logging:
|
||||||
halo:
|
halo:
|
||||||
doc-disabled: false
|
doc-disabled: false
|
||||||
production-env: false
|
production-env: false
|
||||||
|
auth-enabled: false
|
||||||
|
|
Loading…
Reference in New Issue