Java tutorial
/* * Copyright (c) 2013, Helome and/or its affiliates. All rights reserved. * Helome PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. * * Created on 2014-3-27 */ package ext.sns.service; import java.util.HashMap; import java.util.List; import java.util.Map; import org.apache.commons.collections.MapUtils; import org.apache.commons.lang.StringUtils; import ext.sns.auth.AccessTokenResponse; import ext.sns.auth.AuthResponse; import ext.sns.auth.OAuth2Client; import ext.sns.config.ConfigManager; /** * * * @ClassName: OAuthService * @Description: ?? * @date 2014-3-27 ?5:32:01 * @author ShenTeng * */ public class OAuth2Service { /** * ???????? * * @return ??? */ public static List<String> getTypesByProviderName(String providerName) { return ConfigManager.getProviderConfigByName(providerName).getTypes(); } /** * ????? * * @param typeList ??? * * @return ????? */ public static List<String> getProviderNameByTypes(List<String> typeList) { return ConfigManager.getProviderNameByTypes(typeList); } /** * ????? * * @param types ??? * * @return ????? */ public static List<String> getProviderNameByTypes(String... types) { return ConfigManager.getProviderNameByTypes(types); } /** * ????? * * @param providerName ???? * @return ????? */ public static boolean checkProviderName(String providerName) { return ConfigManager.checkProviderName(providerName); } /** * ??URI * * @param providerName ???? * @param type ???nullempty * @param backExtParam ???????nullempty * @param specialParamKey ?Key?providerkey???????null * @return ?URI */ public static String getRequestAuthURI(String providerName, String type, Map<String, String> backExtParam, String specialParamKey) { if (!ConfigManager.getProviderConfigByName(providerName).getTypes().contains(type)) { throw new IllegalArgumentException(providerName + "?" + type + "?."); } if (StringUtils.isBlank(type)) { throw new IllegalArgumentException("type can't be blank."); } Map<String, String> callbackParam = new HashMap<String, String>(); if (MapUtils.isNotEmpty(backExtParam)) { callbackParam.putAll(backExtParam); } return OAuth2Client.getAuthRequestURI(providerName, type, callbackParam, specialParamKey); } /** * ????AuthResponse * * @param params ?? * @return AuthResponse */ public static AuthResponse getAuthResponseByURI(String uri) { Map<String, String> authBackParam = OAuth2Client.getAuthBackParamByURI(uri); return OAuth2Client.getAuthResponse(authBackParam); } /** * ?accessToken */ public static AccessTokenResponse accessToken(AuthResponse authResponse) { if (null == authResponse) { throw new IllegalArgumentException("??authResponse=" + authResponse); } return OAuth2Client.accessToken(authResponse); } }