Skip to content

Commit

Permalink
Made the user manager not to attempt to log in to account types the user
Browse files Browse the repository at this point in the history
do not have
  • Loading branch information
KlasJoensson committed Aug 16, 2012
1 parent 46a15e4 commit 88495e4
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 18 deletions.
Expand Up @@ -12,7 +12,10 @@
package net.bioclipse.usermanager;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;

/**
* The local user with username and password for
Expand Down Expand Up @@ -71,7 +74,16 @@ String getUserName() {
HashMap<String, Account> getAccounts() {
return accounts;
}


public ArrayList<String> getAccountTypes() {
ArrayList<String> accountTypes = new ArrayList<String>();
Collection<Account> myAccounts = accounts.values();
Iterator<Account> itr = myAccounts.iterator();
while (itr.hasNext())
accountTypes.add( itr.next().getAccountType().getName() );
return accountTypes;
}

void addAccount(Account account) {
accounts.put( account.getAccountId(), account );
}
Expand Down
Expand Up @@ -181,7 +181,8 @@ public boolean isLoggedIn() {
* Signs out the current superuser
*/
public void signOut() {
loggedInUser.clearLoggedInAccounts();
if(loggedInUser != null)
loggedInUser.clearLoggedInAccounts();
loggedInUser = null;
textEncryptor = null;
logger.debug( "Signed out user from usercontainer with id: "
Expand Down
Expand Up @@ -184,10 +184,14 @@ public boolean signInToAccount(AccountType accountType) {
* log-in properties if the user have more than one account per account
* type in Bioclipse?*/
private boolean fireLoggin(String accountType) {
boolean result = false;
if (userContainer.isLoggedIn()) {
return listnerIds.get( accountType ).receiveUserManagerEvent( UserManagerEvent.LOGIN );
} else
return false;
for( IUserManagerListener listener : listeners) {
if (listener.getAccountType().equals( accountType ))
result = listener.receiveUserManagerEvent( UserManagerEvent.LOGIN );
}
}
return result;
}

/**
Expand All @@ -206,19 +210,22 @@ private boolean fireLoginWithProgressBar( SubProgressMonitor monitor ) {
try {
for( IUserManagerListener listener : listeners) {
failedLogin.clear();
loginOK = listener.receiveUserManagerEvent( UserManagerEvent.LOGIN );
if (!loginOK) {
name = listener.getClass().getName();
failedLogin.add( name
.substring( 0, name.lastIndexOf( '.' ) ) );
}
if (userContainer.getLoggedInUser().getLoggedInAccounts() != null ) {
name = listener.getClass().getName();
userContainer.getLoggedInUser().addLoggedInAccount( name.substring( 0, name.lastIndexOf( '.' ) ), loginOK );
}
if(usingMonitor) {
monitor.beginTask("signing in", ticks);
monitor.worked( ticks/listeners.size() );
name = listener.getClass().getName();
name = name.substring( 0, name.lastIndexOf( '.' ) );
ArrayList<String> userAccountTypes = userContainer.getLoggedInUser().getAccountTypes();

if (userAccountTypes.contains( listener.getAccountType() )) {
loginOK = listener.receiveUserManagerEvent( UserManagerEvent.LOGIN );
if (!loginOK) {
failedLogin.add( name );
}
if (userContainer.getLoggedInUser().getLoggedInAccounts() != null ) {
userContainer.getLoggedInUser().addLoggedInAccount( name, loginOK );
}
if(usingMonitor) {
monitor.beginTask("signing in", ticks);
monitor.worked( ticks/listeners.size() );
}
}
}
if( isLoggedIn() ) {
Expand Down

0 comments on commit 88495e4

Please sign in to comment.