Remove LDAP and Validation objects - (removing these features)

This commit is contained in:
Robin Bygrave
2013-04-12 00:23:39 +12:00
parent cae8980652
commit f04a4864e9
29 changed files with 0 additions and 2283 deletions
@@ -1,35 +0,0 @@
package com.avaje.tests.ldap;
import junit.framework.Assert;
import junit.framework.TestCase;
import com.avaje.ebean.EbeanServer;
import com.avaje.ebean.EbeanServerFactory;
import com.avaje.ebean.config.ServerConfig;
import com.avaje.ebean.config.ldap.LdapConfig;
import com.avaje.ebean.config.ldap.LdapContextFactory;
public abstract class BaseLdapTest extends TestCase {
public void one() {
Assert.assertTrue(true);
}
protected EbeanServer createServer() {
LdapContextFactory contextFactory = new MockContextFactory();
ServerConfig config = new ServerConfig();
config.setName("h2");
config.setRegister(false);
config.setDefaultServer(false);
config.loadFromProperties();
LdapConfig ldapConfig = new LdapConfig();
ldapConfig.setContextFactory(contextFactory);
config.setLdapConfig(ldapConfig);
return EbeanServerFactory.create(config);
}
}
@@ -1,14 +0,0 @@
package com.avaje.tests.ldap;
import javax.naming.directory.DirContext;
import com.avaje.ebean.config.ldap.LdapContextFactory;
public class MockContextFactory implements LdapContextFactory {
public DirContext createContext() {
return new MockDirContext();
}
}
@@ -1,248 +0,0 @@
package com.avaje.tests.ldap;
import java.util.Hashtable;
import javax.naming.Binding;
import javax.naming.Context;
import javax.naming.Name;
import javax.naming.NameClassPair;
import javax.naming.NameParser;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.directory.Attributes;
import javax.naming.directory.BasicAttributes;
import javax.naming.directory.DirContext;
import javax.naming.directory.ModificationItem;
import javax.naming.directory.SearchControls;
import javax.naming.directory.SearchResult;
public class MockDirContext implements DirContext {
public void bind(Name name, Object obj, Attributes attrs) throws NamingException {
}
public void bind(String name, Object obj, Attributes attrs) throws NamingException {
}
public DirContext createSubcontext(Name name, Attributes attrs) throws NamingException {
return null;
}
public DirContext createSubcontext(String name, Attributes attrs) throws NamingException {
return null;
}
public Attributes getAttributes(Name name, String[] attrIds) throws NamingException {
BasicAttributes a = new BasicAttributes();
a.put("uid", "rbygraveTest01");
return a;
}
public Attributes getAttributes(Name name) throws NamingException {
return null;
}
public Attributes getAttributes(String name, String[] attrIds) throws NamingException {
return null;
}
public Attributes getAttributes(String name) throws NamingException {
return null;
}
public DirContext getSchema(Name name) throws NamingException {
return null;
}
public DirContext getSchema(String name) throws NamingException {
return null;
}
public DirContext getSchemaClassDefinition(Name name) throws NamingException {
return null;
}
public DirContext getSchemaClassDefinition(String name) throws NamingException {
return null;
}
public void modifyAttributes(Name name, int modOp, Attributes attrs) throws NamingException {
}
public void modifyAttributes(Name name, ModificationItem[] mods) throws NamingException {
}
public void modifyAttributes(String name, int modOp, Attributes attrs) throws NamingException {
}
public void modifyAttributes(String name, ModificationItem[] mods) throws NamingException {
}
public void rebind(Name name, Object obj, Attributes attrs) throws NamingException {
}
public void rebind(String name, Object obj, Attributes attrs) throws NamingException {
}
public NamingEnumeration<SearchResult> search(Name name, Attributes matchingAttributes, String[] attributesToReturn)
throws NamingException {
return null;
}
public NamingEnumeration<SearchResult> search(Name name, Attributes matchingAttributes) throws NamingException {
return null;
}
public NamingEnumeration<SearchResult> search(Name name, String filterExpr, Object[] filterArgs, SearchControls cons)
throws NamingException {
return null;
}
public NamingEnumeration<SearchResult> search(Name name, String filter, SearchControls cons) throws NamingException {
return null;
}
public NamingEnumeration<SearchResult> search(String name, Attributes matchingAttributes,
String[] attributesToReturn) throws NamingException {
return null;
}
public NamingEnumeration<SearchResult> search(String name, Attributes matchingAttributes) throws NamingException {
return null;
}
public NamingEnumeration<SearchResult> search(String name, String filterExpr, Object[] filterArgs,
SearchControls cons) throws NamingException {
return null;
}
public NamingEnumeration<SearchResult> search(String name, String filter, SearchControls cons)
throws NamingException {
return null;
}
public Object addToEnvironment(String propName, Object propVal) throws NamingException {
return null;
}
public void bind(Name name, Object obj) throws NamingException {
}
public void bind(String name, Object obj) throws NamingException {
}
public void close() throws NamingException {
}
public Name composeName(Name name, Name prefix) throws NamingException {
return null;
}
public String composeName(String name, String prefix) throws NamingException {
return null;
}
public Context createSubcontext(Name name) throws NamingException {
return null;
}
public Context createSubcontext(String name) throws NamingException {
return null;
}
public void destroySubcontext(Name name) throws NamingException {
}
public void destroySubcontext(String name) throws NamingException {
}
public Hashtable<?, ?> getEnvironment() throws NamingException {
return null;
}
public String getNameInNamespace() throws NamingException {
return null;
}
public NameParser getNameParser(Name name) throws NamingException {
return null;
}
public NameParser getNameParser(String name) throws NamingException {
return null;
}
public NamingEnumeration<NameClassPair> list(Name name) throws NamingException {
return null;
}
public NamingEnumeration<NameClassPair> list(String name) throws NamingException {
return null;
}
public NamingEnumeration<Binding> listBindings(Name name) throws NamingException {
return null;
}
public NamingEnumeration<Binding> listBindings(String name) throws NamingException {
return null;
}
public Object lookup(Name name) throws NamingException {
return null;
}
public Object lookup(String name) throws NamingException {
return null;
}
public Object lookupLink(Name name) throws NamingException {
return null;
}
public Object lookupLink(String name) throws NamingException {
return null;
}
public void rebind(Name name, Object obj) throws NamingException {
}
public void rebind(String name, Object obj) throws NamingException {
}
public Object removeFromEnvironment(String propName) throws NamingException {
return null;
}
public void rename(Name oldName, Name newName) throws NamingException {
}
public void rename(String oldName, String newName) throws NamingException {
}
public void unbind(Name name) throws NamingException {
}
public void unbind(String name) throws NamingException {
}
}
@@ -1,41 +0,0 @@
package com.avaje.tests.ldap;
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.NamingException;
import javax.naming.directory.DirContext;
import javax.naming.directory.InitialDirContext;
import com.avaje.ebean.config.ldap.LdapContextFactory;
public class SimpleContextFactory implements LdapContextFactory {
String url;
String principal;
String credentials;
public SimpleContextFactory(String url, String principal, String credentials) {
this.url = url;
this.principal = principal;
this.credentials = credentials;
}
public DirContext createContext() {
Hashtable<String, String> env = new Hashtable<String, String>();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, url);
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, principal);
env.put(Context.SECURITY_CREDENTIALS, credentials);
try {
return new InitialDirContext(env);
} catch (NamingException e) {
throw new RuntimeException(e);
}
}
}
@@ -1,43 +0,0 @@
package com.avaje.tests.ldap;
import java.util.HashSet;
import java.util.Set;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.directory.Attribute;
import javax.naming.directory.BasicAttribute;
import com.avaje.ebean.config.ldap.LdapAttributeAdapter;
public class SimpleLdapSetAdapater implements LdapAttributeAdapter {
@SuppressWarnings("unchecked")
public Attribute createAttribute(Object beanPropertyValue) {
Set<Long> set = (Set<Long>)beanPropertyValue;
BasicAttribute attr = new BasicAttribute("accounts");
for (Long accVal : set) {
attr.add("acct="+accVal);
}
return attr;
}
public Object readAttribute(Attribute attribute) throws NamingException {
HashSet<Long> set = new HashSet<Long>();
NamingEnumeration<?> all = attribute.getAll();
while (all.hasMoreElements()) {
String s = (String)all.nextElement();
// just trim off the first 5 characters
s = s.substring(5);
set.add(new Long(s));
}
return set;
}
}
@@ -1,68 +0,0 @@
package com.avaje.tests.ldap;
import java.util.Set;
import javax.naming.directory.Attribute;
import junit.framework.Assert;
import com.avaje.ebean.EbeanServer;
import com.avaje.ebean.config.GlobalProperties;
import com.avaje.ebeaninternal.api.SpiEbeanServer;
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor.EntityType;
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
import com.avaje.ebeaninternal.server.deploy.BeanPropertySimpleCollection;
import com.avaje.ebeaninternal.server.type.ScalarType;
import com.avaje.ebeaninternal.server.type.ScalarTypeLdapTimestamp;
import com.avaje.tests.model.ldap.LDPerson;
public class TestLDPersonDeploy extends BaseLdapTest {
public void test() {
boolean b = true;
if (b){
// turn this test off for the moment
return;
}
GlobalProperties.put("ebean.classes", LDPerson.class.toString());
EbeanServer server = createServer();
SpiEbeanServer spiServer = (SpiEbeanServer)server;
BeanDescriptor<LDPerson> descriptor = spiServer.getBeanDescriptor(LDPerson.class);
Assert.assertTrue(EntityType.LDAP.equals(descriptor.getEntityType()));
BeanProperty beanProperty = descriptor.getBeanProperty("modifiedTime");
Assert.assertEquals("modifiedTime", beanProperty.getName());
Assert.assertEquals("modifiedTime", beanProperty.getDbColumn());
ScalarType<?> scalarType = beanProperty.getScalarType();
Assert.assertTrue(scalarType instanceof ScalarTypeLdapTimestamp<?>);
BeanProperty accountsProp = descriptor.getBeanProperty("accounts");
Assert.assertTrue(accountsProp instanceof BeanPropertySimpleCollection<?>);
LDPerson person = new LDPerson();
person.addAccount(1001);
person.addAccount(1002);
person.addAccount(1003);
Attribute acctAttribute = accountsProp.createAttribute(person);
Assert.assertTrue(acctAttribute.size() == 3);
LDPerson newPerson = new LDPerson();
accountsProp.setAttributeValue(newPerson, acctAttribute);
Set<Long> accounts = newPerson.getAccounts();
Assert.assertTrue(accounts.size() == 3);
}
}
@@ -1,75 +0,0 @@
package com.avaje.tests.ldap;
import java.util.List;
import javax.naming.NamingException;
import junit.framework.TestCase;
import org.junit.Assert;
import com.avaje.ebean.EbeanServer;
import com.avaje.ebean.EbeanServerFactory;
import com.avaje.ebean.config.ServerConfig;
import com.avaje.ebean.config.ldap.LdapConfig;
import com.avaje.ebean.config.ldap.LdapContextFactory;
import com.avaje.tests.model.ldap.LDPerson;
import com.avaje.tests.model.ldap.LDPerson.Status;
public class TestLdapQuery extends TestCase {
public void test() throws NamingException {
boolean b = true;
if (b){
// turn this test off for the moment
return;
}
// GlobalProperties.put("ebean.ldapContextFactory", MockContextFactory.class.getName());
ServerConfig config = new ServerConfig();
config.setName("ldap");
config.setRegister(false);
config.setDefaultServer(false);
config.loadFromProperties();
// // built automatically from ebean.ldapContextFactory
// LdapContextFactory ldapContextFactory = config.getLdapConfig().getContextFactory();
// Assert.assertNotNull(ldapContextFactory);
LdapContextFactory contextFactory = new MockContextFactory();
LdapConfig ldapConfig = new LdapConfig();
ldapConfig.setContextFactory(contextFactory);
config.setLdapConfig(ldapConfig);
config.getDataSourceConfig().setOffline(true);
config.setDatabasePlatformName("oracle");
EbeanServer server = EbeanServerFactory.create(config);
LDPerson pRob = server.find(LDPerson.class)
.select("userId, cn")
.setId("rbygraveTest01")
.findUnique();
Assert.assertNotNull(pRob);
List<LDPerson> list = server.find(LDPerson.class)
.select("userId,status")
.where().like("userId","lz*").eq("status", LDPerson.Status.ACTIVE)
.findList();
System.out.println(list);
LDPerson p = new LDPerson();
p.setUserId("rbygraveTest01");
p.setStatus(Status.ACTIVE);
p.setCn("Test01");
p.setSn("Testing123");
p.setGivenName("Ban Dana");
p.setUserPassword("qwerty");
server.save(p);
}
}
@@ -1,53 +0,0 @@
package com.avaje.tests.ldap;
import java.util.Arrays;
import junit.framework.Assert;
import com.avaje.ebean.EbeanServer;
import com.avaje.ebean.Query;
import com.avaje.ebeaninternal.api.SpiEbeanServer;
import com.avaje.ebeaninternal.api.SpiQuery;
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
import com.avaje.ebeaninternal.server.ldap.LdapOrmQueryRequest;
import com.avaje.ebeaninternal.server.ldap.LdapQueryDeployHelper;
import com.avaje.tests.model.ldap.LDPerson;
public class TestLdapQueryParse extends BaseLdapTest{
public void test() {
boolean b = true;
if (b){
// turn this test off for the moment
return;
}
EbeanServer server = createServer();
Query<LDPerson> query = server.createQuery(LDPerson.class);
query.select("uid, cn, status");
query.where("(cn=rob*)");
query.where()
.raw("(inetUserStatus=Banana)")
.eq("status", LDPerson.Status.ACTIVE)
.eq("sn", "bana");
SpiQuery<LDPerson> sq = (SpiQuery<LDPerson>)query;
SpiEbeanServer spiServer = (SpiEbeanServer)server;
BeanDescriptor<LDPerson> desc = spiServer.getBeanDescriptor(LDPerson.class);
LdapOrmQueryRequest<LDPerson> req = new LdapOrmQueryRequest<LDPerson>(sq, desc, null);
LdapQueryDeployHelper deployHelper = new LdapQueryDeployHelper(req);
String[] sp = deployHelper.getSelectedProperties();
String filterExpr = deployHelper.getFilterExpr();
Object[] filterVals = deployHelper.getFilterValues();
System.out.println("filterExpr: "+filterExpr);
System.out.println("filterVals: "+Arrays.toString(filterVals));
Assert.assertNotNull(sp);
}
}
@@ -1,32 +0,0 @@
package com.avaje.tests.ldap;
import junit.framework.TestCase;
import org.joda.time.LocalDateTime;
import org.junit.Assert;
import com.avaje.ebeaninternal.server.type.ScalarTypeJodaLocalDateTime;
import com.avaje.ebeaninternal.server.type.ScalarTypeLdapTimestamp;
public class TestLdapTimestamp extends TestCase {
public void test() {
ScalarTypeJodaLocalDateTime bt = new ScalarTypeJodaLocalDateTime();
ScalarTypeLdapTimestamp<LocalDateTime> s = new ScalarTypeLdapTimestamp<LocalDateTime>(bt);
LocalDateTime now = new LocalDateTime();
Object v = s.toJdbcType(now);
Assert.assertNotNull(v);
Assert.assertTrue(v instanceof String);
Object convertBack = s.toBeanType(v);
Assert.assertTrue(convertBack instanceof LocalDateTime);
// Not equals due to loss of precision in LDAP format
//Assert.assertEquals(now, convertBack);
}
}
@@ -1,130 +0,0 @@
package com.avaje.tests.model.ldap;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import org.joda.time.LocalDateTime;
import com.avaje.ebean.annotation.EnumValue;
import com.avaje.ebean.annotation.LdapAttribute;
import com.avaje.ebean.annotation.LdapDomain;
import com.avaje.tests.ldap.SimpleLdapSetAdapater;
@LdapDomain(
baseDn = "ou=avajepeople,o=avajecustomers,dc=avaje,dc=net,dc=nz",
objectclass = "top,organizationalperson,avajeperson,inetadmin,inetorgperson,person,inetuser")
@Entity
public class LDPerson {
public enum Status {
@EnumValue(value = "Active")
ACTIVE,
@EnumValue(value = "Inactive")
INACTIVE
}
@Id
@Column(name = "uid")
private String userId;
@Column(name = "inetUserStatus")
private Status status;
private String cn;
private String sn;
private String givenName;
private String userPassword;
@Basic(fetch=FetchType.LAZY)
private LocalDateTime modifiedTime;
@Basic(fetch=FetchType.LAZY)
@LdapAttribute(adapter=SimpleLdapSetAdapater.class)
private Set<Long> accounts;
public String toString() {
return userId + " " + status;
}
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public Status getStatus() {
return status;
}
public void setStatus(Status status) {
this.status = status;
}
public String getCn() {
return cn;
}
public void setCn(String cn) {
this.cn = cn;
}
public String getSn() {
return sn;
}
public void setSn(String sn) {
this.sn = sn;
}
public String getGivenName() {
return givenName;
}
public void setGivenName(String givenName) {
this.givenName = givenName;
}
public String getUserPassword() {
return userPassword;
}
public void setUserPassword(String userPassword) {
this.userPassword = userPassword;
}
public LocalDateTime getModifiedTime() {
return modifiedTime;
}
public void setModifiedTime(LocalDateTime modifiedTime) {
this.modifiedTime = modifiedTime;
}
public Set<Long> getAccounts() {
return accounts;
}
public void setAccounts(Set<Long> accounts) {
this.accounts = accounts;
}
public void addAccount(long accountNumber){
if (accounts == null){
accounts = new HashSet<Long>();
}
accounts.add(accountNumber);
}
}