xmlrpc remote fpr ldap user

This commit is contained in:
Peter Hormanns 2018-08-29 18:21:16 +02:00
parent 9f47eba454
commit 75df8a9a85
9 changed files with 152 additions and 40 deletions

View File

@ -0,0 +1,12 @@
package de.hsadmin.service.ldap;
import de.hsadmin.xmlrpc.AbstractRemote;
public class LdapUserRemote extends AbstractRemote<LdapUserVO> {
@Override
protected String getModuleLookup() {
return "LdapUserServiceLocal";
}
}

View File

@ -3,6 +3,11 @@ package de.hsadmin.service.ldap;
import javax.ejb.Stateless; import javax.ejb.Stateless;
import de.hsadmin.common.error.TechnicalException; import de.hsadmin.common.error.TechnicalException;
import de.hsadmin.common.error.UserException;
import de.hsadmin.login.RequestContext;
import de.hsadmin.login.RequiredScope;
import de.hsadmin.login.Role;
import de.hsadmin.login.ScopePolicy;
import de.hsadmin.module.impl.AbstractModule; import de.hsadmin.module.impl.AbstractModule;
@Stateless @Stateless
@ -13,4 +18,12 @@ public class LdapUserService extends AbstractModule<LdapUserVO> implements LdapU
return new LdapUserVO(); return new LdapUserVO();
} }
@Override
@RequiredScope({ @ScopePolicy(Role.SYSTEM), @ScopePolicy(value=Role.CUSTOMER, property="customer") })
public LdapUserVO create(RequestContext requestContext, LdapUserVO prototype)
throws UserException, TechnicalException
{
return super.create(requestContext, prototype);
}
} }

View File

@ -13,42 +13,48 @@ import de.hsadmin.module.property.StringSet;
public class LdapUserVO extends AbstractVO { public class LdapUserVO extends AbstractVO {
@Required(true)
@ReadWrite(ReadWritePolicy.WRITEONCE)
@Search(SearchPolicy.EQUALS)
@Pattern(regexp="[a-z0-9]{3}")
private String customer; // refers to customer
@Required(true) @Required(true)
@ReadWrite(ReadWritePolicy.WRITEONCE) @ReadWrite(ReadWritePolicy.WRITEONCE)
@Search(SearchPolicy.EQUALS) @Search(SearchPolicy.EQUALS)
@Pattern(regexp="[a-z0-9]{3}\\-[a-z0-9]+") @Pattern(regexp="[a-z0-9]{3}\\-[a-z0-9]+")
private String uid; private String username; // ldap uid
@ReadWrite(ReadWritePolicy.READWRITE) @ReadWrite(ReadWritePolicy.READWRITE)
private String userPassword; private String password; // ldap userPassword
@Required(true) @Required(true)
@ReadWrite(ReadWritePolicy.READWRITE) @ReadWrite(ReadWritePolicy.READWRITE)
@Search(SearchPolicy.EQUALS) @Search(SearchPolicy.EQUALS)
private String sn; private String surname; // ldap sn
@ReadWrite(ReadWritePolicy.READWRITE) @ReadWrite(ReadWritePolicy.READWRITE)
@Search(SearchPolicy.EQUALS) @Search(SearchPolicy.EQUALS)
private String givenName; private String givenname; // ldap givenName
@Required(true) @Required(true)
@ReadWrite(ReadWritePolicy.READWRITE) @ReadWrite(ReadWritePolicy.READWRITE)
@Search(SearchPolicy.EQUALS) @Search(SearchPolicy.EQUALS)
@Pattern(regexp="[a-zA-Z0-9\\.\\-\\_]*@[a-z0-9äöüß\\.\\-]*") @Pattern(regexp="[a-zA-Z0-9\\.\\-\\_]*@[a-z0-9äöüß\\.\\-]*")
private String mail; private String mail; // ldap mail
@ReadWrite(ReadWritePolicy.READWRITE) @ReadWrite(ReadWritePolicy.READWRITE)
@Pattern(regexp="[\\+\\d\\-\\ \\(\\)\\/]*") @Pattern(regexp="[\\+\\d\\-\\ \\(\\)\\/]*")
private String mobile; private String mobile; // ldap mobile
@ReadWrite(ReadWritePolicy.READWRITE) @ReadWrite(ReadWritePolicy.READWRITE)
@Pattern(regexp="[\\+\\d\\-\\ \\(\\)\\/]*") @Pattern(regexp="[\\+\\d\\-\\ \\(\\)\\/]*")
private String homePhone; private String phone; // ldap homePhone
@ReadWrite(ReadWritePolicy.READWRITE) @ReadWrite(ReadWritePolicy.READWRITE)
@Search(SearchPolicy.EQUALS) @Search(SearchPolicy.EQUALS)
@Pattern(regexp="[a-z0-9]*") @Pattern(regexp="[a-z0-9]*")
private String nickName; private String nickname; // ldap nickName
@ReadWrite(ReadWritePolicy.READWRITE) @ReadWrite(ReadWritePolicy.READWRITE)
private StringSet sshPublicKey; private StringSet sshPublicKey;
@ -57,36 +63,44 @@ public class LdapUserVO extends AbstractVO {
super(); super();
} }
public String getUid() { public String getCustomer() {
return uid; return customer;
} }
public void setUid(String uid) { public void setCustomer(String customer) {
this.uid = uid; this.customer = customer;
} }
public String getUserPassword() { public String getUsername() {
return userPassword; return username;
} }
public void setUserPassword(String userPassword) { public void setUsername(String uid) {
this.userPassword = userPassword; this.username = uid;
} }
public String getSn() { public String getPassword() {
return sn; return password;
} }
public void setSn(String sn) { public void setPassword(String userPassword) {
this.sn = sn; this.password = userPassword;
} }
public String getGivenName() { public String getSurname() {
return givenName; return surname;
} }
public void setGivenName(String givenName) { public void setSurname(String sn) {
this.givenName = givenName; this.surname = sn;
}
public String getGivenname() {
return givenname;
}
public void setGivenname(String givenName) {
this.givenname = givenName;
} }
public String getMail() { public String getMail() {
@ -105,20 +119,20 @@ public class LdapUserVO extends AbstractVO {
this.mobile = mobile; this.mobile = mobile;
} }
public String getHomePhone() { public String getPhone() {
return homePhone; return phone;
} }
public void setHomePhone(String homePhone) { public void setPhone(String homePhone) {
this.homePhone = homePhone; this.phone = homePhone;
} }
public String getNickName() { public String getNickname() {
return nickName; return nickname;
} }
public void setNickName(String nickName) { public void setNickname(String nickName) {
this.nickName = nickName; this.nickname = nickName;
} }
public StringSet getSshPublicKey() { public StringSet getSshPublicKey() {

View File

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="hsar">
<jta-data-source>HsarDataSource</jta-data-source>
<class>de.hsadmin.bo.customer.Contact</class>
<class>de.hsadmin.bo.customer.Customer</class>
<class>de.hsadmin.bo.customer.MemberShare</class>
<class>de.hsadmin.bo.customer.MemberAsset</class>
<class>de.hsadmin.bo.customer.SEPADirectDebit</class>
<class>de.hsadmin.bo.domain.Domain</class>
<class>de.hsadmin.bo.domain.DomainOption</class>
<class>de.hsadmin.bo.domain.EMailAddress</class>
<class>de.hsadmin.bo.pac.BaseComponent</class>
<class>de.hsadmin.bo.pac.BasePac</class>
<class>de.hsadmin.bo.pac.Component</class>
<class>de.hsadmin.bo.pac.EMailAlias</class>
<class>de.hsadmin.bo.pac.Hive</class>
<class>de.hsadmin.bo.pac.INetAddress</class>
<class>de.hsadmin.bo.pac.Pac</class>
<class>de.hsadmin.bo.pac.PacComponent</class>
<class>de.hsadmin.bo.pac.UnixUser</class>
</persistence-unit>
</persistence>

View File

@ -0,0 +1,2 @@
ldapuser=de.hsadmin.service.ldap.LdapUserRemote
property=de.hsadmin.service.property.PropertyRemote

View File

@ -0,0 +1,20 @@
<?xml version="1.0"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<servlet>
<servlet-name>XmlRpcServlet</servlet-name>
<servlet-class>de.hsadmin.xmlrpc.HSXmlRpcServlet</servlet-class>
<init-param>
<param-name>enabledForExtensions</param-name>
<param-value>true</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>XmlRpcServlet</servlet-name>
<url-pattern>/xmlrpc/*</url-pattern>
</servlet-mapping>
</web-app>

View File

@ -14,23 +14,32 @@ import de.hsadmin.module.property.StringProperty;
public class ValidationTest { public class ValidationTest {
private static final String CUSTOMER = "customer";
private static final String LDAP_SN = "surname";
private static final String LDAP_MAIL = "mail";
private static final String LDAP_UID = "username";
private LdapUserVO vo; private LdapUserVO vo;
private ValidationDelegate<LdapUserVO> val; private ValidationDelegate<LdapUserVO> val;
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
vo = new LdapUserVO(); vo = new LdapUserVO();
final String custOk = "abc";
final String uidOk = "abc-someuid"; final String uidOk = "abc-someuid";
final String mailOk = "someone@example.org"; final String mailOk = "someone@example.org";
final String snOk = "Mustermann"; final String snOk = "Mustermann";
((StringProperty) vo.get("uid")).setValue(uidOk); ((StringProperty) vo.get(CUSTOMER)).setValue(custOk);
String uid = vo.getUid(); String cust = vo.getCustomer();
assertEquals(custOk, cust);
((StringProperty) vo.get(LDAP_UID)).setValue(uidOk);
String uid = vo.getUsername();
assertEquals(uidOk, uid); assertEquals(uidOk, uid);
((StringProperty) vo.get("mail")).setValue(mailOk); ((StringProperty) vo.get(LDAP_MAIL)).setValue(mailOk);
String mail = vo.getMail(); String mail = vo.getMail();
assertEquals(mailOk, mail); assertEquals(mailOk, mail);
((StringProperty) vo.get("sn")).setValue(snOk); ((StringProperty) vo.get(LDAP_SN)).setValue(snOk);
String sn = vo.getSn(); String sn = vo.getSurname();
assertEquals(snOk, sn); assertEquals(snOk, sn);
val = new ValidationDelegate<LdapUserVO>(); val = new ValidationDelegate<LdapUserVO>();
} }
@ -49,8 +58,8 @@ public class ValidationTest {
} }
final String uidFail = "ac-someuid"; final String uidFail = "ac-someuid";
try { try {
((StringProperty) vo.get("uid")).setValue(uidFail); ((StringProperty) vo.get(LDAP_UID)).setValue(uidFail);
String uid = vo.getUid(); String uid = vo.getUsername();
assertEquals(uidFail, uid); assertEquals(uidFail, uid);
val.checkPrototypeIsCreateable(vo); val.checkPrototypeIsCreateable(vo);
fail("expect UserException"); fail("expect UserException");
@ -68,7 +77,7 @@ public class ValidationTest {
public void testSetMail() { public void testSetMail() {
final String mailFail = "someuid"; final String mailFail = "someuid";
try { try {
((StringProperty) vo.get("mail")).setValue(mailFail); ((StringProperty) vo.get(LDAP_MAIL)).setValue(mailFail);
String mail = vo.getMail(); String mail = vo.getMail();
assertEquals(mailFail, mail); assertEquals(mailFail, mail);
val.checkPrototypeIsCreateable(vo); val.checkPrototypeIsCreateable(vo);

View File

@ -0,0 +1,6 @@
ticketvalidator.class=de.hsadmin.login.cas.TestTicketValidator
cas.validate.url=https://login.hostsharing.net:443/cas/proxyValidate
cas.service.url=https://config.hostsharing.net:443/hsar/backend
accountprefix.hostmaster=hsh01
accountprefix.customer=hsh00
domainpostfix.pacdomain=hostsharing.net

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<tomee>
<Resource id="HsarDataSource" type="javax.sql.DataSource">
JtaManager = true
JdbcDriver = org.postgresql.Driver
JdbcUrl = jdbc:postgresql://localhost:5432/hsadmin_db
UserName = hsadmin_dbuser
Password = SelfDefinedPassword
</Resource>
</tomee>