| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
package org.apache.shindig.social.core.oauth; |
| 19 | |
|
| 20 | |
import org.apache.shindig.auth.AuthenticationHandler; |
| 21 | |
import org.apache.shindig.auth.SecurityToken; |
| 22 | |
import org.apache.shindig.social.opensocial.oauth.OAuthLookupService; |
| 23 | |
|
| 24 | |
import com.google.inject.Inject; |
| 25 | |
|
| 26 | |
import net.oauth.OAuth; |
| 27 | |
import net.oauth.OAuthMessage; |
| 28 | |
import net.oauth.server.OAuthServlet; |
| 29 | |
|
| 30 | |
import org.apache.commons.lang.StringUtils; |
| 31 | |
|
| 32 | |
import java.io.IOException; |
| 33 | |
|
| 34 | |
import javax.servlet.http.HttpServletRequest; |
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
public class OAuthConsumerRequestAuthenticationHandler implements AuthenticationHandler { |
| 42 | |
public static final String AUTH_OAUTH_CONSUMER_REQUEST = "OAuth-ConsumerRequest"; |
| 43 | |
public static final String REQUESTOR_ID_PARAM = "xoauth_requestor_id"; |
| 44 | |
private final OAuthLookupService service; |
| 45 | |
|
| 46 | |
@Inject |
| 47 | 3 | public OAuthConsumerRequestAuthenticationHandler(OAuthLookupService service) { |
| 48 | 3 | this.service = service; |
| 49 | 3 | } |
| 50 | |
|
| 51 | |
public String getName() { |
| 52 | 0 | return AUTH_OAUTH_CONSUMER_REQUEST; |
| 53 | |
} |
| 54 | |
|
| 55 | |
public SecurityToken getSecurityTokenFromRequest(HttpServletRequest request) { |
| 56 | 0 | OAuthMessage requestMessage = OAuthServlet.getMessage(request, null); |
| 57 | |
|
| 58 | 0 | String containerKey = getParameter(requestMessage, OAuth.OAUTH_CONSUMER_KEY); |
| 59 | 0 | String containerSignature = getParameter(requestMessage, OAuth.OAUTH_SIGNATURE); |
| 60 | 0 | String userId = StringUtils.trim(request.getParameter(REQUESTOR_ID_PARAM)); |
| 61 | |
|
| 62 | 0 | if (containerKey == null || containerSignature == null || StringUtils.isBlank(userId)) { |
| 63 | |
|
| 64 | 0 | return null; |
| 65 | |
} |
| 66 | |
|
| 67 | 0 | if (service.thirdPartyHasAccessToUser(requestMessage, containerKey, userId)) { |
| 68 | 0 | return service.getSecurityToken(containerKey, userId); |
| 69 | |
} else { |
| 70 | 0 | return null; |
| 71 | |
} |
| 72 | |
} |
| 73 | |
|
| 74 | |
private String getParameter(OAuthMessage requestMessage, String key) { |
| 75 | |
try { |
| 76 | 0 | return requestMessage.getParameter(key); |
| 77 | 0 | } catch (IOException e) { |
| 78 | 0 | return null; |
| 79 | |
} |
| 80 | |
} |
| 81 | |
|
| 82 | |
} |