import javax.jcr.Session;
import javax.jcr.security.Privilege;
-import org.argeo.cms.ui.workbench.internal.useradmin.UsersUtils;
import org.argeo.cms.ui.workbench.useradmin.PickUpUserDialog;
+import org.argeo.cms.util.UserAdminUtils;
import org.argeo.eclipse.ui.EclipseUiException;
import org.argeo.eclipse.ui.EclipseUiUtils;
import org.argeo.jcr.JcrUtils;
protected static final Map<String, String> AUTH_TYPE_DESC;
static {
Map<String, String> tmpMap = new HashMap<String, String>();
- tmpMap.put(Privilege.JCR_READ,
- "The privilege to retrieve a node and get its properties and their values.");
+ tmpMap.put(Privilege.JCR_READ, "The privilege to retrieve a node and get its properties and their values.");
tmpMap.put(Privilege.JCR_WRITE, "An aggregate privilege that "
- + "contains: jcr:modifyProperties, jcr:addChildNodes, "
- + "jcr:removeNode, jcr:removeChildNodes");
- tmpMap.put(Privilege.JCR_ALL, "An aggregate privilege that "
- + "contains all JCR predefined privileges, "
+ + "contains: jcr:modifyProperties, jcr:addChildNodes, " + "jcr:removeNode, jcr:removeChildNodes");
+ tmpMap.put(Privilege.JCR_ALL, "An aggregate privilege that " + "contains all JCR predefined privileges, "
+ "plus all implementation-defined privileges. ");
AUTH_TYPE_DESC = Collections.unmodifiableMap(tmpMap);
}
- public AddPrivilegeWizard(Session currentSession, String path,
- UserAdmin userAdmin) {
+ public AddPrivilegeWizard(Session currentSession, String path, UserAdmin userAdmin) {
super();
this.userAdmin = userAdmin;
this.currentSession = currentSession;
if (!canFinish())
return false;
try {
- JcrUtils.addPrivilege(currentSession, targetPath,
- chosenUser.getName(), jcrPrivilege);
+ JcrUtils.addPrivilege(currentSession, targetPath, chosenUser.getName(), jcrPrivilege);
} catch (RepositoryException re) {
- throw new EclipseUiException("Cannot set " + jcrPrivilege + " for "
- + chosenUser.getName() + " on " + targetPath, re);
+ throw new EclipseUiException(
+ "Cannot set " + jcrPrivilege + " for " + chosenUser.getName() + " on " + targetPath, re);
}
return true;
}
- private class DefinePrivilegePage extends WizardPage implements
- ModifyListener {
+ private class DefinePrivilegePage extends WizardPage implements ModifyListener {
private static final long serialVersionUID = 8084431378762283920L;
// Context
@Override
public void widgetSelected(SelectionEvent e) {
- PickUpUserDialog dialog = new PickUpUserDialog(getShell(),
- "Choose a group or a user", userAdmin);
+ PickUpUserDialog dialog = new PickUpUserDialog(getShell(), "Choose a group or a user", userAdmin);
if (dialog.open() == Window.OK) {
chosenUser = dialog.getSelected();
- groupNameLbl.setText(UsersUtils
- .getCommonName(chosenUser));
+ groupNameLbl.setText(UserAdminUtils.getCommonName(chosenUser));
groupNameTxt.setText(chosenUser.getName());
}
}
try {
newChosen = (User) userAdmin.getRole(dn);
} catch (Exception e) {
- boolean tryAgain = MessageDialog.openQuestion(
- getShell(), "Unvalid DN",
- "DN " + dn + " is not valid.\nError message: "
- + e.getMessage()
+ boolean tryAgain = MessageDialog.openQuestion(getShell(), "Unvalid DN",
+ "DN " + dn + " is not valid.\nError message: " + e.getMessage()
+ "\n\t\tDo you want to try again?");
if (tryAgain)
groupNameTxt.setFocus();
}
if (userAdmin.getRole(dn) == null) {
- boolean tryAgain = MessageDialog.openQuestion(
- getShell(), "Unexisting role", "User/group "
- + dn + " does not exist. "
- + "Do you want to try again?");
+ boolean tryAgain = MessageDialog.openQuestion(getShell(), "Unexisting role",
+ "User/group " + dn + " does not exist. " + "Do you want to try again?");
if (tryAgain)
groupNameTxt.setFocus();
else
resetOnFail();
} else {
chosenUser = newChosen;
- groupNameLbl.setText(UsersUtils
- .getCommonName(chosenUser));
+ groupNameLbl.setText(UserAdminUtils.getCommonName(chosenUser));
}
}
private void resetOnFail() {
- String oldDn = chosenUser == null ? "" : chosenUser
- .getName();
+ String oldDn = chosenUser == null ? "" : chosenUser.getName();
groupNameTxt.setText(oldDn);
}
// JCR Privileges
createBoldLabel(composite, "Privilege type");
- Combo authorizationCmb = new Combo(composite, SWT.BORDER
- | SWT.READ_ONLY | SWT.V_SCROLL);
- authorizationCmb.setItems(AUTH_TYPE_LABELS.values().toArray(
- new String[0]));
+ Combo authorizationCmb = new Combo(composite, SWT.BORDER | SWT.READ_ONLY | SWT.V_SCROLL);
+ authorizationCmb.setItems(AUTH_TYPE_LABELS.values().toArray(new String[0]));
authorizationCmb.setLayoutData(EclipseUiUtils.fillWidth(2));
createBoldLabel(composite, ""); // empty cell
final Label descLbl = new Label(composite, SWT.WRAP);
+++ /dev/null
-package org.argeo.cms.ui.workbench.internal.useradmin;
-
-import java.security.AccessController;
-import java.util.List;
-
-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.eclipse.ui.EclipseUiException;
-import org.argeo.naming.LdapAttrs;
-import org.argeo.node.NodeConstants;
-import org.osgi.service.useradmin.Role;
-import org.osgi.service.useradmin.User;
-
-/**
- * Utility methods to manage user concepts in the ui.workbench bundle
- *
- * FIXME refactor amd centralise userAdminUtils
- */
-@Deprecated
-public class UsersUtils {
-
- public final static boolean isCurrentUser(User user) {
- String userName = getProperty(user, LdapAttrs.DN);
- try {
- LdapName selfUserName = getLdapName();
- LdapName userLdapName = new LdapName(userName);
- if (userLdapName.equals(selfUserName))
- return true;
- else
- return false;
- } catch (InvalidNameException e) {
- throw new EclipseUiException("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 EclipseUiException("Invalid user dn " + name, e);
- }
- return dn;
- }
-
- public final static String getCommonName(User user) {
- return getProperty(user, LdapAttrs.cn.name());
- }
-
- /** Simply retrieves a display name of the relevant domain */
- public final static String getDomainName(User user) {
- String dn = (String) user.getProperties().get(LdapAttrs.DN);
- if (dn.endsWith(NodeConstants.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 (!"dc".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 EclipseUiException("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 "";
- }
-}
package org.argeo.cms.ui.workbench.useradmin;
-import javax.naming.InvalidNameException;
-import javax.naming.ldap.LdapName;
-
import org.argeo.cms.ui.workbench.internal.useradmin.UsersImages;
-import org.argeo.cms.ui.workbench.internal.useradmin.UsersUtils;
-import org.argeo.eclipse.ui.EclipseUiException;
+import org.argeo.cms.util.UserAdminUtils;
import org.argeo.node.NodeConstants;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.viewers.ColumnLabelProvider;
@Override
public Font getFont(Object element) {
- // Self as bold
- try {
- // LdapName selfUserName = new LdapName(CurrentUser.getUsername());
- LdapName selfUserName = UsersUtils.getLdapName();
- String userName = ((User) element).getName();
- LdapName userLdapName = new LdapName(userName);
- if (userLdapName.equals(selfUserName)) {
- if (bold == null)
- bold = JFaceResources.getFontRegistry()
- .defaultFontDescriptor().setStyle(SWT.BOLD)
- .createFont(Display.getCurrent());
- return bold;
- }
- } catch (InvalidNameException e) {
- throw new EclipseUiException("cannot parse dn for " + element, e);
+ // Current user as bold
+ if (UserAdminUtils.isCurrentUser(((User) element))) {
+ if (bold == null)
+ bold = JFaceResources.getFontRegistry().defaultFontDescriptor().setStyle(SWT.BOLD)
+ .createFont(Display.getCurrent());
+ return bold;
}
-
- // Disabled as Italic
- // Node userProfile = (Node) elem;
- // if (!userProfile.getProperty(ARGEO_ENABLED).getBoolean())
- // return italic;
-
return null;
- // return super.getFont(element);
}
@Override
if (COL_DN.equals(currType))
return user.getName();
else if (COL_DISPLAY_NAME.equals(currType))
- return UsersUtils.getCommonName(user);
+ return UserAdminUtils.getCommonName(user);
else if (COL_DOMAIN.equals(currType))
- return UsersUtils.getDomainName(user);
+ return UserAdminUtils.getDomainName(user);
else
return "";
}