// Decompiled by Jad v1.5.8e. Copyright 2001 Pavel Kouznetsov. // Jad home page: http://www.geocities.com/kpdus/jad.html // Decompiler options: braces fieldsfirst space lnc package org.apache.oltu.oauth2.common.validators; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; import javax.servlet.http.HttpServletRequest; import org.apache.oltu.oauth2.common.exception.OAuthProblemException; import org.apache.oltu.oauth2.common.utils.OAuthUtils; // Referenced classes of package org.apache.oltu.oauth2.common.validators: // OAuthValidator public abstract class AbstractValidator implements OAuthValidator { protected boolean enforceClientAuthentication; protected List notAllowedParams; protected Map optionalParams; protected List requiredParams; public AbstractValidator() { requiredParams = new ArrayList(); optionalParams = new HashMap(); notAllowedParams = new ArrayList(); } public void performAllValidations(HttpServletRequest httpservletrequest) throws OAuthProblemException { validateContentType(httpservletrequest); validateMethod(httpservletrequest); validateRequiredParameters(httpservletrequest); validateOptionalParameters(httpservletrequest); validateNotAllowedParameters(httpservletrequest); validateClientAuthenticationCredentials(httpservletrequest); } public void validateClientAuthenticationCredentials(HttpServletRequest httpservletrequest) throws OAuthProblemException { if (enforceClientAuthentication) { HashSet hashset = new HashSet(); String as[] = OAuthUtils.decodeClientAuthenticationHeader(httpservletrequest.getHeader("Authorization")); if (as == null || OAuthUtils.isEmpty(as[0]) || OAuthUtils.isEmpty(as[1])) { if (OAuthUtils.isEmpty(httpservletrequest.getParameter("client_id"))) { hashset.add("client_id"); } if (OAuthUtils.isEmpty(httpservletrequest.getParameter("client_secret"))) { hashset.add("client_secret"); } } if (!hashset.isEmpty()) { throw OAuthUtils.handleMissingParameters(hashset); } } } public void validateContentType(HttpServletRequest httpservletrequest) throws OAuthProblemException { if (!OAuthUtils.hasContentType(httpservletrequest.getContentType(), "application/x-www-form-urlencoded")) { throw OAuthUtils.handleBadContentTypeException("application/x-www-form-urlencoded"); } else { return; } } public void validateMethod(HttpServletRequest httpservletrequest) throws OAuthProblemException { if (!httpservletrequest.getMethod().equals("POST")) { throw OAuthUtils.handleOAuthProblemException("Method not set to POST."); } else { return; } } public void validateNotAllowedParameters(HttpServletRequest httpservletrequest) throws OAuthProblemException { ArrayList arraylist = new ArrayList(); Iterator iterator = notAllowedParams.iterator(); do { if (!iterator.hasNext()) { break; } String s = (String)iterator.next(); if (!OAuthUtils.isEmpty(httpservletrequest.getParameter(s))) { arraylist.add(s); } } while (true); if (!arraylist.isEmpty()) { throw OAuthUtils.handleNotAllowedParametersOAuthException(arraylist); } else { return; } } public void validateOptionalParameters(HttpServletRequest httpservletrequest) throws OAuthProblemException { HashSet hashset = new HashSet(); Iterator iterator = optionalParams.entrySet().iterator(); do { if (!iterator.hasNext()) { break; } java.util.Map.Entry entry = (java.util.Map.Entry)iterator.next(); if (!OAuthUtils.isEmpty(httpservletrequest.getParameter((String)entry.getKey()))) { String as[] = (String[])entry.getValue(); if (!OAuthUtils.hasEmptyValues(as)) { int j = as.length; int i = 0; while (i < j) { String s = as[i]; if (OAuthUtils.isEmpty(httpservletrequest.getParameter(s))) { hashset.add(s); } i++; } } } } while (true); if (!hashset.isEmpty()) { throw OAuthUtils.handleMissingParameters(hashset); } else { return; } } public void validateRequiredParameters(HttpServletRequest httpservletrequest) throws OAuthProblemException { HashSet hashset = new HashSet(); Iterator iterator = requiredParams.iterator(); do { if (!iterator.hasNext()) { break; } String s = (String)iterator.next(); if (OAuthUtils.isEmpty(httpservletrequest.getParameter(s))) { hashset.add(s); } } while (true); if (!hashset.isEmpty()) { throw OAuthUtils.handleMissingParameters(hashset); } else { return; } } }