--- /dev/null
+package org.argeo.cms.util.useradmin;
+
+import java.security.AccessController;
+import java.util.List;
+import java.util.Set;
+
+import javax.naming.InvalidNameException;
+import javax.naming.ldap.LdapName;
+import javax.naming.ldap.Rdn;
+import javax.security.auth.Subject;
+import javax.security.auth.x500.X500Principal;
+
+import org.argeo.ArgeoException;
+import org.argeo.cms.CmsException;
+import org.argeo.cms.CmsView;
+import org.argeo.cms.auth.AuthConstants;
+import org.argeo.cms.auth.CurrentUser;
+import org.argeo.cms.util.CmsUtils;
+import org.argeo.eclipse.ui.EclipseUiUtils;
+import org.argeo.jcr.JcrUtils;
+import org.argeo.osgi.useradmin.LdifName;
+import org.osgi.service.useradmin.Group;
+import org.osgi.service.useradmin.Role;
+import org.osgi.service.useradmin.User;
+import org.osgi.service.useradmin.UserAdmin;
+
+/** Centralise common patterns to manage roles with a user admin */
+public class UserAdminUtils {
+
+ /** Retrieves a {@link User} given a LDAP name */
+ public final static User getUser(UserAdmin userAdmin, LdapName dn) {
+ User user = userAdmin.getUser(LdifName.dn.name(), dn.toString());
+ return user;
+ }
+
+ /** Retrieves the unique local username given a {@link User}. */
+ public final static String getUsername(User user) {
+ String username = null;
+ if (user instanceof Group)
+ username = getProperty(user, LdifName.cn.name());
+ else
+ username = getProperty(user, LdifName.uid.name());
+ return username;
+ }
+
+ /**
+ * Easily retrieves one of the Role property or an empty String if the
+ * requested property is not defined for the passed user
+ */
+ public final static String getProperty(Role role, String key) {
+ Object obj = role.getProperties().get(key);
+ if (obj != null)
+ return (String) obj;
+ else
+ return "";
+ }
+
+ // CENTRALIZE SOME METHODS UNTIL API IS STABLE
+ /** Simply checks if current user is registered */
+ public static boolean isRegistered() {
+ return !CurrentUser.isAnonymous();
+ }
+
+ /** Simply checks if current user as a home */
+ public static boolean hasHome() {
+ return isRegistered();
+ }
+
+ // SELF HELPERS
+ /** Simply retrieves the current logged-in user display name. */
+ public static User getCurrentUser(UserAdmin userAdmin) {
+ return getUser(userAdmin, getCurrentUserLdapName());
+ }
+
+ /** Simply retrieves the current logged-in user display name. */
+ public static String getCurrentUserDisplayName(UserAdmin userAdmin) {
+ String username = getCurrentUsername();
+ return getUserDisplayName(userAdmin, username);
+ }
+
+ /** Simply retrieves the current logged-in user display name. */
+ public static String getCurrentUserMail(UserAdmin userAdmin) {
+ String username = getCurrentUsername();
+ return getUserMail(userAdmin, username);
+ }
+
+ /** Returns the local name of the current connected user */
+ public final static String getUsername(UserAdmin userAdmin) {
+ LdapName dn = getCurrentUserLdapName();
+ return getUsername(getUser(userAdmin, dn));
+ }
+
+ /** Returns true if the current user is in the specified role */
+ public static boolean isUserInRole(String role) {
+ Set<String> roles = CurrentUser.roles();
+ return roles.contains(role);
+ }
+
+ /** Simply checks if current user is the same as the passed one */
+ public static boolean isCurrentUser(User user) {
+ String userName = getProperty(user, LdifName.dn.name());
+ try {
+ LdapName selfUserName = getCurrentUserLdapName();
+ LdapName userLdapName = new LdapName(userName);
+ if (userLdapName.equals(selfUserName))
+ return true;
+ else
+ return false;
+ } catch (InvalidNameException e) {
+ throw new ArgeoException("User " + user + " has an unvalid dn: "
+ + userName, e);
+ }
+ }
+
+ public final static LdapName getCurrentUserLdapName() {
+ String name = getCurrentUsername();
+ return getLdapName(name);
+ }
+
+ /** Simply retrieves username for current user, generally a LDAP dn */
+ public static String getCurrentUsername() {
+ Subject subject = currentSubject();
+ String name = subject.getPrincipals(X500Principal.class).iterator()
+ .next().toString();
+ return name;
+ }
+
+ /**
+ * Fork of the {@link CurrentUser#currentSubject} method that is private.
+ * TODO Enhance and factorize
+ */
+ private static Subject currentSubject() {
+ CmsView cmsView = CmsUtils.getCmsView();
+ if (cmsView != null)
+ return cmsView.getSubject();
+ Subject subject = Subject.getSubject(AccessController.getContext());
+ if (subject != null)
+ return subject;
+ throw new CmsException("Cannot find related subject");
+ }
+
+ // HOME MANAGEMENT
+ /**
+ * Simply retrieves the *relative* path to the current user home node from
+ * the base home node
+ */
+ public static String getCurrentUserHomeRelPath() {
+ return getHomeRelPath(getCurrentUsername());
+ }
+
+ /**
+ * Simply retrieves the *relative* path to the home node of a user given its
+ * userName
+ */
+ public static String getHomeRelPath(String userName) {
+ String id = getUserUid(userName);
+ String currHomePath = JcrUtils.firstCharsToPath(id, 2) + "/" + id;
+ return currHomePath;
+ }
+
+ // HELPERS TO RETRIEVE REMARKABLE PROPERTIES
+ /** Simply retrieves the user uid from his dn with no useradmin */
+ public static String getUserUid(String dn) {
+ try {
+ LdapName ldapName = new LdapName(dn);
+ Rdn last = ldapName.getRdn(ldapName.size() - 1);
+ if (last.getType().equals(LdifName.uid.name()))
+ return (String) last.getValue();
+ else
+ throw new ArgeoException("Cannot retrieve user uid, "
+ + "non valid dn: " + dn);
+ } catch (InvalidNameException e) {
+ throw new ArgeoException("Cannot parse LDAP name " + dn, e);
+ }
+ }
+
+ /**
+ * Returns the local username if no user with this dn is found or if the
+ * found user has no defined display name
+ */
+ public static String getUserDisplayName(UserAdmin userAdmin, String dn) {
+ User user = getUser(userAdmin, getLdapName(dn));
+ if (user == null)
+ return getUserUid(dn);
+ String displayName = getProperty(user, LdifName.displayName.name());
+ if (EclipseUiUtils.isEmpty(displayName))
+ displayName = getProperty(user, LdifName.cn.name());
+ if (EclipseUiUtils.isEmpty(displayName))
+ return getUserUid(dn);
+ else
+ return displayName;
+ }
+
+ /**
+ * Returns null if no user with this dn is found or if the found user has no
+ * defined mail
+ */
+ public static String getUserMail(UserAdmin userAdmin, String dn) {
+ User user = getUser(userAdmin, getLdapName(dn));
+ if (user == null)
+ return null;
+ else
+ return getProperty(user, LdifName.mail.name());
+ }
+
+ // VARIOUS UI HELPERS
+ public final static String getDefaultCn(String firstName, String lastName) {
+ return (firstName.trim() + " " + lastName.trim() + " ").trim();
+ }
+
+ /** Simply retrieves a display name of the relevant domain */
+ public final static String getDomainName(User user) {
+ String dn = user.getName();
+ if (dn.endsWith(AuthConstants.ROLES_BASEDN))
+ return "System roles";
+ try {
+ LdapName name = new LdapName(dn);
+ List<Rdn> rdns = name.getRdns();
+ String dname = null;
+ int i = 0;
+ loop: while (i < rdns.size()) {
+ Rdn currrRdn = rdns.get(i);
+ if (!LdifName.dc.name().equals(currrRdn.getType()))
+ break loop;
+ else {
+ String currVal = (String) currrRdn.getValue();
+ dname = dname == null ? currVal : currVal + "." + dname;
+ }
+ i++;
+ }
+ return dname;
+ } catch (InvalidNameException e) {
+ throw new ArgeoException("Unable to get domain name for " + dn, e);
+ }
+ }
+
+ // Local Helpers
+ /** Simply retrieves a LDAP name from a dn with no exception */
+ public static LdapName getLdapName(String dn) {
+ try {
+ return new LdapName(dn);
+ } catch (InvalidNameException e) {
+ throw new ArgeoException("Cannot parse LDAP name " + dn, e);
+ }
+ }
+
+}
\ No newline at end of file
--- /dev/null
+package org.argeo.cms.util.useradmin;
+
+import java.util.ArrayList;
+import java.util.Dictionary;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.transaction.Status;
+import javax.transaction.UserTransaction;
+
+import org.argeo.ArgeoException;
+import org.argeo.cms.auth.AuthConstants;
+import org.argeo.osgi.useradmin.UserAdminConf;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.useradmin.UserAdmin;
+import org.osgi.service.useradmin.UserAdminEvent;
+import org.osgi.service.useradmin.UserAdminListener;
+
+/**
+ * Base useradmin wrapper. Implementing application might extends to add
+ * business specific behaviour
+ */
+public class UserAdminWrapper {
+ // private Log log = LogFactory.getLog(UserAdminWrapper.class);
+
+ private UserAdmin userAdmin;
+ private ServiceReference<UserAdmin> userAdminServiceReference;
+ private UserTransaction userTransaction;
+
+ /* USER ADMIN LISTENER MANAGEMENT */
+ List<UserAdminListener> listeners = new ArrayList<UserAdminListener>();
+
+ // TODO implement safer mechanism
+ public void addListener(UserAdminListener userAdminListener) {
+ if (!listeners.contains(userAdminListener))
+ listeners.add(userAdminListener);
+ }
+
+ /**
+ * Starts a transaction if none already exists and notify the userAdmin
+ * listeners.Must be called from the UI Thread.
+ */
+ public UserTransaction beginTransactionIfNeeded() {
+ try {
+ if (userTransaction.getStatus() == Status.STATUS_NO_TRANSACTION) {
+ userTransaction.begin();
+ }
+ return userTransaction;
+ } catch (Exception e) {
+ throw new ArgeoException("Unable to begin transaction", e);
+ }
+ }
+
+ // Expose this?
+ public void removeListener(UserAdminListener userAdminListener) {
+ if (listeners.contains(userAdminListener))
+ listeners.remove(userAdminListener);
+ }
+
+ public void notifyListeners(UserAdminEvent event) {
+ for (UserAdminListener listener : listeners)
+ listener.roleChanged(event);
+ }
+
+ public Map<String, String> getKnownBaseDns(boolean onlyWritable) {
+ Map<String, String> dns = new HashMap<String, String>();
+ for (String uri : userAdminServiceReference.getPropertyKeys()) {
+ if (!uri.startsWith("/"))
+ continue;
+ Dictionary<String, ?> props = UserAdminConf.uriAsProperties(uri);
+ String readOnly = UserAdminConf.readOnly.getValue(props);
+ String baseDn = UserAdminConf.baseDn.getValue(props);
+
+ if (onlyWritable && "true".equals(readOnly))
+ continue;
+ if (baseDn.equalsIgnoreCase(AuthConstants.ROLES_BASEDN))
+ continue;
+ dns.put(baseDn, uri);
+ }
+ return dns;
+ }
+
+ public UserAdmin getUserAdmin() {
+ return userAdmin;
+ }
+
+ public UserTransaction getUserTransaction() {
+ return userTransaction;
+ }
+
+ /* DEPENDENCY INJECTION */
+ public void setUserAdmin(UserAdmin userAdmin) {
+ this.userAdmin = userAdmin;
+ }
+
+ public void setUserTransaction(UserTransaction userTransaction) {
+ this.userTransaction = userTransaction;
+ }
+
+ public void setUserAdminServiceReference(
+ ServiceReference<UserAdmin> userAdminServiceReference) {
+ this.userAdminServiceReference = userAdminServiceReference;
+ }
+}
\ No newline at end of file
Require-Bundle: org.eclipse.core.runtime
Import-Package: org.eclipse.core.runtime.jobs,\
+org.argeo.cms.auth,\
org.argeo.eclipse.spring,\
org.eclipse.jface.window,\
org.eclipse.swt,\
IFolderLayout left = layout.createFolder("left", IPageLayout.LEFT,
0.25f, editorArea);
left.addView(UsersView.ID);
+ left.addView(GroupsView.ID);
- IFolderLayout right = layout.createFolder("right", IPageLayout.RIGHT,
- 0.70f, editorArea);
- right.addView(GroupsView.ID);
+ // IFolderLayout right = layout.createFolder("right", IPageLayout.RIGHT,
+ // 0.70f, editorArea);
+ // right.addView(GroupsView.ID);
}
}
package org.argeo.security.ui.admin.internal;
-import java.security.AccessController;
-import java.util.List;
-import java.util.Set;
-
-import javax.naming.InvalidNameException;
-import javax.naming.ldap.LdapName;
-import javax.naming.ldap.Rdn;
-import javax.security.auth.Subject;
-import javax.security.auth.x500.X500Principal;
-import javax.transaction.Status;
import javax.transaction.UserTransaction;
import org.argeo.ArgeoException;
-import org.argeo.cms.auth.AuthConstants;
-import org.argeo.cms.auth.CurrentUser;
-import org.argeo.osgi.useradmin.LdifName;
import org.argeo.security.ui.admin.internal.providers.UserTransactionProvider;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.services.ISourceProviderService;
-import org.osgi.service.useradmin.Role;
-import org.osgi.service.useradmin.User;
-import org.osgi.service.useradmin.UserAdmin;
/** First effort to centralize back end methods used by the user admin UI */
public class UiAdminUtils {
-
- /** returns the local name of the current connected user */
- public final static String getUsername(UserAdmin userAdmin) {
- LdapName dn = getLdapName();
- return getUsername(getUser(userAdmin, dn));
- }
-
- /** Returns true if the current user is in the specified role */
- public static boolean isUserInRole(String role) {
- Set<String> roles = CurrentUser.roles();
- return roles.contains(role);
- }
-
- public final static boolean isCurrentUser(User user) {
- String userName = getProperty(user, LdifName.dn.name());
- try {
- LdapName selfUserName = UiAdminUtils.getLdapName();
- LdapName userLdapName = new LdapName(userName);
- if (userLdapName.equals(selfUserName))
- return true;
- else
- return false;
- } catch (InvalidNameException e) {
- throw new ArgeoException("User " + user + " has an unvalid dn: "
- + userName, e);
- }
- }
-
- public final static LdapName getLdapName() {
- Subject subject = Subject.getSubject(AccessController.getContext());
- String name = subject.getPrincipals(X500Principal.class).iterator()
- .next().toString();
- LdapName dn;
- try {
- dn = new LdapName(name);
- } catch (InvalidNameException e) {
- throw new ArgeoException("Invalid user dn " + name, e);
- }
- return dn;
- }
-
- public final static User getUser(UserAdmin userAdmin, LdapName dn) {
- User user = userAdmin.getUser(LdifName.dn.name(), dn.toString());
- return user;
- }
-
- public final static String getUsername(User user) {
- String cn = getProperty(user, LdifName.cn.name());
- if (isEmpty(cn))
- cn = getProperty(user, LdifName.uid.name());
- return cn;
- }
-
- /** Simply retrieves a display name of the relevant domain */
- public final static String getDomainName(User user) {
- String dn = user.getName();
- if (dn.endsWith(AuthConstants.ROLES_BASEDN))
- return "System roles";
- try {
- LdapName name;
- name = new LdapName(dn);
- List<Rdn> rdns = name.getRdns();
- String dname = null;
- int i = 0;
- loop: while (i < rdns.size()) {
- Rdn currrRdn = rdns.get(i);
- if (!LdifName.dc.name().equals(currrRdn.getType()))
- break loop;
- else {
- String currVal = (String) currrRdn.getValue();
- dname = dname == null ? currVal : currVal + "." + dname;
- }
- i++;
- }
- return dname;
- } catch (InvalidNameException e) {
- throw new ArgeoException("Unable to get domain name for " + dn, e);
- }
- }
-
- public final static String getProperty(Role role, String key) {
- Object obj = role.getProperties().get(key);
- if (obj != null)
- return (String) obj;
- else
- return "";
- }
-
- public final static String getDefaultCn(String firstName, String lastName) {
- return (firstName.trim() + " " + lastName.trim() + " ").trim();
- }
-
/*
* INTERNAL METHODS: Below methods are meant to stay here and are not part
* of a potential generic backend to manage the useradmin
*/
- public final static boolean notNull(String string) {
- if (string == null)
- return false;
- else
- return !"".equals(string.trim());
- }
-
- public final static boolean isEmpty(String string) {
- if (string == null)
- return true;
- else
- return "".equals(string.trim());
- }
-
- /** Must be called from the UI Thread. */
- public final static void beginTransactionIfNeeded(
- UserTransaction userTransaction) {
- try {
- if (userTransaction.getStatus() == Status.STATUS_NO_TRANSACTION) {
- userTransaction.begin();
- notifyTransactionStateChange(userTransaction);
- }
- } catch (Exception e) {
- throw new ArgeoException("Unable to begin transaction", e);
- }
- }
-
/** Easily notify the ActiveWindow that the transaction had a state change */
public final static void notifyTransactionStateChange(
UserTransaction userTransaction) {
package org.argeo.security.ui.admin.internal;
import java.util.ArrayList;
-import java.util.Dictionary;
-import java.util.HashMap;
import java.util.List;
-import java.util.Map;
import javax.transaction.Status;
import javax.transaction.UserTransaction;
import org.argeo.ArgeoException;
-import org.argeo.cms.auth.AuthConstants;
-import org.argeo.osgi.useradmin.UserAdminConf;
-import org.osgi.framework.ServiceReference;
-import org.osgi.service.useradmin.UserAdmin;
import org.osgi.service.useradmin.UserAdminEvent;
import org.osgi.service.useradmin.UserAdminListener;
/** Centralize interaction with the UserAdmin in this bundle */
-public class UserAdminWrapper {
+public class UserAdminWrapper extends
+ org.argeo.cms.util.useradmin.UserAdminWrapper {
// private Log log = LogFactory.getLog(UserAdminWrapper.class);
- private UserAdmin userAdmin;
- private ServiceReference<UserAdmin> userAdminServiceReference;
- private UserTransaction userTransaction;
-
// Registered listeners
List<UserAdminListener> listeners = new ArrayList<UserAdminListener>();
- // TODO implement safer mechanism
- public void addListener(UserAdminListener userAdminListener) {
- if (!listeners.contains(userAdminListener))
- listeners.add(userAdminListener);
- }
-
- /** Must be called from the UI Thread. */
+ /**
+ * Overwrite the normal begin transaction behaviour to also notify the UI.
+ * Must be called from the UI Thread.
+ */
public UserTransaction beginTransactionIfNeeded() {
try {
+ UserTransaction userTransaction = getUserTransaction();
if (userTransaction.getStatus() == Status.STATUS_NO_TRANSACTION) {
userTransaction.begin();
UiAdminUtils.notifyTransactionStateChange(userTransaction);
}
}
+ // TODO implement safer mechanism
+ public void addListener(UserAdminListener userAdminListener) {
+ if (!listeners.contains(userAdminListener))
+ listeners.add(userAdminListener);
+ }
+
// Expose this?
public void removeListener(UserAdminListener userAdminListener) {
if (listeners.contains(userAdminListener))
for (UserAdminListener listener : listeners)
listener.roleChanged(event);
}
-
- public UserAdmin getUserAdmin() {
- return userAdmin;
- }
-
- public UserTransaction getUserTransaction() {
- return userTransaction;
- }
-
- public void setUserAdminServiceReference(
- ServiceReference<UserAdmin> userAdminServiceReference) {
- this.userAdminServiceReference = userAdminServiceReference;
- }
-
- public Map<String, String> getKnownBaseDns(boolean onlyWritable) {
- Map<String, String> dns = new HashMap<String, String>();
- for (String uri : userAdminServiceReference.getPropertyKeys()) {
- if (!uri.startsWith("/"))
- continue;
- Dictionary<String, ?> props = UserAdminConf.uriAsProperties(uri);
- String readOnly = UserAdminConf.readOnly.getValue(props);
- String baseDn = UserAdminConf.baseDn.getValue(props);
-
- if (onlyWritable && "true".equals(readOnly))
- continue;
- if (baseDn.equalsIgnoreCase(AuthConstants.ROLES_BASEDN))
- continue;
- dns.put(baseDn, uri);
- }
- return dns;
- }
-
- /* DEPENDENCY INJECTION */
- public void setUserAdmin(UserAdmin userAdmin) {
- this.userAdmin = userAdmin;
- }
-
- public void setUserTransaction(UserTransaction userTransaction) {
- this.userTransaction = userTransaction;
- }
}
\ No newline at end of file
import java.util.Iterator;
import java.util.List;
+import org.argeo.cms.util.useradmin.UserAdminUtils;
import org.argeo.security.ui.admin.SecurityAdminPlugin;
-import org.argeo.security.ui.admin.internal.UiAdminUtils;
import org.argeo.security.ui.admin.internal.UserAdminWrapper;
import org.argeo.security.ui.admin.internal.parts.UserEditorInput;
import org.eclipse.core.commands.AbstractHandler;
StringBuilder builder = new StringBuilder();
while (it.hasNext()) {
Group currGroup = it.next();
- String groupName = UiAdminUtils.getUsername(currGroup);
+ String groupName = UserAdminUtils.getUsername(currGroup);
// TODO add checks
builder.append(groupName).append("; ");
groups.add(currGroup);
import java.util.Iterator;
import java.util.List;
+import org.argeo.cms.util.useradmin.UserAdminUtils;
import org.argeo.security.ui.admin.SecurityAdminPlugin;
-import org.argeo.security.ui.admin.internal.UiAdminUtils;
import org.argeo.security.ui.admin.internal.UserAdminWrapper;
import org.argeo.security.ui.admin.internal.parts.UserEditorInput;
import org.eclipse.core.commands.AbstractHandler;
while (it.hasNext()) {
User currUser = it.next();
- String userName = UiAdminUtils.getUsername(currUser);
- if (UiAdminUtils.isCurrentUser(currUser)) {
+ String userName = UserAdminUtils.getUsername(currUser);
+ if (UserAdminUtils.isCurrentUser(currUser)) {
MessageDialog.openError(HandlerUtil.getActiveShell(event),
"Deletion forbidden",
"You cannot delete your own user this way.");
import org.argeo.osgi.useradmin.LdifName;
import org.argeo.osgi.useradmin.UserAdminConf;
import org.argeo.security.ui.admin.SecurityAdminPlugin;
-import org.argeo.security.ui.admin.internal.UiAdminUtils;
import org.argeo.security.ui.admin.internal.UserAdminWrapper;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
.createRole(getDn(commonName), Role.GROUP);
Dictionary props = group.getProperties();
String descStr = descriptionTxt.getText();
- if (UiAdminUtils.notNull(descStr))
+ if (EclipseUiUtils.notEmpty(descStr))
props.put(LdifName.description.name(), descStr);
userAdminWrapper.notifyListeners(new UserAdminEvent(null,
UserAdminEvent.ROLE_CREATED, group));
if (EclipseUiUtils.notEmpty(bdn)) {
Dictionary<String, ?> props = UserAdminConf.uriAsProperties(dns
.get(bdn));
- String dn = LdifName.cn.name()+"=" + cn + ","
+ String dn = LdifName.cn.name() + "=" + cn + ","
+ UserAdminConf.groupBase.getValue(props) + "," + bdn;
return dn;
}
import javax.naming.ldap.Rdn;
import org.argeo.ArgeoException;
+import org.argeo.cms.util.useradmin.UserAdminUtils;
import org.argeo.eclipse.ui.EclipseUiUtils;
import org.argeo.eclipse.ui.dialogs.ErrorFeedback;
import org.argeo.jcr.ArgeoNames;
import org.argeo.osgi.useradmin.LdifName;
import org.argeo.osgi.useradmin.UserAdminConf;
import org.argeo.security.ui.admin.SecurityAdminPlugin;
-import org.argeo.security.ui.admin.internal.UiAdminUtils;
import org.argeo.security.ui.admin.internal.UserAdminWrapper;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
Dictionary props = user.getProperties();
String lastNameStr = lastNameTxt.getText();
- if (UiAdminUtils.notNull(lastNameStr))
+ if (EclipseUiUtils.notEmpty(lastNameStr))
props.put(LdifName.sn.name(), lastNameStr);
String firstNameStr = firstNameTxt.getText();
- if (UiAdminUtils.notNull(firstNameStr))
+ if (EclipseUiUtils.notEmpty(firstNameStr))
props.put(LdifName.givenName.name(), firstNameStr);
- String cn = UiAdminUtils
- .getDefaultCn(firstNameStr, lastNameStr);
- if (UiAdminUtils.notNull(cn))
+ String cn = UserAdminUtils.getDefaultCn(firstNameStr,
+ lastNameStr);
+ if (EclipseUiUtils.notEmpty(cn))
props.put(LdifName.cn.name(), cn);
String mailStr = primaryMailTxt.getText();
- if (UiAdminUtils.notNull(mailStr))
+ if (EclipseUiUtils.notEmpty(mailStr))
props.put(LdifName.mail.name(), mailStr);
char[] password = mainUserInfo.getPassword();
import java.util.Iterator;
import java.util.List;
+import org.argeo.cms.util.useradmin.UserAdminUtils;
import org.argeo.eclipse.ui.ColumnDefinition;
import org.argeo.eclipse.ui.EclipseUiUtils;
import org.argeo.eclipse.ui.parts.LdifUsersTable;
import org.argeo.jcr.ArgeoNames;
import org.argeo.osgi.useradmin.LdifName;
import org.argeo.security.ui.admin.SecurityAdminImages;
-import org.argeo.security.ui.admin.internal.UiAdminUtils;
import org.argeo.security.ui.admin.internal.UserAdminWrapper;
import org.argeo.security.ui.admin.internal.parts.UserEditor.GroupChangeListener;
import org.argeo.security.ui.admin.internal.parts.UserEditor.MainInfoListener;
GridLayout layout = new GridLayout(2, false);
body.setLayout(layout);
- final Text dnTxt = createLT(body, "DN",group.getName());
+ final Text dnTxt = createLT(body, "DN", group.getName());
dnTxt.setEnabled(false);
final Text cnTxt = createLT(body, "Common Name",
- UiAdminUtils.getProperty(group, LdifName.cn.name()));
+ UserAdminUtils.getProperty(group, LdifName.cn.name()));
cnTxt.setEnabled(false);
Label descLbl = new Label(body, SWT.LEAD);
public void refresh() {
refreshFormTitle(group);
dnTxt.setText(group.getName());
- cnTxt.setText(UiAdminUtils.getProperty(group,
+ cnTxt.setText(UserAdminUtils.getProperty(group,
LdifName.cn.name()));
- descTxt.setText(UiAdminUtils.getProperty(group,
+ descTxt.setText(UserAdminUtils.getProperty(group,
LdifName.description.name()));
super.refresh();
}
// StringBuilder builder = new StringBuilder();
while (it.hasNext()) {
User currUser = it.next();
- // String groupName = UiAdminUtils.getUsername(currGroup);
+ // String groupName = UserAdminUtils.getUsername(currGroup);
// builder.append(groupName).append("; ");
users.add(currUser);
}
refreshFormTitle(group);
getSection().setText(
"Members of group "
- + UiAdminUtils.getProperty(group,
+ + UserAdminUtils.getProperty(group,
LdifName.cn.name()));
userViewer.refresh();
super.refresh();
// LOCAL HELPERS
private void refreshFormTitle(Group group) {
getManagedForm().getForm().setText(
- UiAdminUtils.getProperty(group, LdifName.cn.name()));
+ UserAdminUtils.getProperty(group, LdifName.cn.name()));
}
private Composite addSection(FormToolkit tk, Composite parent, String title) {
import org.apache.commons.logging.LogFactory;
import org.argeo.ArgeoException;
import org.argeo.cms.auth.AuthConstants;
+import org.argeo.cms.util.useradmin.UserAdminUtils;
import org.argeo.eclipse.ui.ColumnDefinition;
import org.argeo.eclipse.ui.EclipseUiUtils;
import org.argeo.eclipse.ui.parts.LdifUsersTable;
import org.argeo.jcr.ArgeoNames;
import org.argeo.osgi.useradmin.LdifName;
import org.argeo.security.ui.admin.SecurityAdminPlugin;
-import org.argeo.security.ui.admin.internal.UiAdminUtils;
import org.argeo.security.ui.admin.internal.UserAdminWrapper;
import org.argeo.security.ui.admin.internal.providers.CommonNameLP;
import org.argeo.security.ui.admin.internal.providers.DomainNameLP;
public void createPartControl(Composite parent) {
parent.setLayout(EclipseUiUtils.noSpaceGridLayout());
- boolean isAdmin = UiAdminUtils.isUserInRole(AuthConstants.ROLE_ADMIN);
+ boolean isAdmin = UserAdminUtils.isUserInRole(AuthConstants.ROLE_ADMIN);
// Define the displayed columns
columnDefs.add(new ColumnDefinition(new RoleIconLP(), "", 26));
try {
StringBuilder builder = new StringBuilder();
StringBuilder tmpBuilder = new StringBuilder();
- if (UiAdminUtils.notNull(filter))
+ if (EclipseUiUtils.notEmpty(filter))
for (String prop : knownProps) {
tmpBuilder.append("(");
tmpBuilder.append(prop);
import org.apache.commons.logging.LogFactory;
import org.argeo.ArgeoException;
import org.argeo.cms.auth.AuthConstants;
+import org.argeo.cms.util.useradmin.UserAdminUtils;
import org.argeo.eclipse.ui.ColumnDefinition;
import org.argeo.eclipse.ui.EclipseUiUtils;
import org.argeo.eclipse.ui.parts.LdifUsersTable;
200));
// Only show technical DN to admin
- if (UiAdminUtils.isUserInRole(AuthConstants.ROLE_ADMIN))
+ if (UserAdminUtils.isUserInRole(AuthConstants.ROLE_ADMIN))
columnDefs.add(new ColumnDefinition(new UserNameLP(),
"Distinguished Name", 300));
StringBuilder builder = new StringBuilder();
StringBuilder tmpBuilder = new StringBuilder();
- if (UiAdminUtils.notNull(filter))
+ if (EclipseUiUtils.notEmpty(filter))
for (String prop : knownProps) {
tmpBuilder.append("(");
tmpBuilder.append(prop);
for (Role role : roles)
// Prevent current logged in user to perform batch on
// himself
- if (!UiAdminUtils.isCurrentUser((User) role))
+ if (!UserAdminUtils.isCurrentUser((User) role))
users.add((User) role);
return users;
}
columnDefs.add(new ColumnDefinition(new DomainNameLP(), "Domain",
200));
// Only show technical DN to admin
- if (UiAdminUtils.isUserInRole(AuthConstants.ROLE_ADMIN))
+ if (UserAdminUtils.isUserInRole(AuthConstants.ROLE_ADMIN))
columnDefs.add(new ColumnDefinition(new UserNameLP(),
"Distinguished Name", 300));
userTableCmp = new ChosenUsersTableViewer(pageCmp, SWT.MULTI
import java.util.List;
import org.argeo.ArgeoException;
+import org.argeo.cms.util.useradmin.UserAdminUtils;
import org.argeo.osgi.useradmin.LdifName;
import org.argeo.security.ui.admin.SecurityAdminPlugin;
-import org.argeo.security.ui.admin.internal.UiAdminUtils;
import org.argeo.security.ui.admin.internal.UserAdminWrapper;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.swt.events.ModifyEvent;
void updateEditorTitle(String title) {
if (title == null) {
- String commonName = UiAdminUtils.getProperty(user,
+ String commonName = UserAdminUtils.getProperty(user,
LdifName.cn.name());
title = "".equals(commonName) ? user.getName() : commonName;
}
import org.argeo.ArgeoException;
import org.argeo.cms.auth.AuthConstants;
+import org.argeo.cms.util.useradmin.UserAdminUtils;
import org.argeo.eclipse.ui.ColumnDefinition;
import org.argeo.eclipse.ui.EclipseUiUtils;
import org.argeo.eclipse.ui.parts.LdifUsersTable;
import org.argeo.jcr.ArgeoNames;
import org.argeo.osgi.useradmin.LdifName;
import org.argeo.security.ui.admin.SecurityAdminImages;
-import org.argeo.security.ui.admin.internal.UiAdminUtils;
import org.argeo.security.ui.admin.internal.UserAdminWrapper;
import org.argeo.security.ui.admin.internal.parts.UserEditor.GroupChangeListener;
import org.argeo.security.ui.admin.internal.parts.UserEditor.MainInfoListener;
appendOverviewPart(body, user);
// Remove to ability to force the password for his own user. The user
// must then use the change pwd feature
- if (!UiAdminUtils.isCurrentUser(user))
+ if (!UserAdminUtils.isCurrentUser(user))
appendPasswordPart(body, user);
appendMemberOfPart(body, user);
}
body.setLayout(new GridLayout(2, false));
final Text distinguishedName = createLT(tk, body, "User Name",
- UiAdminUtils.getProperty(user, LdifName.uid.name()));
+ UserAdminUtils.getProperty(user, LdifName.uid.name()));
distinguishedName.setEnabled(false);
final Text commonName = createLT(tk, body, "Common Name",
- UiAdminUtils.getProperty(user, LdifName.cn.name()));
+ UserAdminUtils.getProperty(user, LdifName.cn.name()));
commonName.setEnabled(false);
final Text firstName = createLT(tk, body, "First name",
- UiAdminUtils.getProperty(user, LdifName.givenName.name()));
+ UserAdminUtils.getProperty(user, LdifName.givenName.name()));
final Text lastName = createLT(tk, body, "Last name",
- UiAdminUtils.getProperty(user, LdifName.sn.name()));
+ UserAdminUtils.getProperty(user, LdifName.sn.name()));
final Text email = createLT(tk, body, "Email",
- UiAdminUtils.getProperty(user, LdifName.mail.name()));
+ UserAdminUtils.getProperty(user, LdifName.mail.name()));
// create form part (controller)
AbstractFormPart part = new SectionPart((Section) body.getParent()) {
@Override
public void refresh() {
- distinguishedName.setText(UiAdminUtils.getProperty(user,
+ distinguishedName.setText(UserAdminUtils.getProperty(user,
LdifName.uid.name()));
- commonName.setText(UiAdminUtils.getProperty(user,
+ commonName.setText(UserAdminUtils.getProperty(user,
LdifName.cn.name()));
- firstName.setText(UiAdminUtils.getProperty(user,
+ firstName.setText(UserAdminUtils.getProperty(user,
LdifName.givenName.name()));
- lastName.setText(UiAdminUtils.getProperty(user,
+ lastName.setText(UserAdminUtils.getProperty(user,
LdifName.sn.name()));
- email.setText(UiAdminUtils.getProperty(user,
+ email.setText(UserAdminUtils.getProperty(user,
LdifName.mail.name()));
refreshFormTitle(user);
super.refresh();
Composite body = (Composite) section.getClient();
body.setLayout(EclipseUiUtils.noSpaceGridLayout());
- boolean isAdmin = UiAdminUtils.isUserInRole(AuthConstants.ROLE_ADMIN);
+ boolean isAdmin = UserAdminUtils.isUserInRole(AuthConstants.ROLE_ADMIN);
// Displayed columns
List<ColumnDefinition> columnDefs = new ArrayList<ColumnDefinition>();
}
});
- String tooltip = "Remove " + UiAdminUtils.getUsername(user)
+ String tooltip = "Remove " + UserAdminUtils.getUsername(user)
+ " from the below selected groups";
Action action = new RemoveMembershipAction(userViewer, user, tooltip,
SecurityAdminImages.ICON_REMOVE_DESC);
// StringBuilder builder = new StringBuilder();
while (it.hasNext()) {
Group currGroup = it.next();
- // String groupName = UiAdminUtils.getUsername(currGroup);
+ // String groupName = UserAdminUtils.getUsername(currGroup);
// builder.append(groupName).append("; ");
groups.add(currGroup);
}
// LOCAL HELPERS
private void refreshFormTitle(User group) {
getManagedForm().getForm().setText(
- UiAdminUtils.getProperty(group, LdifName.cn.name()));
+ UserAdminUtils.getProperty(group, LdifName.cn.name()));
}
/** Appends a section with a title */
import org.argeo.ArgeoException;
import org.argeo.cms.auth.AuthConstants;
+import org.argeo.cms.util.useradmin.UserAdminUtils;
import org.argeo.eclipse.ui.ColumnDefinition;
import org.argeo.eclipse.ui.EclipseUiUtils;
import org.argeo.eclipse.ui.parts.LdifUsersTable;
import org.argeo.jcr.ArgeoNames;
import org.argeo.osgi.useradmin.LdifName;
import org.argeo.security.ui.admin.SecurityAdminPlugin;
-import org.argeo.security.ui.admin.internal.UiAdminUtils;
import org.argeo.security.ui.admin.internal.UserAdminWrapper;
import org.argeo.security.ui.admin.internal.providers.CommonNameLP;
import org.argeo.security.ui.admin.internal.providers.DomainNameLP;
columnDefs.add(new ColumnDefinition(new MailLP(), "E-mail", 150));
columnDefs.add(new ColumnDefinition(new DomainNameLP(), "Domain", 200));
// Only show technical DN to admin
- if (UiAdminUtils.isUserInRole(AuthConstants.ROLE_ADMIN))
+ if (UserAdminUtils.isUserInRole(AuthConstants.ROLE_ADMIN))
columnDefs.add(new ColumnDefinition(new UserNameLP(),
"Distinguished Name", 300));
StringBuilder builder = new StringBuilder();
StringBuilder tmpBuilder = new StringBuilder();
- if (UiAdminUtils.notNull(filter))
+ if (EclipseUiUtils.notEmpty(filter))
for (String prop : knownProps) {
tmpBuilder.append("(");
tmpBuilder.append(prop);
package org.argeo.security.ui.admin.internal.providers;
+import org.argeo.cms.util.useradmin.UserAdminUtils;
import org.argeo.osgi.useradmin.LdifName;
-import org.argeo.security.ui.admin.internal.UiAdminUtils;
import org.osgi.service.useradmin.User;
/** Simply declare a label provider that returns the common name of a user */
@Override
public String getText(User user) {
- return UiAdminUtils.getProperty(user, LdifName.cn.name());
+ return UserAdminUtils.getProperty(user, LdifName.cn.name());
}
}
\ No newline at end of file
package org.argeo.security.ui.admin.internal.providers;
-import org.argeo.security.ui.admin.internal.UiAdminUtils;
+import org.argeo.cms.util.useradmin.UserAdminUtils;
import org.osgi.service.useradmin.User;
/** The human friendly domain name for the corresponding user. */
@Override
public String getText(User user) {
- return UiAdminUtils.getDomainName(user);
+ return UserAdminUtils.getDomainName(user);
}
}
\ No newline at end of file
package org.argeo.security.ui.admin.internal.providers;
+import org.argeo.cms.util.useradmin.UserAdminUtils;
import org.argeo.osgi.useradmin.LdifName;
-import org.argeo.security.ui.admin.internal.UiAdminUtils;
import org.osgi.service.useradmin.User;
/** Simply declare a label provider that returns the Primary Mail of a user */
@Override
public String getText(User user) {
- return UiAdminUtils.getProperty(user, LdifName.mail.name());
+ return UserAdminUtils.getProperty(user, LdifName.mail.name());
}
}
\ No newline at end of file
import javax.naming.ldap.LdapName;
import org.argeo.ArgeoException;
-import org.argeo.security.ui.admin.internal.UiAdminUtils;
+import org.argeo.cms.util.useradmin.UserAdminUtils;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.swt.SWT;
public Font getFont(Object element) {
// Self as bold
try {
- LdapName selfUserName = UiAdminUtils.getLdapName();
+ LdapName selfUserName = UserAdminUtils.getCurrentUserLdapName();
String userName = ((User) element).getName();
LdapName userLdapName = new LdapName(userName);
if (userLdapName.equals(selfUserName)) {
import static org.argeo.eclipse.ui.EclipseUiUtils.notEmpty;
import org.argeo.cms.auth.AuthConstants;
+import org.argeo.cms.util.useradmin.UserAdminUtils;
import org.argeo.osgi.useradmin.LdifName;
-import org.argeo.security.ui.admin.internal.UiAdminUtils;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerFilter;
import org.osgi.service.useradmin.User;
if (!showSystemRole
&& user.getName().matches(
".*(" + AuthConstants.ROLES_BASEDN + ")"))
- // UiAdminUtils.getProperty(user, LdifName.dn.name())
+ // UserAdminUtils.getProperty(user, LdifName.dn.name())
// .toLowerCase().endsWith(AuthConstants.ROLES_BASEDN))
return false;
return true;
for (String key : knownProps) {
- String currVal = UiAdminUtils.getProperty(user, key);
+ String currVal = UserAdminUtils.getProperty(user, key);
if (notEmpty(currVal)
&& currVal.toLowerCase().matches(searchString))
return true;