All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.textrecruit.ustackserverapi.auth.ReCaptchaAuthorization Maven / Gradle / Ivy

There is a newer version: 1.0.31
Show newest version
package com.textrecruit.ustackserverapi.auth;

import java.util.ArrayList;
import java.util.List;

import com.textrecruit.ustackserverapi.params.ParamNames;
import com.textrecruit.ustackserverapi.params.types.ParameterDefinitionInt;
import com.textrecruit.ustack.data.UniqueReference;
import com.textrecruit.ustack.data.UniqueReference.UniqueLinkStatus;
import com.textrecruit.ustackserverapi.APIException;
import com.textrecruit.ustackserverapi.CallParameters;
import com.textrecruit.ustackserverapi.MethodDefinition;
import com.textrecruit.ustackserverapi.util.ReCaptchaUtil;

public class ReCaptchaAuthorization implements AuthorizationInt {

	private String reCaptchaPrivateKey;
	private static final ReCaptchaAuthorization singleton = new ReCaptchaAuthorization();
	
	/**
	 * No extra parameters required
	 */
    public List> getAuthenticationParameters() {
    	
    	List> ret = new ArrayList>();
    	ret.add(ParamNames.recaptcha_challenge_field);
    	ret.add(ParamNames.recaptcha_response_field);
    	return ret;
    }


	public static ReCaptchaAuthorization getInstance(String reCaptchaPrivateKey) {
		singleton.reCaptchaPrivateKey = reCaptchaPrivateKey;
		return singleton;
	}
	
	/**
	 * Ensures the caller has access to the requested account
	 * 
	 * @param callParams
	 * @throws Exception
	 */
	public void authorize(MethodDefinition method, CallParameters callParams) throws APIException
	{
		if (callParams.get(ParamNames.UID) != null && Boolean.TRUE.equals( (Boolean)method.getData("AllowUIDOverride")))
		{
			if (UniqueReference.getLinkStatus(callParams.get(ParamNames.UID)).equals(UniqueLinkStatus.active))
				return;
		}
		
		ReCaptchaUtil.validateReCaptcha(reCaptchaPrivateKey, callParams);
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy