org.brickred.socialauth.exception.SocialAuthException Java Examples

The following examples show how to use org.brickred.socialauth.exception.SocialAuthException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SocialAuthConfig.java    From socialauth with MIT License 6 votes vote down vote up
/**
 * Updates the provider specific configuration.
 * 
 * @param providerId
 *            the provider id for which configuration need to be add or
 *            update
 * @param config
 *            the OAuthConfig object which contains the configuration.
 */
public void addProviderConfig(final String providerId,
		final OAuthConfig config) throws Exception {
	config.setId(providerId);
	LOG.debug("Adding provider configuration :" + config);
	providersConfig.put(providerId, config);
	if (config.getProviderImplClass() != null) {
		providersImplMap.put(providerId, config.getProviderImplClass());
		domainMap.put(providerId, providerId);
	}
	if (!providersImplMap.containsKey(providerId)) {
		throw new SocialAuthException("Provider Impl class not found");
	} else if (config.getProviderImplClass() == null) {
		config.setProviderImplClass(providersImplMap.get(providerId));
	}
	configSetup = true;
}
 
Example #2
Source File: GenericOAuth2Provider.java    From socialauth with MIT License 6 votes vote down vote up
/**
 * Makes HTTP request to a given URL.It attaches access token in URL.
 * 
 * @param url
 *            URL to make HTTP request.
 * @param methodType
 *            Method type can be GET, POST or PUT
 * @param params
 *            Not using this parameter in Google API function
 * @param headerParams
 *            Parameters need to pass as Header Parameters
 * @param body
 *            Request Body
 * @return Response object
 * @throws Exception
 */
@Override
public Response api(final String url, final String methodType,
		final Map<String, String> params,
		final Map<String, String> headerParams, final String body)
		throws Exception {
	LOG.info("Calling api function for url	:	" + url);
	Response response = null;
	try {
		response = authenticationStrategy.executeFeed(url, methodType,
				params, headerParams, body);
	} catch (Exception e) {
		throw new SocialAuthException(
				"Error while making request to URL : " + url, e);
	}
	return response;
}
 
Example #3
Source File: FourSquareImpl.java    From socialauth with MIT License 6 votes vote down vote up
private Profile doVerifyResponse(final Map<String, String> requestParams)
		throws Exception {
	LOG.info("Verifying the authentication response from provider");
	if (requestParams.get("error") != null
			&& "access_denied".equals(requestParams.get("error"))) {
		throw new UserDeniedPermissionException();
	}

	accessGrant = authenticationStrategy.verifyResponse(requestParams);
	if (accessGrant != null) {
		accessToken = accessGrant.getKey();
		LOG.debug("Obtaining user profile");
		return getProfile();
	} else {
		throw new SocialAuthException("Access token not found");
	}
}
 
Example #4
Source File: GoogleImpl.java    From socialauth with MIT License 6 votes vote down vote up
/**
 * Makes OAuth signed HTTP - GET request to a given URL. It attaches
 * Authorization header with HTTP request.
 * 
 * @param url
 *            URL to make HTTP request.
 * @param methodType
 *            Method type should be GET
 * @param params
 *            Not using this parameter in Google API function
 * @param headerParams
 *            Any additional parameters need to pass as Header Parameters
 * @param body
 *            Request Body
 * @return Response object
 * @throws Exception
 */
@Override
public Response api(final String url, final String methodType,
		final Map<String, String> params,
		final Map<String, String> headerParams, final String body)
		throws Exception {

	Response serviceResponse = null;
	if (!MethodType.GET.toString().equals(methodType)) {
		throw new SocialAuthException(
				"Only GET method is implemented in Google API function");
	}
	LOG.debug("Calling URL : " + url);
	try {
		serviceResponse = authenticationStrategy.executeFeed(url,
				methodType, params, headerParams, body);
	} catch (Exception ie) {
		throw new SocialAuthException(
				"Error while making request to URL : " + url, ie);
	}
	return serviceResponse;
}
 
Example #5
Source File: InstagramImpl.java    From socialauth with MIT License 6 votes vote down vote up
private Profile doVerifyResponse(final Map<String, String> requestParams)
		throws Exception {
	LOG.info("Verifying the authentication response from provider");
	if (requestParams.get("error") != null
			&& "access_denied".equals(requestParams.get("error"))) {
		throw new UserDeniedPermissionException();
	}

	accessGrant = authenticationStrategy.verifyResponse(requestParams,
			MethodType.POST.toString());
	if (accessGrant != null) {
		LOG.debug("Obtaining user profile");
		getUserProfile();
		return this.userProfile;
	} else {
		throw new SocialAuthException("Access token not found");
	}
}
 
Example #6
Source File: HotmailImpl.java    From socialauth with MIT License 6 votes vote down vote up
/**
 * Updates the status on the chosen provider if available. This may not be
 * implemented for all providers.
 * 
 * @param msg
 *            Message to be shown as user's status
 * @throws Exception
 */
@Override
public Response updateStatus(final String msg) throws Exception {
	LOG.info("Updating status : " + msg);
	if (!isVerify) {
		throw new SocialAuthException(
				"Please call verifyResponse function first to get Access Token");
	}
	if (msg == null || msg.trim().length() == 0) {
		throw new ServerDataException("Status cannot be blank");
	}

	Map<String, String> headerParam = new HashMap<String, String>();
	headerParam.put("Authorization", "Bearer " + accessGrant.getKey());
	headerParam.put("Content-Type", "application/json");
	String body = "{message:\"" + msg + "\"}";
	Response serviceResponse;
	serviceResponse = authenticationStrategy.executeFeed(UPDATE_STATUS_URL,
			MethodType.POST.toString(), null, headerParam, body);

	int code = serviceResponse.getStatus();
	LOG.debug("Status updated and return status code is :" + code);
	// return 201
	return serviceResponse;
}
 
Example #7
Source File: HttpUtil.java    From socialauth with MIT License 6 votes vote down vote up
public static String encodeURIComponent(final String value)
		throws Exception {
	if (value == null) {
		return "";
	}

	try {
		return URLEncoder.encode(value, "utf-8")
				// OAuth encodes some characters differently:
				.replace("+", "%20").replace("*", "%2A")
				.replace("%7E", "~");
		// This could be done faster with more hand-crafted code.
	} catch (UnsupportedEncodingException wow) {
		throw new SocialAuthException(wow.getMessage(), wow);
	}
}
 
Example #8
Source File: HotmailImpl.java    From socialauth with MIT License 6 votes vote down vote up
private Profile doVerifyResponse(final Map<String, String> requestParams)
		throws Exception {
	LOG.info("Retrieving Access Token in verify response function");

	if (requestParams.get("wrap_error_reason") != null
			&& "user_denied".equals(requestParams.get("wrap_error_reason"))) {
		throw new UserDeniedPermissionException();
	}

	accessGrant = authenticationStrategy.verifyResponse(requestParams);

	if (accessGrant != null) {
		isVerify = true;
		LOG.debug("Obtaining user profile");
		return getProfile();
	} else {
		throw new SocialAuthException("Unable to get Access token");
	}
}
 
Example #9
Source File: GenericOAuth2Provider.java    From socialauth with MIT License 6 votes vote down vote up
private Profile doVerifyResponse(final Map<String, String> requestParams)
		throws Exception {
	LOG.info("Retrieving Access Token in verify response function");
	if (requestParams.get("error_reason") != null
			&& "user_denied".equals(requestParams.get("error_reason"))) {
		throw new UserDeniedPermissionException();
	}
	accessGrant = authenticationStrategy.verifyResponse(requestParams);

	if (accessGrant != null) {
		LOG.debug("Access grant available");
		return null;
	} else {
		throw new SocialAuthException("Access token not found");
	}
}
 
Example #10
Source File: GitHubImpl.java    From socialauth with MIT License 6 votes vote down vote up
private Profile doVerifyResponse(final Map<String, String> requestParams)
		throws Exception {
	LOG.info("Retrieving Access Token in verify response function");
	if (requestParams.get("error_reason") != null
			&& "user_denied".equals(requestParams.get("error_reason"))) {
		throw new UserDeniedPermissionException();
	}
	accessGrant = authenticationStrategy.verifyResponse(requestParams,
			MethodType.POST.toString());

	if (accessGrant != null) {
		LOG.debug("Obtaining user profile");
		return getProfile();
	} else {
		throw new SocialAuthException("Access token not found");
	}
}
 
Example #11
Source File: MySpaceImpl.java    From socialauth with MIT License 6 votes vote down vote up
/**
 * Updates the status on the chosen provider if available. This may not be
 * implemented for all providers.
 * 
 * @param msg
 *            Message to be shown as user's status
 * @throws Exception
 */
@Override
public Response updateStatus(final String msg) throws Exception {
	if (msg == null || msg.trim().length() == 0) {
		throw new ServerDataException("Status cannot be blank");
	}
	LOG.info("Updating status " + msg + " on " + UPDATE_STATUS_URL);
	String msgBody = "{\"status\":\"" + msg + "\"}";
	Response serviceResponse = null;
	try {
		serviceResponse = authenticationStrategy.executeFeed(
				UPDATE_STATUS_URL, MethodType.PUT.toString(), null, null,
				msgBody);
	} catch (Exception ie) {
		throw new SocialAuthException("Failed to update status on "
				+ UPDATE_STATUS_URL, ie);
	}
	LOG.info("Update Status Response :" + serviceResponse.getStatus());
	return serviceResponse;
}
 
Example #12
Source File: GitHubImpl.java    From socialauth with MIT License 6 votes vote down vote up
@Override
public Response api(final String url, final String methodType,
		final Map<String, String> params,
		final Map<String, String> headerParams, final String body)
		throws Exception {
	LOG.info("Calling api function for url	:	" + url);
	Response response = null;
	try {
		response = authenticationStrategy.executeFeed(url, methodType,
				params, headerParams, body);
	} catch (Exception e) {
		throw new SocialAuthException(
				"Error while making request to URL : " + url, e);
	}
	return response;
}
 
Example #13
Source File: SalesForceImpl.java    From socialauth with MIT License 6 votes vote down vote up
/**
 * Makes HTTP request to a given URL.It attaches access token in URL.
 * 
 * @param url
 *            URL to make HTTP request.
 * @param methodType
 *            Method type can be GET, POST or PUT
 * @param params
 * @param headerParams
 *            Parameters need to pass as Header Parameters
 * @param body
 *            Request Body
 * @return Response object
 * @throws Exception
 */
@Override
public Response api(final String url, final String methodType,
		final Map<String, String> params,
		final Map<String, String> headerParams, final String body)
		throws Exception {
	LOG.info("Calling api function for url	:	" + url);
	Response response = null;
	try {
		response = authenticationStrategy.executeFeed(url, methodType,
				params, headerParams, body);
	} catch (Exception e) {
		throw new SocialAuthException(
				"Error while making request to URL : " + url, e);
	}
	return response;
}
 
Example #14
Source File: SocialAuthUpdateStatusAction.java    From socialauth with MIT License 5 votes vote down vote up
/**
 * Update status for the given provider.
 * 
 * @return String where the action should flow
 * @throws Exception
 *             if an error occurs
 */
@Action(value = "/socialAuthUpdateStatusAction")
public String execute() throws Exception {

	if (statusMessage == null || statusMessage.trim().length() == 0) {
		request.setAttribute("Message", "Status can't be left blank.");
		return "failure";
	}
	SASFHelper helper = SASFStaticHelper.getHelper(request);
	SocialAuthManager manager = helper.getAuthManager();
	AuthProvider provider = null;
	if (manager != null) {
		provider = manager.getCurrentAuthProvider();
	}
	if (provider != null) {
		try {
			provider.updateStatus(statusMessage);
			request.setAttribute("Message", "Status Updated successfully");
			return "success";
		} catch (SocialAuthException e) {
			request.setAttribute("Message", e.getMessage());
			e.printStackTrace();
		}
	}
	return "failure";

}
 
Example #15
Source File: MendeleyImpl.java    From socialauth with MIT License 5 votes vote down vote up
/**
 * Gets the list of followers of the user and their screen name.
 * 
 * @return List of contact objects representing Contacts. Only name, screen
 *         name and profile URL will be available
 */
@Override
public List<Contact> getContactList() throws Exception {
	LOG.warn("WARNING: Not implemented for Mendeley");
	throw new SocialAuthException(
			"Get contact list is not implemented for Mendeley");
}
 
Example #16
Source File: OpenIdImpl.java    From socialauth with MIT License 5 votes vote down vote up
@Override
public Response uploadImage(final String message, final String fileName,
		final InputStream inputStream) throws Exception {
	LOG.warn("WARNING: Not implemented for OpenId");
	throw new SocialAuthException(
			"Upload Image is not implemented for OpenId");
}
 
Example #17
Source File: ProviderSupport.java    From socialauth with MIT License 5 votes vote down vote up
/**
 * Makes OAuth signed HTTP GET request to a given URL.
 * 
 * @param url
 *            URL to make HTTP request.
 * @return Response object
 * @throws Exception
 */
public Response api(final String url) throws Exception {
	Response response = null;
	try {
		response = authenticationStrategy.executeFeed(url,
				MethodType.GET.toString(), null, null, null);
	} catch (Exception e) {
		throw new SocialAuthException(
				"Error while making request to URL : " + url, e);
	}
	return response;
}
 
Example #18
Source File: GenericOAuth1Provider.java    From socialauth with MIT License 5 votes vote down vote up
/**
 * This method is not implemented for GenericOAuth1 provider. Use
 * <code>api()</code> method instead to get user contacts.
 */
@Override
public List<Contact> getContactList() throws Exception {
	LOG.warn("WARNING: Not implemented for GenericOauth1Provider");
	throw new SocialAuthException(
			"Get Contacts is not implemented for GenericOauth1Provider");
}
 
Example #19
Source File: SalesForceImpl.java    From socialauth with MIT License 5 votes vote down vote up
@Override
public Response uploadImage(final String message, final String fileName,
		final InputStream inputStream) throws Exception {
	LOG.warn("WARNING: Not implemented for SalesForce");
	throw new SocialAuthException(
			"Upload Image is not implemented for SalesForce");
}
 
Example #20
Source File: GooglePlusImpl.java    From socialauth with MIT License 5 votes vote down vote up
/**
 * Verifies the user when the external provider redirects back to our
 * application.
 * 
 * 
 * @param requestParams
 *            request parameters, received from the provider
 * @return Profile object containing the profile information
 * @throws Exception
 */

@Override
public Profile verifyResponse(final Map<String, String> requestParams)
		throws Exception {
	if (requestParams.containsKey(Constants.STATE)) {
		String stateStr = requestParams.get(Constants.STATE);
		if (!state.equals(stateStr)) {
			throw new SocialAuthException(
					"State parameter value does not match with expected value");
		}
	}

	return doVerifyResponse(requestParams);
}
 
Example #21
Source File: YahooImpl.java    From socialauth with MIT License 5 votes vote down vote up
@Override
public Response uploadImage(final String message, final String fileName,
		final InputStream inputStream) throws Exception {
	LOG.warn("WARNING: Not implemented for Yahoo");
	throw new SocialAuthException(
			"Upload Image is not implemented for Yahoo");
}
 
Example #22
Source File: GitLabProviderImpl.java    From gocd-oauth-login with Apache License 2.0 5 votes vote down vote up
private Profile getProfile() throws Exception {
    String response;

    String profileUrl = config.getCustomProperties().get("profile_url");
    try {
        response = authenticationStrategy.executeFeed(profileUrl).getResponseBodyAsString(Constants.ENCODING);
    } catch (Exception e) {
        throw new SocialAuthException("Error while getting profile from " + profileUrl, e);
    }
    try {
        LOG.debug("User Profile : " + response);
        JSONObject resp = new JSONObject(response);
        Profile p = new Profile();
        p.setValidatedId(resp.optString("id", null));
        p.setFullName(resp.optString("name", null));
        p.setEmail(resp.optString("email", null));
        p.setDisplayName(resp.optString("login", null));
        p.setProviderId(getProviderId());
        if (config.isSaveRawResponse()) {
            p.setRawResponse(response);
        }
        userProfile = p;
        return userProfile;
    } catch (Exception ex) {
        throw new ServerDataException(
                "Failed to parse the user profile json : " + response, ex);
    }
}
 
Example #23
Source File: YahooImpl.java    From socialauth with MIT License 5 votes vote down vote up
/**
 * Updates the status on the chosen provider if available. This may not be
 * implemented for all providers.
 * 
 * @param msg
 *            Message to be shown as user's status
 * @throws Exception
 */
@Override
public Response updateStatus(final String msg) throws Exception {
	if (msg == null || msg.trim().length() == 0) {
		throw new ServerDataException("Status cannot be blank");
	}
	String url = String.format(UPDATE_STATUS_URL,
			accessToken.getAttribute("xoauth_yahoo_guid"));
	LOG.info("Updating status " + msg + " on " + url);
	String msgBody = "{\"status\":{\"message\":\"" + msg + "\"}}";
	Response serviceResponse = null;
	try {
		serviceResponse = authenticationStrategy.executeFeed(url,
				MethodType.PUT.toString(), null, null, msgBody);
	} catch (Exception ie) {
		throw new SocialAuthException("Failed to update status on " + url,
				ie);
	}

	if (serviceResponse.getStatus() != 204) {
		throw new SocialAuthException(
				"Failed to update status. Return status code :"
						+ serviceResponse.getStatus());
	}
	LOG.debug("Status Updated and return status code is : "
			+ serviceResponse.getStatus());
	// return 204
	return serviceResponse;
}
 
Example #24
Source File: RunkeeperImpl.java    From socialauth with MIT License 5 votes vote down vote up
/**
 * Gets the list of contacts of the user. this may not be available for all
 * providers.
 * 
 * @return List of contact objects representing Contacts.
 */

@Override
public List<Contact> getContactList() throws Exception {
	LOG.warn("WARNING: Not implemented for Runkeeper");
	throw new SocialAuthException(
			"Retrieving contacts is not implemented for Runkeeper");
}
 
Example #25
Source File: FourSquareImpl.java    From socialauth with MIT License 5 votes vote down vote up
@Override
public Response uploadImage(final String message, final String fileName,
		final InputStream inputStream) throws Exception {
	LOG.warn("WARNING: Not implemented for FourSquare");
	throw new SocialAuthException(
			"Update Status is not implemented for FourSquare");
}
 
Example #26
Source File: LinkedInOAuth2Impl.java    From socialauth with MIT License 5 votes vote down vote up
@Override
public Response uploadImage(final String message, final String fileName,
		final InputStream inputStream) throws Exception {
	LOG.warn("WARNING: Not implemented for LinkedIn");
	throw new SocialAuthException(
			"Update Image is not implemented for LinkedIn");
}
 
Example #27
Source File: StackExchangeImpl.java    From socialauth with MIT License 5 votes vote down vote up
@Override
public Response uploadImage(String message, String fileName,
		InputStream inputStream) throws Exception {
	LOG.warn("WARNING: Not implemented for StackExchange");
	throw new SocialAuthException(
			"Upload Image is not implemented for StackExchange");
}
 
Example #28
Source File: SalesForceImpl.java    From socialauth with MIT License 5 votes vote down vote up
/**
 * Gets the list of contacts of the user. this may not be available for all
 * providers.
 * 
 * @return List of contact objects representing Contacts. Only name will be
 *         available
 */

@Override
public List<Contact> getContactList() throws Exception {
	LOG.warn("WARNING: Not implemented for SalesForce");
	throw new SocialAuthException(
			"Retrieving contacts is not implemented for SalesForce");

}
 
Example #29
Source File: MySpaceImpl.java    From socialauth with MIT License 5 votes vote down vote up
@Override
public Response uploadImage(final String message, final String fileName,
		final InputStream inputStream) throws Exception {
	LOG.warn("WARNING: Not implemented for MySpace");
	throw new SocialAuthException(
			"Update Status is not implemented for MySpace");
}
 
Example #30
Source File: InstagramImpl.java    From socialauth with MIT License 5 votes vote down vote up
@Override
public Response api(final String url, final String methodType,
		final Map<String, String> params,
		final Map<String, String> headerParams, final String body)
		throws Exception {

	LOG.debug("Calling URL : " + url);
	try {
		return authenticationStrategy.executeFeed(url, methodType, params,
				headerParams, body);
	} catch (Exception e) {
		throw new SocialAuthException("Error : " + e.getMessage()
				+ "- while making request to URL : " + url, e);
	}
}