* a {@link ModifyListener} to listen on events on the text, can
* be null
* @return the created text
+ *
+ * @deprecated use {@link #createGridLT(Composite, String)} instead
*/
+ @Deprecated
public static Text createGridLT(Composite parent, String label,
ModifyListener modifyListener) {
Label lbl = new Label(parent, SWT.LEAD);
lbl.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
Text txt = new Text(parent, SWT.LEAD | SWT.BORDER);
txt.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
- if (txt != null)
+ if (modifyListener != null)
txt.addModifyListener(modifyListener);
return txt;
}
+ public static Text createGridLT(Composite parent, String label) {
+ return createGridLT(parent, label, null);
+ }
+
+ /**
+ * Creates one label and a text field not editable with background color of
+ * the parent (like a label but with selectable text)
+ */
+ public static Text createGridLL(Composite parent, String label, String text) {
+ Text txt = createGridLT(parent, label);
+ txt.setText(text);
+ txt.setEditable(false);
+ txt.setBackground(parent.getBackground());
+ return txt;
+ }
+
public static Text createGridLP(Composite parent, String label,
ModifyListener modifyListener) {
Label lbl = new Label(parent, SWT.LEAD);
public static Font getBoldItalicFont(Composite parent) {
return JFaceResources.getFontRegistry().defaultFontDescriptor()
- .setStyle(SWT.BOLD | SWT.ITALIC).createFont(parent.getDisplay());
+ .setStyle(SWT.BOLD | SWT.ITALIC)
+ .createFont(parent.getDisplay());
}
}
public final static Set<String> roles() {
Set<String> roles = Collections.synchronizedSet(new HashSet<String>());
+ Authentication authentication = getAuthentication();
+ for (GrantedAuthority ga : authentication.getAuthorities()) {
+ roles.add(ga.getAuthority());
+ }
+ return Collections.unmodifiableSet(roles);
+ }
+ public final static Authentication getAuthentication() {
Set<Authentication> authens = getSubject().getPrincipals(
Authentication.class);
if (authens != null && !authens.isEmpty()) {
Principal principal = authens.iterator().next();
Authentication authentication = (Authentication) principal;
- for (GrantedAuthority ga : authentication.getAuthorities()) {
- roles.add(ga.getAuthority());
- }
+ return authentication;
}
- return Collections.unmodifiableSet(roles);
+ throw new ArgeoException("No authentication found");
}
public final static Subject getSubject() {
package org.argeo.security.ui.views;
+import java.util.TreeSet;
+
+import org.argeo.eclipse.ui.EclipseUiUtils;
import org.argeo.security.ui.SecurityUiPlugin;
import org.argeo.security.ui.internal.CurrentUser;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.part.ViewPart;
+import org.springframework.security.Authentication;
+/** Information about the currently logged in user */
public class UserProfile extends ViewPart {
public static String ID = SecurityUiPlugin.PLUGIN_ID + ".userProfile";
+ private TableViewer viewer;
+
@Override
public void createPartControl(Composite parent) {
- new Label(parent, SWT.NONE).setText(CurrentUser.getUsername());
+ parent.setLayout(new GridLayout(2, false));
+
+ Authentication authentication = CurrentUser.getAuthentication();
+ EclipseUiUtils.createGridLL(parent, "Name", authentication
+ .getPrincipal().toString());
+ EclipseUiUtils.createGridLL(parent, "User ID",
+ CurrentUser.getUsername());
+
+ // roles table
+ Table table = new Table(parent, SWT.V_SCROLL | SWT.BORDER);
+ table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
+ table.setLinesVisible(false);
+ table.setHeaderVisible(false);
+ viewer = new TableViewer(table);
+ viewer.setContentProvider(new RolesContentProvider());
+ viewer.setLabelProvider(new LabelProvider());
+ getViewSite().setSelectionProvider(viewer);
+ viewer.setInput(getViewSite());
}
@Override
public void setFocus() {
+ viewer.getTable();
+ }
+
+ private class RolesContentProvider implements IStructuredContentProvider {
+ public Object[] getElements(Object inputElement) {
+ return new TreeSet<String>(CurrentUser.roles()).toArray();
+ }
+
+ public void dispose() {
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ }
+
}
}
import java.util.List;
import javax.jcr.Node;
+import javax.jcr.Property;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
private final String homePath;
private final String securityWorkspace;
+ /** Human readable user name */
+ private String displayName;
+
protected JcrUserDetails(String securityWorkspace, String homePath,
String username, String password, boolean enabled,
boolean accountNonExpired, boolean credentialsNonExpired,
userProfile.getProperty(ARGEO_CREDENTIALS_NON_EXPIRED)
.getBoolean(), userProfile.getProperty(
ARGEO_ACCOUNT_NON_LOCKED).getBoolean(), authorities);
+ // human readable name
+ if (userProfile.hasProperty(Property.JCR_TITLE)) {
+ displayName = userProfile.getProperty(Property.JCR_TITLE)
+ .getString();
+ if (displayName.trim().equals(""))
+ displayName = null;
+ }
+ if (displayName == null)
+ displayName = userProfile.getProperty(ARGEO_USER_ID).getString();
// home is defined as the parent of the profile
homePath = userProfile.getParent().getPath();
securityWorkspace = userProfile.getSession().getWorkspace().getName();
public String getSecurityWorkspace() {
return securityWorkspace;
}
+
+ /** The human readable name of this user */
+ public String getDisplayName() {
+ return displayName;
+ }
+
+ @Override
+ public String toString() {
+ return getDisplayName();
+ }
+
}