Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Makes login(String user, String pass) work properly.
* Now it don't look up credentials in the usermanager framework, unless
a user is logged in
* It also gets the values (e.g. the default value for the authorization
server) from plugin.xml
  • Loading branch information
KlasJoensson committed Oct 1, 2013
1 parent 54f726a commit 3f24321
Showing 1 changed file with 48 additions and 4 deletions.
Expand Up @@ -20,6 +20,7 @@
import java.util.List;
import java.util.Map;

import javax.naming.CannotProceedException;
import javax.security.auth.login.LoginException;

import net.bioclipse.business.BioclipsePlatformManager;
Expand All @@ -31,6 +32,7 @@
import net.bioclipse.core.domain.StringMatrix;
import net.bioclipse.jobs.IReturner;
import net.bioclipse.managers.business.IBioclipseManager;
import net.bioclipse.opentox.OpenToxConstants;
import net.bioclipse.opentox.OpenToxLogInOutListener;
import net.bioclipse.opentox.api.Algorithm;
import net.bioclipse.opentox.api.Dataset;
Expand All @@ -47,8 +49,13 @@
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.log4j.Logger;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtension;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Platform;

public class OpentoxManager implements IBioclipseManager {

Expand Down Expand Up @@ -130,10 +137,47 @@ public void logout() throws BioclipseException {
}
}

public boolean login(String user, String pass) throws BioclipseException {
/* TODO The account type below (i.e. OpenTox) should not be hard coded.
* It should come from the the extension point somehow */
String authService = userManager.getProperty( "OpenTox", "auth. service" );
public boolean login(String user, String pass) throws BioclipseException,
CannotProceedException {

IExtensionRegistry registry = Platform.getExtensionRegistry();
IExtensionPoint extensionPoint = registry.getExtensionPoint(
"net.bioclipse.usermanager.accountType" );
IExtension[] extensions = extensionPoint.getExtensions();

String authService = "", accountId = "", propertyKey = "";
for (IExtension extension : extensions) {
IConfigurationElement[] configelements = extension.
getConfigurationElements();
for (IConfigurationElement element : configelements) {
String id = element.getAttribute( "id" );
accountId = element.getAttribute( "name" );
if (id.contains( OpenToxConstants.PLUGIN_ID )) {
IConfigurationElement[] test = element.getChildren();
for (IConfigurationElement element2 : test) {
String attribute = element2.
getAttribute( "defaultValue" );
if (attribute != null && attribute.toLowerCase().
startsWith( "http" )) {
propertyKey = element2.getAttribute( "name" );
authService = attribute;
}
}
}
}
}
if (userManager.isLoggedIn()) {
String accountName = userManager.
getAccountIdsByAccountTypeName( accountId ).get( 0 );
authService = userManager.getProperty(accountName, propertyKey );
System.out.println(accountName);
}
if (authService.isEmpty())
throw new CannotProceedException( "Could not decide which " +
"authorization server to be used. Please try \u0027" +
"login(String user, String pass, String authService)" +
"\u0027" );

return login( user, pass, authService );
}

Expand Down

0 comments on commit 3f24321

Please sign in to comment.