]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.security.ui/src/org/argeo/security/ui/views/UserProfile.java
Current user based on pure Spring Security
[lgpl/argeo-commons.git] / org.argeo.security.ui / src / org / argeo / security / ui / views / UserProfile.java
1 /*
2 * Copyright (C) 2007-2012 Argeo GmbH
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.argeo.security.ui.views;
17
18 import java.util.TreeSet;
19
20 import org.argeo.eclipse.ui.EclipseUiUtils;
21 import org.argeo.security.ui.SecurityUiPlugin;
22 import org.argeo.security.ui.internal.CurrentUser;
23 import org.eclipse.jface.viewers.IStructuredContentProvider;
24 import org.eclipse.jface.viewers.LabelProvider;
25 import org.eclipse.jface.viewers.TableViewer;
26 import org.eclipse.jface.viewers.Viewer;
27 import org.eclipse.swt.SWT;
28 import org.eclipse.swt.layout.GridData;
29 import org.eclipse.swt.layout.GridLayout;
30 import org.eclipse.swt.widgets.Composite;
31 import org.eclipse.swt.widgets.Table;
32 import org.eclipse.ui.part.ViewPart;
33 import org.springframework.security.core.Authentication;
34
35 /** Information about the currently logged in user */
36 public class UserProfile extends ViewPart {
37 public static String ID = SecurityUiPlugin.PLUGIN_ID + ".userProfile";
38
39 private TableViewer viewer;
40
41 @Override
42 public void createPartControl(Composite parent) {
43 parent.setLayout(new GridLayout(2, false));
44
45 Authentication authentication = CurrentUser.getAuthentication();
46 EclipseUiUtils.createGridLL(parent, "Name", authentication
47 .getPrincipal().toString());
48 EclipseUiUtils.createGridLL(parent, "User ID",
49 CurrentUser.getUsername());
50
51 // roles table
52 Table table = new Table(parent, SWT.V_SCROLL | SWT.BORDER);
53 table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
54 table.setLinesVisible(false);
55 table.setHeaderVisible(false);
56 viewer = new TableViewer(table);
57 viewer.setContentProvider(new RolesContentProvider());
58 viewer.setLabelProvider(new LabelProvider());
59 getViewSite().setSelectionProvider(viewer);
60 viewer.setInput(getViewSite());
61 }
62
63 @Override
64 public void setFocus() {
65 viewer.getTable();
66 }
67
68 private class RolesContentProvider implements IStructuredContentProvider {
69 private static final long serialVersionUID = -4576917440167866233L;
70
71 public Object[] getElements(Object inputElement) {
72 return new TreeSet<String>(CurrentUser.roles()).toArray();
73 }
74
75 public void dispose() {
76 }
77
78 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
79 }
80
81 }
82
83 }