transform EMailAliasModul zu SessionBean
This commit is contained in:
parent
3a1aefc396
commit
2cf0d6c4b8
@ -23,7 +23,10 @@
|
|||||||
|
|
||||||
<path id="enhance.classpath">
|
<path id="enhance.classpath">
|
||||||
<fileset dir="lib">
|
<fileset dir="lib">
|
||||||
<include name="**/*.jar" />
|
<include name="*.jar" />
|
||||||
|
</fileset>
|
||||||
|
<fileset dir="lib/enhance">
|
||||||
|
<include name="*.jar" />
|
||||||
</fileset>
|
</fileset>
|
||||||
<dirset dir="conf"/>
|
<dirset dir="conf"/>
|
||||||
<dirset dir="${build.home}"/>
|
<dirset dir="${build.home}"/>
|
||||||
@ -68,11 +71,9 @@
|
|||||||
</copy>
|
</copy>
|
||||||
<war destfile="build/hsar.war" basedir="webapp" needxmlfile="false">
|
<war destfile="build/hsar.war" basedir="webapp" needxmlfile="false">
|
||||||
<lib dir="lib">
|
<lib dir="lib">
|
||||||
<include name="**/*.jar"/>
|
<include name="*.jar"/>
|
||||||
<exclude name="**/servlet*.jar"/>
|
<exclude name="servlet*.jar"/>
|
||||||
<exclude name="**/geronimo-jms*.jar"/>
|
<exclude name="javaee*.jar"/>
|
||||||
<exclude name="**/geronimo-j2ee-management*.jar"/>
|
|
||||||
<exclude name="**/activemq*.jar"/>
|
|
||||||
</lib>
|
</lib>
|
||||||
<classes dir="build/cls" />
|
<classes dir="build/cls" />
|
||||||
<classes dir="src">
|
<classes dir="src">
|
||||||
|
@ -14,112 +14,6 @@
|
|||||||
<load-on-startup>1</load-on-startup>
|
<load-on-startup>1</load-on-startup>
|
||||||
</servlet>
|
</servlet>
|
||||||
|
|
||||||
<servlet>
|
|
||||||
<servlet-name>CLI Client Connector</servlet-name>
|
|
||||||
<servlet-class>de.hsadmin.cliClientConnector.CLIClientConnectorServlet</servlet-class>
|
|
||||||
<init-param>
|
|
||||||
<param-name>proxyValidateUrl</param-name>
|
|
||||||
<param-value>TestUmgebung</param-value>
|
|
||||||
</init-param>
|
|
||||||
<init-param>
|
|
||||||
<param-name>proxyServiceUrl</param-name>
|
|
||||||
<param-value>TestUmgebung</param-value>
|
|
||||||
</init-param>
|
|
||||||
<init-param>
|
|
||||||
<param-name>Components</param-name>
|
|
||||||
<param-value>member,pac,user,domain,emailaddress,emailalias,mysqluser,mysqldb,postgresqluser,postgresqldb,q</param-value>
|
|
||||||
</init-param>
|
|
||||||
<init-param>
|
|
||||||
<param-name>ComponentClass_member</param-name>
|
|
||||||
<param-value>de.hsadmin.mods.cust.Customer</param-value>
|
|
||||||
</init-param>
|
|
||||||
<init-param>
|
|
||||||
<param-name>ComponentDescription_member</param-name>
|
|
||||||
<param-value>Mitglieder</param-value>
|
|
||||||
</init-param>
|
|
||||||
<init-param>
|
|
||||||
<param-name>ComponentClass_pac</param-name>
|
|
||||||
<param-value>de.hsadmin.mods.pac.Pac</param-value>
|
|
||||||
</init-param>
|
|
||||||
<init-param>
|
|
||||||
<param-name>ComponentDescription_pac</param-name>
|
|
||||||
<param-value>Pakete</param-value>
|
|
||||||
</init-param>
|
|
||||||
<init-param>
|
|
||||||
<param-name>ComponentClass_user</param-name>
|
|
||||||
<param-value>de.hsadmin.mods.user.UnixUser</param-value>
|
|
||||||
</init-param>
|
|
||||||
<init-param>
|
|
||||||
<param-name>ComponentDescription_user</param-name>
|
|
||||||
<param-value>Benutzer und Postfaecher anlegen</param-value>
|
|
||||||
</init-param>
|
|
||||||
<init-param>
|
|
||||||
<param-name>ComponentClass_domain</param-name>
|
|
||||||
<param-value>de.hsadmin.mods.dom.Domain</param-value>
|
|
||||||
</init-param>
|
|
||||||
<init-param>
|
|
||||||
<param-name>ComponentDescription_domain</param-name>
|
|
||||||
<param-value>Domains aufschalten</param-value>
|
|
||||||
</init-param>
|
|
||||||
<init-param>
|
|
||||||
<param-name>ComponentClass_emailaddress</param-name>
|
|
||||||
<param-value>de.hsadmin.mods.email.EMailAddress</param-value>
|
|
||||||
</init-param>
|
|
||||||
<init-param>
|
|
||||||
<param-name>ComponentDescription_emailaddress</param-name>
|
|
||||||
<param-value>E-Mail Adressen</param-value>
|
|
||||||
</init-param>
|
|
||||||
<init-param>
|
|
||||||
<param-name>ComponentClass_emailalias</param-name>
|
|
||||||
<param-value>de.hsadmin.mods.email.EMailAlias</param-value>
|
|
||||||
</init-param>
|
|
||||||
<init-param>
|
|
||||||
<param-name>ComponentDescription_emailalias</param-name>
|
|
||||||
<param-value>E-Mail Aliases</param-value>
|
|
||||||
</init-param>
|
|
||||||
<init-param>
|
|
||||||
<param-name>ComponentClass_postgresqluser</param-name>
|
|
||||||
<param-value>de.hsadmin.mods.db.PgSqlUser</param-value>
|
|
||||||
</init-param>
|
|
||||||
<init-param>
|
|
||||||
<param-name>ComponentDescription_postgresqluser</param-name>
|
|
||||||
<param-value>PostgreSQL DB-Administrator</param-value>
|
|
||||||
</init-param>
|
|
||||||
<init-param>
|
|
||||||
<param-name>ComponentClass_postgresqldb</param-name>
|
|
||||||
<param-value>de.hsadmin.mods.db.PgSqlDatabase</param-value>
|
|
||||||
</init-param>
|
|
||||||
<init-param>
|
|
||||||
<param-name>ComponentDescription_postgresqldb</param-name>
|
|
||||||
<param-value>PostgreSQL Datenbank</param-value>
|
|
||||||
</init-param>
|
|
||||||
<init-param>
|
|
||||||
<param-name>ComponentClass_mysqluser</param-name>
|
|
||||||
<param-value>de.hsadmin.mods.db.MySqlUser</param-value>
|
|
||||||
</init-param>
|
|
||||||
<init-param>
|
|
||||||
<param-name>ComponentDescription_mysqluser</param-name>
|
|
||||||
<param-value>MySQL DB-Administrator</param-value>
|
|
||||||
</init-param>
|
|
||||||
<init-param>
|
|
||||||
<param-name>ComponentClass_mysqldb</param-name>
|
|
||||||
<param-value>de.hsadmin.mods.db.MySqlDatabase</param-value>
|
|
||||||
</init-param>
|
|
||||||
<init-param>
|
|
||||||
<param-name>ComponentDescription_mysqldb</param-name>
|
|
||||||
<param-value>MySQL Datenbank</param-value>
|
|
||||||
</init-param>
|
|
||||||
<init-param>
|
|
||||||
<param-name>ComponentClass_q</param-name>
|
|
||||||
<param-value>de.hsadmin.core.qserv.QueueTask</param-value>
|
|
||||||
</init-param>
|
|
||||||
<init-param>
|
|
||||||
<param-name>ComponentDescription_q</param-name>
|
|
||||||
<param-value>Offene Aktionen</param-value>
|
|
||||||
</init-param>
|
|
||||||
<load-on-startup>1</load-on-startup>
|
|
||||||
</servlet>
|
|
||||||
|
|
||||||
<servlet>
|
<servlet>
|
||||||
<servlet-name>XmlRpcServlet</servlet-name>
|
<servlet-name>XmlRpcServlet</servlet-name>
|
||||||
<servlet-class>de.hsadmin.remote.HSXmlRpcServlet</servlet-class>
|
<servlet-class>de.hsadmin.remote.HSXmlRpcServlet</servlet-class>
|
||||||
@ -134,11 +28,6 @@
|
|||||||
<url-pattern>/queueStatus</url-pattern>
|
<url-pattern>/queueStatus</url-pattern>
|
||||||
</servlet-mapping>
|
</servlet-mapping>
|
||||||
|
|
||||||
<servlet-mapping>
|
|
||||||
<servlet-name>CLI Client Connector</servlet-name>
|
|
||||||
<url-pattern>/hsadmin/cli-interface/</url-pattern>
|
|
||||||
</servlet-mapping>
|
|
||||||
|
|
||||||
<servlet-mapping>
|
<servlet-mapping>
|
||||||
<servlet-name>XmlRpcServlet</servlet-name>
|
<servlet-name>XmlRpcServlet</servlet-name>
|
||||||
<url-pattern>/xmlrpc/*</url-pattern>
|
<url-pattern>/xmlrpc/*</url-pattern>
|
||||||
|
@ -14,112 +14,6 @@
|
|||||||
<load-on-startup>1</load-on-startup>
|
<load-on-startup>1</load-on-startup>
|
||||||
</servlet>
|
</servlet>
|
||||||
|
|
||||||
<servlet>
|
|
||||||
<servlet-name>CLI Client Connector</servlet-name>
|
|
||||||
<servlet-class>de.hsadmin.cliClientConnector.CLIClientConnectorServlet</servlet-class>
|
|
||||||
<init-param>
|
|
||||||
<param-name>proxyValidateUrl</param-name>
|
|
||||||
<param-value>https://@LOGIN_HOST@:@LOGIN_PORT@/cas/proxyValidate</param-value>
|
|
||||||
</init-param>
|
|
||||||
<init-param>
|
|
||||||
<param-name>proxyServiceUrl</param-name>
|
|
||||||
<param-value>https://@CONFIG_HOST@:@CONFIG_PORT@/hsar/backend</param-value>
|
|
||||||
</init-param>
|
|
||||||
<init-param>
|
|
||||||
<param-name>Components</param-name>
|
|
||||||
<param-value>member,pac,user,domain,emailaddress,emailalias,mysqluser,mysqldb,postgresqluser,postgresqldb,q</param-value>
|
|
||||||
</init-param>
|
|
||||||
<init-param>
|
|
||||||
<param-name>ComponentClass_member</param-name>
|
|
||||||
<param-value>de.hsadmin.mods.cust.Customer</param-value>
|
|
||||||
</init-param>
|
|
||||||
<init-param>
|
|
||||||
<param-name>ComponentDescription_member</param-name>
|
|
||||||
<param-value>Mitglieder</param-value>
|
|
||||||
</init-param>
|
|
||||||
<init-param>
|
|
||||||
<param-name>ComponentClass_pac</param-name>
|
|
||||||
<param-value>de.hsadmin.mods.pac.Pac</param-value>
|
|
||||||
</init-param>
|
|
||||||
<init-param>
|
|
||||||
<param-name>ComponentDescription_pac</param-name>
|
|
||||||
<param-value>Pakete</param-value>
|
|
||||||
</init-param>
|
|
||||||
<init-param>
|
|
||||||
<param-name>ComponentClass_user</param-name>
|
|
||||||
<param-value>de.hsadmin.mods.user.UnixUser</param-value>
|
|
||||||
</init-param>
|
|
||||||
<init-param>
|
|
||||||
<param-name>ComponentDescription_user</param-name>
|
|
||||||
<param-value>Benutzer und Postfaecher anlegen</param-value>
|
|
||||||
</init-param>
|
|
||||||
<init-param>
|
|
||||||
<param-name>ComponentClass_domain</param-name>
|
|
||||||
<param-value>de.hsadmin.mods.dom.Domain</param-value>
|
|
||||||
</init-param>
|
|
||||||
<init-param>
|
|
||||||
<param-name>ComponentDescription_domain</param-name>
|
|
||||||
<param-value>Domains aufschalten</param-value>
|
|
||||||
</init-param>
|
|
||||||
<init-param>
|
|
||||||
<param-name>ComponentClass_emailaddress</param-name>
|
|
||||||
<param-value>de.hsadmin.mods.email.EMailAddress</param-value>
|
|
||||||
</init-param>
|
|
||||||
<init-param>
|
|
||||||
<param-name>ComponentDescription_emailaddress</param-name>
|
|
||||||
<param-value>E-Mail Adressen</param-value>
|
|
||||||
</init-param>
|
|
||||||
<init-param>
|
|
||||||
<param-name>ComponentClass_emailalias</param-name>
|
|
||||||
<param-value>de.hsadmin.mods.email.EMailAlias</param-value>
|
|
||||||
</init-param>
|
|
||||||
<init-param>
|
|
||||||
<param-name>ComponentDescription_emailalias</param-name>
|
|
||||||
<param-value>E-Mail Aliases</param-value>
|
|
||||||
</init-param>
|
|
||||||
<init-param>
|
|
||||||
<param-name>ComponentClass_postgresqluser</param-name>
|
|
||||||
<param-value>de.hsadmin.mods.db.PgSqlUser</param-value>
|
|
||||||
</init-param>
|
|
||||||
<init-param>
|
|
||||||
<param-name>ComponentDescription_postgresqluser</param-name>
|
|
||||||
<param-value>PostgreSQL DB-Administrator</param-value>
|
|
||||||
</init-param>
|
|
||||||
<init-param>
|
|
||||||
<param-name>ComponentClass_postgresqldb</param-name>
|
|
||||||
<param-value>de.hsadmin.mods.db.PgSqlDatabase</param-value>
|
|
||||||
</init-param>
|
|
||||||
<init-param>
|
|
||||||
<param-name>ComponentDescription_postgresqldb</param-name>
|
|
||||||
<param-value>PostgreSQL Datenbank</param-value>
|
|
||||||
</init-param>
|
|
||||||
<init-param>
|
|
||||||
<param-name>ComponentClass_mysqluser</param-name>
|
|
||||||
<param-value>de.hsadmin.mods.db.MySqlUser</param-value>
|
|
||||||
</init-param>
|
|
||||||
<init-param>
|
|
||||||
<param-name>ComponentDescription_mysqluser</param-name>
|
|
||||||
<param-value>MySQL DB-Administrator</param-value>
|
|
||||||
</init-param>
|
|
||||||
<init-param>
|
|
||||||
<param-name>ComponentClass_mysqldb</param-name>
|
|
||||||
<param-value>de.hsadmin.mods.db.MySqlDatabase</param-value>
|
|
||||||
</init-param>
|
|
||||||
<init-param>
|
|
||||||
<param-name>ComponentDescription_mysqldb</param-name>
|
|
||||||
<param-value>MySQL Datenbank</param-value>
|
|
||||||
</init-param>
|
|
||||||
<init-param>
|
|
||||||
<param-name>ComponentClass_q</param-name>
|
|
||||||
<param-value>de.hsadmin.core.qserv.QueueTask</param-value>
|
|
||||||
</init-param>
|
|
||||||
<init-param>
|
|
||||||
<param-name>ComponentDescription_q</param-name>
|
|
||||||
<param-value>Offene Aktionen</param-value>
|
|
||||||
</init-param>
|
|
||||||
<load-on-startup>1</load-on-startup>
|
|
||||||
</servlet>
|
|
||||||
|
|
||||||
<servlet>
|
<servlet>
|
||||||
<servlet-name>XmlRpcServlet</servlet-name>
|
<servlet-name>XmlRpcServlet</servlet-name>
|
||||||
<servlet-class>de.hsadmin.remote.HSXmlRpcServlet</servlet-class>
|
<servlet-class>de.hsadmin.remote.HSXmlRpcServlet</servlet-class>
|
||||||
@ -134,11 +28,6 @@
|
|||||||
<url-pattern>/queueStatus</url-pattern>
|
<url-pattern>/queueStatus</url-pattern>
|
||||||
</servlet-mapping>
|
</servlet-mapping>
|
||||||
|
|
||||||
<servlet-mapping>
|
|
||||||
<servlet-name>CLI Client Connector</servlet-name>
|
|
||||||
<url-pattern>/hsadmin/cli-interface/</url-pattern>
|
|
||||||
</servlet-mapping>
|
|
||||||
|
|
||||||
<servlet-mapping>
|
<servlet-mapping>
|
||||||
<servlet-name>XmlRpcServlet</servlet-name>
|
<servlet-name>XmlRpcServlet</servlet-name>
|
||||||
<url-pattern>/xmlrpc/*</url-pattern>
|
<url-pattern>/xmlrpc/*</url-pattern>
|
||||||
|
@ -14,112 +14,6 @@
|
|||||||
<load-on-startup>1</load-on-startup>
|
<load-on-startup>1</load-on-startup>
|
||||||
</servlet>
|
</servlet>
|
||||||
|
|
||||||
<servlet>
|
|
||||||
<servlet-name>CLI Client Connector</servlet-name>
|
|
||||||
<servlet-class>de.hsadmin.cliClientConnector.CLIClientConnectorServlet</servlet-class>
|
|
||||||
<init-param>
|
|
||||||
<param-name>proxyValidateUrl</param-name>
|
|
||||||
<param-value>https://@LOGIN_HOST@:@LOGIN_PORT@/cas/proxyValidate</param-value>
|
|
||||||
</init-param>
|
|
||||||
<init-param>
|
|
||||||
<param-name>proxyServiceUrl</param-name>
|
|
||||||
<param-value>https://@CONFIG_HOST@:@CONFIG_PORT@/hsar/backend</param-value>
|
|
||||||
</init-param>
|
|
||||||
<init-param>
|
|
||||||
<param-name>Components</param-name>
|
|
||||||
<param-value>member,pac,user,domain,emailaddress,emailalias,mysqluser,mysqldb,postgresqluser,postgresqldb,q</param-value>
|
|
||||||
</init-param>
|
|
||||||
<init-param>
|
|
||||||
<param-name>ComponentClass_member</param-name>
|
|
||||||
<param-value>de.hsadmin.mods.cust.Customer</param-value>
|
|
||||||
</init-param>
|
|
||||||
<init-param>
|
|
||||||
<param-name>ComponentDescription_member</param-name>
|
|
||||||
<param-value>Mitglieder</param-value>
|
|
||||||
</init-param>
|
|
||||||
<init-param>
|
|
||||||
<param-name>ComponentClass_pac</param-name>
|
|
||||||
<param-value>de.hsadmin.mods.pac.Pac</param-value>
|
|
||||||
</init-param>
|
|
||||||
<init-param>
|
|
||||||
<param-name>ComponentDescription_pac</param-name>
|
|
||||||
<param-value>Pakete</param-value>
|
|
||||||
</init-param>
|
|
||||||
<init-param>
|
|
||||||
<param-name>ComponentClass_user</param-name>
|
|
||||||
<param-value>de.hsadmin.mods.user.UnixUser</param-value>
|
|
||||||
</init-param>
|
|
||||||
<init-param>
|
|
||||||
<param-name>ComponentDescription_user</param-name>
|
|
||||||
<param-value>Benutzer und Postfaecher anlegen</param-value>
|
|
||||||
</init-param>
|
|
||||||
<init-param>
|
|
||||||
<param-name>ComponentClass_domain</param-name>
|
|
||||||
<param-value>de.hsadmin.mods.dom.Domain</param-value>
|
|
||||||
</init-param>
|
|
||||||
<init-param>
|
|
||||||
<param-name>ComponentDescription_domain</param-name>
|
|
||||||
<param-value>Domains aufschalten</param-value>
|
|
||||||
</init-param>
|
|
||||||
<init-param>
|
|
||||||
<param-name>ComponentClass_emailaddress</param-name>
|
|
||||||
<param-value>de.hsadmin.mods.email.EMailAddress</param-value>
|
|
||||||
</init-param>
|
|
||||||
<init-param>
|
|
||||||
<param-name>ComponentDescription_emailaddress</param-name>
|
|
||||||
<param-value>E-Mail Adressen</param-value>
|
|
||||||
</init-param>
|
|
||||||
<init-param>
|
|
||||||
<param-name>ComponentClass_emailalias</param-name>
|
|
||||||
<param-value>de.hsadmin.mods.email.EMailAlias</param-value>
|
|
||||||
</init-param>
|
|
||||||
<init-param>
|
|
||||||
<param-name>ComponentDescription_emailalias</param-name>
|
|
||||||
<param-value>E-Mail Aliases</param-value>
|
|
||||||
</init-param>
|
|
||||||
<init-param>
|
|
||||||
<param-name>ComponentClass_postgresqluser</param-name>
|
|
||||||
<param-value>de.hsadmin.mods.db.PgSqlUser</param-value>
|
|
||||||
</init-param>
|
|
||||||
<init-param>
|
|
||||||
<param-name>ComponentDescription_postgresqluser</param-name>
|
|
||||||
<param-value>PostgreSQL DB-Administrator</param-value>
|
|
||||||
</init-param>
|
|
||||||
<init-param>
|
|
||||||
<param-name>ComponentClass_postgresqldb</param-name>
|
|
||||||
<param-value>de.hsadmin.mods.db.PgSqlDatabase</param-value>
|
|
||||||
</init-param>
|
|
||||||
<init-param>
|
|
||||||
<param-name>ComponentDescription_postgresqldb</param-name>
|
|
||||||
<param-value>PostgreSQL Datenbank</param-value>
|
|
||||||
</init-param>
|
|
||||||
<init-param>
|
|
||||||
<param-name>ComponentClass_mysqluser</param-name>
|
|
||||||
<param-value>de.hsadmin.mods.db.MySqlUser</param-value>
|
|
||||||
</init-param>
|
|
||||||
<init-param>
|
|
||||||
<param-name>ComponentDescription_mysqluser</param-name>
|
|
||||||
<param-value>MySQL DB-Administrator</param-value>
|
|
||||||
</init-param>
|
|
||||||
<init-param>
|
|
||||||
<param-name>ComponentClass_mysqldb</param-name>
|
|
||||||
<param-value>de.hsadmin.mods.db.MySqlDatabase</param-value>
|
|
||||||
</init-param>
|
|
||||||
<init-param>
|
|
||||||
<param-name>ComponentDescription_mysqldb</param-name>
|
|
||||||
<param-value>MySQL Datenbank</param-value>
|
|
||||||
</init-param>
|
|
||||||
<init-param>
|
|
||||||
<param-name>ComponentClass_q</param-name>
|
|
||||||
<param-value>de.hsadmin.core.qserv.QueueTask</param-value>
|
|
||||||
</init-param>
|
|
||||||
<init-param>
|
|
||||||
<param-name>ComponentDescription_q</param-name>
|
|
||||||
<param-value>Offene Aktionen</param-value>
|
|
||||||
</init-param>
|
|
||||||
<load-on-startup>1</load-on-startup>
|
|
||||||
</servlet>
|
|
||||||
|
|
||||||
<servlet>
|
<servlet>
|
||||||
<servlet-name>XmlRpcServlet</servlet-name>
|
<servlet-name>XmlRpcServlet</servlet-name>
|
||||||
<servlet-class>de.hsadmin.remote.HSXmlRpcServlet</servlet-class>
|
<servlet-class>de.hsadmin.remote.HSXmlRpcServlet</servlet-class>
|
||||||
@ -134,11 +28,6 @@
|
|||||||
<url-pattern>/queueStatus</url-pattern>
|
<url-pattern>/queueStatus</url-pattern>
|
||||||
</servlet-mapping>
|
</servlet-mapping>
|
||||||
|
|
||||||
<servlet-mapping>
|
|
||||||
<servlet-name>CLI Client Connector</servlet-name>
|
|
||||||
<url-pattern>/hsadmin/cli-interface/</url-pattern>
|
|
||||||
</servlet-mapping>
|
|
||||||
|
|
||||||
<servlet-mapping>
|
<servlet-mapping>
|
||||||
<servlet-name>XmlRpcServlet</servlet-name>
|
<servlet-name>XmlRpcServlet</servlet-name>
|
||||||
<url-pattern>/xmlrpc/*</url-pattern>
|
<url-pattern>/xmlrpc/*</url-pattern>
|
||||||
|
@ -1,357 +0,0 @@
|
|||||||
package de.hsadmin.cliClientConnector;
|
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.text.DateFormat;
|
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.Enumeration;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Hashtable;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import de.hsadmin.cliClientConnector.CLIClientConnectorServlet.FunctionNotKnownException;
|
|
||||||
import de.hsadmin.cliClientConnector.CLIClientConnectorServlet.UnknownModuleException;
|
|
||||||
import de.hsadmin.core.model.AbstractEntity;
|
|
||||||
import de.hsadmin.core.model.ModuleInterface;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parses Arguments for the CLI Client Connector Servlet
|
|
||||||
*
|
|
||||||
* @author Christof Donat
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class ArgumentParser {
|
|
||||||
/// I am working for this Servlet instance
|
|
||||||
private CLIClientConnectorServlet master;
|
|
||||||
private DateFormat df = new SimpleDateFormat( "yyyy-MM-dd");
|
|
||||||
|
|
||||||
public ArgumentParser(CLIClientConnectorServlet master) {
|
|
||||||
this.master = master;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getUsageString() {
|
|
||||||
return " [ (-W name=value|--globalWhere:name=value) ...]\n"+
|
|
||||||
" [ (-S name=value|--globalSet:name=value) ...]\n"+
|
|
||||||
" [ (-D displayspec|--globalDisplay=displayspec) ...]\n"+
|
|
||||||
" [ (-c module.function|--call=module.function)\n" +
|
|
||||||
" [ (-w name=value|--where:name=value) ...]\n"+
|
|
||||||
" [ (-s name=value|--set:name=value) ...]\n"+
|
|
||||||
" [ (-d displayspec|--display:displayspec) ...]\n"+
|
|
||||||
" [ oids ...] ] ]\n"+
|
|
||||||
"\n"+
|
|
||||||
"(" + CLIClientConnectorServlet.version + ")\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
private ArrayList<Method> getMethodList(Object o) {
|
|
||||||
Method[] meths = o.getClass().getMethods();
|
|
||||||
ArrayList<Method> methodlist = new ArrayList<Method>();
|
|
||||||
|
|
||||||
for( int i = 0; i < meths.length; i++ ) {
|
|
||||||
Method m = meths[i];
|
|
||||||
String n = m.getName();
|
|
||||||
if( n.startsWith("get") && !n.equals("getNew") ) {
|
|
||||||
String fn = m.getName().substring(3).toLowerCase();
|
|
||||||
if( fn.equals("class") ) continue;
|
|
||||||
if (m.getParameterTypes().length == 0) {
|
|
||||||
methodlist.add(m);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return methodlist;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Hashtable<String,String> getValues(Object o, ArrayList<Method> methodlist, ArrayList<String>fieldNames, boolean deep, ArrayList<Object> foundObjects) {
|
|
||||||
Hashtable<String,String> row = new Hashtable<String,String>();
|
|
||||||
int i, j;
|
|
||||||
|
|
||||||
if( foundObjects == null ) foundObjects = new ArrayList<Object>();
|
|
||||||
|
|
||||||
for( i = 0; i < methodlist.size(); i++ ) {
|
|
||||||
Method m = methodlist.get(i);
|
|
||||||
try {
|
|
||||||
String name = fieldNames.get(i);
|
|
||||||
String type = m.getReturnType().getCanonicalName();
|
|
||||||
String val = "";
|
|
||||||
|
|
||||||
Object value = null;
|
|
||||||
try {
|
|
||||||
value = m.invoke(o);
|
|
||||||
} catch( Exception e ) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
if( value == null )
|
|
||||||
val = "";
|
|
||||||
else if( type.equals("java.lang.String") )
|
|
||||||
val = (String)value;
|
|
||||||
else if( type.equals("java.lang.Integer") )
|
|
||||||
val = String.valueOf((Integer)value);
|
|
||||||
else if( type.equals("java.lang.Long") )
|
|
||||||
val = String.valueOf((Long)value);
|
|
||||||
else if( type.equals("java.lang.Boolean") )
|
|
||||||
val = String.valueOf((Boolean)value);
|
|
||||||
else if( type.equals("java.util.Date") ) {
|
|
||||||
val = df.format((Date)value);
|
|
||||||
} else if( type.equals("java.util.Set") ) {
|
|
||||||
val = "<Set>";
|
|
||||||
} else try {
|
|
||||||
AbstractEntity v = (AbstractEntity)value;
|
|
||||||
val = v.createStringKey();
|
|
||||||
if( deep && !foundObjects.contains(v) ) {
|
|
||||||
foundObjects.add(v);
|
|
||||||
ArrayList<String> fieldNamesDeep = new ArrayList<String>();
|
|
||||||
ArrayList<Method> methodlistDeep = getMethodList(v);
|
|
||||||
for( j = 0; j < methodlistDeep.size(); j++ ) {
|
|
||||||
fieldNamesDeep.add(methodlistDeep.get(j).getName().substring(3).toLowerCase());
|
|
||||||
}
|
|
||||||
Hashtable<String,String> tmp = getValues(v,methodlistDeep,fieldNamesDeep,deep,foundObjects);
|
|
||||||
Enumeration<String> keys = tmp.keys();
|
|
||||||
while(keys.hasMoreElements()) {
|
|
||||||
try {
|
|
||||||
String k = (String)keys.nextElement();
|
|
||||||
row.put(name+"."+k, tmp.get(k));
|
|
||||||
} catch( Exception e ) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch(ClassCastException e) {
|
|
||||||
val = value.toString();
|
|
||||||
}
|
|
||||||
if (val != null) row.put(name, val);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return row;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String formatObjectsWithoutDisplay(int j, ArrayList<String> fieldNames, ArrayList<Integer>columnWidths, ArrayList<Hashtable<String,String> > rows) {
|
|
||||||
int i;
|
|
||||||
StringBuffer rval = new StringBuffer();
|
|
||||||
|
|
||||||
for( i = 0; i < fieldNames.size(); i++ ) {
|
|
||||||
StringBuffer name = new StringBuffer(fieldNames.get(i));
|
|
||||||
int fieldwidth = columnWidths.get(i);
|
|
||||||
while( name.length() < fieldwidth )
|
|
||||||
name.append(" ");
|
|
||||||
rval.append(name.toString()+((i < fieldNames.size()-1)?" | ":""));
|
|
||||||
}
|
|
||||||
rval.append("\n");
|
|
||||||
for( i = 0; i < j; i++ )
|
|
||||||
rval.append("-");
|
|
||||||
rval.append("\n");
|
|
||||||
|
|
||||||
for( j = 0; j < rows.size(); j++ ) {
|
|
||||||
for( i = 0; i < fieldNames.size(); i++ ) {
|
|
||||||
StringBuffer value = new StringBuffer(rows.get(j).get(fieldNames.get(i)));
|
|
||||||
int fieldwidth = columnWidths.get(i);
|
|
||||||
while( value.length() < fieldwidth )
|
|
||||||
value.append(" ");
|
|
||||||
rval.append(value.toString()+((i < fieldNames.size()-1)?" | ":""));
|
|
||||||
}
|
|
||||||
rval.append("\n");
|
|
||||||
}
|
|
||||||
return rval.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
private String formatObjectsWithDisplay(ArrayList<Hashtable<String,String> > rows, String displayDef) {
|
|
||||||
StringBuffer rval = new StringBuffer();
|
|
||||||
for( int j = 0; j < rows.size(); j++) {
|
|
||||||
String rv = displayDef;
|
|
||||||
Enumeration<String> fNames = rows.get(j).keys();
|
|
||||||
while( fNames.hasMoreElements() ) {
|
|
||||||
String f = (String)fNames.nextElement();
|
|
||||||
rv = rv.replaceAll("\\$\\{"+f+"\\}", rows.get(j).get(f));
|
|
||||||
}
|
|
||||||
rv = rv.replaceAll("\\\\n", "\n");
|
|
||||||
rv = rv.replaceAll("\\\\t", "\t");
|
|
||||||
rv = rv.replaceAll("\\\\(.)?", "$1");
|
|
||||||
rval.append(rv);
|
|
||||||
}
|
|
||||||
return rval.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* format Objects for the output as a Human readable table
|
|
||||||
*
|
|
||||||
* @param objects
|
|
||||||
* format these objects
|
|
||||||
*
|
|
||||||
* @return humanReadableString
|
|
||||||
* a string with the human readable representation of the objects
|
|
||||||
*/
|
|
||||||
public String formatObjects(List<?> objects, String displayDef) {
|
|
||||||
if( objects.size() == 0 ) return "";
|
|
||||||
if( objects.get(0) == null ) return "";
|
|
||||||
ArrayList<Method> methodlist = getMethodList(objects.get(0));
|
|
||||||
ArrayList<Integer>columnWidths = new ArrayList<Integer>();
|
|
||||||
ArrayList<String>fieldNames = new ArrayList<String>();
|
|
||||||
ArrayList<Hashtable<String,String> > rows =
|
|
||||||
new ArrayList<Hashtable<String,String> >();
|
|
||||||
int i, j;
|
|
||||||
|
|
||||||
for( i = 0; i < methodlist.size(); i++ ) {
|
|
||||||
Method m = methodlist.get(i);
|
|
||||||
String n = m.getName();
|
|
||||||
String fn = n.substring(3).toLowerCase();
|
|
||||||
fieldNames.add(fn);
|
|
||||||
columnWidths.add(n.length()+3);
|
|
||||||
}
|
|
||||||
|
|
||||||
for( j = 0; j < objects.size(); j++ ) {
|
|
||||||
Object o = objects.get(j);
|
|
||||||
Hashtable<String,String> row = getValues(o,methodlist,fieldNames,(displayDef != null), null);
|
|
||||||
for( i = 0; i < fieldNames.size(); i++ ) {
|
|
||||||
String val = row.get(fieldNames.get(i));
|
|
||||||
if( val != null && i < columnWidths.size() && val.length()+3 > columnWidths.get(i) )
|
|
||||||
columnWidths.set(i, val.length()+3);
|
|
||||||
}
|
|
||||||
rows.add(row);
|
|
||||||
}
|
|
||||||
|
|
||||||
if( displayDef == null ) {
|
|
||||||
j = 0;
|
|
||||||
for( i = 0; i < columnWidths.size(); i++ ) {
|
|
||||||
j += columnWidths.get(i)+2;
|
|
||||||
}
|
|
||||||
j -= 2;
|
|
||||||
|
|
||||||
return formatObjectsWithoutDisplay(j, fieldNames, columnWidths, rows);
|
|
||||||
} else
|
|
||||||
return formatObjectsWithDisplay(rows, displayDef);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The main parser function. Parses the Parameters, uses the master to call
|
|
||||||
* the functions and returns a formatet output.
|
|
||||||
*
|
|
||||||
* @param arguments
|
|
||||||
* @return humanReadableObjectsString
|
|
||||||
*/
|
|
||||||
public String parse(List<String> arguments, ModuleInterface module) {
|
|
||||||
String rval = "";
|
|
||||||
|
|
||||||
String currentModule = null;
|
|
||||||
String currentFunction = null;
|
|
||||||
Map<String,String> currentWhere = new Hashtable<String,String>();
|
|
||||||
Map<String,String> currentSet = new Hashtable<String,String>();
|
|
||||||
ArrayList<String> currentOIDs = new ArrayList<String>();
|
|
||||||
|
|
||||||
Map<String,String> globalWhere = new Hashtable<String,String>();
|
|
||||||
Map<String,String> globalSet = new Hashtable<String,String>();
|
|
||||||
String display = null;
|
|
||||||
String globalDisplay = null;
|
|
||||||
|
|
||||||
for( int i = 0; i < arguments.size(); i++ ) {
|
|
||||||
String arg = arguments.get(i);
|
|
||||||
|
|
||||||
if( arg.equals("-c") || arg.startsWith("--call:") ) {
|
|
||||||
// call
|
|
||||||
if( currentModule != null ) {
|
|
||||||
try {
|
|
||||||
// execute the last call now
|
|
||||||
rval += formatObjects(master.callModule(
|
|
||||||
currentModule,
|
|
||||||
currentFunction,
|
|
||||||
currentWhere,
|
|
||||||
currentSet,
|
|
||||||
currentOIDs,
|
|
||||||
module),(display==null)?globalDisplay:display);
|
|
||||||
} catch (FunctionNotKnownException e) {
|
|
||||||
rval += "Function unknown: "+currentModule+'.'+currentFunction+"\n";
|
|
||||||
} catch (UnknownModuleException e) {
|
|
||||||
rval += "Module unknown: "+currentModule+"\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// reset parameters for next call
|
|
||||||
currentWhere = new HashMap<String, String>();
|
|
||||||
currentWhere.putAll(globalWhere);
|
|
||||||
currentSet = new HashMap<String, String>();
|
|
||||||
currentSet.putAll(globalSet);
|
|
||||||
currentOIDs = new ArrayList<String>();
|
|
||||||
display = null;
|
|
||||||
|
|
||||||
// set the new call
|
|
||||||
boolean isShortParam = arg.equals("-c");
|
|
||||||
String calldef = isShortParam?arguments.get(i+1):arg.substring(7);
|
|
||||||
|
|
||||||
if( calldef != null ) {
|
|
||||||
String[] split = calldef.split("[.]", 2);
|
|
||||||
currentModule = split[0];
|
|
||||||
currentFunction = split[1];
|
|
||||||
}
|
|
||||||
if( isShortParam ) i++;
|
|
||||||
} else if( arg.equals("-w") || arg.startsWith("--where:") ) {
|
|
||||||
// where
|
|
||||||
boolean isShortParam = arg.equals("-w");
|
|
||||||
String wheredef = isShortParam?arguments.get(i+1):arg.substring(8);
|
|
||||||
if( wheredef != null ) {
|
|
||||||
String[] split = wheredef.split("[=]", 2);
|
|
||||||
currentWhere.put(split[0],split[1]);
|
|
||||||
}
|
|
||||||
if( isShortParam ) i++;
|
|
||||||
} else if( arg.equals("-W") || arg.startsWith("--globalWhere:") ) {
|
|
||||||
// global where
|
|
||||||
boolean isShortParam = arg.equals("-W");
|
|
||||||
String gwheredef = isShortParam?arguments.get(i+1):arg.substring(14);
|
|
||||||
if( gwheredef != null ) {
|
|
||||||
String[] split = gwheredef.split("[=]", 2);
|
|
||||||
globalWhere.put(split[0],split[1]);
|
|
||||||
}
|
|
||||||
if( isShortParam ) i++;
|
|
||||||
} else if( arg.equals("-s") || arg.startsWith("--set:") ) {
|
|
||||||
// set
|
|
||||||
boolean isShortParam = arg.equals("-s");
|
|
||||||
String setdef = isShortParam?arguments.get(i+1):arg.substring(6);
|
|
||||||
if( setdef != null ) {
|
|
||||||
String[] split = setdef.split("[=]", 2);
|
|
||||||
currentSet.put(split[0],split[1]);
|
|
||||||
}
|
|
||||||
if( isShortParam ) i++;
|
|
||||||
} else if( arg.equals("-S") || arg.startsWith("--globalSet:") ) {
|
|
||||||
// global set
|
|
||||||
boolean isShortParam = arg.equals("-S");
|
|
||||||
String gsetdef = isShortParam?arguments.get(i+1):arg.substring(12);
|
|
||||||
if( gsetdef != null ) {
|
|
||||||
String[] split = gsetdef.split("[=]", 2);
|
|
||||||
globalSet.put(split[0],split[1]);
|
|
||||||
}
|
|
||||||
if( isShortParam ) i++;
|
|
||||||
} else if( arg.equals("-d") || arg.startsWith("--display:") ) {
|
|
||||||
// display
|
|
||||||
boolean isShortParam = arg.equals("-d");
|
|
||||||
display = isShortParam?arguments.get(i+1):arg.substring(10);
|
|
||||||
if( isShortParam ) i++;
|
|
||||||
} else if( arg.equals("-D") || arg.startsWith("--globalDisplay:") ) {
|
|
||||||
// global display
|
|
||||||
boolean isShortParam = arg.equals("-D");
|
|
||||||
globalDisplay = isShortParam?arguments.get(i+1):arg.substring(16);
|
|
||||||
if( isShortParam ) i++;
|
|
||||||
} else if( arg.equals("-h") || arg.equals("--help") ) {
|
|
||||||
return getUsageString();
|
|
||||||
} else if( arg.startsWith("-") ) {
|
|
||||||
return "unknown option '"+arg+"'\n"+getUsageString();
|
|
||||||
} else currentOIDs.add(arg);
|
|
||||||
}
|
|
||||||
if( currentModule != null ) {
|
|
||||||
try {
|
|
||||||
rval += formatObjects(master.callModule(
|
|
||||||
currentModule,
|
|
||||||
currentFunction,
|
|
||||||
currentWhere,
|
|
||||||
currentSet,
|
|
||||||
currentOIDs,
|
|
||||||
module),(display==null)?globalDisplay:display);
|
|
||||||
} catch (FunctionNotKnownException e) {
|
|
||||||
rval += "Function unknown: "+currentModule+'.'+currentFunction+"\n";
|
|
||||||
} catch (UnknownModuleException e) {
|
|
||||||
rval += "Module unknown: "+currentModule+"\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return rval;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,15 +0,0 @@
|
|||||||
package de.hsadmin.cliClientConnector;
|
|
||||||
|
|
||||||
public class BusinessException extends RuntimeException {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
public BusinessException(String msg) {
|
|
||||||
super(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
public BusinessException(Exception exc) {
|
|
||||||
super(exc.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,497 +0,0 @@
|
|||||||
package de.hsadmin.cliClientConnector;
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.text.DateFormat;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import javax.servlet.ServletConfig;
|
|
||||||
import javax.servlet.ServletException;
|
|
||||||
import javax.servlet.http.HttpServlet;
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
|
||||||
|
|
||||||
import org.apache.commons.codec.binary.Base64;
|
|
||||||
|
|
||||||
import de.hsadmin.core.model.AbstractEntity;
|
|
||||||
import de.hsadmin.core.model.GenericModuleImpl;
|
|
||||||
import de.hsadmin.core.model.ModuleInterface;
|
|
||||||
import de.hsadmin.core.model.TicketValidator;
|
|
||||||
import de.hsadmin.core.model.Transaction;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* actually this is the core of the CLI-Client. The other CLI-Client is just a
|
|
||||||
* rather simple HTTP Client that calls this Servlet.
|
|
||||||
*
|
|
||||||
* @author Christof Donat
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class CLIClientConnectorServlet extends HttpServlet {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 7150004719303750077L;
|
|
||||||
public static final String version = "CLI Servlet 2.0.0 (2011/May/21 09:00 MEST)";
|
|
||||||
|
|
||||||
private Map<String, Class<?>> componentmap;
|
|
||||||
private Map<String, String> componentDescriptions;
|
|
||||||
private ArgumentParser parser;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Servlet initialization
|
|
||||||
*/
|
|
||||||
public void init(ServletConfig cfg) {
|
|
||||||
// init ticket validator
|
|
||||||
String validateURL = cfg.getInitParameter("proxyValidateUrl");
|
|
||||||
String serviceURL = cfg.getInitParameter("proxyServiceUrl");
|
|
||||||
TicketValidator.getInstance().initialize(validateURL, serviceURL);
|
|
||||||
// find components
|
|
||||||
String cstring = cfg.getInitParameter("Components");
|
|
||||||
String[] components = cstring.split(",");
|
|
||||||
|
|
||||||
componentmap = new HashMap<String, Class<?>>();
|
|
||||||
componentDescriptions = new HashMap<String, String>();
|
|
||||||
for (int i = 0; i < components.length; i++) {
|
|
||||||
// get everything for this component and create an entry.
|
|
||||||
try {
|
|
||||||
// component class
|
|
||||||
String classname = cfg.getInitParameter("ComponentClass_"
|
|
||||||
+ components[i]);
|
|
||||||
if (classname == null)
|
|
||||||
throw new NullPointerException(
|
|
||||||
"no class name found for Component "
|
|
||||||
+ components[i]);
|
|
||||||
Class<?> cls = Class.forName(classname);
|
|
||||||
componentmap.put(components[i], cls);
|
|
||||||
// description
|
|
||||||
String descr = cfg.getInitParameter("ComponentDescription_"
|
|
||||||
+ components[i]);
|
|
||||||
if (descr != null)
|
|
||||||
componentDescriptions.put(components[i], descr);
|
|
||||||
else
|
|
||||||
componentDescriptions.put(components[i], "");
|
|
||||||
} catch (ClassNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// TODO: get username, password from http session
|
|
||||||
parser = new ArgumentParser(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* set values to a given entity Object
|
|
||||||
*
|
|
||||||
* @param o
|
|
||||||
* the entity Object
|
|
||||||
* @param set
|
|
||||||
* Hashtable with names and values that sould be changed in o
|
|
||||||
*/
|
|
||||||
private void setValues(Object o, Map<String, String> set, ModuleInterface module) {
|
|
||||||
Iterator<String> keys = set.keySet().iterator();
|
|
||||||
while (keys.hasNext()) {
|
|
||||||
String key = keys.next();
|
|
||||||
String[] ns = key.split("[.]", 2);
|
|
||||||
Object realO = o;
|
|
||||||
for (int i = 0; i < ns.length - 1; i++) {
|
|
||||||
Method[] m = realO.getClass().getMethods();
|
|
||||||
boolean oFound = false;
|
|
||||||
for (int j = 0; j < m.length; j++) {
|
|
||||||
if (m[j].getName().toLowerCase().equals(
|
|
||||||
"get" + ns[i].toLowerCase())) {
|
|
||||||
try {
|
|
||||||
realO = m[j].invoke(realO, (Object[]) null);
|
|
||||||
oFound = (realO != null);
|
|
||||||
break;
|
|
||||||
} catch (Exception e) {
|
|
||||||
new TechnicalException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!oFound)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
Method[] m = realO.getClass().getMethods();
|
|
||||||
String value = set.get(key);
|
|
||||||
for (int j = 0; j < m.length; j++) {
|
|
||||||
if (!m[j].getName().toLowerCase().equals(
|
|
||||||
"set" + ns[ns.length - 1].toLowerCase()))
|
|
||||||
continue;
|
|
||||||
String type = m[j].getParameterTypes()[0].getCanonicalName();
|
|
||||||
try {
|
|
||||||
if (type.equals("java.lang.String"))
|
|
||||||
m[j].invoke(realO, value);
|
|
||||||
else if (type.equals("java.lang.Integer") || type.equals("int"))
|
|
||||||
m[j].invoke(realO, Integer.parseInt(value));
|
|
||||||
else if (type.equals("java.lang.Long") || type.equals("long"))
|
|
||||||
m[j].invoke(realO, Long.parseLong(value));
|
|
||||||
else if (type.equals("java.lang.Boolean") || type.equals("boolean"))
|
|
||||||
m[j].invoke(realO, Boolean.valueOf(value));
|
|
||||||
else if (type.equals("java.util.Date")) {
|
|
||||||
DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, Locale.GERMANY);
|
|
||||||
m[j].invoke(realO, df.parse(value));
|
|
||||||
} else {
|
|
||||||
Method m2 = module.getClass().getMethod(
|
|
||||||
"findByString", Class.class, String.class);
|
|
||||||
Object entity =
|
|
||||||
m2.invoke(module, m[j].getParameterTypes()[0], value);
|
|
||||||
if (entity != null)
|
|
||||||
m[j].invoke(realO, entity);
|
|
||||||
else
|
|
||||||
throw new BusinessException(
|
|
||||||
"not object found for '" + value + "'");
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new TechnicalException(e); // TODO: this needs to be
|
|
||||||
// more specific for
|
|
||||||
// some cases
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private String hasGetter(Class<?> eType, String name) {
|
|
||||||
String rval = null;
|
|
||||||
String[] ns = name.split("[.]", 2);
|
|
||||||
String n1 = ns[0];
|
|
||||||
Method meth = null;
|
|
||||||
|
|
||||||
for (Method m : eType.getMethods()) {
|
|
||||||
String n = m.getName();
|
|
||||||
if (n.startsWith("get")) {
|
|
||||||
String fn = m.getName().substring(3).toLowerCase();
|
|
||||||
if (fn != "class" && fn.equals(n1)) {
|
|
||||||
meth = m;
|
|
||||||
rval = fn;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (meth != null) {
|
|
||||||
Class<?> returnType = meth.getReturnType();
|
|
||||||
if (rval != null && ns.length > 1 && meth != null)
|
|
||||||
return hasGetter(returnType, ns[1]);
|
|
||||||
if (returnType.getCanonicalName().startsWith("de.hsadmin.mods")) {
|
|
||||||
try {
|
|
||||||
if (returnType.getMethod("getName") != null) {
|
|
||||||
return rval + ".name";
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
// no method found
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return rval;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* builds a query from a where clause and some objectIDs.
|
|
||||||
*
|
|
||||||
* @param eType
|
|
||||||
* The class of the Entity Object for which the string should be
|
|
||||||
* built. We need this to call the static method
|
|
||||||
* "createQueryFromStringKey"
|
|
||||||
* @param where
|
|
||||||
* Hashtable with where parameters. Only objects which match all
|
|
||||||
* where parameters are found
|
|
||||||
* @param oids
|
|
||||||
* Only objects with one of these object IDs are found
|
|
||||||
*
|
|
||||||
* @return queryString a query string that can be used to select the
|
|
||||||
* required Objects
|
|
||||||
* @throws ServletException
|
|
||||||
*/
|
|
||||||
private String buildQuery(Class<?> eType, Map<String, String> where,
|
|
||||||
ArrayList<String> oids) throws ServletException {
|
|
||||||
String rval = "";
|
|
||||||
|
|
||||||
boolean first = true;
|
|
||||||
Iterator<String> wkeys = where.keySet().iterator();
|
|
||||||
while (wkeys.hasNext()) {
|
|
||||||
String k = (String) wkeys.next();
|
|
||||||
String kname = hasGetter(eType, k);
|
|
||||||
String kvalue = ( (k.equals("id"))
|
|
||||||
? ( AbstractEntity.escapeString(where.get(k)) )
|
|
||||||
: ( "'" + AbstractEntity.escapeString(where.get(k)) + "'" ) );
|
|
||||||
if (kname != null) {
|
|
||||||
rval += (first ? "" : " and ")
|
|
||||||
+ "(obj." + AbstractEntity.escapeString(kname) + " = " + kvalue + ")";
|
|
||||||
first = false;
|
|
||||||
} else {
|
|
||||||
throw new ServletException("illegal input (unknown field: " + k + ")");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
String rv = "";
|
|
||||||
if (oids != null)
|
|
||||||
try {
|
|
||||||
Method m;
|
|
||||||
m = eType.getMethod("createQueryFromStringKey", String.class);
|
|
||||||
|
|
||||||
first = true;
|
|
||||||
for (String s : oids) {
|
|
||||||
rv += (first ? "" : " or ") + "("
|
|
||||||
+ (String) m.invoke(eType, s) + ")";
|
|
||||||
first = false;
|
|
||||||
}
|
|
||||||
if (rv != "" && rval != "")
|
|
||||||
rval = rval + " and (" + rv + ")";
|
|
||||||
else if (rv != "")
|
|
||||||
rval = rv;
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new TechnicalException(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (rval == "") ? null : rval;
|
|
||||||
}
|
|
||||||
|
|
||||||
public class FunctionNotKnownException extends Exception {
|
|
||||||
private static final long serialVersionUID = -6330015688609717838L;
|
|
||||||
}
|
|
||||||
|
|
||||||
public class UnknownModuleException extends Exception {
|
|
||||||
private static final long serialVersionUID = 696641072107896601L;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Object callAdd(Class<?> cls, Map<String, String> set, ModuleInterface module) {
|
|
||||||
Transaction transaction = module.getTransaction();
|
|
||||||
transaction.beginTransaction();
|
|
||||||
try {
|
|
||||||
Method m = module.getClass().getMethod("add", AbstractEntity.class);
|
|
||||||
Object o = cls.newInstance();
|
|
||||||
setValues(o, set, module);
|
|
||||||
m.invoke(module, o);
|
|
||||||
transaction.commitTransaction();
|
|
||||||
return null;
|
|
||||||
} catch (Exception e) {
|
|
||||||
transaction.rollbackTransaction();
|
|
||||||
// TODO: this needs to be more specific, but how?
|
|
||||||
throw new TechnicalException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
private List<Object> callSearch(Class<?> cls, Map<String, String> where,
|
|
||||||
ArrayList<String> oids, ModuleInterface module) {
|
|
||||||
try {
|
|
||||||
Method m = module.getClass().getMethod("search", Class.class,
|
|
||||||
String.class, String.class);
|
|
||||||
return (List<Object>) m.invoke(module, cls,
|
|
||||||
buildQuery(cls, where, oids), null);
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new TechnicalException(e); // TODO: this needs to be more
|
|
||||||
// specific, but how?
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// / checks wheather all 'oids' are in 'list'
|
|
||||||
private void checkOids(List<AbstractEntity> list, List<String> oids) {
|
|
||||||
List<String> oidsNotFound = new ArrayList<String>();
|
|
||||||
for (String id : oids) {
|
|
||||||
boolean found = false;
|
|
||||||
for (AbstractEntity e : list) {
|
|
||||||
String foundKey = e.createStringKey();
|
|
||||||
if (foundKey.equals(id)) {
|
|
||||||
found = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!found)
|
|
||||||
oidsNotFound.add(id);
|
|
||||||
}
|
|
||||||
if (oidsNotFound.size() > 0) {
|
|
||||||
throw new OidsNotFoundException(oids);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
private List<Object> callUpdate(Class<?> cls, Map<String, String> where,
|
|
||||||
ArrayList<String> oids, Map<String, String> set,
|
|
||||||
ModuleInterface module) {
|
|
||||||
// better safe than sorry - alsd hso same behavior as UNIX rm
|
|
||||||
if (where.size() == 0 && oids.size() == 0)
|
|
||||||
throw new BusinessException(
|
|
||||||
"better safe than sorry - 'update' needs a -w/--where-query or object id");
|
|
||||||
Transaction tx = module.getTransaction();
|
|
||||||
tx.beginTransaction();
|
|
||||||
try {
|
|
||||||
Method m = module.getClass().getMethod("search", Class.class,
|
|
||||||
String.class, String.class);
|
|
||||||
List<AbstractEntity> list = (List<AbstractEntity>) m.invoke(module, cls,
|
|
||||||
buildQuery(cls, where, oids), null);
|
|
||||||
checkOids(list, oids);
|
|
||||||
Method m2 = module.getClass().getMethod("update", AbstractEntity.class);
|
|
||||||
for (int i = 0; i < list.size(); i++) {
|
|
||||||
AbstractEntity entity = list.get(i);
|
|
||||||
tx.detach(entity);
|
|
||||||
setValues(entity, set, module);
|
|
||||||
m2.invoke(module, entity);
|
|
||||||
}
|
|
||||||
tx.commitTransaction();
|
|
||||||
} catch (Exception e) {
|
|
||||||
tx.rollbackTransaction();
|
|
||||||
// TODO: this needs to be more specific, but how?
|
|
||||||
throw new TechnicalException(e);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
private void callDelete(Class<?> cls, Map<String, String> where,
|
|
||||||
ArrayList<String> oids, ModuleInterface module) {
|
|
||||||
// better safe than sorry - also same behavior as UNIX rm
|
|
||||||
if (where.size() == 0 && oids.size() == 0)
|
|
||||||
throw new BusinessException(
|
|
||||||
"better safe than sorry - 'update' needs a -w/--where-query or object id");
|
|
||||||
Transaction tx = module.getTransaction();
|
|
||||||
tx.beginTransaction();
|
|
||||||
try {
|
|
||||||
Method m =
|
|
||||||
module.getClass().getMethod("search", Class.class, String.class, String.class);
|
|
||||||
List<AbstractEntity> list =
|
|
||||||
(List<AbstractEntity>) m.invoke(module, cls, buildQuery(cls, where, oids), null);
|
|
||||||
checkOids(list, oids);
|
|
||||||
Method m2 = module.getClass().getMethod("delete", AbstractEntity.class);
|
|
||||||
for (int i = 0; i < list.size(); i++) {
|
|
||||||
Object o = list.get(i);
|
|
||||||
m2.invoke(module, o);
|
|
||||||
}
|
|
||||||
tx.commitTransaction();
|
|
||||||
} catch (Exception e) {
|
|
||||||
tx.rollbackTransaction();
|
|
||||||
// TODO: this needs to be more specific, but how?
|
|
||||||
throw new TechnicalException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Call one of the EntitySessions methods
|
|
||||||
*
|
|
||||||
* @param moduleName
|
|
||||||
* Defines the Entity class that will be given to the
|
|
||||||
* EntitySession
|
|
||||||
* @param function
|
|
||||||
* Defines the method that will be called. The function can be
|
|
||||||
* "add", "search", "update" and "delete".
|
|
||||||
* @param where
|
|
||||||
* Reduces the set of Entity objects which the function operates
|
|
||||||
* on to those matched by the where parameters. Only for
|
|
||||||
* "search", "update" and "delete". Will be ignored otherwise.
|
|
||||||
* @param set
|
|
||||||
* Set these values on all Objects - only for "add" and "update".
|
|
||||||
* Will be ignored otherwise.
|
|
||||||
* @param oids
|
|
||||||
* Works on Objects with these IDs. Only for "search", "update"
|
|
||||||
* and "delete". Will be ignored for "add".
|
|
||||||
* @return foundObjects
|
|
||||||
* @throws FunctionNotKnownException
|
|
||||||
*/
|
|
||||||
public List<Object> callModule(String moduleName, String function,
|
|
||||||
Map<String, String> where, Map<String, String> set,
|
|
||||||
ArrayList<String> oids, ModuleInterface module)
|
|
||||||
throws FunctionNotKnownException, UnknownModuleException {
|
|
||||||
List<Object> rval = new ArrayList<Object>();
|
|
||||||
|
|
||||||
// handle calls to the virtual module "modules"
|
|
||||||
if (moduleName.equals("modules")) {
|
|
||||||
// only search, no manipulation is possible
|
|
||||||
if (function.equals("search")) {
|
|
||||||
Iterator<?> m = componentDescriptions.keySet().iterator();
|
|
||||||
while (m.hasNext()) {
|
|
||||||
String mn = (String) m.next();
|
|
||||||
rval.add(new ModuleModel(mn, componentDescriptions.get(mn)));
|
|
||||||
}
|
|
||||||
} else if (function.equals("version")) {
|
|
||||||
rval.add(new VersionModel(version));
|
|
||||||
} else {
|
|
||||||
throw new FunctionNotKnownException();
|
|
||||||
}
|
|
||||||
return rval;
|
|
||||||
}
|
|
||||||
|
|
||||||
// find the component for the named module
|
|
||||||
Class<?> cls = componentmap.get(moduleName);
|
|
||||||
if (cls == null)
|
|
||||||
throw (new UnknownModuleException());
|
|
||||||
|
|
||||||
// call the appropriate methods
|
|
||||||
if (function.equals("add"))
|
|
||||||
rval.add(callAdd(cls, set, module));
|
|
||||||
else if (function.equals("search")) {
|
|
||||||
List<Object> r = callSearch(cls, where, oids, module);
|
|
||||||
if (r != null)
|
|
||||||
return r;
|
|
||||||
} else if (function.equals("update")) {
|
|
||||||
List<Object> r = callUpdate(cls, where, oids, set, module);
|
|
||||||
if (r != null)
|
|
||||||
return callUpdate(cls, where, oids, set, module);
|
|
||||||
} else if (function.equals("delete")) {
|
|
||||||
callDelete(cls, where, oids, module);
|
|
||||||
} else
|
|
||||||
throw (new FunctionNotKnownException());
|
|
||||||
return rval;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* handle put method
|
|
||||||
*/
|
|
||||||
public void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException {
|
|
||||||
try {
|
|
||||||
ModuleInterface module = null;
|
|
||||||
Transaction tx = null;
|
|
||||||
// check login
|
|
||||||
String auth = req.getHeader("authorization");
|
|
||||||
if (auth == null) {
|
|
||||||
// no login information at all - get it
|
|
||||||
resp.setHeader("WWW-Authenticate",
|
|
||||||
"Basic realm=\"CLIClientConnector\"");
|
|
||||||
resp.getOutputStream().println("login Failed.");
|
|
||||||
resp.sendError(HttpServletResponse.SC_UNAUTHORIZED);
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
// parse login information
|
|
||||||
String[] a = auth.split(" ", 2);
|
|
||||||
String ticket = a[1];
|
|
||||||
byte[] decoded = Base64.decodeBase64(ticket.trim().getBytes());
|
|
||||||
String s = new String(decoded);
|
|
||||||
a = s.split(":", 2);
|
|
||||||
// try to log in
|
|
||||||
String login = a[0];
|
|
||||||
ticket = a[1];
|
|
||||||
try {
|
|
||||||
tx = new Transaction(login);
|
|
||||||
if (tx.login(login, ticket)) {
|
|
||||||
// login successful
|
|
||||||
module = new GenericModuleImpl(tx);
|
|
||||||
|
|
||||||
// read arguments
|
|
||||||
BufferedReader read = req.getReader();
|
|
||||||
|
|
||||||
String tmpbuf;
|
|
||||||
ArrayList<String> arguments = new ArrayList<String>();
|
|
||||||
while ((tmpbuf = read.readLine()) != null) {
|
|
||||||
arguments.add(tmpbuf);
|
|
||||||
}
|
|
||||||
|
|
||||||
// actually handle the request and write result to output
|
|
||||||
String output = parser.parse(arguments, module);
|
|
||||||
resp.getWriter().write(output);
|
|
||||||
} else {
|
|
||||||
resp.addHeader("X-hsadmin-error", "authentication failed");
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
resp.addHeader("X-hsadmin-error", "exception: " + e.getMessage());
|
|
||||||
} finally {
|
|
||||||
if (tx != null) {
|
|
||||||
tx.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,19 +0,0 @@
|
|||||||
package de.hsadmin.cliClientConnector;
|
|
||||||
|
|
||||||
public class ModuleModel {
|
|
||||||
private String name;
|
|
||||||
private String description;
|
|
||||||
|
|
||||||
public ModuleModel(String name, String description) {
|
|
||||||
this.name = name;
|
|
||||||
this.description = description;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return this.name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDescription() {
|
|
||||||
return this.description;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,25 +0,0 @@
|
|||||||
package de.hsadmin.cliClientConnector;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
|
||||||
public class OidsNotFoundException
|
|
||||||
extends RuntimeException
|
|
||||||
{
|
|
||||||
static private String oidsAsString(List<String> oids)
|
|
||||||
{
|
|
||||||
StringBuilder oidsBuilder = new StringBuilder();
|
|
||||||
for ( String id: oids )
|
|
||||||
oidsBuilder.append(", " + id);
|
|
||||||
if ( oidsBuilder.length() > 0 )
|
|
||||||
return oidsBuilder.substring(2);
|
|
||||||
throw new RuntimeException( "an empty list of missing OIDS does not make sense" );
|
|
||||||
}
|
|
||||||
|
|
||||||
public OidsNotFoundException(List<String> oids)
|
|
||||||
{
|
|
||||||
super("OIDS not found: " + oidsAsString(oids));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,14 +0,0 @@
|
|||||||
package de.hsadmin.cliClientConnector;
|
|
||||||
|
|
||||||
public class VersionModel
|
|
||||||
{
|
|
||||||
private String version;
|
|
||||||
|
|
||||||
public VersionModel( String version) {
|
|
||||||
this.version = version;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getVersion() {
|
|
||||||
return this.version;
|
|
||||||
}
|
|
||||||
}
|
|
93
hsarback/src/de/hsadmin/core/model/LoginSession.java
Normal file
93
hsarback/src/de/hsadmin/core/model/LoginSession.java
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
package de.hsadmin.core.model;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import javax.ejb.Stateless;
|
||||||
|
import javax.persistence.EntityManager;
|
||||||
|
import javax.persistence.PersistenceContext;
|
||||||
|
import javax.persistence.Query;
|
||||||
|
|
||||||
|
import de.hsadmin.core.util.Config;
|
||||||
|
import de.hsadmin.mods.cust.Customer;
|
||||||
|
import de.hsadmin.mods.pac.Pac;
|
||||||
|
import de.hsadmin.mods.user.UnixUser;
|
||||||
|
|
||||||
|
@Stateless
|
||||||
|
public class LoginSession {
|
||||||
|
|
||||||
|
@PersistenceContext(name="hsadmin")
|
||||||
|
private EntityManager entityManager;
|
||||||
|
|
||||||
|
private String loginName;
|
||||||
|
|
||||||
|
public UnixUser getLoginUser() {
|
||||||
|
String loginName = getLoginName();
|
||||||
|
if (loginName != null && loginName.length() == 2) {
|
||||||
|
loginName = Config.getInstance().getProperty("accountprefix.hostmaster", "hsh01") + "-" + loginName;
|
||||||
|
}
|
||||||
|
if (loginName != null && loginName.length() == 3) {
|
||||||
|
loginName = Config.getInstance().getProperty("accountprefix.customer", "hsh00") + "-" + loginName;
|
||||||
|
}
|
||||||
|
Query userQuery = entityManager.createQuery("SELECT u FROM UnixUsers u WHERE u.name = :username");
|
||||||
|
userQuery.setParameter("username", loginName);
|
||||||
|
UnixUser unixUser = (UnixUser) userQuery.getSingleResult();
|
||||||
|
return unixUser;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLoginName() {
|
||||||
|
if (loginName != null) {
|
||||||
|
return loginName;
|
||||||
|
}
|
||||||
|
throw new TechnicalException("no login");
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean login(String user, String ticket) throws AuthenticationException {
|
||||||
|
String ticketUser = TicketValidator.getInstance().validateTicket(ticket);
|
||||||
|
if (user != null && user.equals(ticketUser)) {
|
||||||
|
loginName = ticketUser;
|
||||||
|
return true; // user himself
|
||||||
|
}
|
||||||
|
if (ticketUser != null && ticketUser.length() == 2) {
|
||||||
|
loginName = ticketUser;
|
||||||
|
return true; // 2-letter hostmaster
|
||||||
|
}
|
||||||
|
String hostmasterAccountPrefix = Config.getInstance().getProperty("accountprefix.hostmaster", "hsh01") + "-";
|
||||||
|
if (ticketUser != null && ticketUser.startsWith(hostmasterAccountPrefix) && ticketUser.length() == 8) {
|
||||||
|
loginName = ticketUser;
|
||||||
|
return true; // hsh01 hostmaster
|
||||||
|
}
|
||||||
|
if (ticketUser != null && ticketUser.length() == 5) {
|
||||||
|
Query userQuery = entityManager.createQuery("SELECT u FROM UnixUsers u WHERE u.name = :username");
|
||||||
|
userQuery.setParameter("username", user);
|
||||||
|
UnixUser unixUser = (UnixUser) userQuery.getSingleResult();
|
||||||
|
String pacName = unixUser.getPac().getName();
|
||||||
|
boolean loginOk = ticketUser.equals(pacName);
|
||||||
|
if (loginOk) {
|
||||||
|
loginName = ticketUser;
|
||||||
|
}
|
||||||
|
return loginOk; // pac-admin
|
||||||
|
}
|
||||||
|
String memberAccountPrefix = Config.getInstance().getProperty("accountprefix.customer", "hsh00") + "-";
|
||||||
|
if (ticketUser != null && (ticketUser.length() == 3 || (ticketUser.length() >= 9 && ticketUser.startsWith(memberAccountPrefix)))) {
|
||||||
|
Query memberQuery = entityManager.createQuery("SELECT c FROM Customers c WHERE c.name = :membername");
|
||||||
|
memberQuery.setParameter("membername", ticketUser.length() == 3 ? (memberAccountPrefix + ticketUser) : ticketUser);
|
||||||
|
Customer member = (Customer) memberQuery.getSingleResult();
|
||||||
|
Set<Pac> pacs = member.getPacs();
|
||||||
|
for (Pac p : pacs) {
|
||||||
|
if (p.getName().equals(user)) {
|
||||||
|
loginName = ticketUser;
|
||||||
|
return true; // member as pac-admin
|
||||||
|
}
|
||||||
|
Set<UnixUser> users = p.getUnixUser();
|
||||||
|
for (UnixUser u : users) {
|
||||||
|
if (u.getName().equals(user)) {
|
||||||
|
loginName = ticketUser;
|
||||||
|
return true; // member as pac-user
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new AuthenticationException("User " + ticketUser + " is not allowed to run as " + user);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
46
hsarback/src/de/hsadmin/core/model/QueueManager.java
Normal file
46
hsarback/src/de/hsadmin/core/model/QueueManager.java
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
package de.hsadmin.core.model;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.ejb.Stateless;
|
||||||
|
|
||||||
|
import de.hsadmin.core.qserv.QueueTask;
|
||||||
|
|
||||||
|
@Stateless
|
||||||
|
public class QueueManager {
|
||||||
|
|
||||||
|
private final Map<String, QueueTaskStore> taskStores;
|
||||||
|
|
||||||
|
public QueueManager() {
|
||||||
|
taskStores = new HashMap<String, QueueManager.QueueTaskStore>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void enqueue(String hiveName, QueueTask task) {
|
||||||
|
QueueTaskStore taskStore = taskStores.get(hiveName);
|
||||||
|
if (taskStore == null) {
|
||||||
|
taskStore = new QueueTaskStore();
|
||||||
|
taskStores.put(hiveName, taskStore);
|
||||||
|
}
|
||||||
|
taskStore.add(task);
|
||||||
|
}
|
||||||
|
|
||||||
|
class QueueTaskStore {
|
||||||
|
private List<QueueTask> taskList;
|
||||||
|
QueueTaskStore() {
|
||||||
|
taskList = new ArrayList<QueueTask>();
|
||||||
|
}
|
||||||
|
public void clear() {
|
||||||
|
taskList = new ArrayList<QueueTask>();
|
||||||
|
}
|
||||||
|
void add(QueueTask t) {
|
||||||
|
taskList.add(t);
|
||||||
|
}
|
||||||
|
Iterable<QueueTask> getTasks() {
|
||||||
|
return taskList;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package de.hsadmin.cliClientConnector;
|
package de.hsadmin.core.model;
|
||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
@ -28,6 +28,7 @@ public class TicketValidator {
|
|||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME wird nicht aufgerufen
|
||||||
public void initialize(String validateURL, String serviceURL) {
|
public void initialize(String validateURL, String serviceURL) {
|
||||||
proxyServiceURL = serviceURL;
|
proxyServiceURL = serviceURL;
|
||||||
proxyValidateURL = validateURL;
|
proxyValidateURL = validateURL;
|
||||||
|
@ -15,7 +15,6 @@ import javax.persistence.EntityManager;
|
|||||||
import javax.persistence.EntityTransaction;
|
import javax.persistence.EntityTransaction;
|
||||||
import javax.persistence.Query;
|
import javax.persistence.Query;
|
||||||
|
|
||||||
import de.hsadmin.cliClientConnector.TechnicalException;
|
|
||||||
import de.hsadmin.core.qserv.QueueClient;
|
import de.hsadmin.core.qserv.QueueClient;
|
||||||
import de.hsadmin.core.qserv.QueueTask;
|
import de.hsadmin.core.qserv.QueueTask;
|
||||||
import de.hsadmin.core.util.Config;
|
import de.hsadmin.core.util.Config;
|
||||||
|
@ -23,7 +23,7 @@ import javax.servlet.http.HttpServlet;
|
|||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import de.hsadmin.cliClientConnector.TechnicalException;
|
import de.hsadmin.core.model.TechnicalException;
|
||||||
import de.hsadmin.core.model.Transaction;
|
import de.hsadmin.core.model.Transaction;
|
||||||
import de.hsadmin.core.util.Config;
|
import de.hsadmin.core.util.Config;
|
||||||
|
|
||||||
|
@ -8,9 +8,9 @@ import java.util.List;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
|
|
||||||
import de.hsadmin.cliClientConnector.TechnicalException;
|
|
||||||
import de.hsadmin.core.model.AbstractEntity;
|
import de.hsadmin.core.model.AbstractEntity;
|
||||||
import de.hsadmin.core.model.AnnFieldIO;
|
import de.hsadmin.core.model.AnnFieldIO;
|
||||||
|
import de.hsadmin.core.model.TechnicalException;
|
||||||
|
|
||||||
public class ReflectionUtil {
|
public class ReflectionUtil {
|
||||||
|
|
||||||
|
@ -5,9 +5,9 @@ import java.util.List;
|
|||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import javax.persistence.Query;
|
import javax.persistence.Query;
|
||||||
|
|
||||||
|
import de.hsadmin.core.model.AbstractEntity;
|
||||||
import de.hsadmin.core.model.AbstractModuleImpl;
|
import de.hsadmin.core.model.AbstractModuleImpl;
|
||||||
import de.hsadmin.core.model.AuthorisationException;
|
import de.hsadmin.core.model.AuthorisationException;
|
||||||
import de.hsadmin.core.model.AbstractEntity;
|
|
||||||
import de.hsadmin.core.model.HSAdminException;
|
import de.hsadmin.core.model.HSAdminException;
|
||||||
import de.hsadmin.core.model.Transaction;
|
import de.hsadmin.core.model.Transaction;
|
||||||
import de.hsadmin.hostsharing.BasePacType;
|
import de.hsadmin.hostsharing.BasePacType;
|
||||||
|
@ -1,22 +1,44 @@
|
|||||||
package de.hsadmin.mods.email;
|
package de.hsadmin.mods.email;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.ejb.EJB;
|
||||||
|
import javax.ejb.Stateless;
|
||||||
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
|
import javax.persistence.NonUniqueResultException;
|
||||||
|
import javax.persistence.PersistenceContext;
|
||||||
import javax.persistence.Query;
|
import javax.persistence.Query;
|
||||||
|
|
||||||
import de.hsadmin.core.model.AbstractEntity;
|
import de.hsadmin.core.model.AbstractEntity;
|
||||||
import de.hsadmin.core.model.AbstractModuleImpl;
|
import de.hsadmin.core.model.AbstractModuleImpl;
|
||||||
import de.hsadmin.core.model.AuthorisationException;
|
import de.hsadmin.core.model.AuthorisationException;
|
||||||
import de.hsadmin.core.model.HSAdminException;
|
import de.hsadmin.core.model.HSAdminException;
|
||||||
import de.hsadmin.core.model.Transaction;
|
import de.hsadmin.core.model.LoginSession;
|
||||||
|
import de.hsadmin.core.model.QueueManager;
|
||||||
|
import de.hsadmin.core.qserv.EntityProcessorFactory;
|
||||||
|
import de.hsadmin.core.qserv.NullProcessor;
|
||||||
|
import de.hsadmin.core.qserv.Processor;
|
||||||
|
import de.hsadmin.core.qserv.QueueTask;
|
||||||
import de.hsadmin.hostsharing.BasePacType;
|
import de.hsadmin.hostsharing.BasePacType;
|
||||||
import de.hsadmin.hostsharing.MultiOption;
|
import de.hsadmin.hostsharing.MultiOption;
|
||||||
import de.hsadmin.mods.pac.Pac;
|
import de.hsadmin.mods.pac.Pac;
|
||||||
import de.hsadmin.mods.user.UnixUser;
|
import de.hsadmin.mods.user.UnixUser;
|
||||||
|
|
||||||
|
@Stateless
|
||||||
public class EMailAliasModuleImpl extends AbstractModuleImpl {
|
public class EMailAliasModuleImpl extends AbstractModuleImpl {
|
||||||
|
|
||||||
|
@PersistenceContext(name="hsadmin")
|
||||||
|
private EntityManager entityManager;
|
||||||
|
|
||||||
|
@EJB
|
||||||
|
private LoginSession session;
|
||||||
|
|
||||||
|
@EJB
|
||||||
|
private QueueManager queueManager;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<AbstractEntity> search(Class<? extends AbstractEntity> entityClass,
|
public List<AbstractEntity> search(Class<? extends AbstractEntity> entityClass,
|
||||||
String condition, String orderBy) throws HSAdminException {
|
String condition, String orderBy) throws HSAdminException {
|
||||||
@ -28,15 +50,13 @@ public class EMailAliasModuleImpl extends AbstractModuleImpl {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AbstractEntity add(AbstractEntity newEntity) throws HSAdminException {
|
public AbstractEntity add(AbstractEntity newEntity) throws HSAdminException {
|
||||||
Transaction transaction = getTransaction();
|
UnixUser loginUser = session.getLoginUser();
|
||||||
UnixUser loginUser = transaction.getLoginUser();
|
|
||||||
EMailAlias alias = (EMailAlias) newEntity;
|
EMailAlias alias = (EMailAlias) newEntity;
|
||||||
String name = alias.getName();
|
String name = alias.getName();
|
||||||
if (name.length() > 5 && (name.charAt(5) != '-') || name.length() == 6) {
|
if (name.length() > 5 && (name.charAt(5) != '-') || name.length() == 6) {
|
||||||
throw new AuthorisationException(loginUser, "add", newEntity);
|
throw new AuthorisationException(loginUser, "add", newEntity);
|
||||||
}
|
}
|
||||||
EntityManager em = getTransaction().getEntityManager();
|
Query qPac = entityManager.createQuery("SELECT obj FROM Pacs obj WHERE obj.name = :pacName");
|
||||||
Query qPac = em.createQuery("SELECT obj FROM Pacs obj WHERE obj.name = :pacName");
|
|
||||||
qPac.setParameter("pacName", name.substring(0, 5));
|
qPac.setParameter("pacName", name.substring(0, 5));
|
||||||
Object singleResult = qPac.getSingleResult();
|
Object singleResult = qPac.getSingleResult();
|
||||||
Pac pac = (Pac) singleResult;
|
Pac pac = (Pac) singleResult;
|
||||||
@ -52,9 +72,9 @@ public class EMailAliasModuleImpl extends AbstractModuleImpl {
|
|||||||
throw new HSAdminException("not allowed for this packet type");
|
throw new HSAdminException("not allowed for this packet type");
|
||||||
}
|
}
|
||||||
//TODO: Needs better implementation
|
//TODO: Needs better implementation
|
||||||
Query qEmailAliases = em.createQuery("SELECT obj FROM EMailAliases obj WHERE obj.pac.id = :pacId");
|
Query qEmailAliases = entityManager.createQuery("SELECT obj FROM EMailAliases obj WHERE obj.pac.id = :pacId");
|
||||||
qEmailAliases.setParameter("pacId", pac.getId());
|
qEmailAliases.setParameter("pacId", pac.getId());
|
||||||
Query qEmailAddresses = em.createQuery("SELECT obj FROM EMailAddresses obj WHERE obj.domain.user.pac.id = :pacId");
|
Query qEmailAddresses = entityManager.createQuery("SELECT obj FROM EMailAddresses obj WHERE obj.domain.user.pac.id = :pacId");
|
||||||
qEmailAddresses.setParameter("pacId", pac.getId());
|
qEmailAddresses.setParameter("pacId", pac.getId());
|
||||||
if (qEmailAliases.getResultList().size() + qEmailAddresses.getResultList().size() >= MultiOption.EMAIL_ITEMS_PER_OPTION * pac.getQuantityByComponentName("MULTI")) {
|
if (qEmailAliases.getResultList().size() + qEmailAddresses.getResultList().size() >= MultiOption.EMAIL_ITEMS_PER_OPTION * pac.getQuantityByComponentName("MULTI")) {
|
||||||
throw new HSAdminException("included email addresses/aliases exceeded");
|
throw new HSAdminException("included email addresses/aliases exceeded");
|
||||||
@ -63,4 +83,204 @@ public class EMailAliasModuleImpl extends AbstractModuleImpl {
|
|||||||
return super.add(newEntity);
|
return super.add(newEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void detach(AbstractEntity attached) {
|
||||||
|
entityManager.detach(attached);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO extract copied code
|
||||||
|
|
||||||
|
public AbstractEntity initialize(AbstractEntity newEntity)
|
||||||
|
throws AuthorisationException {
|
||||||
|
newEntity.initialize(entityManager, session.getLoginUser());
|
||||||
|
return newEntity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AbstractEntity superadd(AbstractEntity newEntity) throws HSAdminException {
|
||||||
|
UnixUser loginUser = session.getLoginUser();
|
||||||
|
newEntity.complete(entityManager, loginUser);
|
||||||
|
entityManager.persist(newEntity);
|
||||||
|
if (!newEntity.isWriteAllowedFor(loginUser)) {
|
||||||
|
throw new AuthorisationException(loginUser, "add", newEntity);
|
||||||
|
}
|
||||||
|
EntityProcessorFactory procFact = createProcessorFactory(newEntity.getClass());
|
||||||
|
if (procFact != null) {
|
||||||
|
Processor proc = procFact.createCreateProcessor(entityManager, newEntity);
|
||||||
|
queueProcessor(proc, loginUser, newEntity, "hinzugefuegt");
|
||||||
|
}
|
||||||
|
return newEntity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AbstractEntity find(Class<? extends AbstractEntity> entityClass, Object key) throws HSAdminException {
|
||||||
|
AbstractEntity entity = entityManager.find(entityClass, key);
|
||||||
|
UnixUser loginUser = session.getLoginUser();
|
||||||
|
if (!entity.isReadAllowedFor(loginUser)) {
|
||||||
|
throw new AuthorisationException(loginUser, "add", entity);
|
||||||
|
}
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AbstractEntity findByString(Class<? extends AbstractEntity> entityClass, String key) throws HSAdminException {
|
||||||
|
Method method = null;
|
||||||
|
try {
|
||||||
|
method = entityClass.getDeclaredMethod("createQueryFromStringKey", String.class);
|
||||||
|
} catch (SecurityException e) {
|
||||||
|
throw new HSAdminException(e);
|
||||||
|
} catch (NoSuchMethodException e) {
|
||||||
|
method = null;
|
||||||
|
}
|
||||||
|
AbstractEntity entity = null;
|
||||||
|
if (method == null) {
|
||||||
|
entity = entityManager.find(entityClass, key);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
String query = null;
|
||||||
|
try {
|
||||||
|
query = (String) method.invoke(null, key);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new HSAdminException(e);
|
||||||
|
}
|
||||||
|
List<AbstractEntity> result = search(entityClass, query, null);
|
||||||
|
if (result.size() > 1) throw new NonUniqueResultException();
|
||||||
|
if (result.size() == 0) return null;
|
||||||
|
entity = result.get(0);
|
||||||
|
}
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<AbstractEntity> supersearch(Class<? extends AbstractEntity> entityClass, String condition, String orderBy) throws HSAdminException {
|
||||||
|
UnixUser loginUser = session.getLoginUser();
|
||||||
|
condition = restrict(entityClass, loginUser, condition);
|
||||||
|
Entity entityAnnot = entityClass.getAnnotation(Entity.class);
|
||||||
|
String queryString = "SELECT obj FROM " + entityAnnot.name() + " obj";
|
||||||
|
if (condition != null && condition.length() > 0) {
|
||||||
|
queryString += " WHERE " + condition;
|
||||||
|
}
|
||||||
|
if (condition != null && condition.contains("AND (FALSE)")) {
|
||||||
|
return new LinkedList<AbstractEntity>();
|
||||||
|
}
|
||||||
|
if (orderBy != null) {
|
||||||
|
queryString += " ";
|
||||||
|
queryString += orderBy;
|
||||||
|
}
|
||||||
|
entityManager.clear();
|
||||||
|
Query query = entityManager.createQuery(queryString);
|
||||||
|
setQueryParameter(query, queryString, "loginUser", loginUser);
|
||||||
|
setQueryParameter(query, queryString, "loginUserName", loginUser.getName());
|
||||||
|
setQueryParameter(query, queryString, "loginUserPac", loginUser.getPac());
|
||||||
|
try {
|
||||||
|
List<?> res = query.getResultList();
|
||||||
|
List<AbstractEntity> ret = new LinkedList<AbstractEntity>();
|
||||||
|
// remove entities where login user has no access rights
|
||||||
|
for (Object entity : res) {
|
||||||
|
if (entity instanceof AbstractEntity) {
|
||||||
|
AbstractEntity returnedEntity = (AbstractEntity) entity;
|
||||||
|
if (returnedEntity.isReadAllowedFor(session.getLoginUser())) {
|
||||||
|
ret.add(returnedEntity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
} catch (Exception ex) {
|
||||||
|
throw new HSAdminException(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public AbstractEntity update(AbstractEntity existingEntity) throws HSAdminException {
|
||||||
|
UnixUser loginUser = session.getLoginUser();
|
||||||
|
existingEntity = existingEntity.merge(entityManager, loginUser);
|
||||||
|
if (!existingEntity.isWriteAllowedFor(loginUser)) {
|
||||||
|
throw new AuthorisationException(loginUser, "update", existingEntity);
|
||||||
|
}
|
||||||
|
EntityProcessorFactory procFact = createProcessorFactory(existingEntity.getClass());
|
||||||
|
if (procFact != null) {
|
||||||
|
Processor proc = procFact.createUpdateProcessor(entityManager, existingEntity);
|
||||||
|
queueProcessor(proc, loginUser, existingEntity, "aktualisiert");
|
||||||
|
}
|
||||||
|
return existingEntity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void delete(AbstractEntity existingEntity) throws HSAdminException {
|
||||||
|
UnixUser loginUser = session.getLoginUser();
|
||||||
|
existingEntity = entityManager.find(existingEntity.getClass(), existingEntity.id());
|
||||||
|
if (!existingEntity.isWriteAllowedFor(loginUser)) {
|
||||||
|
throw new AuthorisationException(loginUser, "add", existingEntity);
|
||||||
|
}
|
||||||
|
entityManager.remove(existingEntity);
|
||||||
|
EntityProcessorFactory procFact = createProcessorFactory(existingEntity.getClass());
|
||||||
|
if (procFact != null) {
|
||||||
|
Processor proc = procFact.createDeleteProcessor(entityManager, existingEntity);
|
||||||
|
queueProcessor(proc, loginUser, existingEntity, "geloescht");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected EntityProcessorFactory createProcessorFactory(Class<? extends AbstractEntity> entityClass)
|
||||||
|
throws HSAdminException {
|
||||||
|
String procFactName = entityClass.getCanonicalName() + "ProcessorFactory";
|
||||||
|
Class<?> procFactClass = null;
|
||||||
|
EntityProcessorFactory procFact = null;
|
||||||
|
try {
|
||||||
|
procFactClass = Class.forName(procFactName);
|
||||||
|
if (procFactClass != null) {
|
||||||
|
procFact = (EntityProcessorFactory) procFactClass.newInstance();
|
||||||
|
}
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
// no processor defined
|
||||||
|
} catch (InstantiationException e) {
|
||||||
|
throw new HSAdminException(e);
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
throw new HSAdminException(e);
|
||||||
|
}
|
||||||
|
return procFact;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void queueProcessor(Processor proc, UnixUser user, AbstractEntity entity, String action) {
|
||||||
|
if (proc == null || proc instanceof NullProcessor) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Entity entityInfo = entity.getClass().getAnnotation(Entity.class);
|
||||||
|
String entityTypeName = entityInfo != null ? entityInfo.name() : entity.getClass().getSimpleName();
|
||||||
|
StringBuilder details = new StringBuilder();
|
||||||
|
String title = entityTypeName + " (" + entity.createStringKey() + ") " + action;
|
||||||
|
QueueTask task = new QueueTask(user, title, details.toString(), proc);
|
||||||
|
entityManager.persist(task);
|
||||||
|
queueManager.enqueue(entity.getHiveName(), task);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString(StackTraceElement[] stackTrace) {
|
||||||
|
StringBuilder stack = new StringBuilder();
|
||||||
|
for (StackTraceElement e : stackTrace) {
|
||||||
|
stack.append(e.getFileName() + ":" + e.getLineNumber() + "\n");
|
||||||
|
}
|
||||||
|
return stack.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* apply access restriction to JPA-QL condition.
|
||||||
|
*/
|
||||||
|
private String restrict(Class<?> entityClass, UnixUser loginUser, String condition) {
|
||||||
|
String restriction = AbstractEntity.restriction(entityClass, loginUser);
|
||||||
|
if (restriction == null)
|
||||||
|
return condition;
|
||||||
|
if (condition != null && condition.length() > 0)
|
||||||
|
condition = "(" + condition + ") AND (" + restriction + ")";
|
||||||
|
else
|
||||||
|
condition = restriction;
|
||||||
|
return condition;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setQueryParameter(Query query, String queryString,
|
||||||
|
String argName, Object argValue) {
|
||||||
|
int argLen = argName.length();
|
||||||
|
int iMax = queryString.length();
|
||||||
|
int i = 0;
|
||||||
|
while ((i = queryString.indexOf(argName, i)) >= 0) {
|
||||||
|
if ((i + argLen) >= iMax || queryString.charAt(i + argLen) < 'A') {
|
||||||
|
query.setParameter(argName, argValue);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,18 +1,201 @@
|
|||||||
package de.hsadmin.remote;
|
package de.hsadmin.remote;
|
||||||
|
|
||||||
|
import java.lang.reflect.Constructor;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.StringTokenizer;
|
import java.util.StringTokenizer;
|
||||||
|
|
||||||
|
import javax.ejb.EJB;
|
||||||
|
|
||||||
import de.hsadmin.core.model.AbstractEntity;
|
import de.hsadmin.core.model.AbstractEntity;
|
||||||
import de.hsadmin.core.model.Transaction;
|
import de.hsadmin.core.model.AuthenticationException;
|
||||||
|
import de.hsadmin.core.model.AuthorisationException;
|
||||||
|
import de.hsadmin.core.model.HSAdminException;
|
||||||
|
import de.hsadmin.core.model.LoginSession;
|
||||||
import de.hsadmin.mods.email.EMailAlias;
|
import de.hsadmin.mods.email.EMailAlias;
|
||||||
|
import de.hsadmin.mods.email.EMailAliasModuleImpl;
|
||||||
|
import de.hsadmin.mods.user.UnixUser;
|
||||||
|
|
||||||
public class EMailAliasRemote extends AbstractRemote {
|
public class EMailAliasRemote {
|
||||||
|
|
||||||
@Override
|
@EJB
|
||||||
protected void entity2map(Transaction tx, AbstractEntity entity, Map<String, Object> map) {
|
private LoginSession session;
|
||||||
|
|
||||||
|
@EJB
|
||||||
|
private EMailAliasModuleImpl module;
|
||||||
|
|
||||||
|
public List<Map<String, Object>> search(String runAsUser, String ticket,
|
||||||
|
Map<String, String> whereParams) throws HSAdminException {
|
||||||
|
String user = runAsUser;
|
||||||
|
try {
|
||||||
|
if (session.login(user, ticket)) {
|
||||||
|
UnixUser unixUser = session.getLoginUser();
|
||||||
|
List<AbstractEntity> list = module.search(getEntityClass(),
|
||||||
|
buildQueryCondition(whereParams), null);
|
||||||
|
if (list == null) {
|
||||||
|
throw new HSAdminException("result list is null, runtime-error?");
|
||||||
|
}
|
||||||
|
ArrayList<Map<String, Object>> result = new ArrayList<Map<String, Object>>();
|
||||||
|
for (AbstractEntity e : list) {
|
||||||
|
HashMap<String, Object> entry = new HashMap<String, Object>();
|
||||||
|
entity2map(e, entry);
|
||||||
|
if (e.isReadAllowedFor(unixUser)) {
|
||||||
|
result.add(entry);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
} else {
|
||||||
|
throw new AuthenticationException("authentication failed");
|
||||||
|
}
|
||||||
|
} catch (SecurityException e) {
|
||||||
|
throw new HSAdminException(e);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
throw new HSAdminException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, Object> add(String runAsUser, String ticket,
|
||||||
|
Map<String, Object> setParams) throws HSAdminException {
|
||||||
|
String user = runAsUser;
|
||||||
|
try {
|
||||||
|
if (session.login(user, ticket)) {
|
||||||
|
Constructor<? extends AbstractEntity> constructor =
|
||||||
|
getEntityClass().getConstructor();
|
||||||
|
AbstractEntity entity = constructor.newInstance();
|
||||||
|
module.initialize(entity);
|
||||||
|
map2entity(setParams, entity);
|
||||||
|
AbstractEntity insertedEntity = module.add(entity);
|
||||||
|
HashMap<String, Object> entry = new HashMap<String, Object>();
|
||||||
|
entity2map(insertedEntity, entry);
|
||||||
|
return entry;
|
||||||
|
} else {
|
||||||
|
throw new AuthenticationException("authentication failed");
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new HSAdminException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void delete(String runAsUser, String ticket,
|
||||||
|
Map<String, String> whereParams) throws HSAdminException {
|
||||||
|
String user = runAsUser;
|
||||||
|
try {
|
||||||
|
if (session.login(user, ticket)) {
|
||||||
|
UnixUser unixUser = session.getLoginUser();
|
||||||
|
String queryCondition = buildQueryCondition(whereParams);
|
||||||
|
if (queryCondition == null || queryCondition.length() == 0) {
|
||||||
|
throw new HSAdminException(
|
||||||
|
"better safe than sorry: no where parameter found");
|
||||||
|
}
|
||||||
|
List<AbstractEntity> list = module.search(getEntityClass(),
|
||||||
|
queryCondition, null);
|
||||||
|
for (AbstractEntity e : list) {
|
||||||
|
if (e.isWriteAllowedFor(unixUser)) {
|
||||||
|
module.delete(e);
|
||||||
|
} else {
|
||||||
|
throw new AuthorisationException(unixUser, "delete", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new AuthenticationException("authentication failed");
|
||||||
|
}
|
||||||
|
} catch (SecurityException e) {
|
||||||
|
throw new HSAdminException(e);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
throw new HSAdminException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Map<String, Object>> update(String runAsUser, String ticket,
|
||||||
|
Map<String, Object> setParams, Map<String, String> whereParams)
|
||||||
|
throws HSAdminException {
|
||||||
|
String user = runAsUser;
|
||||||
|
try {
|
||||||
|
if (session.login(user, ticket)) {
|
||||||
|
UnixUser unixUser = session.getLoginUser();
|
||||||
|
ArrayList<Map<String, Object>> result = new ArrayList<Map<String, Object>>();
|
||||||
|
String queryCondition = buildQueryCondition(whereParams);
|
||||||
|
if (queryCondition == null || queryCondition.length() == 0) {
|
||||||
|
throw new HSAdminException(
|
||||||
|
"better safe than sorry: no where parameter found");
|
||||||
|
}
|
||||||
|
List<AbstractEntity> list = module.search(getEntityClass(),
|
||||||
|
queryCondition, getOrderBy());
|
||||||
|
for (AbstractEntity update : list) {
|
||||||
|
if (update.isWriteAllowedFor(unixUser)) {
|
||||||
|
module.detach(update);
|
||||||
|
map2entity(setParams, update);
|
||||||
|
update = module.update(update);
|
||||||
|
HashMap<String, Object> entry = new HashMap<String, Object>();
|
||||||
|
entity2map(update, entry);
|
||||||
|
result.add(entry);
|
||||||
|
} else {
|
||||||
|
throw new AuthorisationException(unixUser, "update", update);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
} else {
|
||||||
|
throw new AuthenticationException("authentication failed");
|
||||||
|
}
|
||||||
|
} catch (SecurityException e) {
|
||||||
|
throw new HSAdminException(e);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
throw new HSAdminException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String getOrderBy() {
|
||||||
|
return "ORDER BY obj.name ASC";
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean assertNotNull(String string) {
|
||||||
|
return string != null && string.length() > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean assertNotNull(Integer integ) {
|
||||||
|
return integ != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void replaceKey(Map<String, String> whereParams, String shortKey, String regularKey) {
|
||||||
|
if (whereParams.containsKey(shortKey)) {
|
||||||
|
String value = whereParams.get(shortKey);
|
||||||
|
whereParams.remove(shortKey);
|
||||||
|
whereParams.put(regularKey, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean assertNotNull(Date aDate) {
|
||||||
|
return aDate != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String buildQueryCondition(Map<String, String> whereParams) {
|
||||||
|
regularizeKeys(whereParams);
|
||||||
|
StringBuffer cond = new StringBuffer();
|
||||||
|
Iterator<String> keyIterator = whereParams.keySet().iterator();
|
||||||
|
while (keyIterator.hasNext()) {
|
||||||
|
if (cond.length() > 0) {
|
||||||
|
cond.append(" AND ");
|
||||||
|
}
|
||||||
|
String field = keyIterator.next();
|
||||||
|
String value = whereParams.get(field).replaceAll("'", "\'");
|
||||||
|
cond.append("obj.");
|
||||||
|
cond.append(field);
|
||||||
|
cond.append(" = ");
|
||||||
|
boolean numeric = "id".equals(field);
|
||||||
|
if (!numeric) cond.append("'");
|
||||||
|
cond.append(value);
|
||||||
|
if (!numeric) cond.append("'");
|
||||||
|
}
|
||||||
|
return cond.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
protected void entity2map(AbstractEntity entity, Map<String, Object> map) {
|
||||||
EMailAlias alias = (EMailAlias) entity;
|
EMailAlias alias = (EMailAlias) entity;
|
||||||
String id = Long.toString(alias.getId());
|
String id = Long.toString(alias.getId());
|
||||||
String name = alias.getName();
|
String name = alias.getName();
|
||||||
@ -29,13 +212,13 @@ public class EMailAliasRemote extends AbstractRemote {
|
|||||||
map.put("target", tokenList);
|
map.put("target", tokenList);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Class<? extends AbstractEntity> getEntityClass() {
|
protected Class<? extends AbstractEntity> getEntityClass() {
|
||||||
return EMailAlias.class;
|
return EMailAlias.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void map2entity(Transaction tx, Map<String, Object> map, AbstractEntity entity) {
|
protected void map2entity(Map<String, Object> map, AbstractEntity entity) {
|
||||||
EMailAlias alias = (EMailAlias) entity;
|
EMailAlias alias = (EMailAlias) entity;
|
||||||
String name = (String) map.get("name");
|
String name = (String) map.get("name");
|
||||||
if (assertNotNull(name)) {
|
if (assertNotNull(name)) {
|
||||||
@ -64,7 +247,7 @@ public class EMailAliasRemote extends AbstractRemote {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void regularizeKeys(Map<String, String> whereParams) {
|
protected void regularizeKeys(Map<String, String> whereParams) {
|
||||||
replaceKey(whereParams, "pac", "pac.name");
|
replaceKey(whereParams, "pac", "pac.name");
|
||||||
}
|
}
|
||||||
|
@ -5,11 +5,11 @@ import java.util.Map;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import de.hsadmin.cliClientConnector.TechnicalException;
|
|
||||||
import de.hsadmin.core.model.AbstractEntity;
|
import de.hsadmin.core.model.AbstractEntity;
|
||||||
import de.hsadmin.core.model.AnnFieldIO;
|
import de.hsadmin.core.model.AnnFieldIO;
|
||||||
import de.hsadmin.core.model.HSAdminException;
|
import de.hsadmin.core.model.HSAdminException;
|
||||||
import de.hsadmin.core.model.ReadWriteAccess;
|
import de.hsadmin.core.model.ReadWriteAccess;
|
||||||
|
import de.hsadmin.core.model.TechnicalException;
|
||||||
import de.hsadmin.core.model.Transaction;
|
import de.hsadmin.core.model.Transaction;
|
||||||
import de.hsadmin.core.util.ReflectionUtil;
|
import de.hsadmin.core.util.ReflectionUtil;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user