use of com.microsoft.azure.oidc.exception.PreconditionException in project azure-tools-for-java by Microsoft.
the class SimpleAuthenticationHelper method getTokenString.
@Override
public String getTokenString(final HttpServletRequest httpRequest, final HttpServletResponse httpResponse, final String tokenName) {
if (httpRequest == null || httpResponse == null || tokenName == null) {
throw new PreconditionException("Required parameter is null");
}
final String tokenString = httpRequest.getParameter(tokenName);
if (tokenString != null) {
return addCookie(httpRequest, httpResponse, tokenName, tokenString);
}
final Cookie cookieToken = getCookie(httpRequest, tokenName);
if (cookieToken != null) {
return addCookie(httpRequest, httpResponse, tokenName, cookieToken.getValue());
}
return null;
}
use of com.microsoft.azure.oidc.exception.PreconditionException 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);
}
}
Aggregations