From 3102d8bce3426d9cf41aeaf201c360d342677770 Mon Sep 17 00:00:00 2001 From: Jesse Morgan Date: Sat, 9 Apr 2016 14:22:20 -0700 Subject: Switching from Ivy+Ant to Maven. --- .../p4square/f1oauth/SecondPartyAuthenticator.java | 52 ++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/main/java/com/p4square/f1oauth/SecondPartyAuthenticator.java (limited to 'src/main/java/com/p4square/f1oauth/SecondPartyAuthenticator.java') diff --git a/src/main/java/com/p4square/f1oauth/SecondPartyAuthenticator.java b/src/main/java/com/p4square/f1oauth/SecondPartyAuthenticator.java new file mode 100644 index 0000000..8deefec --- /dev/null +++ b/src/main/java/com/p4square/f1oauth/SecondPartyAuthenticator.java @@ -0,0 +1,52 @@ +/* + * Copyright 2013 Jesse Morgan + */ + +package com.p4square.f1oauth; + +import org.apache.log4j.Logger; + +import com.p4square.restlet.oauth.OAuthException; +import com.p4square.restlet.oauth.OAuthUser; + +import org.restlet.Context; +import org.restlet.Request; +import org.restlet.Response; +import org.restlet.security.Authenticator; + +/** + * Restlet Authenticator for 2nd + * @author Jesse Morgan + */ +public class SecondPartyAuthenticator extends Authenticator { + private static final Logger LOG = Logger.getLogger(SecondPartyAuthenticator.class); + + private final F1Access mHelper; + + public SecondPartyAuthenticator(Context context, boolean optional, F1Access helper) { + super(context, optional); + + mHelper = helper; + } + + protected boolean authenticate(Request request, Response response) { + if (request.getChallengeResponse() == null) { + return false; // no credentials + } + + String username = request.getChallengeResponse().getIdentifier(); + String password = new String(request.getChallengeResponse().getSecret()); + + try { + OAuthUser user = mHelper.getAccessToken(username, password); + request.getClientInfo().setUser(user); + + return true; + + } catch (OAuthException e) { + LOG.info("OAuth Exception: " + e); + } + + return false; // Invalid credentials + } +} -- cgit v1.2.3