diff --git a/hsarweb/lib/ws-commons-util-1.0.2.jar b/hsarweb/lib/ws-commons-util-1.0.2.jar new file mode 100644 index 0000000..3fc364e Binary files /dev/null and b/hsarweb/lib/ws-commons-util-1.0.2.jar differ diff --git a/hsarweb/lib/xmlrpc-client-3.1.3.jar b/hsarweb/lib/xmlrpc-client-3.1.3.jar new file mode 100644 index 0000000..38e3359 Binary files /dev/null and b/hsarweb/lib/xmlrpc-client-3.1.3.jar differ diff --git a/hsarweb/lib/xmlrpc-common-3.1.3.jar b/hsarweb/lib/xmlrpc-common-3.1.3.jar new file mode 100644 index 0000000..b5eb9df Binary files /dev/null and b/hsarweb/lib/xmlrpc-common-3.1.3.jar differ diff --git a/hsarweb/src/de/hsadmin/web/Bean.java b/hsarweb/src/de/hsadmin/web/Bean.java index a6d3c63..44da213 100644 --- a/hsarweb/src/de/hsadmin/web/Bean.java +++ b/hsarweb/src/de/hsadmin/web/Bean.java @@ -2,22 +2,52 @@ package de.hsadmin.web; import java.text.DateFormat; import java.util.Date; +import java.util.HashMap; +import java.util.Map; import javax.faces.bean.ManagedBean; +import javax.faces.bean.ManagedProperty; import javax.faces.bean.SessionScoped; -@ManagedBean +@ManagedBean(name="hello") @SessionScoped public class Bean { public final static DateFormat df = DateFormat.getTimeInstance(DateFormat.SHORT); + @ManagedProperty(value="#{context}") + private Context context; + + @ManagedProperty(value="#{remote}") + private Remote remote; + public String getMessage() { - return "Hallo Welt"; + Map where = new HashMap(); + where.put("name", context.getUser()); + String name = "Welt"; + try { + Object test = remote.callSearch("user", context.getUser(), where); + if (test instanceof Object[] && ((Object[])test).length > 0 ) { + if (((Object[])test)[0] instanceof Map) { + name = (String) ((Map)((Object[])test)[0]).get("comment"); + } + } + } catch (HsarwebException e) { + e.printStackTrace(); + } + return "Hallo " + name; } public String getTime() { return df.format(new Date()); } + public void setContext(Context context) { + this.context = context; + } + + public void setRemote(Remote remote) { + this.remote = remote; + } + } diff --git a/hsarweb/src/de/hsadmin/web/Context.java b/hsarweb/src/de/hsadmin/web/Context.java index 8564434..8139f8a 100644 --- a/hsarweb/src/de/hsadmin/web/Context.java +++ b/hsarweb/src/de/hsadmin/web/Context.java @@ -9,19 +9,29 @@ import org.jasig.cas.client.authentication.AttributePrincipal; import org.jasig.cas.client.util.AbstractCasFilter; import org.jasig.cas.client.validation.Assertion; -@ManagedBean +@ManagedBean(name="context") @SessionScoped public class Context { - private ExternalContext getContext() { + private ExternalContext getExternalContext() { return FacesContext.getCurrentInstance().getExternalContext(); } - public String getUser() { - Assertion assertion = (Assertion) getContext().getSessionMap().get(AbstractCasFilter.CONST_CAS_ASSERTION); - AttributePrincipal principal = assertion.getPrincipal(); - String proxyTicket = principal.getProxyTicketFor("https://agnes.ostwall195.de/backend"); - return principal.getName(); + private AttributePrincipal getPrincipal() { + ExternalContext context = getExternalContext(); + Assertion assertion = (Assertion) context.getSessionMap().get(AbstractCasFilter.CONST_CAS_ASSERTION); + return assertion.getPrincipal(); } + public String getUser() { + return getPrincipal().getName(); + } + + public String getProxyTicket() { + return getPrincipal().getProxyTicketFor("https://agnes.ostwall195.de:9443/hsar/backend"); + } + + public String getContextPath() { + return getExternalContext().getRequestContextPath(); + } } diff --git a/hsarweb/src/de/hsadmin/web/HsarwebException.java b/hsarweb/src/de/hsadmin/web/HsarwebException.java new file mode 100644 index 0000000..50761a9 --- /dev/null +++ b/hsarweb/src/de/hsadmin/web/HsarwebException.java @@ -0,0 +1,20 @@ +package de.hsadmin.web; + + +public class HsarwebException extends Exception { + + private static final long serialVersionUID = 1L; + + public HsarwebException(String msg, Exception e) { + super(msg, e); + } + + public HsarwebException(Exception e) { + super(e); + } + + public HsarwebException(String msg) { + super(msg); + } + +} diff --git a/hsarweb/src/de/hsadmin/web/Modules.java b/hsarweb/src/de/hsadmin/web/Modules.java index bff8508..f516e0a 100644 --- a/hsarweb/src/de/hsadmin/web/Modules.java +++ b/hsarweb/src/de/hsadmin/web/Modules.java @@ -3,20 +3,31 @@ package de.hsadmin.web; import java.util.ArrayList; import java.util.List; -import javax.faces.bean.ApplicationScoped; import javax.faces.bean.ManagedBean; +import javax.faces.bean.ManagedProperty; +import javax.faces.bean.SessionScoped; -@ManagedBean -@ApplicationScoped +@ManagedBean(name="modules") +@SessionScoped public class Modules { + @ManagedProperty(value="#{context}") + private Context context; + public String[] pageNames = new String[] { "hello" }; public List getPageNames() { ArrayList names = new ArrayList(); + String path = context.getContextPath() + "/"; + names.add(path + context.getUser()); for (String name : pageNames) { - names.add(name); + names.add(path + name); } return names; } + + public void setContext(Context context) { + this.context = context; + } + } diff --git a/hsarweb/src/de/hsadmin/web/Remote.java b/hsarweb/src/de/hsadmin/web/Remote.java new file mode 100644 index 0000000..ad61670 --- /dev/null +++ b/hsarweb/src/de/hsadmin/web/Remote.java @@ -0,0 +1,52 @@ +package de.hsadmin.web; + +import java.net.MalformedURLException; +import java.net.URL; +import java.util.Map; + +import javax.faces.bean.ManagedBean; +import javax.faces.bean.ManagedProperty; +import javax.faces.bean.SessionScoped; + +import org.apache.xmlrpc.XmlRpcException; +import org.apache.xmlrpc.client.XmlRpcClient; +import org.apache.xmlrpc.client.XmlRpcClientConfigImpl; + +@ManagedBean(name="remote") +@SessionScoped +public class Remote { + + private XmlRpcClient client; + + @ManagedProperty(value="#{context}") + private Context context; + + public Remote() throws HsarwebException { + XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl(); + try { + config.setServerURL(new URL("https://agnes.ostwall195.de:9443/hsar/xmlrpc/hsadmin")); + } catch (MalformedURLException e) { + throw new HsarwebException("error in remote server url", e); + } + client = new XmlRpcClient(); + client.setConfig(config); + } + + public Object callSearch(String module, String user, Map where) throws HsarwebException { + Object[] params = new Object[3]; + params[0] = user; + params[1] = context.getProxyTicket(); + params[2] = where; + Object res; + try { + res = client.execute(module + ".search", params); + } catch (XmlRpcException e) { + throw new HsarwebException("error in remote server call", e); + } + return res; + } + + public void setContext(Context context) { + this.context = context; + } +} diff --git a/hsarweb/webapp/hello/index.xhtml b/hsarweb/webapp/hello/index.xhtml index cd95698..db691aa 100644 --- a/hsarweb/webapp/hello/index.xhtml +++ b/hsarweb/webapp/hello/index.xhtml @@ -13,7 +13,7 @@ - Hallo  , es ist jetzt  Uhr. + , es ist jetzt  Uhr. diff --git a/hsarweb/webapp/resources/styles/hsar.css b/hsarweb/webapp/resources/styles/hsar.css index bc514e7..4d2f7d7 100644 --- a/hsarweb/webapp/resources/styles/hsar.css +++ b/hsarweb/webapp/resources/styles/hsar.css @@ -54,6 +54,9 @@ body { padding-left:0px; padding-right:0px; } +.dummy { + clear:both; +} .content { width:606px; margin-left:304px; diff --git a/hsarweb/webapp/templates/template.xhtml b/hsarweb/webapp/templates/template.xhtml index 8d3d4af..fb960e7 100644 --- a/hsarweb/webapp/templates/template.xhtml +++ b/hsarweb/webapp/templates/template.xhtml @@ -24,6 +24,7 @@
Default Content
+