use of net.oauth.OAuthConsumer in project cxf by apache.
the class TemporaryCredentialsController method handleRequest.
@RequestMapping("/handleTemporaryCredentials")
public ModelAndView handleRequest(@ModelAttribute(value = "oAuthParams") OAuthParams oAuthParams, HttpServletResponse response) {
OAuthServiceProvider provider;
OAuthConsumer consumer;
OAuthAccessor accessor;
OAuthClient client = new OAuthClient(new URLConnectionClient());
oAuthParams.setErrorMessage(null);
String temporaryCredentialsEndpointUrl = oAuthParams.getTemporaryCredentialsEndpoint();
if (temporaryCredentialsEndpointUrl == null || "".equals(temporaryCredentialsEndpointUrl)) {
oAuthParams.setErrorMessage("Missing temporary credentials endpoint url");
}
String clientId = oAuthParams.getClientID();
if (clientId == null || "".equals(clientId)) {
oAuthParams.setErrorMessage("Missing client identifier");
}
String secret = oAuthParams.getClientSecret();
if (secret == null || "".equals(secret)) {
oAuthParams.setErrorMessage("Missing client shared-secret");
}
if (oAuthParams.getErrorMessage() == null) {
provider = new OAuthServiceProvider(temporaryCredentialsEndpointUrl, oAuthParams.getResourceOwnerAuthorizationEndpoint(), oAuthParams.getTokenRequestEndpoint());
consumer = new OAuthConsumer(null, clientId, secret, provider);
accessor = new OAuthAccessor(consumer);
Map<String, String> parameters = new HashMap<>();
parameters.put(OAuth.OAUTH_SIGNATURE_METHOD, oAuthParams.getSignatureMethod());
parameters.put(OAuth.OAUTH_NONCE, UUID.randomUUID().toString());
parameters.put(OAuth.OAUTH_TIMESTAMP, String.valueOf(System.currentTimeMillis() / 1000));
parameters.put(OAuth.OAUTH_CALLBACK, oAuthParams.getCallbackURL());
parameters.put("realm", "private");
parameters.put("scope", "read_info modify_info");
try {
accessor.consumer.setProperty(OAuthClient.PARAMETER_STYLE, ParameterStyle.AUTHORIZATION_HEADER);
client.getRequestToken(accessor, OAuthMessage.POST, parameters.entrySet());
} catch (Exception e) {
oAuthParams.setErrorMessage(e.toString());
}
oAuthParams.setOauthToken(accessor.requestToken);
oAuthParams.setOauthTokenSecret(accessor.tokenSecret);
Cookie cId = new Cookie("clientID", oAuthParams.getClientID());
Cookie cSec = new Cookie("clientSecret", oAuthParams.getClientSecret());
Cookie tokenSec = new Cookie("tokenSec", accessor.tokenSecret);
response.addCookie(cId);
response.addCookie(cSec);
response.addCookie(tokenSec);
}
ModelAndView modelAndView = new ModelAndView();
if (oAuthParams.getErrorMessage() != null) {
modelAndView.setViewName("temporaryCredentials");
} else {
modelAndView.setViewName("authorizeResourceOwner");
}
return modelAndView;
}
use of net.oauth.OAuthConsumer in project bigbluebutton by bigbluebutton.
the class IMSPOXRequest method validateRequest.
// Assumes data is all loaded
public void validateRequest(String oauth_consumer_key, String oauth_secret, HttpServletRequest request) {
valid = false;
OAuthMessage oam = OAuthServlet.getMessage(request, null);
OAuthValidator oav = new SimpleOAuthValidator();
OAuthConsumer cons = new OAuthConsumer("about:blank#OAuth+CallBack+NotUsed", oauth_consumer_key, oauth_secret, null);
OAuthAccessor acc = new OAuthAccessor(cons);
try {
base_string = OAuthSignatureMethod.getBaseString(oam);
} catch (Exception e) {
base_string = null;
}
try {
oav.validateMessage(oam, acc);
} catch (Exception e) {
errorMessage = "Launch fails OAuth validation: " + e.getMessage();
return;
}
valid = true;
}
use of net.oauth.OAuthConsumer in project zm-mailbox by Zimbra.
the class OAuthAccessorSerializer method deserialize.
@Override
public OAuthAccessor deserialize(Object obj) throws ServiceException {
String value = (String) obj;
LOG.debug("get value: " + value);
String consumer_key = value.substring(0, value.indexOf(",token_secret")).substring(13);
String token_secret = value.substring(value.indexOf(",token_secret"), value.indexOf(",callback")).substring(14);
String callback = value.substring(value.indexOf(",callback"), value.indexOf(",user")).substring(10);
String user = value.substring(value.indexOf(",user"), value.indexOf(",authorized")).substring(6);
String authorized = value.substring(value.indexOf(",authorized"), value.indexOf(",zauthtoken")).substring(12);
String zauthtoken = value.substring(value.indexOf(",zauthtoken"), value.indexOf(",verifier")).substring(12);
String verifier = value.substring(value.indexOf(",verifier"), value.indexOf(",approved_on")).substring(10);
String approved_on = value.substring(value.indexOf(",approved_on"), value.indexOf(",device")).substring(13);
String device = value.substring(value.indexOf(",device")).substring(8);
LOG.debug("[consumer_key:%s, callback:%s, user:%s, authorized:%s, zauthtoken:%s, verifier:%s, approved_on:%s, device:%s]", consumer_key, callback, user, authorized, zauthtoken, verifier, approved_on, device);
try {
OAuthConsumer consumer = OAuthServiceProvider.getConsumer(consumer_key);
OAuthAccessor accessor = new OAuthAccessor(consumer);
accessor.tokenSecret = token_secret;
accessor.setProperty(OAuth.OAUTH_CALLBACK, callback);
if (!user.equals("null")) {
accessor.setProperty("user", user);
}
if (authorized.equalsIgnoreCase(Boolean.FALSE.toString())) {
accessor.setProperty("authorized", Boolean.FALSE);
} else if (authorized.equalsIgnoreCase(Boolean.TRUE.toString())) {
accessor.setProperty("authorized", Boolean.TRUE);
}
if (!zauthtoken.equals("null")) {
accessor.setProperty("ZM_AUTH_TOKEN", zauthtoken);
AuthToken zimbraAuthToken = ZimbraAuthToken.getAuthToken(zauthtoken);
final Account account = zimbraAuthToken.getAccount();
OAuthServiceProvider.setAccountPropertiesForAccessor(account, accessor);
}
if (!verifier.equals("null")) {
accessor.setProperty(OAuth.OAUTH_VERIFIER, verifier);
}
if (null != approved_on) {
accessor.consumer.setProperty("approved_on", approved_on);
}
if (null != device) {
accessor.consumer.setProperty("device", device);
}
return accessor;
} catch (Exception e) {
//need more hack here for hadnling IOException properly
throw ServiceException.FAILURE("IOException", e);
}
}
use of net.oauth.OAuthConsumer in project zm-mailbox by Zimbra.
the class OAuthServiceProvider method getConsumer.
public static synchronized OAuthConsumer getConsumer(String consumer_key) throws IOException, OAuthProblemException {
String[] registeredConsumers;
try {
// TODO - need to lookup the domain first
registeredConsumers = Provisioning.getInstance().getConfig().getMultiAttr(Provisioning.A_zimbraOAuthConsumerCredentials);
} catch (ServiceException e) {
throw new OAuthProblemException("token_rejected");
}
OAuthConsumer oAuthConsumer = null;
for (String consumer : registeredConsumers) {
String[] s = consumer.split(":");
if (s.length >= 2 && s[0].equals(consumer_key)) {
oAuthConsumer = new OAuthConsumer(null, consumer_key, s[1], null);
oAuthConsumer.setProperty("key", consumer_key);
oAuthConsumer.setProperty("app_name", s.length > 2 ? s[2] : "");
break;
}
}
if (oAuthConsumer == null) {
throw new OAuthProblemException("token_rejected");
}
return oAuthConsumer;
}
use of net.oauth.OAuthConsumer in project cxf by apache.
the class TokenRequestController method handleRequest.
@RequestMapping("/tokenRequest")
protected ModelAndView handleRequest(@ModelAttribute("oAuthParams") OAuthParams oAuthParams, HttpServletRequest request) throws Exception {
String oauthToken = oAuthParams.getOauthToken();
String tokenRequestEndpoint = oAuthParams.getTokenRequestEndpoint();
String clientID = oAuthParams.getClientID();
if (tokenRequestEndpoint == null || "".equals(tokenRequestEndpoint)) {
oAuthParams.setErrorMessage("Missing token request URI");
}
if (clientID == null || "".equals(clientID)) {
oAuthParams.setErrorMessage("Missing consumer key");
}
if (oauthToken == null || "".equals(oauthToken)) {
oAuthParams.setErrorMessage("Missing oauth token");
}
String verifier = oAuthParams.getOauthVerifier();
if (verifier == null || "".equals(verifier)) {
oAuthParams.setErrorMessage("Missing oauth verifier");
}
if (oAuthParams.getErrorMessage() == null) {
OAuthClient client = new OAuthClient(new URLConnectionClient());
OAuthServiceProvider provider = new OAuthServiceProvider(oAuthParams.getTemporaryCredentialsEndpoint(), oAuthParams.getResourceOwnerAuthorizationEndpoint(), tokenRequestEndpoint);
OAuthConsumer consumer = new OAuthConsumer(null, clientID, oAuthParams.getClientSecret(), provider);
OAuthAccessor accessor = new OAuthAccessor(consumer);
accessor.requestToken = oauthToken;
accessor.tokenSecret = Common.findCookieValue(request, "tokenSec");
Map<String, String> parameters = new HashMap<>();
parameters.put(OAuth.OAUTH_SIGNATURE_METHOD, oAuthParams.getSignatureMethod());
parameters.put(OAuth.OAUTH_NONCE, UUID.randomUUID().toString());
parameters.put(OAuth.OAUTH_TIMESTAMP, String.valueOf(System.currentTimeMillis() / 1000));
parameters.put(OAuth.OAUTH_TOKEN, oauthToken);
parameters.put(OAuth.OAUTH_VERIFIER, oAuthParams.getOauthVerifier());
try {
client.getAccessToken(accessor, OAuthMessage.GET, parameters.entrySet());
oAuthParams.setOauthToken(accessor.accessToken);
} catch (Exception e) {
oAuthParams.setErrorMessage(e.toString());
oAuthParams.setOauthToken(oauthToken);
return new ModelAndView("tokenRequest");
}
oAuthParams.setOauthTokenSecret(accessor.tokenSecret);
}
oAuthParams.setClientID(Common.findCookieValue(request, "clientID"));
oAuthParams.setClientSecret(Common.findCookieValue(request, "clientSecret"));
return new ModelAndView("accessToken");
}
Aggregations