Search in sources :

Example 1 with Token

use of com.microsoft.azure.oidc.token.Token in project azure-tools-for-java by Microsoft.

the class SimpleAuthenticationFilter method doFilter.

@Override
public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException {
    final HttpServletRequest httpRequest = (HttpServletRequest) request;
    final HttpServletResponse httpResponse = (HttpServletResponse) response;
    try {
        final String tokenString = getHelper().getTokenString(httpRequest, httpResponse, TOKEN_NAME);
        final String errorString = getHelper().getErrorString(httpRequest, ERROR_NAME);
        final Boolean isAuthenticationError = getHelper().isAuthenticationError(errorString);
        final Boolean isUnauthenticated = tokenString == NO_TOKEN_STRING;
        if (isUnauthenticated || isAuthenticationError) {
            getHelper().doUnauthenticatedAction(chain, httpRequest, httpResponse, NO_TOKEN, isAuthenticationError);
            return;
        }
        final Token token = getHelper().getToken(tokenString);
        final Boolean isInvalidToken = !getHelper().isValidToken(token);
        if (isInvalidToken) {
            getHelper().doInvalidTokenAction(httpResponse);
            return;
        }
        final Boolean isActiveToken = getHelper().isActiveToken(token);
        if (isActiveToken) {
            getHelper().doActiveTokenAction(chain, httpRequest, httpResponse, token);
            return;
        }
        getHelper().doUnauthenticatedAction(chain, httpRequest, httpResponse, token, isAuthenticationError);
    } catch (GeneralException | PreconditionException e) {
        getHelper().doExceptionAction(httpResponse, e);
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) GeneralException(com.microsoft.azure.oidc.exception.GeneralException) HttpServletResponse(javax.servlet.http.HttpServletResponse) Token(com.microsoft.azure.oidc.token.Token) PreconditionException(com.microsoft.azure.oidc.exception.PreconditionException)

Aggregations

GeneralException (com.microsoft.azure.oidc.exception.GeneralException)1 PreconditionException (com.microsoft.azure.oidc.exception.PreconditionException)1 Token (com.microsoft.azure.oidc.token.Token)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1