Compare commits

...

7 Commits

Author SHA1 Message Date
Peter Hormanns
66349fbd80 web client uses hsadmin.properties 2017-04-28 17:28:10 +02:00
Peter Hormanns
c205ce0975 use same Config class everywhere 2017-04-28 17:07:10 +02:00
Peter Hormanns
254db2b9a1 merge fix PropertyService 2017-04-18 17:04:41 +02:00
Peter Hormanns
bb44a3233a PacAdministrationVO in ContactVO 2017-04-13 19:29:47 +02:00
Peter Hormanns
8b5994e429 database migration 2017-04-12 19:22:28 +02:00
Peter Hormanns
2304ce3f23 same database everywhere 2017-04-12 15:31:53 +02:00
Peter Hormanns
d7a4a4f63d create and update entities 2017-04-12 12:53:57 +02:00
22 changed files with 378 additions and 135 deletions

View File

@ -14,6 +14,11 @@
<name>HSAdmin-Cli</name>
<dependencies>
<dependency>
<groupId>de.hsadmin</groupId>
<artifactId>framework</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.xmlrpc</groupId>
<artifactId>xmlrpc-client</artifactId>

View File

@ -11,7 +11,8 @@ import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.client.XmlRpcClient;
import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
import de.hsadmin.jscli.conf.Config;
import de.hsadmin.common.config.Config;
import de.hsadmin.common.error.TechnicalException;
import de.hsadmin.jscli.exception.JSCliException;
public class RpcClient {
@ -37,6 +38,8 @@ public class RpcClient {
}
} catch (MalformedURLException e) {
throw new JSCliException(e);
} catch (TechnicalException e) {
throw new JSCliException(e);
}
}

View File

@ -18,8 +18,9 @@ import java.util.Properties;
import javax.net.ssl.HttpsURLConnection;
import de.hsadmin.common.config.Config;
import de.hsadmin.common.error.TechnicalException;
import de.hsadmin.jscli.TicketProvider;
import de.hsadmin.jscli.conf.Config;
import de.hsadmin.jscli.console.PasswordReader;
import de.hsadmin.jscli.exception.JSCliException;
@ -81,11 +82,11 @@ public class CASTicketProvider implements TicketProvider {
private String getGrantingTicket() throws JSCliException {
grantingTicket = null;
String password = Config.getInstance().getProperty(user + ".passWord");
if (password == null || password.length() <= 0) {
password = readPasswordFromConsole();
}
try {
String password = Config.getInstance().getProperty(user + ".passWord");
if (password == null || password.length() <= 0) {
password = readPasswordFromConsole();
}
String encodedParams = URLEncoder.encode("username", "UTF-8")
+ "=" + URLEncoder.encode(user, "UTF-8")
+ "&" + URLEncoder.encode("password", "UTF-8")
@ -95,6 +96,8 @@ public class CASTicketProvider implements TicketProvider {
throw new JSCliException(e);
} catch (FileNotFoundException e) {
throw new JSCliException("cas server not available: " + loginURL);
} catch (TechnicalException e) {
throw new JSCliException(e);
}
return grantingTicket;
}

View File

@ -1,7 +1,8 @@
package de.hsadmin.jscli.cas;
import de.hsadmin.common.config.Config;
import de.hsadmin.common.error.TechnicalException;
import de.hsadmin.jscli.TicketProvider;
import de.hsadmin.jscli.conf.Config;
import de.hsadmin.jscli.console.PasswordReader;
import de.hsadmin.jscli.exception.JSCliException;
@ -12,13 +13,18 @@ public class TicketProviderFactory {
public static TicketProvider getInstance(final PasswordReader console, final String user, final String runAs) throws JSCliException
{
final Config config = Config.getInstance();
final String backendURL = config.getProperty("backendURL", HOSTSHARING_BACKEND_URL);
final String loginURL = config.getProperty("loginURL", HOSTSHARING_LOGIN_URL);
if ("TestUmgebung".equalsIgnoreCase(loginURL)) {
return new TestTicketProvider(user, runAs);
} else {
return new CASTicketProvider(console, user, runAs, backendURL, loginURL);
Config config;
try {
config = Config.getInstance();
final String backendURL = config.getProperty("backendURL", HOSTSHARING_BACKEND_URL);
final String loginURL = config.getProperty("loginURL", HOSTSHARING_LOGIN_URL);
if ("TestUmgebung".equalsIgnoreCase(loginURL)) {
return new TestTicketProvider(user, runAs);
} else {
return new CASTicketProvider(console, user, runAs, backendURL, loginURL);
}
} catch (TechnicalException e) {
throw new JSCliException(e);
}
}

View File

@ -6,6 +6,8 @@ import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.commons.cli.PosixParser;
import de.hsadmin.common.config.Config;
import de.hsadmin.common.error.TechnicalException;
import de.hsadmin.jscli.exception.JSCliException;
public class CommandlineParser {
@ -38,13 +40,13 @@ public class CommandlineParser {
}
}
public String getUser() {
public String getUser() throws TechnicalException {
final String systemUser = System.getProperty("user.name");
final String configUser = Config.getInstance().getProperty("userName", systemUser);
return cmd.getOptionValue("user", configUser);
}
public String getRunAs() {
public String getRunAs() throws TechnicalException {
return cmd.getOptionValue("runas", getUser());
}

View File

@ -1,57 +0,0 @@
package de.hsadmin.jscli.conf;
import java.io.File;
import java.io.FileReader;
import java.util.Properties;
public class Config {
private static Config instance;
private Properties props;
private Config() {
props = new Properties();
File file = new File(System.getProperty("user.dir") + "/hsadmin.properties");
if (!file.canRead()) {
file = new File(System.getProperty("user.dir") + "/conf/hsadmin.properties");
}
if (!file.canRead()) {
file = new File(System.getProperty("user.home") + "/.hsadmin.properties");
}
if (!file.canRead()) {
file = new File("/etc/hsadmin.properties");
}
if (!file.canRead()) {
file = new File("/etc/hsadmin/hsadmin.properties");
}
if (file.canRead()) {
try {
props.load(new FileReader(file));
} catch (Exception e) {
// should not happen
e.printStackTrace();
}
}
}
public static Config getInstance() {
if (instance == null) {
instance = new Config();
}
return instance;
}
public String getProperty(String propertyName) {
String property = props.getProperty(propertyName);
if (property == null) {
return null;
}
return property.trim();
}
public String getProperty(String propertyName, String defaultValue) {
return props.getProperty(propertyName, defaultValue).trim();
}
}

View File

@ -105,6 +105,7 @@
<debug>false</debug>
<debugPort>8000</debugPort>
<config>${project.basedir}/src/test/tomee/conf</config>
<context>cust-webapp</context>
<libs>
<lib>org.postgresql:postgresql:9.4.1212.jre7</lib>
</libs>

View File

@ -1,5 +1,6 @@
package de.hsadmin.bo.customer;
import static javax.persistence.CascadeType.ALL;
import static javax.persistence.FetchType.EAGER;
import java.io.Serializable;
@ -9,12 +10,15 @@ import javax.persistence.CollectionTable;
import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;
@Entity(name = "Contact")
@Table(name = "contact")
@ -31,6 +35,12 @@ public class Contact implements Serializable {
@ManyToOne(fetch = EAGER)
private Customer customer;
@Column(name = "login", columnDefinition = "character varying(40)")
private String login;
@Transient
private String password;
@Column(name = "salut", columnDefinition = "character varying(30)")
private String salut;
@ -84,6 +94,9 @@ public class Contact implements Serializable {
@Column(name="role")
private List<String> roles;
@OneToMany(fetch=FetchType.LAZY, cascade = ALL, mappedBy = "contact")
private List<PacAdministration> pacAdminList;
public Contact() {
}
@ -103,6 +116,22 @@ public class Contact implements Serializable {
this.customer = customer;
}
public String getLogin() {
return login;
}
public void setLogin(String login) {
this.login = login;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getSalut() {
return salut;
}
@ -231,4 +260,12 @@ public class Contact implements Serializable {
this.roles = roles;
}
public List<PacAdministration> getPacAdminList() {
return pacAdminList;
}
public void setPacAdminList(List<PacAdministration> pacAdminList) {
this.pacAdminList = pacAdminList;
}
}

View File

@ -0,0 +1,60 @@
package de.hsadmin.bo.customer;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import de.hsadmin.bo.pac.Pac;
@Entity
@Table(name="pac_administration")
public class PacAdministration {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "pac_administration_id", columnDefinition = "integer")
private long pacAdministrationId;
@ManyToOne(fetch=FetchType.EAGER)
@JoinColumn(name="contact_id")
private Contact contact;
@ManyToOne(fetch=FetchType.EAGER)
@JoinColumn(name="pac_id")
private Pac pac;
public PacAdministration() {
}
public long getPacAdministrationId() {
return pacAdministrationId;
}
public void setPacAdministrationId(long pacAdministrationId) {
this.pacAdministrationId = pacAdministrationId;
}
public Contact getContact() {
return contact;
}
public void setContact(Contact contact) {
this.contact = contact;
}
public Pac getPac() {
return pac;
}
public void setPac(Pac pac) {
this.pac = pac;
}
}

View File

@ -12,7 +12,7 @@ import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
// import javax.persistence.EntityListeners;
import javax.persistence.EntityManager;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
@ -26,11 +26,12 @@ import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import de.hsadmin.bo.customer.Customer;
import de.hsadmin.bo.customer.PacAdministration;
@Entity(name = "Pac")
@Table(name = "packet")
@SequenceGenerator(name = "PacsSeqGen", sequenceName = "packet_packet_id_seq")
@EntityListeners({PacEntityListener.class})
// @EntityListeners({PacEntityListener.class})
public class Pac implements Serializable {
private static final long serialVersionUID = 1L;
@ -81,6 +82,9 @@ public class Pac implements Serializable {
@OneToMany(fetch = LAZY, cascade = ALL, mappedBy="pac")
private Set<UnixUser> unixUser;
@OneToMany(fetch = LAZY, cascade = ALL, mappedBy="pac")
private Set<PacAdministration> pacAdministrations;
public void initPacComponents(final EntityManager em, final BasePac aBasepac, final boolean setDefaults) {
final Query qAttachedBasepac = em.createQuery("SELECT b FROM BasePac b WHERE b.valid = :valid AND b.name = :name");
@ -205,6 +209,14 @@ public class Pac implements Serializable {
this.unixUser = unixUser;
}
public Set<PacAdministration> getPacAdministrations() {
return pacAdministrations;
}
public void setPacAdministrations(Set<PacAdministration> pacAdministrations) {
this.pacAdministrations = pacAdministrations;
}
public String toString() {
return super.toString() + "{ name=" + name + " }";
}

View File

@ -1,11 +1,14 @@
package de.hsadmin.service.customer;
import java.util.List;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;
import de.hsadmin.common.error.TechnicalException;
import de.hsadmin.module.ValueObject;
import de.hsadmin.module.impl.AbstractVO;
import de.hsadmin.module.property.ElementsType;
import de.hsadmin.module.property.ReadWrite;
import de.hsadmin.module.property.ReadWritePolicy;
import de.hsadmin.module.property.Required;
@ -26,6 +29,11 @@ public class ContactVO extends AbstractVO implements ValueObject {
@Search(SearchPolicy.EQUALS)
private String customer;
@Pattern(regexp="[a-z0-9\\-]*")
@Size(min=0,max=40)
@ReadWrite(ReadWritePolicy.READWRITE)
private String login;
@Pattern(regexp="[A-Za-z]*")
@Size(min=0,max=16)
@ReadWrite(ReadWritePolicy.READWRITE)
@ -103,6 +111,10 @@ public class ContactVO extends AbstractVO implements ValueObject {
@ReadWrite(ReadWritePolicy.READWRITE)
private final StringSet roles;
@ReadWrite(ReadWritePolicy.READWRITE)
@ElementsType(PacAdministrationVO.class)
private List<PacAdministrationVO> pacAdminList;
public ContactVO() throws TechnicalException {
super();
@ -117,6 +129,14 @@ public class ContactVO extends AbstractVO implements ValueObject {
this.customer = customer;
}
public String getLogin() {
return login;
}
public void setLogin(String login) {
this.login = login;
}
public String getSalut() {
return salut;
}
@ -245,4 +265,12 @@ public class ContactVO extends AbstractVO implements ValueObject {
roles.setStrings(changedRoles);
}
public List<PacAdministrationVO> getPacAdminList() {
return pacAdminList;
}
public void setPacAdminList(List<PacAdministrationVO> pacAdminList) {
this.pacAdminList = pacAdminList;
}
}

View File

@ -0,0 +1,63 @@
package de.hsadmin.service.customer;
import de.hsadmin.common.error.TechnicalException;
import de.hsadmin.module.ValueObject;
import de.hsadmin.module.impl.AbstractVO;
import de.hsadmin.module.property.ReadWrite;
import de.hsadmin.module.property.ReadWritePolicy;
import de.hsadmin.module.property.mapping.DefaultStringParameterMapMapper;
import de.hsadmin.module.property.mapping.Mapping;
import de.hsadmin.module.property.mapping.ReferredStringPersistentObjectMapper;
public class PacAdministrationVO extends AbstractVO implements ValueObject {
@Mapping(
boMapping=ReferredStringPersistentObjectMapper.class,
rpcMapping=DefaultStringParameterMapMapper.class,
boMappingPath="contact.customer.name")
@ReadWrite(ReadWritePolicy.READ)
private String customer;
@Mapping(
boMapping=ReferredStringPersistentObjectMapper.class,
rpcMapping=DefaultStringParameterMapMapper.class,
boMappingPath="contact.login")
@ReadWrite(ReadWritePolicy.READ)
private String contactLogin;
@Mapping(
boMapping=ReferredStringPersistentObjectMapper.class,
rpcMapping=DefaultStringParameterMapMapper.class,
boMappingPath="pac.name")
@ReadWrite(ReadWritePolicy.READ)
private String packetName;
public PacAdministrationVO() throws TechnicalException {
super();
}
public String getCustomer() {
return customer;
}
public void setCustomer(String customer) {
this.customer = customer;
}
public String getContactLogin() {
return contactLogin;
}
public void setContactLogin(String contactLogin) {
this.contactLogin = contactLogin;
}
public String getPacketName() {
return packetName;
}
public void setPacketName(String packetName) {
this.packetName = packetName;
}
}

View File

@ -8,6 +8,7 @@
<class>de.hsadmin.bo.customer.Contact</class>
<class>de.hsadmin.bo.customer.Customer</class>
<class>de.hsadmin.bo.customer.SEPADirectDebit</class>
<class>de.hsadmin.bo.customer.PacAdministration</class>
<class>de.hsadmin.bo.domain.Domain</class>
<class>de.hsadmin.bo.domain.DomainOption</class>
<class>de.hsadmin.bo.domain.EMailAddress</class>

View File

@ -0,0 +1,29 @@
CREATE TABLE pac_administration (
pac_administration_id integer NOT NULL,
contact_id integer NOT NULL,
pac_id integer NOT NULL
);
CREATE SEQUENCE pac_administration_pac_administration_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE pac_administration_pac_administration_id_seq OWNED BY pac_administration.pac_administration_id;
ALTER TABLE ONLY pac_administration
ALTER COLUMN pac_administration_id SET DEFAULT nextval('pac_administration_pac_administration_id_seq'::regclass);
ALTER TABLE ONLY pac_administration
ADD CONSTRAINT pk_pac_administration PRIMARY KEY (pac_administration_id);
ALTER TABLE ONLY pac_administration
ADD CONSTRAINT pac_administration_contact_ref FOREIGN KEY (contact_id) REFERENCES contact(contact_id);
ALTER TABLE ONLY pac_administration
ADD CONSTRAINT pac_administration_pac_ref FOREIGN KEY (pac_id) REFERENCES packet(packet_id);
ALTER TABLE ONLY contact
ADD COLUMN login character varying(40);

View File

@ -752,4 +752,33 @@
</createTable>
</changeSet>
<changeSet author="phormanns" id="ph-20170412-01">
<createTable tableName="pac_administration">
<column autoIncrement="true" name="pac_administration_id" type="SERIAL">
<constraints primaryKey="true" primaryKeyName="pk_pac_administration"/>
</column>
<column name="contact_id" type="INT">
<constraints
foreignKeyName="pac_administration_contact_ref"
referencedTableName="contact"
referencedColumnNames="contact_id"
nullable="false"/>
</column>
<column name="pac_id" type="INT">
<constraints
foreignKeyName="pac_administration_pac_ref"
referencedTableName="packet"
referencedColumnNames="packet_id"
nullable="false"/>
</column>
</createTable>
<addColumn tableName="contact">
<column name="login" type="VARCHAR(40)"/>
</addColumn>
<addUniqueConstraint
columnNames="login"
constraintName="unique_contact_login"
tableName="contact"/>
</changeSet>
</databaseChangeLog>

View File

@ -1,7 +1,7 @@
changeLogFile=target/classes/liquibase/db.changelog.xml
driver=org.postgresql.Driver
url=jdbc:postgresql://localhost:5432/hsadmin_migdb
url=jdbc:postgresql://localhost:5432/hsadmin_db
username=hsadmin_dbuser
password=SelfDefinedPassword
verbose=true
dropFirst=false
dropFirst=false

View File

@ -2,7 +2,7 @@
<tomee>
<Resource id="hsar-ds" type="javax.sql.DataSource">
JdbcDriver = org.postgresql.Driver
JdbcUrl = jdbc:postgresql://localhost:5432/hsadmin_migdb
JdbcUrl = jdbc:postgresql://localhost:5432/hsadmin_db
UserName = hsadmin_dbuser
Password = SelfDefinedPassword
</Resource>

View File

@ -86,7 +86,7 @@ public abstract class AbstractVO implements ValueObject {
}
private boolean isPropertyField(final Field f) {
ReadWrite annotation = f.getAnnotation(ReadWrite.class);
final ReadWrite annotation = f.getAnnotation(ReadWrite.class);
return annotation != null;
}
@ -102,12 +102,15 @@ public abstract class AbstractVO implements ValueObject {
final Class<?> type = Class.forName("de.hsadmin.module.property." + simplePropertyClassName + "Property");
final Constructor<?> constructor = type.getConstructor(ValueObject.class, String.class, ReadWritePolicy.class, SearchPolicy.class, boolean.class);
final Property<?> newInstance = (Property<?>) constructor.newInstance(this, f.getName(), getReadWritePolicy(f), getSearchPolicy(f), isRequired(f));
set(f.getName(), newInstance);
final String propertyName = f.getName();
assert propertyName != null && propertyName.length() > 0;
assert newInstance != null;
propertiesMap.put(propertyName, newInstance);
if (ContainsElements.class.isAssignableFrom(type)) {
ContainsElements container = (ContainsElements) newInstance;
container.setElementsType(getElementsType(f));
}
Mapping mapping = f.getAnnotation(Mapping.class);
final Mapping mapping = f.getAnnotation(Mapping.class);
if (mapping != null && newInstance instanceof AbstractProperty<?>) {
AbstractProperty<?> prop = (AbstractProperty<?>) newInstance;
PersistentObjectMapper<?> persistentObjectMapper = mapping.boMapping().newInstance();
@ -119,17 +122,11 @@ public abstract class AbstractVO implements ValueObject {
}
}
} catch (IllegalArgumentException | IllegalAccessException | InstantiationException | InvocationTargetException
| NoSuchMethodException | SecurityException | UserException | ClassNotFoundException e) {
| NoSuchMethodException | SecurityException | ClassNotFoundException e) {
throw new TechnicalException(e);
}
}
private void set(final String propertyName, final Property<?> propertyInstance) throws UserException {
assert propertyName != null && propertyName.length() > 0;
assert propertyInstance != null;
propertiesMap.put(propertyName, propertyInstance);
}
private SearchPolicy getSearchPolicy(final Field f) {
final Search search = f.getAnnotation(Search.class);
SearchPolicy searchPolicy = SearchPolicy.NONE;

View File

@ -1,7 +1,6 @@
package de.hsadmin.service.property;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.Enumeration;
import java.util.List;
import java.util.Properties;
@ -14,6 +13,7 @@ import javax.validation.constraints.Size;
import de.hsadmin.common.error.TechnicalException;
import de.hsadmin.common.error.UserException;
import de.hsadmin.common.util.ReflectionUtil;
import de.hsadmin.login.RequestContext;
import de.hsadmin.login.RequiredScope;
import de.hsadmin.login.Role;
@ -22,6 +22,7 @@ import de.hsadmin.module.ValueObject;
import de.hsadmin.module.impl.AbstractModule;
import de.hsadmin.module.property.Display;
import de.hsadmin.module.property.DisplayPolicy;
import de.hsadmin.module.property.Property;
import de.hsadmin.module.property.ReadWrite;
import de.hsadmin.module.property.ReadWritePolicy;
import de.hsadmin.module.property.Search;
@ -31,6 +32,8 @@ import de.hsadmin.xmlrpc.AbstractRemote;
@Stateless
public class PropertyService extends AbstractModule<PropertyVO> implements PropertyServiceLocal {
public static final String DEFAULT_VALIDATION_REGEXP = "[a-zA-Z0-9\\_\\-\\.\\,\\ ]*";
@PersistenceContext(name="hsar")
private EntityManager entityManager;
@ -47,6 +50,7 @@ public class PropertyService extends AbstractModule<PropertyVO> implements Prope
}
@Override
@SuppressWarnings("unchecked")
@RequiredScope({@ScopePolicy(Role.ANY)})
public List<PropertyVO> read(final RequestContext requestContext, final PropertyVO criteria)
throws UserException, TechnicalException {
@ -55,56 +59,57 @@ public class PropertyService extends AbstractModule<PropertyVO> implements Prope
final String requestedModuleName = criteria.getModule();
try {
remoteServicesProperties.load(getClass().getClassLoader().getResourceAsStream("org/apache/xmlrpc/webserver/XmlRpcServlet.properties"));
final Enumeration<?> propertyNames = remoteServicesProperties.propertyNames();
while (propertyNames.hasMoreElements()) {
final String properyName = (String) propertyNames.nextElement();
if (requestedModuleName != null && !requestedModuleName.equals(properyName)) {
final Enumeration<?> remoteModuleNames = remoteServicesProperties.propertyNames();
while (remoteModuleNames.hasMoreElements()) {
final String moduleName = (String) remoteModuleNames.nextElement();
if (requestedModuleName != null && !requestedModuleName.equals(moduleName)) {
continue;
}
final Class<?> serviceRemoteClass = Class.forName(remoteServicesProperties.getProperty(properyName));
@SuppressWarnings("unchecked")
final Class<?> serviceRemoteClass = Class.forName(remoteServicesProperties.getProperty(moduleName));
final AbstractRemote<ValueObject> serviceRemote = (AbstractRemote<ValueObject>) serviceRemoteClass.newInstance();
final ValueObject valueObject = serviceRemote.createValueObject();
final Field[] declaredFields = valueObject.getClass().getDeclaredFields();
for (Field f : declaredFields) {
final Class<? extends ValueObject> voClass = valueObject.getClass();
final List<Property<?>> propertiesList = valueObject.properties();
for (final Property<?> prop : propertiesList) {
final PropertyVO vo = buildVO();
vo.setModule(properyName);
vo.setName(f.getName());
final ReadWrite readWrite = f.getAnnotation(ReadWrite.class);
final String propName = prop.getName();
setStringValue(vo, "module", moduleName);
setStringValue(vo, "name", propName);
final ReadWrite readWrite = (ReadWrite) ReflectionUtil.getAnnotation(voClass, propName, ReadWrite.class);
if (readWrite == null) {
vo.setReadwriteable(ReadWritePolicy.NONE.name().toLowerCase());
setStringValue(vo, "readwriteable", ReadWritePolicy.NONE.name().toLowerCase());
} else {
vo.setReadwriteable(readWrite.value().name().toLowerCase());
setStringValue(vo, "readwriteable", readWrite.value().name().toLowerCase());
}
final Search search = f.getAnnotation(Search.class);
final Search search = (Search) ReflectionUtil.getAnnotation(voClass, propName, Search.class);
if (search == null) {
vo.setSearchable(SearchPolicy.NONE.name().toLowerCase());
setStringValue(vo, "searchable", SearchPolicy.NONE.name().toLowerCase());
} else {
vo.setSearchable(search.value().name().toLowerCase());
setStringValue(vo, "searchable", search.value().name().toLowerCase());
}
final Display sequence = f.getAnnotation(Display.class);
final Display sequence = (Display) ReflectionUtil.getAnnotation(voClass, propName, Display.class);
if (sequence == null) {
vo.setDisplaySequence(Integer.valueOf(9999));
vo.setDisplayVisible(DisplayPolicy.ALWAYS.name().toLowerCase());;
setIntValue(vo, "displaySequence", 9999);
setStringValue(vo, "displayVisible", DisplayPolicy.ALWAYS.name().toLowerCase());
} else {
vo.setDisplaySequence(sequence.sequence());
vo.setDisplayVisible(sequence.visible().name().toLowerCase());;
setIntValue(vo, "displaySequence", sequence.sequence());
setStringValue(vo, "displayVisible", sequence.visible().name().toLowerCase());
}
final Pattern pattern = f.getAnnotation(Pattern.class);
final Pattern pattern = (Pattern) ReflectionUtil.getAnnotation(voClass, propName, Pattern.class);
if (pattern == null) {
vo.setValidationRegexp("[a-zA-Z0-9\\_\\-\\.\\,\\ ]*");
setStringValue(vo, "validationRegexp", DEFAULT_VALIDATION_REGEXP);
} else {
vo.setValidationRegexp(pattern.regexp());
setStringValue(vo, "validationRegexp", pattern.regexp());
}
final Size size = f.getAnnotation(Size.class);
final Size size = (Size) ReflectionUtil.getAnnotation(voClass, propName, Size.class);
if (size == null) {
vo.setMinLength(Integer.valueOf(0));
vo.setMaxLength(Integer.valueOf(999));
setIntValue(vo, "minLength", 0);
setIntValue(vo, "maxLength", 999);
} else {
vo.setMinLength(size.min());
vo.setMaxLength(size.max());
setIntValue(vo, "minLength", size.min());
setIntValue(vo, "maxLength", size.max());
}
vo.setType(printableTypeName(valueObject.get(f.getName()).getValueType()));
setStringValue(vo, "type", printableTypeName(valueObject.get(propName).getValueType()));
emptyList.add(vo);
}
}
@ -114,6 +119,18 @@ public class PropertyService extends AbstractModule<PropertyVO> implements Prope
return emptyList;
}
private void setStringValue(final PropertyVO vo, final String propertyName, final String value) throws TechnicalException, UserException {
@SuppressWarnings("unchecked")
final Property<String> property = (Property<String>) vo.get(propertyName);
property.setValue(value);
}
private void setIntValue(final PropertyVO vo, final String propertyName, final int value) throws TechnicalException, UserException {
@SuppressWarnings("unchecked")
final Property<Integer> property = (Property<Integer>) vo.get(propertyName);
property.setValue(value);
}
private String printableTypeName(Class<?> type) {
String name = type.getName().toLowerCase();
if (name.indexOf('.') >= 0) {

View File

@ -21,6 +21,12 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>de.hsadmin</groupId>
<artifactId>framework</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.xmlrpc</groupId>
<artifactId>xmlrpc-client</artifactId>

View File

@ -10,6 +10,7 @@ import java.net.URLEncoder;
import javax.net.ssl.HttpsURLConnection;
import de.hsadmin.common.config.Config;
import de.hsadmin.rpc.RpcException;
/**
@ -21,18 +22,17 @@ import de.hsadmin.rpc.RpcException;
*/
public class TicketService implements Serializable {
public static final String SERVICE_URL = "https://config.hostsharing.net:443/hsar/backend";
public static final String CAS_URL = "https://login.hostsharing.net/cas/v1/tickets";
private static final long serialVersionUID = 1L;
public String getGrantingTicket(final String user, final String password) throws RpcException {
String ticket = null;
try {
String userParam = "username=" + URLEncoder.encode(user, "UTF-8");
String passwordParam = "password=" + URLEncoder.encode(password, "UTF-8");
String encodedData = userParam + "&" + passwordParam;
URL url = new URL(CAS_URL);
final Config conf = Config.getInstance();
final String userParam = "username=" + URLEncoder.encode(user, "UTF-8");
final String passwordParam = "password=" + URLEncoder.encode(password, "UTF-8");
final String encodedData = userParam + "&" + passwordParam;
final String casUrl = conf.getProperty("loginURL");
final URL url = new URL(casUrl);
final HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
connection.setRequestMethod("POST");
@ -56,8 +56,10 @@ public class TicketService implements Serializable {
public String getServiceTicket(String grantingTicket) throws RpcException {
String ticket = null;
try {
String serviceParam = "service=" + URLEncoder.encode(SERVICE_URL, "UTF-8");
URL url = new URL(grantingTicket);
final Config conf = Config.getInstance();
final String backendURL = conf.getProperty("backendURL");
final String serviceParam = "service=" + URLEncoder.encode(backendURL, "UTF-8");
final URL url = new URL(grantingTicket);
final HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
connection.setRequestMethod("POST");

View File

@ -14,6 +14,8 @@ import com.vaadin.ui.HorizontalSplitPanel;
import com.vaadin.ui.Panel;
import com.vaadin.ui.VerticalLayout;
import de.hsadmin.common.config.Config;
import de.hsadmin.common.error.TechnicalException;
import de.hsadmin.model.TicketService;
import de.hsadmin.rpc.HSAdminSession;
import de.hsadmin.rpc.ModulesManager;
@ -26,11 +28,6 @@ public class MainWindow extends CustomComponent implements HSAdminSession {
private static final Logger LOG = Logger.getLogger(MainWindow.class);
public static final String[] SERVICE_URLS = new String[] {
"https://config2.hostsharing.net:443/hsar/xmlrpc/hsadmin",
"https://config.hostsharing.net:443/hsar/xmlrpc/hsadmin"
};
final private TicketService ticketService;
final private String grantingTicket;
final private String username;
@ -52,11 +49,13 @@ public class MainWindow extends CustomComponent implements HSAdminSession {
mainPanel.setContent(vl);
try {
final Config conf = Config.getInstance();
final String[] rpcUrls = conf.getProperty("xmlrpcURL").split(",");
final MainToolbar mainToolbar = new MainToolbar(this);
vl.addComponent(mainToolbar);
vl.setExpandRatio(mainToolbar, 0.0f);
final ModulesManagerFactory modulesManagerFactory = new ModulesManagerFactory(grantingTicket, username);
modulesManager = modulesManagerFactory.newModulesManager(SERVICE_URLS);
modulesManager = modulesManagerFactory.newModulesManager(rpcUrls);
content = new HorizontalSplitPanel();
content.setSizeFull();
vl.addComponent(content);
@ -66,7 +65,7 @@ public class MainWindow extends CustomComponent implements HSAdminSession {
content.setFirstComponent(entryPoints);
content.setSecondComponent(new MainPanel());
content.setSplitPosition(26.6f);
} catch (RpcException e) {
} catch (RpcException | TechnicalException e) {
LOG.fatal(e.getLocalizedMessage(), e);
}
}