-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.enonic.xp.web.impl.auth; | ||
|
||
import javax.servlet.Filter; | ||
import javax.servlet.FilterChain; | ||
import javax.servlet.annotation.WebFilter; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
import org.osgi.service.component.annotations.Component; | ||
|
||
import com.google.common.net.HttpHeaders; | ||
|
||
import com.enonic.xp.annotation.Order; | ||
import com.enonic.xp.web.filter.OncePerRequestFilter; | ||
|
||
@Component(immediate = true, service = Filter.class, property = {"connector=api"}) | ||
@Order(-20) | ||
@WebFilter("/*") | ||
public class AuthRequiredFilter | ||
Check warning on line 19 in modules/web/web-impl/src/main/java/com/enonic/xp/web/impl/auth/AuthRequiredFilter.java Codecov / codecov/patchmodules/web/web-impl/src/main/java/com/enonic/xp/web/impl/auth/AuthRequiredFilter.java#L19
|
||
extends OncePerRequestFilter | ||
{ | ||
@Override | ||
protected void doHandle( final HttpServletRequest req, final HttpServletResponse res, final FilterChain chain ) | ||
throws Exception | ||
{ | ||
if ( req.getUserPrincipal() == null ) | ||
{ | ||
res.addHeader( HttpHeaders.WWW_AUTHENTICATE, "Basic"); | ||
res.addHeader( HttpHeaders.WWW_AUTHENTICATE, "Bearer"); | ||
res.sendError( HttpServletResponse.SC_UNAUTHORIZED ); | ||
return; | ||
Check warning on line 31 in modules/web/web-impl/src/main/java/com/enonic/xp/web/impl/auth/AuthRequiredFilter.java Codecov / codecov/patchmodules/web/web-impl/src/main/java/com/enonic/xp/web/impl/auth/AuthRequiredFilter.java#L28-L31
|
||
} | ||
chain.doFilter( req, res ); | ||
} | ||
Check warning on line 34 in modules/web/web-impl/src/main/java/com/enonic/xp/web/impl/auth/AuthRequiredFilter.java Codecov / codecov/patchmodules/web/web-impl/src/main/java/com/enonic/xp/web/impl/auth/AuthRequiredFilter.java#L33-L34
|
||
} |