Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ganttproject/data/resources/language/i18n.properties
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,7 @@ resource.copy.prefix = {0}_{1}
resource.delete = $Delete Resource...
resource.delete.description = Delete resource
resource.import = Import Resources...
resource.importLDAP = Import from Ldap
resource.move.down = Down
resource.move.down.description = Move resource down
resource.move.up = Up
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ public TaskContainmentHierarchyFacade createFacade() {
}
mHuman.add(myResourceActions.getResourceSendMailAction());
mHuman.add(myResourceActions.getResourceImportAction());
mHuman.add(myResourceActions.getResourceLdapImportAction());
bar.add(mHuman);

HelpMenu helpMenu = new HelpMenu(getProject(), getUIFacade(), getProjectUIFacade());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public class ResourceActionSet {

private final AssignmentDeleteAction myAssignmentDelete;

private final ResourceImportLdapAction myResourceLdapImportAction;

private AbstractAction[] myActions;

public ResourceActionSet(ResourceContext resourceContext, AssignmentContext assignmentContext,
Expand All @@ -60,6 +62,7 @@ public ResourceActionSet(ResourceContext resourceContext, AssignmentContext assi
myResourceSendMailAction = new ResourceSendMailAction(table);
myResourceImportAction = new ResourceImportAction(manager, projectFrame.getTaskManager(),
projectFrame.getRoleManager(), projectFrame);
myResourceLdapImportAction = new ResourceImportLdapAction(manager,projectFrame.getTaskManager(),projectFrame.getRoleManager(),projectFrame);
myAssignmentDelete = new AssignmentDeleteAction(assignmentContext, uiFacade);
}

Expand All @@ -69,6 +72,7 @@ public AbstractAction[] getActions() {
myResourcePropertiesAction.putValue(Action.SHORT_DESCRIPTION, null);
myResourceSendMailAction.putValue(Action.SHORT_DESCRIPTION, null);
myResourceImportAction.putValue(Action.SHORT_DESCRIPTION, null);
myResourceLdapImportAction.putValue(Action.SHORT_DESCRIPTION,null);
myActions = new AbstractAction[] { myResourceNewAction, myResourcePropertiesAction };
}
return myActions;
Expand Down Expand Up @@ -102,6 +106,10 @@ public ResourceImportAction getResourceImportAction() {
return myResourceImportAction;
}

public ResourceImportLdapAction getResourceLdapImportAction() {
return myResourceLdapImportAction;
}

public AssignmentDeleteAction getAssignmentDelete() {
return myAssignmentDelete;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package net.sourceforge.ganttproject.action.resource;

import java.awt.event.ActionEvent;

import net.sourceforge.ganttproject.GanttProject;
import net.sourceforge.ganttproject.gui.GanttDialogImportLdap;
import net.sourceforge.ganttproject.gui.UIFacade;
import net.sourceforge.ganttproject.resource.HumanResourceManager;
import net.sourceforge.ganttproject.roles.RoleManager;
import net.sourceforge.ganttproject.task.TaskManager;

public class ResourceImportLdapAction extends ResourceAction {

private final TaskManager myTaskManager;

private final RoleManager myRoleManager;

private final UIFacade myUiFacade;

private final HumanResourceManager myHRManager;

public ResourceImportLdapAction(HumanResourceManager hrManager,TaskManager taskManager, RoleManager roleManager,
GanttProject project) {
super("resource.importLDAP", hrManager);

myTaskManager = taskManager;
myRoleManager = roleManager;
myUiFacade = project.getUIFacade();
myHRManager = hrManager;


// TODO Auto-generated constructor stub
}

@Override
public void actionPerformed(ActionEvent e) {
GanttDialogImportLdap gd = new GanttDialogImportLdap(myUiFacade,myHRManager);
gd.setVisible(true);

}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
package net.sourceforge.ganttproject.gui;

import java.awt.Component;

import java.awt.event.ActionEvent;
import java.util.Hashtable;

import javax.naming.Context;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.directory.InitialDirContext;
import javax.naming.directory.SearchControls;
import javax.naming.directory.SearchResult;
import javax.swing.Action;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JComponent;

import javax.swing.JTabbedPane;

import net.sourceforge.ganttproject.action.CancelAction;
import net.sourceforge.ganttproject.action.OkAction;
import net.sourceforge.ganttproject.gui.options.OptionsPageBuilder;
import net.sourceforge.ganttproject.language.GanttLanguage;
import net.sourceforge.ganttproject.resource.HumanResource;
import net.sourceforge.ganttproject.resource.HumanResourceManager;
import biz.ganttproject.core.option.DefaultStringOption;
import biz.ganttproject.core.option.GPOption;
import biz.ganttproject.core.option.GPOptionGroup;
import biz.ganttproject.core.option.StringOption;


public class GanttDialogImportLdap {

private JTabbedPane tabbedPane;

private boolean change = false;

private final GPOptionGroup myGroup;
private final UIFacade myUIFacade;
private final HumanResourceManager myHumanResourceManager;
private static final GanttLanguage language = GanttLanguage.getInstance();

private final StringOption myBaseDNField = new DefaultStringOption("Base DN");
private final StringOption myServerField = new DefaultStringOption("server");
private final StringOption myFilterField = new DefaultStringOption("Filter");
private final StringOption myUsernameField = new DefaultStringOption("userName");
private final StringOption myPasswordField = new DefaultStringOption("password");

private SearchControls ctls;

public GanttDialogImportLdap(UIFacade uiFacade,HumanResourceManager hrm) {
myUIFacade = uiFacade;
myPasswordField.setScreened(true);
myFilterField.setValue("(&(objectClass=user)(objectcategory=person))");
myHumanResourceManager = hrm;
myGroup = new GPOptionGroup("", new GPOption[] { myServerField,myBaseDNField,myFilterField,myUsernameField,myPasswordField });
myGroup.setTitled(false);
}

private Component getComponent( ) {
OptionsPageBuilder builder = new OptionsPageBuilder();
OptionsPageBuilder.I18N i18n = new OptionsPageBuilder.I18N() {
@Override
public String getOptionLabel(GPOptionGroup group, GPOption<?> option) {
return getValue(option.getID());
}
};
builder.setI18N(i18n);
final JComponent mainPage = builder.buildPlanePage(new GPOptionGroup[] { myGroup });
mainPage.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

tabbedPane = new JTabbedPane();

tabbedPane.addTab(language.getText("general"), new ImageIcon(getClass().getResource("/icons/properties_16.gif")),
mainPage);

return tabbedPane;

}

public void setVisible(boolean isVisible) {
if (isVisible) {
//loadFields();
Component contentPane = getComponent();
OkAction okAction = new OkAction() {
@Override
public void actionPerformed(ActionEvent e) {
myGroup.commit();
okButtonActionPerformed();
}
};
CancelAction cancelAction = new CancelAction() {
@Override
public void actionPerformed(ActionEvent e) {
myGroup.rollback();
change = false;
}
};
myUIFacade.createDialog(contentPane, new Action[] { okAction, cancelAction }, language.getCorrectedLabel("human")).show();
}
}

private void okButtonActionPerformed() {
ctls = new SearchControls();
String[] returnedAttrs = { "sn","givenName","samAccountName","mail","userPrincipalName","displayName" };
ctls.setReturningAttributes(returnedAttrs);
ctls.setSearchScope(SearchControls.SUBTREE_SCOPE);

try {
String providerURL = myServerField.getValue();

Hashtable<String,Object> env = new Hashtable<>();
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, myUsernameField.getValue());
env.put(Context.SECURITY_CREDENTIALS, myPasswordField.getValue());
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, providerURL);
env.put("java.naming.ldap.attributes.binary", "objectSID");
InitialDirContext context = new InitialDirContext(env);

NamingEnumeration<SearchResult> sre = context.search(myBaseDNField.getValue(), myFilterField.getValue() , ctls);

while(sre.hasMoreElements()) {
SearchResult sr = sre.next();

if(sr.getAttributes().get("displayName") != null) {
HumanResource hr = myHumanResourceManager.newHumanResource();
hr.setName(sr.getAttributes().get("displayName").get().toString());
myHumanResourceManager.add(hr);
}
}
sre.close();


} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}


}