Skip to content

Commit

Permalink
511216: Support central USS OAuth login in MPC
Browse files Browse the repository at this point in the history
Use USS 1.1. Remove reflective compatibility layer to support old and
new USS releases.

Bug: 511216
Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=511216
  • Loading branch information
creckord committed Apr 13, 2017
1 parent 07d1821 commit d55d913
Show file tree
Hide file tree
Showing 12 changed files with 70 additions and 727 deletions.
4 changes: 2 additions & 2 deletions org.eclipse.epp.mpc.core/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ Require-Bundle: org.eclipse.osgi;bundle-version="3.6.0",
org.eclipse.equinox.ds;bundle-version="1.4.100",
org.eclipse.osgi.services;bundle-version="3.3.100",
org.eclipse.equinox.util;bundle-version="1.0.500",
org.eclipse.userstorage;bundle-version="[1.0.1,1.2.0)",
org.eclipse.userstorage.oauth;bundle-version="[1.0.0,1.2.0)";resolution:=optional,
org.eclipse.userstorage;bundle-version="[1.1.0,2.0.0)",
org.eclipse.userstorage.oauth;bundle-version="[1.0.0,2.0.0)",
org.eclipse.equinox.security;bundle-version="1.2.0"
Export-Package: org.eclipse.epp.internal.mpc.core;x-friends:="org.eclipse.epp.mpc.ui",
org.eclipse.epp.internal.mpc.core.model;x-friends:="org.eclipse.epp.mpc.ui",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*******************************************************************************
* Copyright (c) 2010 The Eclipse Foundation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* The Eclipse Foundation - initial API and implementation
*******************************************************************************/
package org.eclipse.epp.internal.mpc.core.service;

import org.eclipse.userstorage.oauth.OAuthParameters;

final class MPCOAuthParameters extends OAuthParameters {

private static final String SERVICE_NAME = "mpc"; //$NON-NLS-1$

private static final String CLIENT_ID = "1e8b68d6e5015c2bcf8e03d44dd97fc431f17e394860f08f1a05978c"; //$NON-NLS-1$

private static final String CLIENT_SECRET = "26e9f81e5d02d4a019e042d012a861f34a446c35cb84070e80278d8e"; //$NON-NLS-1$

private static final String CLIENT_KEY = "9d08c11f742f53a2cd6348d373fd1fa0b079694199f760b315a12a"; //$NON-NLS-1$

// FIXME: these should be the uss_project_* alternatives
//private static final String[] DEFAULT_MPC_SCOPES = { "profile", "uss_project_retrieve", "uss_project_update", "uss_project_delete" };
private static final String[] DEFAULT_MPC_SCOPES = { "profile", "uss_retrieve", "uss_update" }; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$

@Override
protected String getServiceName() {
return SERVICE_NAME;
}

@Override
protected String getDefaultClientId() {
return CLIENT_ID;
}

@Override
protected String getDefaultClientSecret() {
return CLIENT_SECRET;
}

@Override
protected String getDefaultClientKey() {
return CLIENT_KEY;
}

@Override
protected String[] getDefaultScopes() {
return DEFAULT_MPC_SCOPES;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.util.concurrent.Callable;
import java.util.concurrent.CopyOnWriteArrayList;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.epp.internal.mpc.core.MarketplaceClientCore;
import org.eclipse.epp.internal.mpc.core.util.ServiceUtil;
import org.eclipse.epp.mpc.core.service.IMarketplaceStorageService;
Expand Down Expand Up @@ -65,8 +64,6 @@ public class MarketplaceStorageService implements IMarketplaceStorageService {

private EclipseOAuthCredentialsProvider credentialsProvider;

private StorageConfigurer configurer;

public URI getServiceUri() {
return serviceUri;
}
Expand Down Expand Up @@ -104,14 +101,9 @@ protected StorageFactory createStorageFactory() {
protected IStorage createStorage() {
IStorage storage = getStorageFactory().create(applicationToken,
new FileStorageCache.SingleApplication(this.applicationToken));
try {
configurer = StorageConfigurer.get();
configurer.configure(storage);
configurer.setInteractive(storage, false);
} catch (CoreException e) {
configurer = null;
MarketplaceClientCore.error(e);
}
credentialsProvider = new EclipseOAuthCredentialsProvider(new MPCOAuthParameters());
credentialsProvider.setInteractive(false);
storage.setCredentialsProvider(credentialsProvider);
return storage;
}

Expand All @@ -137,10 +129,13 @@ public String getRegisteredUser() {

public <T> T runWithLogin(Callable<T> c) throws Exception {
String oldUser = getCurrentUser();
boolean wasInteractive = credentialsProvider.isInteractive();
credentialsProvider.setInteractive(true);
try {
T result = configurer != null ? configurer.runWithLogin(storage, c) : c.call();
T result = c.call();
return result;
} finally {
credentialsProvider.setInteractive(wasInteractive);
String newUser = getCurrentUser();//TODO the OAuth token might change with the user staying the same - this would cause an unnecessary refresh event
notifyLoginChanged(oldUser, newUser);
}
Expand Down Expand Up @@ -186,8 +181,7 @@ private Credentials getStorageCredentials() {
return null;
}
IStorageService service = getStorage().getService();
//return provider.hasCredentials(service) ? provider.getCredentials(service) : null;
return ((StorageService) service).getCredentials();
return provider.hasCredentials(service) ? provider.getCredentials(service) : null;
}

public void activate(BundleContext context, Map<?, ?> properties) {
Expand Down

This file was deleted.

This file was deleted.

Loading

0 comments on commit d55d913

Please sign in to comment.