Revision 41696

View differences:

trunk/org.gvsig.desktop/org.gvsig.desktop.framework/org.gvsig.andami/src/main/java/org/gvsig/andami/PluginServices.java
48 48
import javax.swing.SwingUtilities;
49 49
import javax.swing.Timer;
50 50

  
51
import org.gvsig.andami.authentication.IAuthentication;
52
// import org.gvsig.andami.messages.Messages;
53 51
import org.gvsig.andami.messages.NotificationManager;
54 52
import org.gvsig.andami.plugins.ExclusiveUIExtension;
55 53
import org.gvsig.andami.plugins.ExtensionDecorator;
......
93 91

  
94 92
    private static String[] arguments;
95 93

  
96
    private static IAuthentication authentication;
97

  
98 94
    private static ExclusiveUIExtension exclusiveUIExtension = null;
99 95

  
100 96
    private PluginClassLoader loader;
......
585 581
        return logger;
586 582
    }
587 583

  
588
    public static IAuthentication getAuthentication() {
589
        return authentication;
590
    }
591

  
592
    public static void setAuthentication(IAuthentication authen) {
593
        authentication = authen;
594
    }
595

  
596 584
    public static DlgPreferences getDlgPreferences() {
597 585
        return DlgPreferences.getInstance();
598 586
    }
trunk/org.gvsig.desktop/org.gvsig.desktop.framework/org.gvsig.andami/src/main/java/org/gvsig/andami/actioninfo/impl/DefaultActionInfo.java
42 42
import org.gvsig.andami.plugins.ExtensionHelper;
43 43
import org.gvsig.andami.plugins.IExtension;
44 44
import org.gvsig.andami.ui.mdiFrame.KeyMapping;
45
import org.gvsig.tools.ToolsLocator;
46
import org.gvsig.tools.identitymanagement.SimpleIdentity;
47
import org.gvsig.tools.identitymanagement.SimpleIdentityManager;
45 48
import org.gvsig.tools.swing.api.ToolsSwingLocator;
46 49
import org.gvsig.tools.swing.icontheme.IconTheme;
47 50
import org.slf4j.Logger;
......
70 73
    private boolean active;
71 74

  
72 75
    private Boolean previousEnabled = null;
76
    private SimpleIdentityManager identityManager;
73 77

  
74 78
    DefaultActionInfo(Class<? extends IExtension> extension, String name,
75 79
            String text, String command, String icon, String accelerator,
......
185 189
        return this.extensionClass.getName();
186 190
    }
187 191

  
192
    private SimpleIdentityManager getIdentityManager() {
193
        if( this.identityManager == null ) {
194
            this.identityManager = ToolsLocator.getIdentityManager();
195
        }
196
        return this.identityManager;
197
    }
198
    
199
    private SimpleIdentity getCurrentUser() {
200
        return this.getIdentityManager().getCurrentIdentity();
201
    }
202
    
188 203
    public boolean isVisible() {
204
        if( !this.getCurrentUser().isAuthorized(this.getName()) ) {
205
            return false;
206
        }
189 207
        if (!this.isActive()) {
190 208
            logger.info("isVisible(), action {} not active", this.getName());
191 209
            return false;
......
205 223

  
206 224
    public boolean isEnabled() {
207 225
        boolean value;
226
        if( !this.getCurrentUser().isAuthorized(this.getName()) ) {
227
            return false;
228
        }
208 229
        if (!this.isActive()) {
209 230
            logger.info("isEnabled(), action {} not active", this.getName());
210 231
            value = false;
......
246 267
//			logger.info("execute(), action {} not active",  this.getName());
247 268
//			return;
248 269
//		}
270
        if( !this.getCurrentUser().isAuthorized(this.getName()) ) {
271
            logger.warn("Current user '"+this.getCurrentUser().getID()+"' not authorized to execute this action '"+this.getName()+"'.");
272
            return ;
273
        }
249 274
        ActionInfo redirection = this.getRedirection();
250 275
        if (redirection != null) {
251 276
            logger.info("{}.execute('{}') redirected", this.getPluginName()
......
264 289
//			logger.info("execute(args), action {} not active", this.getName());
265 290
//			return;
266 291
//		}
292
        if( !this.getCurrentUser().isAuthorized(this.getName()) ) {
293
            logger.warn("Current user '"+this.getCurrentUser().getID()+"' not authorized to execute this action '"+this.getName()+"'.");
294
            return ;
295
        }
267 296
        ActionInfo redirection = this.getRedirection();
268 297
        if (redirection != null) {
269 298
            logger.info("{}.execute('{}', args) redirected", this.getPluginName()
......
286 315
    }
287 316

  
288 317
    public void execute(Map args) {
318
        if( !this.getCurrentUser().isAuthorized(this.getName()) ) {
319
            logger.warn("Current user '"+this.getCurrentUser().getID()+"' not authorized to execute this action '"+this.getName()+"'.");
320
            return ;
321
        }
289 322
        logger.info("{}.execute('{}', Map args)",
290 323
                this.getPluginName() + ":" + this.getExtensionName(),
291 324
                this.getCommand());
trunk/org.gvsig.desktop/org.gvsig.desktop.framework/org.gvsig.andami/src/main/java/org/gvsig/andami/Launcher.java
76 76
import java.util.Properties;
77 77
import java.util.Set;
78 78
import java.util.TreeSet;
79
import java.util.logging.Level;
79 80
import java.util.prefs.Preferences;
80 81

  
81 82
import javax.swing.ImageIcon;
......
94 95
import org.apache.commons.cli.Options;
95 96
import org.apache.commons.cli.ParseException;
96 97
import org.apache.commons.cli.PosixParser;
98
import org.apache.commons.configuration.PropertiesConfiguration;
97 99
import org.apache.commons.io.FileUtils;
98 100
import org.apache.commons.lang3.JavaVersion;
99 101
import org.apache.commons.lang3.SystemUtils;
......
107 109
import org.exolab.castor.xml.ValidationException;
108 110
import org.gvsig.andami.actioninfo.ActionInfo;
109 111
import org.gvsig.andami.actioninfo.ActionInfoManager;
110
import org.gvsig.andami.authentication.IAuthentication;
111 112
import org.gvsig.andami.config.generate.Andami;
112 113
import org.gvsig.andami.config.generate.AndamiConfig;
113 114
import org.gvsig.andami.config.generate.Plugin;
......
159 160
import org.gvsig.installer.swing.api.execution.AbstractInstallPackageWizard;
160 161
import org.gvsig.installer.swing.api.wizard.InstallerWizardActionListener;
161 162
import org.gvsig.installer.swing.api.wizard.InstallerWizardPanel;
163
import org.gvsig.tools.ToolsLocator;
162 164
import org.gvsig.tools.exception.ListBaseException;
163 165
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer;
164 166
import org.gvsig.tools.swing.api.ToolsSwingLocator;
......
481 483
		} catch (Exception ex) {
482 484
			this.addError("Can't register icons", ex);
483 485
		}
484
		validate();
485 486

  
486 487
		// Obtener la personalizaci�n de la aplicacion.
487 488
		try {
......
513 514

  
514 515
		// Initialize andami libraries
515 516
		splashWindow.process(translate("SplashWindow.initialize_install_manager"));
516
		
517
		File defaultAddonsRepository = PluginsLocator.getManager()
518
				.getPluginsFolder();
519
		InstallerManager installerManager = InstallerLocator
520
				.getInstallerManager();
521
		installerManager.addLocalAddonRepository(defaultAddonsRepository,"plugin");
522
		installerManager.setDefaultLocalAddonRepository(defaultAddonsRepository);
517
		PluginsManager pluginmgr = PluginsLocator.getManager();
518
		File defaultAddonsRepository = pluginmgr.getPluginsFolder();
519
		InstallerManager installerManager = InstallerLocator.getInstallerManager();
520
		installerManager.setDefaultLocalAddonRepository(defaultAddonsRepository,"plugin");
523 521

  
524 522
		splashWindow.process(translate("SplashWindow.initialize_list_of_addons_installeds"));
525 523
		// ---------------------------------------------
526 524
		// Get the list of installed packages
527
		PluginsManager pluginmgr = PluginsLocator.getManager();
528
		InstallerManager installmgr = InstallerLocator.getInstallerManager();
529

  
525
		
530 526
		PackageInfo[] installedPackages = null;
531 527
		try {
532
			installedPackages = installmgr.getInstalledPackages(
528
			installedPackages = installerManager.getInstalledPackages(
533 529
                                pluginmgr.getPluginsFolder()
534 530
                        );
535 531
		} catch (MakePluginPackageServiceException e) {
......
553 549
		splashWindow.process(translate("SplashWindow.check_incompatible_plugins"));
554 550
		fixIncompatiblePlugins(installedPackages);
555 551
		
552
                
556 553
		// Se configura el classloader del plugin
557 554
		splashWindow.process(translate("SplashWindow.setup_plugins_configuration"));
558 555
		try {
......
561 558
		} catch (Throwable ex) {
562 559
			this.addError("Can't initialize plugin's classloaders  ", ex);
563 560
		}
561
                
562
                initializeIdentityManagement(new File(andamiConfig.getPluginsDirectory()).getAbsoluteFile());
564 563

  
565 564
		// Initialize libraries
566 565
		splashWindow.process(translate("SplashWindow.initialize_plugins_libraries"));
......
2896 2895
		}
2897 2896
	}
2898 2897

  
2899
	/**
2900
	 * validates the user before starting gvsig
2901
	 * 
2902
	 */
2903
	private static void validate() {
2904

  
2905
		IAuthentication session = null;
2906
		try {
2907
			session = (IAuthentication) Class.forName(
2908
					"com.iver.andami.authentication.Session").newInstance();
2909

  
2910
		} catch (ClassNotFoundException e) {
2911
			return;
2912
		} catch (InstantiationException e) {
2913
			return;
2914
		} catch (IllegalAccessException e) {
2915
			return;
2916
		}
2917

  
2918
		session.setPluginDirectory(andamiConfig.getPluginsDirectory());
2919
		if (session.validationRequired()) {
2920
			if (session.Login()) {
2921
				logger.info("You are logged in");
2922
			} else {
2923
				JOptionPane.showMessageDialog((Component) PluginServices
2924
						.getMainFrame(), "You are not logged in");
2925
			}
2926
			PluginServices.setAuthentication(session);
2927
		}
2928
	}
2929

  
2930 2898
	public static String getDefaultLookAndFeel() {
2931 2899
		String osName = (String) System.getProperty("os.name");
2932 2900

  
......
3982 3950
			return values;
3983 3951
		}
3984 3952
	}
3953
        
3954
        
3955
    private void initializeIdentityManagement(File pluginsFolder) {
3956
        File identityManagementConfigFile = null;
3957
        PluginServices plugin = null;
3958
        Iterator<Entry<String, PluginConfig>> it = pluginsConfig.entrySet().iterator();
3959
        while ( it.hasNext() ) {
3960
            Entry<String, PluginConfig> entry = it.next();
3961
            File pluginFolder = new File(pluginsFolder,entry.getKey());
3962
            File f = new File(pluginFolder,"identity-management.ini");
3963
            if( f.exists() ) {
3964
                if( identityManagementConfigFile!=null ) {
3965
                    logger.warn("Too many identity-managemnt plugins. Disable all.");
3966
                } else {
3967
                    identityManagementConfigFile = f;
3968
                    plugin = PluginServices.getPluginServices(entry.getKey());
3969
                }
3970
            }
3971
        }
3972
        if( identityManagementConfigFile==null || plugin==null ) {
3973
            return;
3974
        }
3975
        if (!identityManagementConfigFile.canRead()) {
3976
            return ;
3977
        }
3978
        PropertiesConfiguration identityManagementConfig = null;
3979
        try {
3980
            identityManagementConfig = new PropertiesConfiguration(identityManagementConfigFile);
3981
        } catch (Exception ex) {
3982
            logger.warn("Can't open identity management config file '" + identityManagementConfigFile.getAbsolutePath() + "'.", ex);
3983
            return;
3984
        }
3985
        String identityManagerClassName = identityManagementConfig.getString("IdentityManager", null);
3986
        String identityManagementInitializerClassName = identityManagementConfig.getString("IdentityManagementInitializer", null);
3987
        try {
3988
            if( identityManagerClassName != null ) {
3989
                Class identityManagerClass = plugin.getClassLoader().loadClass(identityManagerClassName);
3990
                ToolsLocator.registerIdentityManager(identityManagerClass);
3991
            } else {
3992
                logger.info("Entry IdentityManager not found in identity management config file '" + identityManagementConfigFile.getAbsolutePath() + "'.");
3993
            }
3994

  
3995
            if( identityManagementInitializerClassName != null ) {
3996
                Class identityManagerInitializerClass = plugin.getClassLoader().loadClass(identityManagementInitializerClassName);
3997
                Runnable identityManagerInitializer = (Runnable) identityManagerInitializerClass.newInstance();
3998
                identityManagerInitializer.run();
3999
            } else {
4000
                logger.info("Entry IdentityManagementInitializer not found in identity management config file '" + identityManagementConfigFile.getAbsolutePath() + "'.");
4001
            }
4002

  
4003
        } catch (Exception ex) {
4004
            logger.warn("Can't initialize the identity manager from '"+identityManagementConfigFile.getAbsolutePath()+".",ex);
4005
            return;
4006
        }
4007
        logger.info("Loaded a identity manager from plugin '"+plugin.getPluginName()+".");
4008
    }
4009
    
4010
    
3985 4011
}

Also available in: Unified diff