runAs Feature

This commit is contained in:
Peter Hormanns 2012-10-30 18:13:59 +01:00
parent c6bbeed75a
commit 05b105028c
11 changed files with 104 additions and 20 deletions

View File

@ -57,6 +57,7 @@
</init-param>
</filter>
<filter-mapping>
<filter-name>CAS Validation Filter</filter-name>
<url-pattern>/*</url-pattern>
@ -66,7 +67,7 @@
<filter-name>CAS Authentication Filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>Logout Servlet</servlet-name>
<servlet-class>de.hsadmin.logout.LogoutServlet</servlet-class>
@ -93,11 +94,15 @@
<servlet-mapping>
<servlet-name>HSAdmin Web</servlet-name>
<url-pattern>/*</url-pattern>
<url-pattern>/MainApplication/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>HSAdmin Web</servlet-name>
<url-pattern>/VAADIN/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>

View File

@ -4,12 +4,15 @@ import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import com.vaadin.data.Property;
import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.terminal.Sizeable;
import com.vaadin.terminal.ThemeResource;
import com.vaadin.ui.Button;
import com.vaadin.ui.Component;
import com.vaadin.ui.Form;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Select;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Window;
import com.vaadin.ui.Button.ClickEvent;
@ -28,23 +31,73 @@ public abstract class AbstractModule implements Module, Serializable {
private VerticalLayout layout;
private Component component;
private ComponentFactory componentFactory;
private Select selRunAs;
public Component getComponent() {
return layout;
}
public void reload() throws HsarwebException {
if (selRunAs != null) {
selRunAs.select(application.getRunAs());
selRunAs.setScrollToSelectedItem(true);
}
componentFactory.loadData();
}
private void initLayout() {
private void initLayout() throws HsarwebException {
layout = new VerticalLayout();
layout.setSizeFull();
final Module thisModule = this;
final ModuleConfig moduleConfig = getModuleConfig();
final LocaleConfig localeConfig = application.getLocaleConfig();
if (this instanceof SearchAble || this instanceof InsertAble) {
if (this instanceof SearchAble || this instanceof InsertAble ||
!("USER".equals(application.getLoginUserRole()) || "NONE".equals(application.getLoginUserRole()))) {
HorizontalLayout toolbar = new HorizontalLayout();
if (!("USER".equals(application.getLoginUserRole()) || "NONE".equals(application.getLoginUserRole()))) {
selRunAs = new Select();
selRunAs.setWidth(100.0f, Sizeable.UNITS_PIXELS);
selRunAs.setImmediate(true);
selRunAs.setNewItemsAllowed(false);
selRunAs.setNullSelectionAllowed(false);
if (!application.getLoginUserRole().startsWith("PAC")) {
// if (application.getLoginUserRole().startsWith("PAC")) {
//
// }
selRunAs.addItem(application.getLogin());
Object custListObj = application.getRemote().callSearch("member", new HashMap<String, String>());
if (custListObj instanceof Object[]) {
Object[] custList = (Object[]) custListObj;
for (Object custObj : custList) {
if (custObj instanceof Map<?, ?>) {
Map<?, ?> custHash = (Map<?, ?>)custObj;
selRunAs.addItem(custHash.get("membercode"));
}
}
}
}
Object pacListObj = application.getRemote().callSearch("pac", new HashMap<String, String>());
if (pacListObj instanceof Object[]) {
Object[] pacList = (Object[]) pacListObj;
for (Object pacObj : pacList) {
if (pacObj instanceof Map<?, ?>) {
Map<?, ?> pacHash = (Map<?, ?>)pacObj;
selRunAs.addItem(pacHash.get("name"));
}
}
}
selRunAs.select(application.getRunAs());
selRunAs.setScrollToSelectedItem(true);
selRunAs.addListener(new Property.ValueChangeListener() {
private static final long serialVersionUID = 1L;
@Override
public void valueChange(ValueChangeEvent event) {
Property property = event.getProperty();
application.setRunAs(property.getValue().toString());
}
});
toolbar.addComponent(selRunAs);
}
if (this instanceof InsertAble) {
Button btNew = new Button(moduleConfig.getLabel("new"));
ThemeResource icon = new ThemeResource("../runo/icons/16/document-add.png");

View File

@ -29,7 +29,7 @@ public abstract class DatabaseModule extends GenericModule {
protected void initModule() {
MainApplication application = getApplication();
moduleConfig = new ModuleConfig(getModuleIdent(), application.getLocale());
String login = application.getLogin();
String login = application.getRunAs();
final String pac = login.length() >= 5 ? login.substring(0, 5) : "";
PropertyConfig idProp = new PropertyConfig(moduleConfig, "id", Long.class, PropertyTableColumn.INTERNAL_KEY);
idProp.setReadOnly(true);

View File

@ -24,7 +24,7 @@ public abstract class DatabaseUserModule extends GenericModule {
protected void initModule() {
MainApplication application = getApplication();
moduleConfig = new ModuleConfig(getModuleIdent(), application.getLocale());
String login = application.getLogin();
String login = application.getRunAs();
final String pac = login.length() >= 5 ? login.substring(0, 5) : "";
PropertyConfig idProp = new PropertyConfig(moduleConfig, "id", Long.class, PropertyTableColumn.INTERNAL_KEY);
idProp.setReadOnly(true);

View File

@ -23,7 +23,7 @@ public class DomainModule extends GenericModule {
protected void initModule() {
MainApplication application = getApplication();
moduleConfig = new ModuleConfig("domain", application.getLocale());
String login = application.getLogin();
String login = application.getRunAs();
final String pac = login.length() >= 5 ? login.substring(0, 5) : "";
PropertyConfig idProp = new PropertyConfig(moduleConfig, "id", Long.class, PropertyTableColumn.INTERNAL_KEY);
idProp.setReadOnly(true);

View File

@ -22,7 +22,7 @@ public class EMailAddressModule extends GenericModule {
protected void initModule() {
MainApplication application = getApplication();
moduleConfig = new ModuleConfig("emailaddress", application.getLocale());
String login = application.getLogin();
String login = application.getRunAs();
final String pac = login.length() >= 5 ? login.substring(0, 5) : "";
PropertyConfig idProp = new PropertyConfig(moduleConfig, "id", Long.class, PropertyTableColumn.INTERNAL_KEY);
idProp.setReadOnly(true);

View File

@ -22,7 +22,7 @@ public class EMailAliasModule extends GenericModule {
protected void initModule() {
MainApplication application = getApplication();
moduleConfig = new ModuleConfig("emailalias", application.getLocale());
String login = application.getLogin();
String login = application.getRunAs();
final String pac = login.length() >= 5 ? login.substring(0, 5) : "";
PropertyConfig idProp = new PropertyConfig(moduleConfig, "id", Long.class, PropertyTableColumn.INTERNAL_KEY);
idProp.setReadOnly(true);

View File

@ -95,7 +95,7 @@ public class HomeModule extends AbstractModule implements ComponentFactory, Upda
ThemeResource icon = new ThemeResource(moduleConfig.getLabel("change_password_icon"));
button.setIcon(icon);
Map<String, String> whereHash = new HashMap<String, String>();
whereHash.put("name", application.getLogin());
whereHash.put("name", application.getRunAs());
Long key = -1L;
try {
Object object = application.getRemote().callSearch(moduleConfig.getRemoteName(), whereHash);

View File

@ -46,6 +46,9 @@ public class MainApplication extends Application implements HttpServletRequestLi
private Remote remote;
private Map<String, Module> modules;
private Locale requestLocale;
private String role = "NONE";
private String runAs = null;
private TabSheet tabSheet;
@Override
@ -56,7 +59,6 @@ public class MainApplication extends Application implements HttpServletRequestLi
}
localeConfig = new LocaleConfig(locale, "main");
remote = new Remote(this);
String role = "NONE";
try {
Object rolesArrayObj = remote.callSearch("role", null);
if (rolesArrayObj != null && rolesArrayObj instanceof Object[]) {
@ -69,8 +71,8 @@ public class MainApplication extends Application implements HttpServletRequestLi
showSystemException(e);
}
Window mainWindow = new Window(localeConfig.getText("applicationtitle"));
TabSheet tabs = new TabSheet();
tabs.setSizeFull();
tabSheet = new TabSheet();
tabSheet.setSizeFull();
String modulesParamString = localeConfig.getText("modules." + role);
modules = new HashMap<String, Module>();
Module firstModule = null;
@ -84,13 +86,13 @@ public class MainApplication extends Application implements HttpServletRequestLi
ModuleConfig moduleConfig = module.getModuleConfig();
String label = moduleConfig.getLabel("moduletitle");
modules.put(label, module);
tabs.addTab((Component) module.getComponent(), label, new ThemeResource(moduleConfig.getLabel("moduleicon")));
tabSheet.addTab((Component) module.getComponent(), label, new ThemeResource(moduleConfig.getLabel("moduleicon")));
} catch (Exception e) {
showSystemException(e);
}
}
tabs.addListener(this);
mainWindow.setContent(tabs);
tabSheet.addListener(this);
mainWindow.setContent(tabSheet);
setMainWindow(mainWindow);
setErrorHandler(new Terminal.ErrorListener() {
private static final long serialVersionUID = 1L;
@ -105,6 +107,10 @@ public class MainApplication extends Application implements HttpServletRequestLi
showSystemException(e);
}
}
public String getLoginUserRole() {
return role;
}
public String getProxyTicket() {
return userPrincipal.getProxyTicketFor(servletContext.getInitParameter("backendURL"));
@ -186,4 +192,24 @@ public class MainApplication extends Application implements HttpServletRequestLi
getMainWindow().showNotification("System-Fehler", "<br />Bitte informieren Sie den Support<br/ >" + e.getMessage(), Notification.TYPE_ERROR_MESSAGE);
}
public String getRunAs() {
if (runAs == null) {
return getLogin();
}
return runAs;
}
public void setRunAs(String runAs) {
this.runAs = runAs;
Component selectedTab = tabSheet.getSelectedTab();
Tab tab = tabSheet.getTab(selectedTab);
Module module = modules.get(tab.getCaption());
try {
module.reload();
} catch (HsarwebException e) {
e.printStackTrace();
showSystemException(e);
}
}
}

View File

@ -36,7 +36,7 @@ public class Remote {
private Object xmlrpcCall(String module, String operation, Map<String, String> param1) throws HsarwebException {
Object[] params = new Object[3];
params[0] = app.getLogin();
params[0] = app.getRunAs();
params[1] = app.getProxyTicket();
params[2] = param1 != null ? param1 : new HashMap<String, String>();
return xmlrpcCall(module + "." + operation, params);
@ -44,7 +44,7 @@ public class Remote {
private Object xmlrpcCall(String module, String operation, Map<String, String> param1, Map<String, String> param2) throws HsarwebException {
Object[] params = new Object[4];
params[0] = app.getLogin();
params[0] = app.getRunAs();
params[1] = app.getProxyTicket();
params[2] = param1 != null ? param1 : new HashMap<String, String>();
params[3] = param2 != null ? param2 : new HashMap<String, String>();

View File

@ -22,7 +22,7 @@ public class UnixUserModule extends GenericModule {
protected void initModule() {
MainApplication application = getApplication();
moduleConfig = new ModuleConfig("user", application.getLocale());
String login = application.getLogin();
String login = application.getRunAs();
final String pac = login.length() >= 5 ? login.substring(0, 5) : "";
PropertyConfig pacProp = new PropertyConfig(moduleConfig, "pac", String.class, PropertyTableColumn.HIDDEN, new SelectPropertyFieldFactory());
pacProp.setSelectValues(new PropertySelectValues() {