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.ui.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;
private Session currentSession;
private String targetPath;
// Chosen parameters
+ private String chosenDn;
private User chosenUser;
private String jcrPrivilege;
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);
+ String username = chosenUser.getName();
+ if (EclipseUiUtils.notEmpty(chosenDn) && chosenDn.equalsIgnoreCase(username))
+ // Enable forcing the username case. TODO clean once this issue
+ // has been generally addressed
+ username = chosenDn;
+ JcrUtils.addPrivilege(currentSession, targetPath, username, 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
// specify subject
createBoldLabel(composite, "User or group name");
- final Label groupNameLbl = new Label(composite, SWT.LEAD);
- groupNameLbl.setLayoutData(EclipseUiUtils.fillWidth());
+ final Label userNameLbl = new Label(composite, SWT.LEAD);
+ userNameLbl.setLayoutData(EclipseUiUtils.fillWidth());
Link pickUpLk = new Link(composite, SWT.LEFT);
pickUpLk.setText(" <a>Change</a> ");
createBoldLabel(composite, "User or group DN");
- final Text groupNameTxt = new Text(composite, SWT.LEAD | SWT.BORDER);
- groupNameTxt.setLayoutData(EclipseUiUtils.fillWidth(2));
+ final Text userNameTxt = new Text(composite, SWT.LEAD | SWT.BORDER);
+ userNameTxt.setLayoutData(EclipseUiUtils.fillWidth(2));
pickUpLk.addSelectionListener(new SelectionAdapter() {
private static final long serialVersionUID = 1L;
@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));
- groupNameTxt.setText(chosenUser.getName());
+ userNameLbl.setText(UserAdminUtils.getCommonName(chosenUser));
+ userNameTxt.setText(chosenUser.getName());
}
}
});
- groupNameTxt.addFocusListener(new FocusListener() {
+ userNameTxt.addFocusListener(new FocusListener() {
private static final long serialVersionUID = 1965498600105667738L;
@Override
public void focusLost(FocusEvent event) {
- String dn = groupNameTxt.getText();
+ String dn = userNameTxt.getText();
if (EclipseUiUtils.isEmpty(dn))
return;
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();
+ userNameTxt.setFocus();
else
resetOnFail();
}
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();
+ userNameTxt.setFocus();
else
resetOnFail();
} else {
chosenUser = newChosen;
- groupNameLbl.setText(UsersUtils
- .getCommonName(chosenUser));
+ chosenDn = dn;
+ userNameLbl.setText(UserAdminUtils.getCommonName(chosenUser));
}
}
private void resetOnFail() {
- String oldDn = chosenUser == null ? "" : chosenUser
- .getName();
- groupNameTxt.setText(oldDn);
+ String oldDn = chosenUser == null ? "" : chosenUser.getName();
+ userNameTxt.setText(oldDn);
}
@Override
// 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);
label.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
return label;
}
-}
\ No newline at end of file
+}