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,
|
||||
StringCacheStore cacheStore) {
|
||||
AdminAuthenticationFilter adminFilter = new AdminAuthenticationFilter(cacheStore, "/admin/api/login");
|
||||
// Set auth enabled
|
||||
adminFilter.setAuthEnabled(haloProperties.getAuthEnabled());
|
||||
|
||||
// Set failure handler
|
||||
adminFilter.setFailureHandler(new AdminAuthenticationFailureHandler(haloProperties.getProductionEnv(), objectMapper));
|
||||
|
||||
|
|
|
@ -24,6 +24,11 @@ public class HaloProperties {
|
|||
*/
|
||||
private Boolean productionEnv = true;
|
||||
|
||||
/**
|
||||
* Authentication enabled
|
||||
*/
|
||||
private Boolean authEnabled = true;
|
||||
|
||||
/**
|
||||
* Work directory.
|
||||
*/
|
||||
|
|
|
@ -50,6 +50,11 @@ public class AdminAuthenticationFilter extends OncePerRequestFilter {
|
|||
|
||||
private AuthenticationFailureHandler failureHandler;
|
||||
|
||||
/**
|
||||
* Authentication enabled.
|
||||
*/
|
||||
private boolean authEnabled = true;
|
||||
|
||||
private final StringCacheStore cacheStore;
|
||||
|
||||
private final Collection<String> excludeUrlPatterns;
|
||||
|
@ -64,6 +69,13 @@ public class AdminAuthenticationFilter extends OncePerRequestFilter {
|
|||
|
||||
@Override
|
||||
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
|
||||
String token = getTokenFromRequest(request);
|
||||
|
||||
|
@ -112,6 +124,10 @@ public class AdminAuthenticationFilter extends OncePerRequestFilter {
|
|||
this.failureHandler = failureHandler;
|
||||
}
|
||||
|
||||
public void setAuthEnabled(boolean authEnabled) {
|
||||
this.authEnabled = authEnabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets token from request.
|
||||
*
|
||||
|
|
|
@ -54,3 +54,4 @@ logging:
|
|||
halo:
|
||||
doc-disabled: false
|
||||
production-env: false
|
||||
auth-enabled: false
|
||||
|
|
Loading…
Reference in New Issue