mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-10 03:45:46 +00:00
Main dev tree synch up
This commit is contained in:
parent
7af53d1c82
commit
6ce40d4e24
@ -29,87 +29,87 @@ import java.util.*;
|
||||
*/
|
||||
class AttributesImpl implements Attributes {
|
||||
|
||||
// TODO Create JndiAttribute class so that getAttributeDefinition and
|
||||
// getAttributeSyntaxDefinition can be implemented
|
||||
// TODO Create JndiAttribute class so that getAttributeDefinition and
|
||||
// getAttributeSyntaxDefinition can be implemented
|
||||
|
||||
LDAPAttributeSet m_attrSet;
|
||||
LDAPAttributeSet m_attrSet;
|
||||
|
||||
/**
|
||||
* A list of predefined binary attribute name
|
||||
*/
|
||||
static String[] m_binaryAttrs = {
|
||||
"photo", "userpassword", "jpegphoto", "audio", "thumbnailphoto", "thumbnaillogo",
|
||||
"usercertificate", "cacertificate", "certificaterevocationlist",
|
||||
"authorityrevocationlist", "crosscertificatepair", "personalsignature",
|
||||
"x500uniqueidentifier", "javaserializeddata"};
|
||||
|
||||
/**
|
||||
* A list of predefined binary attribute name
|
||||
*/
|
||||
static String[] m_binaryAttrs = {
|
||||
"photo", "userpassword", "jpegphoto", "audio", "thumbnailphoto", "thumbnaillogo",
|
||||
"usercertificate", "cacertificate", "certificaterevocationlist",
|
||||
"authorityrevocationlist", "crosscertificatepair", "personalsignature",
|
||||
"x500uniqueidentifier", "javaserializeddata"};
|
||||
|
||||
/**
|
||||
* A list of user defined binary attributes specified with the environment
|
||||
* property java.naming.ldap.attributes.binary
|
||||
*/
|
||||
static String[] m_userBinaryAttrs = null;
|
||||
|
||||
public AttributesImpl(LDAPAttributeSet attrSet, String[] userBinaryAttrs) {
|
||||
m_attrSet = attrSet;
|
||||
m_userBinaryAttrs = userBinaryAttrs;
|
||||
}
|
||||
public AttributesImpl(LDAPAttributeSet attrSet, String[] userBinaryAttrs) {
|
||||
m_attrSet = attrSet;
|
||||
m_userBinaryAttrs = userBinaryAttrs;
|
||||
}
|
||||
|
||||
public Object clone() {
|
||||
return new AttributesImpl((LDAPAttributeSet)m_attrSet.clone(), m_userBinaryAttrs);
|
||||
}
|
||||
return new AttributesImpl((LDAPAttributeSet)m_attrSet.clone(), m_userBinaryAttrs);
|
||||
}
|
||||
|
||||
public Attribute get(String attrID) {
|
||||
LDAPAttribute attr = m_attrSet.getAttribute(attrID);
|
||||
return (attr == null) ? null : ldapAttrToJndiAttr(attr);
|
||||
LDAPAttribute attr = m_attrSet.getAttribute(attrID);
|
||||
return (attr == null) ? null : ldapAttrToJndiAttr(attr);
|
||||
}
|
||||
|
||||
public NamingEnumeration getAll() {
|
||||
return new AttributeEnum(m_attrSet.getAttributes());
|
||||
return new AttributeEnum(m_attrSet.getAttributes());
|
||||
}
|
||||
|
||||
public NamingEnumeration getIDs() {
|
||||
return new AttributeIDEnum(m_attrSet.getAttributes());
|
||||
return new AttributeIDEnum(m_attrSet.getAttributes());
|
||||
}
|
||||
|
||||
public boolean isCaseIgnored() {
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
public Attribute put(String attrID, Object val) {
|
||||
LDAPAttribute attr = m_attrSet.getAttribute(attrID);
|
||||
if (val == null) { // no Value
|
||||
m_attrSet.add(new LDAPAttribute(attrID));
|
||||
}
|
||||
else if (val instanceof byte[]) {
|
||||
m_attrSet.add(new LDAPAttribute(attrID, (byte[])val));
|
||||
}
|
||||
else {
|
||||
m_attrSet.add(new LDAPAttribute(attrID, val.toString()));
|
||||
}
|
||||
return (attr == null) ? null : ldapAttrToJndiAttr(attr);
|
||||
LDAPAttribute attr = m_attrSet.getAttribute(attrID);
|
||||
if (val == null) { // no Value
|
||||
m_attrSet.add(new LDAPAttribute(attrID));
|
||||
}
|
||||
else if (val instanceof byte[]) {
|
||||
m_attrSet.add(new LDAPAttribute(attrID, (byte[])val));
|
||||
}
|
||||
else {
|
||||
m_attrSet.add(new LDAPAttribute(attrID, val.toString()));
|
||||
}
|
||||
return (attr == null) ? null : ldapAttrToJndiAttr(attr);
|
||||
}
|
||||
|
||||
public Attribute put(Attribute jndiAttr) {
|
||||
try {
|
||||
LDAPAttribute oldAttr = m_attrSet.getAttribute(jndiAttr.getID());
|
||||
m_attrSet.add(jndiAttrToLdapAttr(jndiAttr));
|
||||
return (oldAttr == null) ? null : ldapAttrToJndiAttr(oldAttr);
|
||||
}
|
||||
catch (NamingException e) {
|
||||
System.err.println( "Error in AttributesImpl.put(): " + e.toString() );
|
||||
e.printStackTrace(System.err);
|
||||
}
|
||||
return null;
|
||||
LDAPAttribute oldAttr = m_attrSet.getAttribute(jndiAttr.getID());
|
||||
m_attrSet.add(jndiAttrToLdapAttr(jndiAttr));
|
||||
return (oldAttr == null) ? null : ldapAttrToJndiAttr(oldAttr);
|
||||
}
|
||||
catch (NamingException e) {
|
||||
System.err.println( "Error in AttributesImpl.put(): " + e.toString() );
|
||||
e.printStackTrace(System.err);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Attribute remove(String attrID) {
|
||||
Attribute attr = get(attrID);
|
||||
m_attrSet.remove(attrID);
|
||||
return attr;
|
||||
}
|
||||
|
||||
Attribute attr = get(attrID);
|
||||
m_attrSet.remove(attrID);
|
||||
return attr;
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return m_attrSet.size();
|
||||
return m_attrSet.size();
|
||||
}
|
||||
|
||||
|
||||
@ -117,130 +117,130 @@ class AttributesImpl implements Attributes {
|
||||
* Check if an attribute is a binary one
|
||||
*/
|
||||
static boolean isBinaryAttribute(String attrID) {
|
||||
|
||||
// attr name contains ";binary"
|
||||
if (attrID.indexOf(";binary") >=0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
attrID = attrID.toLowerCase();
|
||||
|
||||
// check the predefined binary attr table
|
||||
for (int i=0; i < m_binaryAttrs.length; i++) {
|
||||
if (m_binaryAttrs[i].equals(attrID)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// check user specified binary attrs with
|
||||
for (int i=0; m_userBinaryAttrs != null && i < m_userBinaryAttrs.length; i++) {
|
||||
if (m_userBinaryAttrs[i].equals(attrID)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
// attr name contains ";binary"
|
||||
if (attrID.indexOf(";binary") >=0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
attrID = attrID.toLowerCase();
|
||||
|
||||
// check the predefined binary attr table
|
||||
for (int i=0; i < m_binaryAttrs.length; i++) {
|
||||
if (m_binaryAttrs[i].equals(attrID)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// check user specified binary attrs with
|
||||
for (int i=0; m_userBinaryAttrs != null && i < m_userBinaryAttrs.length; i++) {
|
||||
if (m_userBinaryAttrs[i].equals(attrID)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a JNDI Attributes object into a LDAPAttributeSet
|
||||
*/
|
||||
static LDAPAttributeSet jndiAttrsToLdapAttrSet(Attributes jndiAttrs) throws NamingException{
|
||||
LDAPAttributeSet attrs = new LDAPAttributeSet();
|
||||
for (Enumeration enum = jndiAttrs.getAll(); enum.hasMoreElements();) {
|
||||
attrs.add(jndiAttrToLdapAttr((Attribute) enum.nextElement()));
|
||||
}
|
||||
return attrs;
|
||||
}
|
||||
|
||||
static LDAPAttributeSet jndiAttrsToLdapAttrSet(Attributes jndiAttrs) throws NamingException{
|
||||
LDAPAttributeSet attrs = new LDAPAttributeSet();
|
||||
for (Enumeration enum = jndiAttrs.getAll(); enum.hasMoreElements();) {
|
||||
attrs.add(jndiAttrToLdapAttr((Attribute) enum.nextElement()));
|
||||
}
|
||||
return attrs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a JNDI Attribute to a LDAPAttribute
|
||||
*/
|
||||
static LDAPAttribute jndiAttrToLdapAttr(Attribute jndiAttr) throws NamingException{
|
||||
LDAPAttribute attr = new LDAPAttribute(jndiAttr.getID());
|
||||
|
||||
for (NamingEnumeration vals = jndiAttr.getAll(); vals.hasMoreElements();) {
|
||||
Object val = vals.nextElement();
|
||||
if (val == null) {
|
||||
; // no value
|
||||
}
|
||||
else if (val instanceof byte[]) {
|
||||
attr.addValue((byte[])val);
|
||||
}
|
||||
static LDAPAttribute jndiAttrToLdapAttr(Attribute jndiAttr) throws NamingException{
|
||||
LDAPAttribute attr = new LDAPAttribute(jndiAttr.getID());
|
||||
|
||||
for (NamingEnumeration vals = jndiAttr.getAll(); vals.hasMoreElements();) {
|
||||
Object val = vals.nextElement();
|
||||
if (val == null) {
|
||||
; // no value
|
||||
}
|
||||
else if (val instanceof byte[]) {
|
||||
attr.addValue((byte[])val);
|
||||
}
|
||||
else {
|
||||
attr.addValue(val.toString());
|
||||
}
|
||||
}
|
||||
return attr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a LDAPAttribute to a JNDI Attribute
|
||||
*/
|
||||
static Attribute ldapAttrToJndiAttr(LDAPAttribute attr) {
|
||||
BasicAttribute jndiAttr = new BasicAttribute(attr.getName());
|
||||
Enumeration enumVals = null;
|
||||
if (isBinaryAttribute(attr.getName())) {
|
||||
enumVals = attr.getByteValues();
|
||||
}
|
||||
else {
|
||||
enumVals = attr.getStringValues();
|
||||
}
|
||||
if (enumVals != null) {
|
||||
while ( enumVals.hasMoreElements() ) {
|
||||
jndiAttr.add(enumVals.nextElement());
|
||||
}
|
||||
}
|
||||
return jndiAttr;
|
||||
}
|
||||
}
|
||||
return attr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a LDAPAttribute to a JNDI Attribute
|
||||
*/
|
||||
static Attribute ldapAttrToJndiAttr(LDAPAttribute attr) {
|
||||
BasicAttribute jndiAttr = new BasicAttribute(attr.getName());
|
||||
Enumeration enumVals = null;
|
||||
if (isBinaryAttribute(attr.getName())) {
|
||||
enumVals = attr.getByteValues();
|
||||
}
|
||||
else {
|
||||
enumVals = attr.getStringValues();
|
||||
}
|
||||
if (enumVals != null) {
|
||||
while ( enumVals.hasMoreElements() ) {
|
||||
jndiAttr.add(enumVals.nextElement());
|
||||
}
|
||||
}
|
||||
return jndiAttr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert and array of JNDI ModificationItem to a LDAPModificationSet
|
||||
*/
|
||||
static LDAPModificationSet jndiModsToLdapModSet(ModificationItem[] jndiMods) throws NamingException{
|
||||
LDAPModificationSet mods = new LDAPModificationSet();
|
||||
for (int i=0; i < jndiMods.length; i++) {
|
||||
int modop = jndiMods[i].getModificationOp();
|
||||
LDAPAttribute attr = jndiAttrToLdapAttr(jndiMods[i].getAttribute());
|
||||
if (modop == DirContext.ADD_ATTRIBUTE) {
|
||||
mods.add(LDAPModification.ADD, attr);
|
||||
}
|
||||
else if (modop == DirContext.REPLACE_ATTRIBUTE) {
|
||||
mods.add(LDAPModification.REPLACE, attr);
|
||||
}
|
||||
else if (modop == DirContext.REMOVE_ATTRIBUTE) {
|
||||
mods.add(LDAPModification.DELETE, attr);
|
||||
}
|
||||
else {
|
||||
// Should never come here. ModificationItem can not
|
||||
// be constructed with a wrong value
|
||||
}
|
||||
}
|
||||
return mods;
|
||||
}
|
||||
static LDAPModificationSet jndiModsToLdapModSet(ModificationItem[] jndiMods) throws NamingException{
|
||||
LDAPModificationSet mods = new LDAPModificationSet();
|
||||
for (int i=0; i < jndiMods.length; i++) {
|
||||
int modop = jndiMods[i].getModificationOp();
|
||||
LDAPAttribute attr = jndiAttrToLdapAttr(jndiMods[i].getAttribute());
|
||||
if (modop == DirContext.ADD_ATTRIBUTE) {
|
||||
mods.add(LDAPModification.ADD, attr);
|
||||
}
|
||||
else if (modop == DirContext.REPLACE_ATTRIBUTE) {
|
||||
mods.add(LDAPModification.REPLACE, attr);
|
||||
}
|
||||
else if (modop == DirContext.REMOVE_ATTRIBUTE) {
|
||||
mods.add(LDAPModification.DELETE, attr);
|
||||
}
|
||||
else {
|
||||
// Should never come here. ModificationItem can not
|
||||
// be constructed with a wrong value
|
||||
}
|
||||
}
|
||||
return mods;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a LDAPModificationSet from a JNDI mod operation and JNDI Attributes
|
||||
*/
|
||||
static LDAPModificationSet jndiAttrsToLdapModSet(int modop, Attributes jndiAttrs) throws NamingException{
|
||||
LDAPModificationSet mods = new LDAPModificationSet();
|
||||
for (NamingEnumeration attrEnum = jndiAttrs.getAll(); attrEnum.hasMore();) {
|
||||
LDAPAttribute attr = jndiAttrToLdapAttr((Attribute)attrEnum.next());
|
||||
if (modop == DirContext.ADD_ATTRIBUTE) {
|
||||
mods.add(LDAPModification.ADD, attr);
|
||||
}
|
||||
else if (modop == DirContext.REPLACE_ATTRIBUTE) {
|
||||
mods.add(LDAPModification.REPLACE, attr);
|
||||
}
|
||||
else if (modop == DirContext.REMOVE_ATTRIBUTE) {
|
||||
mods.add(LDAPModification.DELETE, attr);
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException("Illegal Attribute Modification Operation");
|
||||
}
|
||||
}
|
||||
return mods;
|
||||
}
|
||||
static LDAPModificationSet jndiAttrsToLdapModSet(int modop, Attributes jndiAttrs) throws NamingException{
|
||||
LDAPModificationSet mods = new LDAPModificationSet();
|
||||
for (NamingEnumeration attrEnum = jndiAttrs.getAll(); attrEnum.hasMore();) {
|
||||
LDAPAttribute attr = jndiAttrToLdapAttr((Attribute)attrEnum.next());
|
||||
if (modop == DirContext.ADD_ATTRIBUTE) {
|
||||
mods.add(LDAPModification.ADD, attr);
|
||||
}
|
||||
else if (modop == DirContext.REPLACE_ATTRIBUTE) {
|
||||
mods.add(LDAPModification.REPLACE, attr);
|
||||
}
|
||||
else if (modop == DirContext.REMOVE_ATTRIBUTE) {
|
||||
mods.add(LDAPModification.DELETE, attr);
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException("Illegal Attribute Modification Operation");
|
||||
}
|
||||
}
|
||||
return mods;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -248,33 +248,33 @@ class AttributesImpl implements Attributes {
|
||||
* into a JNDI Attribute accessed through the NamingEnumeration
|
||||
*/
|
||||
class AttributeEnum implements NamingEnumeration {
|
||||
|
||||
Enumeration _attrEnum;
|
||||
|
||||
public AttributeEnum(Enumeration attrEnum) {
|
||||
_attrEnum = attrEnum;
|
||||
}
|
||||
|
||||
Enumeration _attrEnum;
|
||||
|
||||
public AttributeEnum(Enumeration attrEnum) {
|
||||
_attrEnum = attrEnum;
|
||||
}
|
||||
|
||||
public Object next() throws NamingException{
|
||||
LDAPAttribute attr = (LDAPAttribute) _attrEnum.nextElement();
|
||||
return AttributesImpl.ldapAttrToJndiAttr(attr);
|
||||
}
|
||||
public Object next() throws NamingException{
|
||||
LDAPAttribute attr = (LDAPAttribute) _attrEnum.nextElement();
|
||||
return AttributesImpl.ldapAttrToJndiAttr(attr);
|
||||
}
|
||||
|
||||
public Object nextElement() {
|
||||
LDAPAttribute attr = (LDAPAttribute) _attrEnum.nextElement();
|
||||
return AttributesImpl.ldapAttrToJndiAttr(attr);
|
||||
}
|
||||
public Object nextElement() {
|
||||
LDAPAttribute attr = (LDAPAttribute) _attrEnum.nextElement();
|
||||
return AttributesImpl.ldapAttrToJndiAttr(attr);
|
||||
}
|
||||
|
||||
public boolean hasMore() throws NamingException{
|
||||
return _attrEnum.hasMoreElements();
|
||||
}
|
||||
public boolean hasMore() throws NamingException{
|
||||
return _attrEnum.hasMoreElements();
|
||||
}
|
||||
|
||||
public boolean hasMoreElements() {
|
||||
return _attrEnum.hasMoreElements();
|
||||
}
|
||||
public boolean hasMoreElements() {
|
||||
return _attrEnum.hasMoreElements();
|
||||
}
|
||||
|
||||
public void close() {
|
||||
}
|
||||
public void close() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -283,30 +283,30 @@ class AttributeEnum implements NamingEnumeration {
|
||||
*/
|
||||
class AttributeIDEnum implements NamingEnumeration {
|
||||
|
||||
Enumeration _attrEnum;
|
||||
|
||||
public AttributeIDEnum(Enumeration attrEnum) {
|
||||
_attrEnum = attrEnum;
|
||||
}
|
||||
Enumeration _attrEnum;
|
||||
|
||||
public AttributeIDEnum(Enumeration attrEnum) {
|
||||
_attrEnum = attrEnum;
|
||||
}
|
||||
|
||||
public Object next() throws NamingException{
|
||||
LDAPAttribute attr = (LDAPAttribute) _attrEnum.nextElement();
|
||||
return attr.getName();
|
||||
}
|
||||
public Object next() throws NamingException{
|
||||
LDAPAttribute attr = (LDAPAttribute) _attrEnum.nextElement();
|
||||
return attr.getName();
|
||||
}
|
||||
|
||||
public Object nextElement() {
|
||||
LDAPAttribute attr = (LDAPAttribute) _attrEnum.nextElement();
|
||||
return attr.getName();
|
||||
}
|
||||
public Object nextElement() {
|
||||
LDAPAttribute attr = (LDAPAttribute) _attrEnum.nextElement();
|
||||
return attr.getName();
|
||||
}
|
||||
|
||||
public boolean hasMore() throws NamingException{
|
||||
return _attrEnum.hasMoreElements();
|
||||
}
|
||||
public boolean hasMore() throws NamingException{
|
||||
return _attrEnum.hasMoreElements();
|
||||
}
|
||||
|
||||
public boolean hasMoreElements() {
|
||||
return _attrEnum.hasMoreElements();
|
||||
}
|
||||
public boolean hasMoreElements() {
|
||||
return _attrEnum.hasMoreElements();
|
||||
}
|
||||
|
||||
public void close() {
|
||||
}
|
||||
}
|
||||
public void close() {
|
||||
}
|
||||
}
|
||||
|
@ -33,63 +33,63 @@ import java.util.*;
|
||||
*/
|
||||
class BindingEnum implements NamingEnumeration {
|
||||
|
||||
LDAPSearchResults m_res;
|
||||
LdapContextImpl m_ctx;
|
||||
Name m_ctxName;
|
||||
LDAPSearchResults m_res;
|
||||
LdapContextImpl m_ctx;
|
||||
Name m_ctxName;
|
||||
|
||||
public BindingEnum(LDAPSearchResults res, LdapContextImpl ctx) throws NamingException {
|
||||
m_res = res;
|
||||
m_ctx = ctx;
|
||||
try {
|
||||
m_ctxName = LdapNameParser.getParser().parse(m_ctx.m_ctxDN);
|
||||
}
|
||||
catch ( NamingException e ) {
|
||||
throw ExceptionMapper.getNamingException(e);
|
||||
}
|
||||
}
|
||||
public BindingEnum(LDAPSearchResults res, LdapContextImpl ctx) throws NamingException {
|
||||
m_res = res;
|
||||
m_ctx = ctx;
|
||||
try {
|
||||
m_ctxName = LdapNameParser.getParser().parse(m_ctx.m_ctxDN);
|
||||
}
|
||||
catch ( NamingException e ) {
|
||||
throw ExceptionMapper.getNamingException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public Object next() throws NamingException{
|
||||
try {
|
||||
LDAPEntry entry = m_res.next();
|
||||
String name = LdapNameParser.getRelativeName(m_ctxName, entry.getDN());
|
||||
Object obj = ObjectMapper.entryToObject(entry, m_ctx);
|
||||
String className = obj.getClass().getName();
|
||||
return new Binding(name, className, obj, /*isRelative=*/true);
|
||||
public Object next() throws NamingException{
|
||||
try {
|
||||
LDAPEntry entry = m_res.next();
|
||||
String name = LdapNameParser.getRelativeName(m_ctxName, entry.getDN());
|
||||
Object obj = ObjectMapper.entryToObject(entry, m_ctx);
|
||||
String className = obj.getClass().getName();
|
||||
return new Binding(name, className, obj, /*isRelative=*/true);
|
||||
|
||||
}
|
||||
catch (LDAPReferralException e) {
|
||||
throw new LdapReferralException(m_ctx, e);
|
||||
}
|
||||
catch ( LDAPException e ) {
|
||||
throw ExceptionMapper.getNamingException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (LDAPReferralException e) {
|
||||
throw new LdapReferralException(m_ctx, e);
|
||||
}
|
||||
catch ( LDAPException e ) {
|
||||
throw ExceptionMapper.getNamingException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public Object nextElement() {
|
||||
try {
|
||||
return next();
|
||||
}
|
||||
catch ( Exception e ) {
|
||||
System.err.println( "Error in BindingEnum.nextElement(): " + e.toString() );
|
||||
e.printStackTrace(System.err);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public Object nextElement() {
|
||||
try {
|
||||
return next();
|
||||
}
|
||||
catch ( Exception e ) {
|
||||
System.err.println( "Error in BindingEnum.nextElement(): " + e.toString() );
|
||||
e.printStackTrace(System.err);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasMore() throws NamingException{
|
||||
return m_res.hasMoreElements();
|
||||
}
|
||||
public boolean hasMore() throws NamingException{
|
||||
return m_res.hasMoreElements();
|
||||
}
|
||||
|
||||
public boolean hasMoreElements() {
|
||||
return m_res.hasMoreElements();
|
||||
}
|
||||
public boolean hasMoreElements() {
|
||||
return m_res.hasMoreElements();
|
||||
}
|
||||
|
||||
public void close() throws NamingException{
|
||||
try {
|
||||
m_ctx.m_ldapSvc.getConnection().abandon(m_res);
|
||||
}
|
||||
catch (LDAPException e) {
|
||||
throw ExceptionMapper.getNamingException(e);
|
||||
}
|
||||
}
|
||||
public void close() throws NamingException{
|
||||
try {
|
||||
m_ctx.m_ldapSvc.getConnection().abandon(m_res);
|
||||
}
|
||||
catch (LDAPException e) {
|
||||
throw ExceptionMapper.getNamingException(e);
|
||||
}
|
||||
}
|
||||
}
|
@ -33,119 +33,119 @@ import java.util.*;
|
||||
*/
|
||||
class ContextEnv extends ShareableEnv {
|
||||
|
||||
public static final String DEFAULT_HOST = "localhost";
|
||||
public static final int DEFAULT_PORT = LDAPv2.DEFAULT_PORT;
|
||||
public static final int DEFAULT_SSL_PORT = 636;
|
||||
public static final int DEFAULT_LDAP_VERSION = 3;
|
||||
public static final String DEFAULT_HOST = "localhost";
|
||||
public static final int DEFAULT_PORT = LDAPv2.DEFAULT_PORT;
|
||||
public static final int DEFAULT_SSL_PORT = 636;
|
||||
public static final int DEFAULT_LDAP_VERSION = 3;
|
||||
|
||||
// JNDI defined environment propertiies
|
||||
public static final String P_PROVIDER_URL = Context.PROVIDER_URL;
|
||||
public static final String P_SECURITY_PROTOCOL = Context.SECURITY_PROTOCOL;
|
||||
public static final String P_SECURITY_AUTHMODE = Context.SECURITY_AUTHENTICATION;
|
||||
public static final String P_USER_DN = Context.SECURITY_PRINCIPAL;
|
||||
public static final String P_USER_PASSWORD = Context.SECURITY_CREDENTIALS;
|
||||
public static final String P_APPLET = Context.APPLET;
|
||||
public static final String P_AUTHORITATIVE = Context.AUTHORITATIVE;
|
||||
public static final String P_LANGUAGE = Context.LANGUAGE;
|
||||
public static final String P_BATCHSIZE = Context.BATCHSIZE;
|
||||
public static final String P_REFERRAL_MODE = Context.REFERRAL;
|
||||
// JNDI defined environment propertiies
|
||||
public static final String P_PROVIDER_URL = Context.PROVIDER_URL;
|
||||
public static final String P_SECURITY_PROTOCOL = Context.SECURITY_PROTOCOL;
|
||||
public static final String P_SECURITY_AUTHMODE = Context.SECURITY_AUTHENTICATION;
|
||||
public static final String P_USER_DN = Context.SECURITY_PRINCIPAL;
|
||||
public static final String P_USER_PASSWORD = Context.SECURITY_CREDENTIALS;
|
||||
public static final String P_APPLET = Context.APPLET;
|
||||
public static final String P_AUTHORITATIVE = Context.AUTHORITATIVE;
|
||||
public static final String P_LANGUAGE = Context.LANGUAGE;
|
||||
public static final String P_BATCHSIZE = Context.BATCHSIZE;
|
||||
public static final String P_REFERRAL_MODE = Context.REFERRAL;
|
||||
|
||||
// Custom properties
|
||||
public static final String P_CONNECT_CTRLS = "java.naming.ldap.control.connect";
|
||||
public static final String P_BINARY_ATTRS = "java.naming.ldap.attributes.binary";
|
||||
public static final String P_ATTRS_ONLY = "java.naming.ldap.typesOnly";
|
||||
public static final String P_DELETE_OLDRDN = "java.naming.ldap.deleteRDN";
|
||||
public static final String P_SOCKET_FACTORY = "java.naming.ldap.factory.socket";
|
||||
public static final String P_CIPHER_SUITE = "java.naming.ldap.ssl.ciphers"; // new
|
||||
public static final String P_TIME_LIMIT = "java.naming.ldap.timelimit"; // new
|
||||
public static final String P_MAX_RESULTS = "java.naming.ldap.maxresults"; // new
|
||||
public static final String P_DEREF_ALIASES = "java.naming.ldap.derefAliases";
|
||||
public static final String P_REFERRAL_HOPLIMIT = "java.naming.referral.limit";
|
||||
public static final String P_LDAP_VERSION = "java.naming.ldap.version";
|
||||
public static final String P_JNDIREF_SEPARATOR = "java.naming.ref.separator";
|
||||
|
||||
// Possible values for the Context.REFERRAL env property
|
||||
private static final String V_REFERRAL_FOLLOW = "follow";
|
||||
private static final String V_REFERRAL_IGNORE = "ignore";
|
||||
private static final String V_REFERRAL_THROW_EXCEPTION = "throw";
|
||||
// Custom properties
|
||||
public static final String P_CONNECT_CTRLS = "java.naming.ldap.control.connect";
|
||||
public static final String P_BINARY_ATTRS = "java.naming.ldap.attributes.binary";
|
||||
public static final String P_ATTRS_ONLY = "java.naming.ldap.typesOnly";
|
||||
public static final String P_DELETE_OLDRDN = "java.naming.ldap.deleteRDN";
|
||||
public static final String P_SOCKET_FACTORY = "java.naming.ldap.factory.socket";
|
||||
public static final String P_CIPHER_SUITE = "java.naming.ldap.ssl.ciphers"; // new
|
||||
public static final String P_TIME_LIMIT = "java.naming.ldap.timelimit"; // new
|
||||
public static final String P_MAX_RESULTS = "java.naming.ldap.maxresults"; // new
|
||||
public static final String P_DEREF_ALIASES = "java.naming.ldap.derefAliases";
|
||||
public static final String P_REFERRAL_HOPLIMIT = "java.naming.referral.limit";
|
||||
public static final String P_LDAP_VERSION = "java.naming.ldap.version";
|
||||
public static final String P_JNDIREF_SEPARATOR = "java.naming.ref.separator";
|
||||
|
||||
// Possible values for the Context.REFERRAL env property
|
||||
private static final String V_REFERRAL_FOLLOW = "follow";
|
||||
private static final String V_REFERRAL_IGNORE = "ignore";
|
||||
private static final String V_REFERRAL_THROW_EXCEPTION = "throw";
|
||||
|
||||
// Possible values for the java.naming.ldap.derefAliases env property
|
||||
private static final String V_DEREF_NEVER = "never";
|
||||
|
||||
private static final String V_DEREF_SEARCHING = "searching";
|
||||
private static final String V_DEREF_FINDING = "finding";
|
||||
private static final String V_DEREF_ALWAYS = "always";
|
||||
|
||||
// Possible values for the java.naming... env property
|
||||
private static final String V_AUTH_NONE = "none";
|
||||
private static final String V_AUTH_SIMPLE = "simple";
|
||||
private static final String V_AUTH_STRONG = "strong";
|
||||
// Possible values for the java.naming.ldap.derefAliases env property
|
||||
private static final String V_DEREF_NEVER = "never";
|
||||
|
||||
private static final String V_DEREF_SEARCHING = "searching";
|
||||
private static final String V_DEREF_FINDING = "finding";
|
||||
private static final String V_DEREF_ALWAYS = "always";
|
||||
|
||||
// Possible values for the java.naming... env property
|
||||
private static final String V_AUTH_NONE = "none";
|
||||
private static final String V_AUTH_SIMPLE = "simple";
|
||||
private static final String V_AUTH_STRONG = "strong";
|
||||
|
||||
/**
|
||||
* Constructor for non root Contexts
|
||||
*
|
||||
* @param parent A reference to the parent context environment
|
||||
* @param parentSharedEnvIdx index into parent's shared environemnt list
|
||||
*/
|
||||
public ContextEnv(ShareableEnv parent, int parentSharedEnvIdx) {
|
||||
super(parent, parentSharedEnvIdx);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for the root context
|
||||
*
|
||||
* @param initialEnv a hashtable with environemnt properties
|
||||
*/
|
||||
public ContextEnv(Hashtable initialEnv) {
|
||||
super(initialEnv);
|
||||
}
|
||||
/**
|
||||
* Constructor for non root Contexts
|
||||
*
|
||||
* @param parent A reference to the parent context environment
|
||||
* @param parentSharedEnvIdx index into parent's shared environemnt list
|
||||
*/
|
||||
public ContextEnv(ShareableEnv parent, int parentSharedEnvIdx) {
|
||||
super(parent, parentSharedEnvIdx);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for the root context
|
||||
*
|
||||
* @param initialEnv a hashtable with environemnt properties
|
||||
*/
|
||||
public ContextEnv(Hashtable initialEnv) {
|
||||
super(initialEnv);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clone ContextEnv
|
||||
*
|
||||
* @return A "clone" of the current context environment
|
||||
*/
|
||||
/**
|
||||
* Clone ShareableEnv
|
||||
* The code is the same as in the superclass (ShareableEnv) except that
|
||||
* a ContextEnv instance is returned
|
||||
*
|
||||
* @return A "clone" of the current context environment
|
||||
*/
|
||||
public Object clone() {
|
||||
|
||||
// First freeze updates for this context
|
||||
freezeUpdates();
|
||||
|
||||
// If the context has been modified, then it is the parent of the clone
|
||||
if (m_sharedEnv != null) {
|
||||
return new ContextEnv(this, m_sharedEnv.size()-1);
|
||||
}
|
||||
|
||||
// No changes has been done to the inherited parent context. Pass the parent
|
||||
// context to the clone
|
||||
else {
|
||||
return new ContextEnv(m_parentEnv, m_parentSharedEnvIdx);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Clone ContextEnv
|
||||
*
|
||||
* @return A "clone" of the current context environment
|
||||
*/
|
||||
/**
|
||||
* Clone ShareableEnv
|
||||
* The code is the same as in the superclass (ShareableEnv) except that
|
||||
* a ContextEnv instance is returned
|
||||
*
|
||||
* @return A "clone" of the current context environment
|
||||
*/
|
||||
public Object clone() {
|
||||
|
||||
// First freeze updates for this context
|
||||
freezeUpdates();
|
||||
|
||||
// If the context has been modified, then it is the parent of the clone
|
||||
if (m_sharedEnv != null) {
|
||||
return new ContextEnv(this, m_sharedEnv.size()-1);
|
||||
}
|
||||
|
||||
// No changes has been done to the inherited parent context. Pass the parent
|
||||
// context to the clone
|
||||
else {
|
||||
return new ContextEnv(m_parentEnv, m_parentSharedEnvIdx);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update property value. Properties that pertain to LDAPSearchConstraints
|
||||
* are immediately propagated. To take effect of properties that are connection
|
||||
* related, (like user name/password, ssl mode) the context mujst be reconnected
|
||||
* after the change of environment
|
||||
*/
|
||||
/**
|
||||
* Update property value. Properties that pertain to LDAPSearchConstraints
|
||||
* are immediately propagated. To take effect of properties that are connection
|
||||
* related, (like user name/password, ssl mode) the context mujst be reconnected
|
||||
* after the change of environment
|
||||
*/
|
||||
Object updateProperty(String name, Object val, LDAPSearchConstraints cons) throws NamingException{
|
||||
Object oldVal = getProperty(name);
|
||||
Object oldVal = getProperty(name);
|
||||
setProperty(name,val);
|
||||
try {
|
||||
if (name.equalsIgnoreCase(P_BATCHSIZE)) {
|
||||
updateBatchSize(cons);
|
||||
}
|
||||
else if (name.equalsIgnoreCase(P_TIME_LIMIT)) {
|
||||
updateTimeLimit(cons);
|
||||
}
|
||||
else if (name.equalsIgnoreCase(P_MAX_RESULTS)) {
|
||||
if (name.equalsIgnoreCase(P_BATCHSIZE)) {
|
||||
updateBatchSize(cons);
|
||||
}
|
||||
else if (name.equalsIgnoreCase(P_TIME_LIMIT)) {
|
||||
updateTimeLimit(cons);
|
||||
}
|
||||
else if (name.equalsIgnoreCase(P_MAX_RESULTS)) {
|
||||
updateMaxResults(cons);
|
||||
}
|
||||
else if (name.equalsIgnoreCase(P_DEREF_ALIASES)) {
|
||||
@ -170,9 +170,9 @@ class ContextEnv extends ShareableEnv {
|
||||
return oldVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize LDAPSearchConstraints with environment properties
|
||||
*/
|
||||
/**
|
||||
* Initialize LDAPSearchConstraints with environment properties
|
||||
*/
|
||||
void updateSearchCons(LDAPSearchConstraints cons) throws NamingException{
|
||||
updateBatchSize(cons);
|
||||
updateTimeLimit(cons);
|
||||
@ -182,274 +182,274 @@ class ContextEnv extends ShareableEnv {
|
||||
updateReferralHopLimit(cons);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the suggested number of result to return at a time during search in the
|
||||
* default SearchConstraints for the connection.
|
||||
* Specified with the env property java.naming.batchsize
|
||||
*/
|
||||
void updateBatchSize(LDAPSearchConstraints cons) {
|
||||
String size = (String)getProperty(P_BATCHSIZE);
|
||||
if (size != null) {
|
||||
int n = -1;
|
||||
try {
|
||||
n = Integer.parseInt(size);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new IllegalArgumentException("Illegal value for " + P_BATCHSIZE);
|
||||
}
|
||||
cons.setBatchSize(n);
|
||||
/**
|
||||
* Set the suggested number of result to return at a time during search in the
|
||||
* default SearchConstraints for the connection.
|
||||
* Specified with the env property java.naming.batchsize
|
||||
*/
|
||||
void updateBatchSize(LDAPSearchConstraints cons) {
|
||||
String size = (String)getProperty(P_BATCHSIZE);
|
||||
if (size != null) {
|
||||
int n = -1;
|
||||
try {
|
||||
n = Integer.parseInt(size);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new IllegalArgumentException("Illegal value for " + P_BATCHSIZE);
|
||||
}
|
||||
cons.setBatchSize(n);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the maximum number of miliseconds to wait for any operation under default
|
||||
* SearchConstraints for the connection.
|
||||
* Specified with the env property java.naming.ldap.timelimit
|
||||
* Note: sun ldap does not have this property
|
||||
*/
|
||||
void updateTimeLimit(LDAPSearchConstraints cons) {
|
||||
String millis = (String)getProperty(P_TIME_LIMIT);
|
||||
if (millis != null) {
|
||||
int n = -1;
|
||||
try {
|
||||
n = Integer.parseInt(millis);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new IllegalArgumentException("Illegal value for " + P_TIME_LIMIT);
|
||||
}
|
||||
cons.setTimeLimit(n);
|
||||
/**
|
||||
* Set the maximum number of miliseconds to wait for any operation under default
|
||||
* SearchConstraints for the connection.
|
||||
* Specified with the env property java.naming.ldap.timelimit
|
||||
* Note: sun ldap does not have this property
|
||||
*/
|
||||
void updateTimeLimit(LDAPSearchConstraints cons) {
|
||||
String millis = (String)getProperty(P_TIME_LIMIT);
|
||||
if (millis != null) {
|
||||
int n = -1;
|
||||
try {
|
||||
n = Integer.parseInt(millis);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new IllegalArgumentException("Illegal value for " + P_TIME_LIMIT);
|
||||
}
|
||||
cons.setTimeLimit(n);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the maximum number of search results to be returned under default
|
||||
* SearchConstraints for the connection.
|
||||
* Specified with the env property java.naming.ldap.maxresults
|
||||
* Note: sun ldap does not have this property
|
||||
*/
|
||||
void updateMaxResults(LDAPSearchConstraints cons) {
|
||||
String max = (String)getProperty(P_MAX_RESULTS);
|
||||
if (max != null) {
|
||||
int n = -1;
|
||||
try {
|
||||
n = Integer.parseInt(max);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new IllegalArgumentException(
|
||||
"Illegal value for " + P_MAX_RESULTS);
|
||||
}
|
||||
cons.setMaxResults(n);
|
||||
/**
|
||||
* Set the maximum number of search results to be returned under default
|
||||
* SearchConstraints for the connection.
|
||||
* Specified with the env property java.naming.ldap.maxresults
|
||||
* Note: sun ldap does not have this property
|
||||
*/
|
||||
void updateMaxResults(LDAPSearchConstraints cons) {
|
||||
String max = (String)getProperty(P_MAX_RESULTS);
|
||||
if (max != null) {
|
||||
int n = -1;
|
||||
try {
|
||||
n = Integer.parseInt(max);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new IllegalArgumentException(
|
||||
"Illegal value for " + P_MAX_RESULTS);
|
||||
}
|
||||
cons.setMaxResults(n);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set how aliases should be dereferenced under default SearchConstraints for the
|
||||
* connection.
|
||||
* Specified with the env property java.naming.ldap.derefAliases
|
||||
*/
|
||||
final void updateDerefAliases(LDAPSearchConstraints cons) throws IllegalArgumentException{
|
||||
String deref = (String)getProperty(P_DEREF_ALIASES);
|
||||
if(deref != null) {
|
||||
if(deref.equalsIgnoreCase(V_DEREF_NEVER)) {
|
||||
cons.setDereference(LDAPv2.DEREF_NEVER);
|
||||
}
|
||||
else if(deref.equalsIgnoreCase(V_DEREF_SEARCHING)) {
|
||||
cons.setDereference(LDAPv2.DEREF_SEARCHING);
|
||||
}
|
||||
else if(deref.equalsIgnoreCase(V_DEREF_FINDING)) {
|
||||
cons.setDereference(LDAPv2.DEREF_FINDING);
|
||||
}
|
||||
else if(deref.equalsIgnoreCase(V_DEREF_ALWAYS)) {
|
||||
cons.setDereference(LDAPv2.DEREF_ALWAYS);
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException("Illegal value for " + P_DEREF_ALIASES);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Set how aliases should be dereferenced under default SearchConstraints for the
|
||||
* connection.
|
||||
* Specified with the env property java.naming.ldap.derefAliases
|
||||
*/
|
||||
final void updateDerefAliases(LDAPSearchConstraints cons) throws IllegalArgumentException{
|
||||
String deref = (String)getProperty(P_DEREF_ALIASES);
|
||||
if(deref != null) {
|
||||
if(deref.equalsIgnoreCase(V_DEREF_NEVER)) {
|
||||
cons.setDereference(LDAPv2.DEREF_NEVER);
|
||||
}
|
||||
else if(deref.equalsIgnoreCase(V_DEREF_SEARCHING)) {
|
||||
cons.setDereference(LDAPv2.DEREF_SEARCHING);
|
||||
}
|
||||
else if(deref.equalsIgnoreCase(V_DEREF_FINDING)) {
|
||||
cons.setDereference(LDAPv2.DEREF_FINDING);
|
||||
}
|
||||
else if(deref.equalsIgnoreCase(V_DEREF_ALWAYS)) {
|
||||
cons.setDereference(LDAPv2.DEREF_ALWAYS);
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException("Illegal value for " + P_DEREF_ALIASES);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set referral parameters for the default SearchConstraints for the connection.
|
||||
* Specified with the env property java.naming.referral
|
||||
*/
|
||||
void updateReferralMode(LDAPSearchConstraints cons) {
|
||||
String mode = (String)getProperty(P_REFERRAL_MODE);
|
||||
if(mode != null) {
|
||||
if(mode.equalsIgnoreCase(V_REFERRAL_FOLLOW)) {
|
||||
cons.setReferrals(true);
|
||||
String user = getUserDN(), passwd = getUserPassword();
|
||||
if (user != null && passwd != null) {
|
||||
cons.setRebindProc(new ReferralRebindProc(user, passwd));
|
||||
}
|
||||
}
|
||||
else if(mode.equalsIgnoreCase(V_REFERRAL_THROW_EXCEPTION)) {
|
||||
cons.setReferrals(false);
|
||||
}
|
||||
else if(mode.equalsIgnoreCase(V_REFERRAL_IGNORE)) {
|
||||
//TODO If MANAGEDSAIT control is not supported by the server
|
||||
//(e.g. Active Directory) should enable exception and ignore it
|
||||
cons.setServerControls(new LDAPControl(
|
||||
LDAPControl.MANAGEDSAIT, /*critical=*/false, null));
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException("Illegal value for " + P_REFERRAL_MODE);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Set referral parameters for the default SearchConstraints for the connection.
|
||||
* Specified with the env property java.naming.referral
|
||||
*/
|
||||
void updateReferralMode(LDAPSearchConstraints cons) {
|
||||
String mode = (String)getProperty(P_REFERRAL_MODE);
|
||||
if(mode != null) {
|
||||
if(mode.equalsIgnoreCase(V_REFERRAL_FOLLOW)) {
|
||||
cons.setReferrals(true);
|
||||
String user = getUserDN(), passwd = getUserPassword();
|
||||
if (user != null && passwd != null) {
|
||||
cons.setRebindProc(new ReferralRebindProc(user, passwd));
|
||||
}
|
||||
}
|
||||
else if(mode.equalsIgnoreCase(V_REFERRAL_THROW_EXCEPTION)) {
|
||||
cons.setReferrals(false);
|
||||
}
|
||||
else if(mode.equalsIgnoreCase(V_REFERRAL_IGNORE)) {
|
||||
//TODO If MANAGEDSAIT control is not supported by the server
|
||||
//(e.g. Active Directory) should enable exception and ignore it
|
||||
cons.setServerControls(new LDAPControl(
|
||||
LDAPControl.MANAGEDSAIT, /*critical=*/false, null));
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException("Illegal value for " + P_REFERRAL_MODE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation for LDAPRebind interface. Provide user name, password
|
||||
* to autenticate with the referred to directory server.
|
||||
*/
|
||||
static class ReferralRebindProc implements LDAPRebind {
|
||||
LDAPRebindAuth auth;
|
||||
|
||||
public ReferralRebindProc(String user, String passwd) {
|
||||
auth = new LDAPRebindAuth(user, passwd);
|
||||
}
|
||||
|
||||
public LDAPRebindAuth getRebindAuthentication(String host, int port) {
|
||||
return auth;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Implementation for LDAPRebind interface. Provide user name, password
|
||||
* to autenticate with the referred to directory server.
|
||||
*/
|
||||
static class ReferralRebindProc implements LDAPRebind {
|
||||
LDAPRebindAuth auth;
|
||||
|
||||
public ReferralRebindProc(String user, String passwd) {
|
||||
auth = new LDAPRebindAuth(user, passwd);
|
||||
}
|
||||
|
||||
public LDAPRebindAuth getRebindAuthentication(String host, int port) {
|
||||
return auth;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set maximal number of referral hops under default SearchConstraints for the
|
||||
* connection.
|
||||
* Specified with the env property java.naming.referral.limit
|
||||
*/
|
||||
void updateReferralHopLimit(LDAPSearchConstraints cons) throws IllegalArgumentException{
|
||||
String limit = (String)getProperty(P_REFERRAL_HOPLIMIT);
|
||||
if(limit != null) {
|
||||
int n = -1;
|
||||
try {
|
||||
n = Integer.parseInt(limit);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new IllegalArgumentException("Illegal value for " + P_REFERRAL_HOPLIMIT);
|
||||
}
|
||||
cons.setHopLimit(n);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Set maximal number of referral hops under default SearchConstraints for the
|
||||
* connection.
|
||||
* Specified with the env property java.naming.referral.limit
|
||||
*/
|
||||
void updateReferralHopLimit(LDAPSearchConstraints cons) throws IllegalArgumentException{
|
||||
String limit = (String)getProperty(P_REFERRAL_HOPLIMIT);
|
||||
if(limit != null) {
|
||||
int n = -1;
|
||||
try {
|
||||
n = Integer.parseInt(limit);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new IllegalArgumentException("Illegal value for " + P_REFERRAL_HOPLIMIT);
|
||||
}
|
||||
cons.setHopLimit(n);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if simple auth mode is explicitly requested. If that's the case
|
||||
* user DN and password must be specified as well
|
||||
*/
|
||||
boolean useSimpleAuth() throws NamingException {
|
||||
String authMode = (String)getProperty(P_SECURITY_AUTHMODE);
|
||||
/**
|
||||
* Check if simple auth mode is explicitly requested. If that's the case
|
||||
* user DN and password must be specified as well
|
||||
*/
|
||||
boolean useSimpleAuth() throws NamingException {
|
||||
String authMode = (String)getProperty(P_SECURITY_AUTHMODE);
|
||||
if(authMode != null) {
|
||||
if(authMode.equalsIgnoreCase(V_AUTH_NONE)) {
|
||||
return false;
|
||||
}
|
||||
else if (authMode.equalsIgnoreCase(V_AUTH_SIMPLE)) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
throw new AuthenticationNotSupportedException(
|
||||
"Unsupported value for " + P_SECURITY_AUTHMODE);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if(authMode.equalsIgnoreCase(V_AUTH_NONE)) {
|
||||
return false;
|
||||
}
|
||||
else if (authMode.equalsIgnoreCase(V_AUTH_SIMPLE)) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
throw new AuthenticationNotSupportedException(
|
||||
"Unsupported value for " + P_SECURITY_AUTHMODE);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if SSL mode is enabled
|
||||
*/
|
||||
boolean isSSLEnabled() throws NamingException {
|
||||
String secMode = (String)getProperty(P_SECURITY_PROTOCOL);
|
||||
/**
|
||||
* Check if SSL mode is enabled
|
||||
*/
|
||||
boolean isSSLEnabled() throws NamingException {
|
||||
String secMode = (String)getProperty(P_SECURITY_PROTOCOL);
|
||||
if(secMode != null) {
|
||||
if(secMode.equalsIgnoreCase("ssl")) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
throw new AuthenticationNotSupportedException(
|
||||
"Unsupported value for " + P_SECURITY_PROTOCOL);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if(secMode.equalsIgnoreCase("ssl")) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
throw new AuthenticationNotSupportedException(
|
||||
"Unsupported value for " + P_SECURITY_PROTOCOL);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Directory Server URL
|
||||
*/
|
||||
LDAPUrl getDirectoryServerURL() throws NamingException{
|
||||
String url = (String) getProperty(Context.PROVIDER_URL);
|
||||
try {
|
||||
return (url == null) ? null : new LDAPUrl(url);
|
||||
}
|
||||
catch (java.net.MalformedURLException e) {
|
||||
throw new IllegalArgumentException(
|
||||
"Illegal value for " + Context.PROVIDER_URL);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Get the Directory Server URL
|
||||
*/
|
||||
LDAPUrl getDirectoryServerURL() throws NamingException{
|
||||
String url = (String) getProperty(Context.PROVIDER_URL);
|
||||
try {
|
||||
return (url == null) ? null : new LDAPUrl(url);
|
||||
}
|
||||
catch (java.net.MalformedURLException e) {
|
||||
throw new IllegalArgumentException(
|
||||
"Illegal value for " + Context.PROVIDER_URL);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Ldap Version. If not specified the default is version 3
|
||||
*/
|
||||
int getLdapVersion() throws NamingException{
|
||||
String version = (String) getProperty(P_LDAP_VERSION);
|
||||
if (version != null) {
|
||||
int v = -1;
|
||||
try {
|
||||
v = Integer.parseInt(version);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new IllegalArgumentException(
|
||||
"Illegal value for java.naming.ldap.version property.");
|
||||
}
|
||||
/*if ( v !=2 && v !=3) {
|
||||
throw new IllegalArgumentException(
|
||||
"Illegal value for + java.naming.ldap.version property.");
|
||||
}BLITS*/
|
||||
return v;
|
||||
}
|
||||
return DEFAULT_LDAP_VERSION;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user authenticate name
|
||||
*/
|
||||
String getUserDN() {
|
||||
return (String) getProperty(Context.SECURITY_PRINCIPAL);
|
||||
}
|
||||
/**
|
||||
* Get Ldap Version. If not specified the default is version 3
|
||||
*/
|
||||
int getLdapVersion() throws NamingException{
|
||||
String version = (String) getProperty(P_LDAP_VERSION);
|
||||
if (version != null) {
|
||||
int v = -1;
|
||||
try {
|
||||
v = Integer.parseInt(version);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new IllegalArgumentException(
|
||||
"Illegal value for java.naming.ldap.version property.");
|
||||
}
|
||||
/*if ( v !=2 && v !=3) {
|
||||
throw new IllegalArgumentException(
|
||||
"Illegal value for + java.naming.ldap.version property.");
|
||||
}BLITS*/
|
||||
return v;
|
||||
}
|
||||
return DEFAULT_LDAP_VERSION;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user authenticate name
|
||||
*/
|
||||
String getUserDN() {
|
||||
return (String) getProperty(Context.SECURITY_PRINCIPAL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user authenticate password
|
||||
*/
|
||||
String getUserPassword() {
|
||||
return (String) getProperty(Context.SECURITY_CREDENTIALS);
|
||||
}
|
||||
/**
|
||||
* Get user authenticate password
|
||||
*/
|
||||
String getUserPassword() {
|
||||
return (String) getProperty(Context.SECURITY_CREDENTIALS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get full qualified socket factory class name
|
||||
*/
|
||||
String getSocketFactory() {
|
||||
return (String)getProperty(P_SOCKET_FACTORY);
|
||||
}
|
||||
/**
|
||||
* Get full qualified socket factory class name
|
||||
*/
|
||||
String getSocketFactory() {
|
||||
return (String)getProperty(P_SOCKET_FACTORY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cipher suite for the socket factory
|
||||
*/
|
||||
Object getCipherSuite() {
|
||||
return getProperty(P_CIPHER_SUITE);
|
||||
}
|
||||
/**
|
||||
* Get cipher suite for the socket factory
|
||||
*/
|
||||
Object getCipherSuite() {
|
||||
return getProperty(P_CIPHER_SUITE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get controls to be used during a connection request like ProxyAuth
|
||||
*/
|
||||
LDAPControl[] getConnectControls() throws NamingException{
|
||||
Control[] reqCtls = (Control[])getProperty(P_CONNECT_CTRLS);
|
||||
if (reqCtls != null) {
|
||||
LDAPControl[] ldapCtls = new LDAPControl[reqCtls.length];
|
||||
for (int i=0; i < reqCtls.length; i++) {
|
||||
try {
|
||||
ldapCtls[i] = (LDAPControl) reqCtls[i];
|
||||
}
|
||||
catch (ClassCastException ex) {
|
||||
throw new NamingException(
|
||||
"Unsupported control type " + reqCtls[i].getClass().getName());
|
||||
/**
|
||||
* Get controls to be used during a connection request like ProxyAuth
|
||||
*/
|
||||
LDAPControl[] getConnectControls() throws NamingException{
|
||||
Control[] reqCtls = (Control[])getProperty(P_CONNECT_CTRLS);
|
||||
if (reqCtls != null) {
|
||||
LDAPControl[] ldapCtls = new LDAPControl[reqCtls.length];
|
||||
for (int i=0; i < reqCtls.length; i++) {
|
||||
try {
|
||||
ldapCtls[i] = (LDAPControl) reqCtls[i];
|
||||
}
|
||||
catch (ClassCastException ex) {
|
||||
throw new NamingException(
|
||||
"Unsupported control type " + reqCtls[i].getClass().getName());
|
||||
}
|
||||
}
|
||||
return ldapCtls;
|
||||
@ -457,81 +457,81 @@ class ContextEnv extends ShareableEnv {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Flag whether search operation should return attribute names only
|
||||
* (no values). Read environment property P_ATTRS_ONLY. If not defined
|
||||
* FALSE is returned (return attribute values by default)
|
||||
*/
|
||||
boolean getAttrsOnlyFlag() {
|
||||
String flag = (String)getProperty(P_ATTRS_ONLY);
|
||||
if (flag == null) {
|
||||
return false; //default
|
||||
}
|
||||
else if (flag.equalsIgnoreCase("true")) {
|
||||
return true;
|
||||
}
|
||||
else if (flag.equalsIgnoreCase("false")) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException("Illegal value for " + P_ATTRS_ONLY);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Flag whether search operation should return attribute names only
|
||||
* (no values). Read environment property P_ATTRS_ONLY. If not defined
|
||||
* FALSE is returned (return attribute values by default)
|
||||
*/
|
||||
boolean getAttrsOnlyFlag() {
|
||||
String flag = (String)getProperty(P_ATTRS_ONLY);
|
||||
if (flag == null) {
|
||||
return false; //default
|
||||
}
|
||||
else if (flag.equalsIgnoreCase("true")) {
|
||||
return true;
|
||||
}
|
||||
else if (flag.equalsIgnoreCase("false")) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException("Illegal value for " + P_ATTRS_ONLY);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Flag whether rename operation should delete old RDN
|
||||
* Read environment property P_ATTRS_ONLY. If not defined
|
||||
* TRUE is returned (delete old RDN by default)
|
||||
*/
|
||||
boolean getDeleteOldRDNFlag() {
|
||||
String flag = (String)getProperty(P_DELETE_OLDRDN);
|
||||
if (flag == null) {
|
||||
return true; //default
|
||||
}
|
||||
else if (flag.equalsIgnoreCase("true")) {
|
||||
return true;
|
||||
}
|
||||
else if (flag.equalsIgnoreCase("false")) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException("Illegal value for " + P_DELETE_OLDRDN);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Flag whether rename operation should delete old RDN
|
||||
* Read environment property P_ATTRS_ONLY. If not defined
|
||||
* TRUE is returned (delete old RDN by default)
|
||||
*/
|
||||
boolean getDeleteOldRDNFlag() {
|
||||
String flag = (String)getProperty(P_DELETE_OLDRDN);
|
||||
if (flag == null) {
|
||||
return true; //default
|
||||
}
|
||||
else if (flag.equalsIgnoreCase("true")) {
|
||||
return true;
|
||||
}
|
||||
else if (flag.equalsIgnoreCase("false")) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException("Illegal value for " + P_DELETE_OLDRDN);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A user defined value for the separator for JNDI References.
|
||||
* The default value is '#'.
|
||||
* Read environment property P_JNDIREF_SEPARATOR.
|
||||
*/
|
||||
char getRefSeparator() throws NamingException{
|
||||
String sep = (String)getProperty(P_JNDIREF_SEPARATOR );
|
||||
if(sep != null) {
|
||||
if (sep.length() !=1) {
|
||||
throw new IllegalArgumentException("Illegal value for " + P_JNDIREF_SEPARATOR);
|
||||
}
|
||||
return sep.charAt(0);
|
||||
}
|
||||
return '#';
|
||||
}
|
||||
/**
|
||||
* A user defined value for the separator for JNDI References.
|
||||
* The default value is '#'.
|
||||
* Read environment property P_JNDIREF_SEPARATOR.
|
||||
*/
|
||||
char getRefSeparator() throws NamingException{
|
||||
String sep = (String)getProperty(P_JNDIREF_SEPARATOR );
|
||||
if(sep != null) {
|
||||
if (sep.length() !=1) {
|
||||
throw new IllegalArgumentException("Illegal value for " + P_JNDIREF_SEPARATOR);
|
||||
}
|
||||
return sep.charAt(0);
|
||||
}
|
||||
return '#';
|
||||
}
|
||||
|
||||
/**
|
||||
* A user defined list of names of binary attributes. This list augments the
|
||||
* default list of well-known binary attributes. List entries are space separated
|
||||
* Read environment property P_BINARY_ATTRS.
|
||||
*/
|
||||
String[] getUserDefBinaryAttrs() {
|
||||
String binAttrList = (String)getProperty(P_BINARY_ATTRS);
|
||||
if (binAttrList == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
StringTokenizer tok = new StringTokenizer(binAttrList);
|
||||
String[] binAttrs = new String[tok.countTokens()];
|
||||
for (int i=0; tok.hasMoreTokens(); i++) {
|
||||
binAttrs[i] = tok.nextToken();
|
||||
}
|
||||
return binAttrs;
|
||||
}
|
||||
|
||||
/**
|
||||
* A user defined list of names of binary attributes. This list augments the
|
||||
* default list of well-known binary attributes. List entries are space separated
|
||||
* Read environment property P_BINARY_ATTRS.
|
||||
*/
|
||||
String[] getUserDefBinaryAttrs() {
|
||||
String binAttrList = (String)getProperty(P_BINARY_ATTRS);
|
||||
if (binAttrList == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
StringTokenizer tok = new StringTokenizer(binAttrList);
|
||||
String[] binAttrs = new String[tok.countTokens()];
|
||||
for (int i=0; tok.hasMoreTokens(); i++) {
|
||||
binAttrs[i] = tok.nextToken();
|
||||
}
|
||||
return binAttrs;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -47,10 +47,10 @@ class EventService implements Runnable{
|
||||
m_ldapSvc = ldapSvc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add change event listener
|
||||
*/
|
||||
synchronized void addListener (LdapContextImpl ctx, String name,
|
||||
/**
|
||||
* Add change event listener
|
||||
*/
|
||||
synchronized void addListener (LdapContextImpl ctx, String name,
|
||||
String filter,SearchControls jndiCtrls, NamingListener l)
|
||||
throws NamingException{
|
||||
|
||||
@ -59,43 +59,43 @@ class EventService implements Runnable{
|
||||
|
||||
Debug.println(1, "ADD LISTENER");
|
||||
|
||||
// Create DN by appending the name to the current context
|
||||
String base = ctx.getDN();
|
||||
if (name.length() > 0) {
|
||||
if (base.length() > 0) {
|
||||
base = name + "," + base;
|
||||
}
|
||||
else {
|
||||
base = name;
|
||||
}
|
||||
}
|
||||
|
||||
// Create DN by appending the name to the current context
|
||||
String base = ctx.getDN();
|
||||
if (name.length() > 0) {
|
||||
if (base.length() > 0) {
|
||||
base = name + "," + base;
|
||||
}
|
||||
else {
|
||||
base = name;
|
||||
}
|
||||
}
|
||||
|
||||
//Create search constraints
|
||||
LDAPConnection ld = (LDAPConnection) m_ldapSvc.getConnection().clone();
|
||||
LDAPSearchConstraints cons=ld.getSearchConstraints();
|
||||
LDAPPersistSearchControl psearchCtrl = createSrchCtrl(l);
|
||||
LDAPConnection ld = (LDAPConnection) m_ldapSvc.getConnection().clone();
|
||||
LDAPSearchConstraints cons=ld.getSearchConstraints();
|
||||
LDAPPersistSearchControl psearchCtrl = createSrchCtrl(l);
|
||||
cons.setServerControls(psearchCtrl);
|
||||
|
||||
// return obj flag is ignored in this implementation
|
||||
boolean returnObjs = jndiCtrls.getReturningObjFlag();
|
||||
|
||||
// Attributes in jndiCtrls.getReturningAttributes() are ignored
|
||||
// Attributes in jndiCtrls.getReturningAttributes() are ignored
|
||||
// This is because we are not returning objects in the NamingEvent
|
||||
// and thus listeners can not read attributes from the event.
|
||||
// Request only javaClassName to be able to determine object type
|
||||
String[] attrs = new String[] { "javaclassname" };
|
||||
|
||||
// Search scope
|
||||
int scope = ProviderUtils.jndiSearchScopeToLdap(jndiCtrls.getSearchScope());
|
||||
String[] attrs = new String[] { "javaclassname" };
|
||||
|
||||
// Search scope
|
||||
int scope = ProviderUtils.jndiSearchScopeToLdap(jndiCtrls.getSearchScope());
|
||||
|
||||
// Check if such change is already monitored, search for the event entry
|
||||
for (int i=0; i < m_eventList.size(); i++) {
|
||||
EventEntry ee = (EventEntry) m_eventList.elementAt(i);
|
||||
if (ee.isEqualEvent(base, scope, filter, attrs, cons)) {
|
||||
event = ee;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Check if such change is already monitored, search for the event entry
|
||||
for (int i=0; i < m_eventList.size(); i++) {
|
||||
EventEntry ee = (EventEntry) m_eventList.elementAt(i);
|
||||
if (ee.isEqualEvent(base, scope, filter, attrs, cons)) {
|
||||
event = ee;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// If event entry does not exist, send an asynch persistent search
|
||||
// request and create a new event entry
|
||||
@ -126,34 +126,34 @@ class EventService implements Runnable{
|
||||
m_msgQueue.merge(sl);
|
||||
}
|
||||
|
||||
// Create new event if reqested change is not already monitored
|
||||
if (m_monitorThread == null) {
|
||||
m_monitorThread = new Thread (this, "EventService");
|
||||
m_monitorThread.setDaemon(true);
|
||||
m_monitorThread.start();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove change event listener
|
||||
*/
|
||||
synchronized void removeListener(NamingListener listener)throws NamingException {
|
||||
boolean removed = false;
|
||||
// Create new event if reqested change is not already monitored
|
||||
if (m_monitorThread == null) {
|
||||
m_monitorThread = new Thread (this, "EventService");
|
||||
m_monitorThread.setDaemon(true);
|
||||
m_monitorThread.start();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove change event listener
|
||||
*/
|
||||
synchronized void removeListener(NamingListener listener)throws NamingException {
|
||||
boolean removed = false;
|
||||
|
||||
// Check and the listener against all event entries. If an event is
|
||||
// left with no listeners, abandon associated ldap request
|
||||
for(int i = m_eventList.size()-1; i>=0; i--) {
|
||||
EventEntry ee = (EventEntry)m_eventList.elementAt(i);
|
||||
if (ee.removeListener(listener)) {
|
||||
removed = true;
|
||||
EventEntry ee = (EventEntry)m_eventList.elementAt(i);
|
||||
if (ee.removeListener(listener)) {
|
||||
removed = true;
|
||||
|
||||
// If no listeners left abandon persistant search and
|
||||
// delete entry
|
||||
if (ee.isEmpty()) {
|
||||
if (ee.isEmpty()) {
|
||||
abandonRequest(ee.id);
|
||||
m_eventList.removeElement(ee);
|
||||
}
|
||||
}
|
||||
m_eventList.removeElement(ee);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Stop the monitor thread if no events are left
|
||||
@ -162,11 +162,11 @@ class EventService implements Runnable{
|
||||
if (m_eventList.size() == 0) {
|
||||
m_monitorThread = null;
|
||||
}
|
||||
|
||||
if (!removed) {
|
||||
throw new NamingException("Listener not found");
|
||||
}
|
||||
}
|
||||
|
||||
if (!removed) {
|
||||
throw new NamingException("Listener not found");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Abandon LDAP request with the specified message ID
|
||||
@ -174,11 +174,11 @@ class EventService implements Runnable{
|
||||
private void abandonRequest(int id) {
|
||||
LDAPConnection ldc = m_ldapSvc.getConnection();
|
||||
try {
|
||||
ldc.abandon(id);
|
||||
ldc.abandon(id);
|
||||
}
|
||||
catch (LDAPException ex) {}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Main monitor thread loop. Wait for persistent search change notifications
|
||||
@ -209,21 +209,21 @@ class EventService implements Runnable{
|
||||
|
||||
synchronized (EventService.this) {
|
||||
|
||||
EventEntry eventEntry = getEventEntry(msg.getId());
|
||||
EventEntry eventEntry = getEventEntry(msg.getID());
|
||||
|
||||
// If no listeners, abandon this message id
|
||||
if (eventEntry == null) {
|
||||
Debug.println(1, "Received ldap msg with unknown id="+msg.getId());
|
||||
Debug.println(1, "Received ldap msg with unknown id="+msg.getID());
|
||||
|
||||
if (! (msg instanceof LDAPResponse)) {
|
||||
abandonRequest(msg.getId());
|
||||
abandonRequest(msg.getID());
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check for error message ...
|
||||
if (msg instanceof LDAPResponse) {
|
||||
processResponseMsg((LDAPResponse) msg, eventEntry);
|
||||
processResponseMsg((LDAPResponse) msg, eventEntry);
|
||||
}
|
||||
|
||||
// ... or referral ...
|
||||
@ -276,7 +276,7 @@ class EventService implements Runnable{
|
||||
*/
|
||||
private void processSearchResultMsg(LDAPSearchResult res, EventEntry ee) {
|
||||
LDAPEntry modEntry = res.getEntry();
|
||||
|
||||
|
||||
Debug.println(1, "Changed " + modEntry.getDN());
|
||||
|
||||
/* Get any entry change controls. */
|
||||
@ -326,12 +326,12 @@ class EventService implements Runnable{
|
||||
* Find event entry by message ID
|
||||
*/
|
||||
private EventEntry getEventEntry(int id) {
|
||||
for (int i=0; i < m_eventList.size(); i++) {
|
||||
EventEntry ee = (EventEntry) m_eventList.elementAt(i);
|
||||
for (int i=0; i < m_eventList.size(); i++) {
|
||||
EventEntry ee = (EventEntry) m_eventList.elementAt(i);
|
||||
if (ee.id == id) {
|
||||
return ee;
|
||||
}
|
||||
}
|
||||
return ee;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -448,18 +448,18 @@ class EventService implements Runnable{
|
||||
* described with a set of search parameters, and a list of listeners
|
||||
*/
|
||||
static private class EventEntry {
|
||||
|
||||
LdapContextImpl ctx;
|
||||
|
||||
LdapContextImpl ctx;
|
||||
String base, filter, attrs[];
|
||||
int scope;
|
||||
LDAPSearchConstraints cons;
|
||||
int scope;
|
||||
LDAPSearchConstraints cons;
|
||||
int id; // ldap message id
|
||||
Vector listeners = new Vector(); // vector of NamingListener
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
EventEntry(int id, LdapContextImpl ctx, String base, int scope,
|
||||
EventEntry(int id, LdapContextImpl ctx, String base, int scope,
|
||||
String filter, String[] attrs, LDAPSearchConstraints cons) {
|
||||
|
||||
this.id = id;
|
||||
@ -496,8 +496,8 @@ class EventService implements Runnable{
|
||||
/**
|
||||
* Check whether this event paramaters are matched
|
||||
*/
|
||||
boolean isEqualEvent(String base, int scope, String filter,
|
||||
String[] attrs, LDAPSearchConstraints cons) {
|
||||
boolean isEqualEvent(String base, int scope, String filter,
|
||||
String[] attrs, LDAPSearchConstraints cons) {
|
||||
|
||||
if (!this.base.equals(base) || this.scope != scope ||
|
||||
!this.filter.equals(filter)) {
|
||||
|
@ -25,23 +25,23 @@ import java.util.*;
|
||||
|
||||
public class LdapContextFactory implements InitialContextFactory {
|
||||
|
||||
public Context getInitialContext(Hashtable env) throws NamingException {
|
||||
Hashtable ctxEnv = (Hashtable)env.clone();
|
||||
public Context getInitialContext(Hashtable env) throws NamingException {
|
||||
Hashtable ctxEnv = (Hashtable)env.clone();
|
||||
|
||||
// Read system properties as well. Add a system property to the
|
||||
// env if it's name start with "java.naming." and it is not already
|
||||
// present in the env (env has precedence over the System properties)
|
||||
for (Enumeration e = System.getProperties().keys(); e.hasMoreElements();) {
|
||||
// Read system properties as well. Add a system property to the
|
||||
// env if it's name start with "java.naming." and it is not already
|
||||
// present in the env (env has precedence over the System properties)
|
||||
for (Enumeration e = System.getProperties().keys(); e.hasMoreElements();) {
|
||||
String key = (String) e.nextElement();
|
||||
if (key.startsWith("java.naming.")) {
|
||||
if (ctxEnv.get(key) == null) {
|
||||
ctxEnv.put(key,System.getProperty(key));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (key.startsWith("java.naming.")) {
|
||||
if (ctxEnv.get(key) == null) {
|
||||
ctxEnv.put(key,System.getProperty(key));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
EventDirContext ctx = new LdapContextImpl(ctxEnv);
|
||||
return ctx;
|
||||
}
|
||||
EventDirContext ctx = new LdapContextImpl(ctxEnv);
|
||||
return ctx;
|
||||
}
|
||||
}
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -23,9 +23,9 @@ import javax.naming.*;
|
||||
|
||||
class LdapNameParser implements NameParser {
|
||||
|
||||
private static LdapNameParser m_parser;
|
||||
|
||||
// A table with compound name syntax properties
|
||||
private static LdapNameParser m_parser;
|
||||
|
||||
// A table with compound name syntax properties
|
||||
static Properties nameSyntax;
|
||||
static {
|
||||
nameSyntax = new Properties();
|
||||
@ -39,18 +39,18 @@ class LdapNameParser implements NameParser {
|
||||
nameSyntax.put("jndi.syntax.separator.typeval", "=");
|
||||
}
|
||||
|
||||
// Can not be constructed
|
||||
private LdapNameParser() {}
|
||||
|
||||
// Shared instance must be used
|
||||
public static LdapNameParser getParser() {
|
||||
if (m_parser == null) {
|
||||
m_parser = new LdapNameParser();
|
||||
}
|
||||
return m_parser;
|
||||
}
|
||||
|
||||
// implements parse
|
||||
// Can not be constructed
|
||||
private LdapNameParser() {}
|
||||
|
||||
// Shared instance must be used
|
||||
public static LdapNameParser getParser() {
|
||||
if (m_parser == null) {
|
||||
m_parser = new LdapNameParser();
|
||||
}
|
||||
return m_parser;
|
||||
}
|
||||
|
||||
// implements parse
|
||||
public Name parse(String name) throws NamingException {
|
||||
return new CompoundName(name, nameSyntax);
|
||||
}
|
||||
@ -64,7 +64,7 @@ class LdapNameParser implements NameParser {
|
||||
static String getRDN(String dn) throws NamingException {
|
||||
Name parsedName = getParser().parse(dn);
|
||||
if (parsedName.size() > 0) {
|
||||
return parsedName.get(parsedName.size()-1);
|
||||
return parsedName.get(parsedName.size()-1);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
@ -75,8 +75,8 @@ class LdapNameParser implements NameParser {
|
||||
* @param nameEqVal name=value
|
||||
*/
|
||||
static String getAttrName(String nameEqVal) throws NamingException {
|
||||
int eq = nameEqVal.indexOf("=");
|
||||
return (eq >= 0) ? nameEqVal.substring(0,eq).trim() : null;
|
||||
int eq = nameEqVal.indexOf("=");
|
||||
return (eq >= 0) ? nameEqVal.substring(0,eq).trim() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -85,8 +85,8 @@ class LdapNameParser implements NameParser {
|
||||
* @param nameEqVal name=value
|
||||
*/
|
||||
static String getAttrValue(String nameEqVal) throws NamingException {
|
||||
int eq = nameEqVal.indexOf("=");
|
||||
return (eq >= 0) ? nameEqVal.substring(eq+1).trim() : null;
|
||||
int eq = nameEqVal.indexOf("=");
|
||||
return (eq >= 0) ? nameEqVal.substring(eq+1).trim() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -95,17 +95,17 @@ class LdapNameParser implements NameParser {
|
||||
* @param ctx ancestor context distinguished name
|
||||
* @param entry distinguished name
|
||||
*/
|
||||
static String getRelativeName(String ctx, String entry) throws NamingException{
|
||||
if (entry==null) {
|
||||
entry = "";
|
||||
}
|
||||
Name contextName = getParser().parse(ctx);
|
||||
Name entryName = getParser().parse(entry);
|
||||
if (!entryName.startsWith(contextName)) {
|
||||
throw new NamingException("Name not in context");
|
||||
}
|
||||
return entryName.getSuffix(contextName.size()).toString();
|
||||
}
|
||||
static String getRelativeName(String ctx, String entry) throws NamingException{
|
||||
if (entry==null) {
|
||||
entry = "";
|
||||
}
|
||||
Name contextName = getParser().parse(ctx);
|
||||
Name entryName = getParser().parse(entry);
|
||||
if (!entryName.startsWith(contextName)) {
|
||||
throw new NamingException("Name not in context");
|
||||
}
|
||||
return entryName.getSuffix(contextName.size()).toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* A convenience method for extracting relative name from the ancestor context
|
||||
@ -113,52 +113,52 @@ class LdapNameParser implements NameParser {
|
||||
* @param ctx ancestor context distinguished name
|
||||
* @param entry distinguished name
|
||||
*/
|
||||
static String getRelativeName(Name contextName, String entry) throws NamingException{
|
||||
if (entry==null) {
|
||||
entry = "";
|
||||
}
|
||||
Name entryName = getParser().parse(entry);
|
||||
if (!entryName.startsWith(contextName)) {
|
||||
throw new NamingException("Name not in context");
|
||||
}
|
||||
return entryName.getSuffix(contextName.size()).toString();
|
||||
}
|
||||
static String getRelativeName(Name contextName, String entry) throws NamingException{
|
||||
if (entry==null) {
|
||||
entry = "";
|
||||
}
|
||||
Name entryName = getParser().parse(entry);
|
||||
if (!entryName.startsWith(contextName)) {
|
||||
throw new NamingException("Name not in context");
|
||||
}
|
||||
return entryName.getSuffix(contextName.size()).toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Unit test
|
||||
*/
|
||||
/**
|
||||
* Unit test
|
||||
*/
|
||||
public static void main0(String[] args) {
|
||||
if (args.length != 1) {
|
||||
System.out.println("Usage LdapNameParser <name>");
|
||||
System.exit(1);
|
||||
}
|
||||
try {
|
||||
Name name = getParser().parse(args[0]);
|
||||
System.out.println(name);
|
||||
System.out.println("rdn: " + getParser().getRDN(args[0]));
|
||||
name.add("attr=val");
|
||||
System.out.println(name);
|
||||
System.out.println(name.get(0));
|
||||
System.out.println("in name=val name:<" + getAttrName("name=val ") +
|
||||
"> val:<" + getAttrValue("name=val ") + ">");
|
||||
}
|
||||
catch (Exception e) {
|
||||
System.err.println(e);
|
||||
}
|
||||
}
|
||||
if (args.length != 1) {
|
||||
System.out.println("Usage LdapNameParser <name>");
|
||||
System.exit(1);
|
||||
}
|
||||
try {
|
||||
Name name = getParser().parse(args[0]);
|
||||
System.out.println(name);
|
||||
System.out.println("rdn: " + getParser().getRDN(args[0]));
|
||||
name.add("attr=val");
|
||||
System.out.println(name);
|
||||
System.out.println(name.get(0));
|
||||
System.out.println("in name=val name:<" + getAttrName("name=val ") +
|
||||
"> val:<" + getAttrValue("name=val ") + ">");
|
||||
}
|
||||
catch (Exception e) {
|
||||
System.err.println(e);
|
||||
}
|
||||
}
|
||||
|
||||
// Relative name test
|
||||
// Relative name test
|
||||
public static void main(String[] args) {
|
||||
if (args.length != 2) {
|
||||
System.out.println("Usage LdapNameParser <ctxname> <entryname>");
|
||||
System.exit(1);
|
||||
}
|
||||
try {
|
||||
System.out.println("relativeName: " + getParser().getRelativeName(args[0], args[1]));
|
||||
}
|
||||
catch (Exception e) {
|
||||
System.err.println(e);
|
||||
}
|
||||
}
|
||||
if (args.length != 2) {
|
||||
System.out.println("Usage LdapNameParser <ctxname> <entryname>");
|
||||
System.exit(1);
|
||||
}
|
||||
try {
|
||||
System.out.println("relativeName: " + getParser().getRelativeName(args[0], args[1]));
|
||||
}
|
||||
catch (Exception e) {
|
||||
System.err.println(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -40,124 +40,140 @@ import com.netscape.jndi.ldap.schema.SchemaRoot;
|
||||
*/
|
||||
class LdapService {
|
||||
|
||||
public static final String DEFAULT_FILTER = "(objectclass=*)";
|
||||
public static final int DEFAULT_SCOPE = LDAPv3.SCOPE_SUB;
|
||||
public static final String DEFAULT_HOST = "localhost";
|
||||
public static final int DEFAULT_PORT = LDAPv2.DEFAULT_PORT;
|
||||
public static final int DEFAULT_SSL_PORT = 636;
|
||||
|
||||
private LdapContextImpl m_initialCtx;
|
||||
private LDAPConnection m_ld;
|
||||
private EventService m_eventSvc;
|
||||
|
||||
/**
|
||||
* The number of contexts that are currently sharing this LdapService.
|
||||
* Essentially, a reference counter. Incremented in the LdapContextImpl
|
||||
* copy constructor. Decremented in the LdapService.disconnect().
|
||||
* When the count reaches zero, the LDAPConnection is released.
|
||||
*/
|
||||
private int m_clientCount;
|
||||
|
||||
|
||||
public LdapService(LdapContextImpl initialCtx) {
|
||||
m_initialCtx = initialCtx;
|
||||
m_ld = new LDAPConnection();
|
||||
m_clientCount = 1;
|
||||
}
|
||||
|
||||
LDAPConnection getConnection() {
|
||||
return m_ld;
|
||||
}
|
||||
|
||||
/**
|
||||
* Connect to the server and send bind request to authenticate the user
|
||||
*/
|
||||
void connect() throws NamingException{
|
||||
|
||||
if (m_ld.isConnected()) {
|
||||
return; //already connected
|
||||
}
|
||||
|
||||
LDAPUrl url = m_initialCtx.m_ctxEnv.getDirectoryServerURL();
|
||||
String host = (url != null) ? url.getHost() : DEFAULT_HOST;
|
||||
int port = (url != null) ? url.getPort() : DEFAULT_PORT;
|
||||
String user = m_initialCtx.m_ctxEnv.getUserDN();
|
||||
String passwd = m_initialCtx.m_ctxEnv.getUserPassword();
|
||||
String socketFactory = m_initialCtx.m_ctxEnv.getSocketFactory();
|
||||
Object cipherSuite = m_initialCtx.m_ctxEnv.getCipherSuite();
|
||||
int ldapVersion = m_initialCtx.m_ctxEnv.getLdapVersion();
|
||||
boolean isSSLEnabled = m_initialCtx.m_ctxEnv.isSSLEnabled();
|
||||
boolean useSimpleAuth= m_initialCtx.m_ctxEnv.useSimpleAuth();
|
||||
LDAPControl[] ldCtrls= m_initialCtx.m_ctxEnv.getConnectControls();
|
||||
|
||||
// Set default ssl port if DS not specifed
|
||||
if (isSSLEnabled && url == null) {
|
||||
port = DEFAULT_SSL_PORT;
|
||||
}
|
||||
|
||||
// SSL is enabled but no Socket factory specified. Use the
|
||||
// ldapjdk default one
|
||||
if (isSSLEnabled && socketFactory == null) {
|
||||
m_ld = new LDAPConnection(new LDAPSSLSocketFactory());
|
||||
}
|
||||
|
||||
// Set the socket factory and cipher suite if cpecified
|
||||
if (socketFactory != null) {
|
||||
try {
|
||||
LDAPSSLSocketFactory sf = null;
|
||||
if (cipherSuite != null) {
|
||||
Debug.println(1, "CIPHERS=" + cipherSuite);
|
||||
sf = new LDAPSSLSocketFactory(socketFactory, cipherSuite);
|
||||
}
|
||||
else {
|
||||
sf = new LDAPSSLSocketFactory(socketFactory);
|
||||
}
|
||||
m_ld = new LDAPConnection(sf);
|
||||
Debug.println(1, "SSL CONNECTION");
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new IllegalArgumentException(
|
||||
"Illegal value for java.naming.ldap.factory.socket: " + e);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
if (ldCtrls != null) {
|
||||
m_ld.setOption(LDAPv3.SERVERCONTROLS, ldCtrls);
|
||||
}
|
||||
m_ld.connect(ldapVersion, host, port, user, passwd);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw ExceptionMapper.getNamingException(e);
|
||||
}
|
||||
}
|
||||
|
||||
protected void finalize() {
|
||||
try {
|
||||
m_ld.disconnect();
|
||||
}
|
||||
catch (Exception e) {}
|
||||
public static final String DEFAULT_FILTER = "(objectclass=*)";
|
||||
public static final int DEFAULT_SCOPE = LDAPv3.SCOPE_SUB;
|
||||
public static final String DEFAULT_HOST = "localhost";
|
||||
public static final int DEFAULT_PORT = LDAPv2.DEFAULT_PORT;
|
||||
public static final int DEFAULT_SSL_PORT = 636;
|
||||
|
||||
private LdapContextImpl m_initialCtx;
|
||||
private LDAPConnection m_ld;
|
||||
private EventService m_eventSvc;
|
||||
|
||||
/**
|
||||
* The number of contexts that are currently sharing this LdapService.
|
||||
* Essentially, a reference counter. Incremented in the LdapContextImpl
|
||||
* copy constructor. Decremented in the LdapService.disconnect().
|
||||
* When the count reaches zero, the LDAPConnection is released.
|
||||
*/
|
||||
private int m_clientCount;
|
||||
|
||||
|
||||
public LdapService(LdapContextImpl initialCtx) {
|
||||
m_initialCtx = initialCtx;
|
||||
m_ld = new LDAPConnection();
|
||||
m_clientCount = 1;
|
||||
}
|
||||
|
||||
boolean isConnected() {
|
||||
return (m_ld.isConnected());
|
||||
}
|
||||
|
||||
LDAPConnection getConnection() {
|
||||
return m_ld;
|
||||
}
|
||||
|
||||
/**
|
||||
* Connect to the server and send bind request to authenticate the user
|
||||
*/
|
||||
void connect() throws NamingException{
|
||||
|
||||
if (m_ld.isConnected()) {
|
||||
return; //already connected
|
||||
}
|
||||
|
||||
LDAPUrl url = m_initialCtx.m_ctxEnv.getDirectoryServerURL();
|
||||
String host = (url != null) ? url.getHost() : DEFAULT_HOST;
|
||||
int port = (url != null) ? url.getPort() : DEFAULT_PORT;
|
||||
String user = m_initialCtx.m_ctxEnv.getUserDN();
|
||||
String passwd = m_initialCtx.m_ctxEnv.getUserPassword();
|
||||
String socketFactory = m_initialCtx.m_ctxEnv.getSocketFactory();
|
||||
Object cipherSuite = m_initialCtx.m_ctxEnv.getCipherSuite();
|
||||
int ldapVersion = m_initialCtx.m_ctxEnv.getLdapVersion();
|
||||
boolean isSSLEnabled = m_initialCtx.m_ctxEnv.isSSLEnabled();
|
||||
boolean useSimpleAuth= m_initialCtx.m_ctxEnv.useSimpleAuth();
|
||||
LDAPControl[] ldCtrls= m_initialCtx.m_ctxEnv.getConnectControls();
|
||||
|
||||
// Set default ssl port if DS not specifed
|
||||
if (isSSLEnabled && url == null) {
|
||||
port = DEFAULT_SSL_PORT;
|
||||
}
|
||||
|
||||
// SSL is enabled but no Socket factory specified. Use the
|
||||
// ldapjdk default one
|
||||
if (isSSLEnabled && socketFactory == null) {
|
||||
m_ld = new LDAPConnection(new LDAPSSLSocketFactory());
|
||||
}
|
||||
|
||||
// Set the socket factory and cipher suite if cpecified
|
||||
if (socketFactory != null) {
|
||||
try {
|
||||
LDAPSSLSocketFactory sf = null;
|
||||
if (cipherSuite != null) {
|
||||
Debug.println(1, "CIPHERS=" + cipherSuite);
|
||||
sf = new LDAPSSLSocketFactory(socketFactory, cipherSuite);
|
||||
}
|
||||
else {
|
||||
sf = new LDAPSSLSocketFactory(socketFactory);
|
||||
}
|
||||
m_ld = new LDAPConnection(sf);
|
||||
Debug.println(1, "SSL CONNECTION");
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new IllegalArgumentException(
|
||||
"Illegal value for java.naming.ldap.factory.socket: " + e);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
if (ldCtrls != null) {
|
||||
m_ld.setOption(LDAPv3.SERVERCONTROLS, ldCtrls);
|
||||
}
|
||||
m_ld.connect(ldapVersion, host, port, user, passwd);
|
||||
}
|
||||
catch (LDAPException e) {
|
||||
// If ldapVersion is not specified in ctx env
|
||||
// fallback to ldap v2 if v3 is bot supported
|
||||
if (e.getLDAPResultCode() == e.PROTOCOL_ERROR &&
|
||||
ldapVersion == 3 &&
|
||||
m_initialCtx.m_ctxEnv.getProperty(
|
||||
m_initialCtx.m_ctxEnv.P_LDAP_VERSION) == null) {
|
||||
|
||||
try {
|
||||
m_ld.connect(2, host, port, user, passwd);
|
||||
}
|
||||
catch (LDAPException e2) {
|
||||
throw ExceptionMapper.getNamingException(e2);
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw ExceptionMapper.getNamingException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void finalize() {
|
||||
try {
|
||||
m_ld.disconnect();
|
||||
}
|
||||
catch (Exception e) {}
|
||||
}
|
||||
|
||||
boolean isConnected() {
|
||||
return (m_ld.isConnected());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Physically disconect only if the client count is zero
|
||||
*/
|
||||
synchronized void disconnect() {
|
||||
try {
|
||||
if (m_clientCount > 0) {
|
||||
m_clientCount--;
|
||||
}
|
||||
if (m_clientCount == 0 && isConnected()) {
|
||||
m_ld.disconnect();
|
||||
}
|
||||
}
|
||||
catch (Exception e) {}
|
||||
}
|
||||
synchronized void disconnect() {
|
||||
try {
|
||||
if (m_clientCount > 0) {
|
||||
m_clientCount--;
|
||||
}
|
||||
if (m_clientCount == 0 && isConnected()) {
|
||||
m_ld.disconnect();
|
||||
}
|
||||
}
|
||||
catch (Exception e) {}
|
||||
}
|
||||
|
||||
/**
|
||||
* Increment client count
|
||||
@ -166,350 +182,350 @@ class LdapService {
|
||||
m_clientCount++;
|
||||
}
|
||||
|
||||
/**
|
||||
* LDAP search operation
|
||||
*/
|
||||
NamingEnumeration search (LdapContextImpl ctx, String name, String filter, String[] attrs, SearchControls jndiCtrls) throws NamingException{
|
||||
Debug.println(1, "SEARCH");
|
||||
String base = ctx.getDN();
|
||||
int scope = LDAPConnection.SCOPE_SUB;
|
||||
LDAPSearchConstraints cons=ctx.getSearchConstraints();
|
||||
boolean returnObjs = false;
|
||||
|
||||
connect(); // Lazy Connect
|
||||
/**
|
||||
* LDAP search operation
|
||||
*/
|
||||
NamingEnumeration search (LdapContextImpl ctx, String name, String filter, String[] attrs, SearchControls jndiCtrls) throws NamingException{
|
||||
Debug.println(1, "SEARCH");
|
||||
String base = ctx.getDN();
|
||||
int scope = LDAPConnection.SCOPE_SUB;
|
||||
LDAPSearchConstraints cons=ctx.getSearchConstraints();
|
||||
boolean returnObjs = false;
|
||||
|
||||
connect(); // Lazy Connect
|
||||
|
||||
// Create DN by appending the name to the current context
|
||||
if (name.length() > 0) {
|
||||
if (base.length() > 0) {
|
||||
base = name + "," + base;
|
||||
}
|
||||
else {
|
||||
base = name;
|
||||
}
|
||||
}
|
||||
|
||||
// Map JNDI SearchControls to ldapjdk LDAPSearchConstraints
|
||||
if (jndiCtrls != null) {
|
||||
int maxResults = (int)jndiCtrls.getCountLimit();
|
||||
int timeLimitInMsec = jndiCtrls.getTimeLimit();
|
||||
// Convert timeLimit in msec to sec
|
||||
int timeLimit = timeLimitInMsec/1000;
|
||||
if (timeLimitInMsec > 0 && timeLimitInMsec < 1000) {
|
||||
timeLimit = 1; //sec
|
||||
}
|
||||
|
||||
// Clone cons if maxResults or timeLimit is different from the default one
|
||||
if (cons.getServerTimeLimit() != timeLimit || cons.getMaxResults() != maxResults) {
|
||||
cons = (LDAPSearchConstraints)cons.clone();
|
||||
cons.setMaxResults(maxResults);
|
||||
cons.setServerTimeLimit(timeLimit);
|
||||
}
|
||||
|
||||
// TODO The concept of links is not well described in JNDI docs.
|
||||
// We can only specify dereferencing of Aliases, but Links and
|
||||
// Aliases are not the same; IGNORE jndiCtrls.getDerefLinkFlag()
|
||||
|
||||
// Attributes to return
|
||||
attrs = jndiCtrls.getReturningAttributes();
|
||||
if (attrs != null && attrs.length==0) {
|
||||
//return no attributes
|
||||
attrs = new String[] { "1.1" };
|
||||
// Create DN by appending the name to the current context
|
||||
if (name.length() > 0) {
|
||||
if (base.length() > 0) {
|
||||
base = name + "," + base;
|
||||
}
|
||||
else {
|
||||
base = name;
|
||||
}
|
||||
}
|
||||
|
||||
// Map JNDI SearchControls to ldapjdk LDAPSearchConstraints
|
||||
if (jndiCtrls != null) {
|
||||
int maxResults = (int)jndiCtrls.getCountLimit();
|
||||
int timeLimitInMsec = jndiCtrls.getTimeLimit();
|
||||
// Convert timeLimit in msec to sec
|
||||
int timeLimit = timeLimitInMsec/1000;
|
||||
if (timeLimitInMsec > 0 && timeLimitInMsec < 1000) {
|
||||
timeLimit = 1; //sec
|
||||
}
|
||||
|
||||
// Clone cons if maxResults or timeLimit is different from the default one
|
||||
if (cons.getServerTimeLimit() != timeLimit || cons.getMaxResults() != maxResults) {
|
||||
cons = (LDAPSearchConstraints)cons.clone();
|
||||
cons.setMaxResults(maxResults);
|
||||
cons.setServerTimeLimit(timeLimit);
|
||||
}
|
||||
|
||||
// TODO The concept of links is not well described in JNDI docs.
|
||||
// We can only specify dereferencing of Aliases, but Links and
|
||||
// Aliases are not the same; IGNORE jndiCtrls.getDerefLinkFlag()
|
||||
|
||||
// Attributes to return
|
||||
attrs = jndiCtrls.getReturningAttributes();
|
||||
if (attrs != null && attrs.length==0) {
|
||||
//return no attributes
|
||||
attrs = new String[] { "1.1" };
|
||||
|
||||
// TODO check whether ldap compare operation should be performed
|
||||
// That's the case if: (1) scope is OBJECT_SCOPE, (2) no attrs
|
||||
// are requested to return (3) filter has the form (name==value)
|
||||
// where no wildcards ()&|!=~><* are used.
|
||||
|
||||
}
|
||||
|
||||
// Search scope
|
||||
scope = ProviderUtils.jndiSearchScopeToLdap(jndiCtrls.getSearchScope());
|
||||
|
||||
}
|
||||
|
||||
// Search scope
|
||||
scope = ProviderUtils.jndiSearchScopeToLdap(jndiCtrls.getSearchScope());
|
||||
|
||||
// return obj flag
|
||||
returnObjs = jndiCtrls.getReturningObjFlag();
|
||||
}
|
||||
|
||||
try {
|
||||
// Perform Search
|
||||
boolean attrsOnly = ctx.m_ctxEnv.getAttrsOnlyFlag();
|
||||
LDAPSearchResults res = m_ld.search( base, scope, filter, attrs, attrsOnly, cons );
|
||||
return new SearchResultEnum(res, returnObjs, ctx);
|
||||
}
|
||||
catch (LDAPReferralException e) {
|
||||
throw new LdapReferralException(ctx, e);
|
||||
}
|
||||
catch (LDAPException e) {
|
||||
throw ExceptionMapper.getNamingException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* List child entries using LDAP lookup operation
|
||||
*/
|
||||
NamingEnumeration listEntries(LdapContextImpl ctx, String name, boolean returnBindings) throws NamingException{
|
||||
Debug.println(1, "LIST " + (returnBindings ? "BINDINGS" : ""));
|
||||
String base = ctx.getDN();
|
||||
}
|
||||
|
||||
try {
|
||||
// Perform Search
|
||||
boolean attrsOnly = ctx.m_ctxEnv.getAttrsOnlyFlag();
|
||||
LDAPSearchResults res = m_ld.search( base, scope, filter, attrs, attrsOnly, cons );
|
||||
return new SearchResultEnum(res, returnObjs, ctx);
|
||||
}
|
||||
catch (LDAPReferralException e) {
|
||||
throw new LdapReferralException(ctx, e);
|
||||
}
|
||||
catch (LDAPException e) {
|
||||
throw ExceptionMapper.getNamingException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* List child entries using LDAP lookup operation
|
||||
*/
|
||||
NamingEnumeration listEntries(LdapContextImpl ctx, String name, boolean returnBindings) throws NamingException{
|
||||
Debug.println(1, "LIST " + (returnBindings ? "BINDINGS" : ""));
|
||||
String base = ctx.getDN();
|
||||
|
||||
connect(); // Lazy Connect
|
||||
|
||||
// Create DN by appending the name to the current context
|
||||
if (name.length() > 0) {
|
||||
if (base.length() > 0) {
|
||||
base = name + "," + base;
|
||||
}
|
||||
else {
|
||||
base = name;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
// Perform One Level Search
|
||||
String[] attrs = null; // return all attributes if Bindings are requested
|
||||
if (!returnBindings) { // for ClassNamePairs
|
||||
attrs = new String[]{"javaclassname"}; //attr names must be in lowercase
|
||||
}
|
||||
LDAPSearchConstraints cons=ctx.getSearchConstraints();
|
||||
LDAPSearchResults res = m_ld.search( base, LDAPConnection.SCOPE_ONE, DEFAULT_FILTER, attrs, /*attrsOnly=*/false, cons);
|
||||
if (returnBindings) {
|
||||
return new BindingEnum(res, ctx);
|
||||
}
|
||||
else {
|
||||
return new NameClassPairEnum(res, ctx);
|
||||
}
|
||||
}
|
||||
catch (LDAPReferralException e) {
|
||||
throw new LdapReferralException(ctx, e);
|
||||
}
|
||||
catch (LDAPException e) {
|
||||
throw ExceptionMapper.getNamingException(e);
|
||||
}
|
||||
}
|
||||
connect(); // Lazy Connect
|
||||
|
||||
// Create DN by appending the name to the current context
|
||||
if (name.length() > 0) {
|
||||
if (base.length() > 0) {
|
||||
base = name + "," + base;
|
||||
}
|
||||
else {
|
||||
base = name;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
// Perform One Level Search
|
||||
String[] attrs = null; // return all attributes if Bindings are requested
|
||||
if (!returnBindings) { // for ClassNamePairs
|
||||
attrs = new String[]{"javaclassname"}; //attr names must be in lowercase
|
||||
}
|
||||
LDAPSearchConstraints cons=ctx.getSearchConstraints();
|
||||
LDAPSearchResults res = m_ld.search( base, LDAPConnection.SCOPE_ONE, DEFAULT_FILTER, attrs, /*attrsOnly=*/false, cons);
|
||||
if (returnBindings) {
|
||||
return new BindingEnum(res, ctx);
|
||||
}
|
||||
else {
|
||||
return new NameClassPairEnum(res, ctx);
|
||||
}
|
||||
}
|
||||
catch (LDAPReferralException e) {
|
||||
throw new LdapReferralException(ctx, e);
|
||||
}
|
||||
catch (LDAPException e) {
|
||||
throw ExceptionMapper.getNamingException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Lookup an entry using LDAP search operation
|
||||
*/
|
||||
Object lookup(LdapContextImpl ctx, String name) throws NamingException{
|
||||
Debug.println(1, "LOOKUP");
|
||||
String base = ctx.getDN();
|
||||
/**
|
||||
* Lookup an entry using LDAP search operation
|
||||
*/
|
||||
Object lookup(LdapContextImpl ctx, String name) throws NamingException{
|
||||
Debug.println(1, "LOOKUP");
|
||||
String base = ctx.getDN();
|
||||
|
||||
connect(); // Lazy Connect
|
||||
connect(); // Lazy Connect
|
||||
|
||||
// Create DN by appending the name to the current context
|
||||
if (name.length() > 0) {
|
||||
if (base.length() > 0) {
|
||||
base = name + "," + base;
|
||||
}
|
||||
else {
|
||||
base = name;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
// Perform Base Search
|
||||
String[] attrs = null; // return all attrs
|
||||
LDAPSearchConstraints cons=ctx.getSearchConstraints();
|
||||
LDAPSearchResults res = m_ld.search( base, LDAPConnection.SCOPE_BASE, DEFAULT_FILTER, attrs, /*attrsOnly=*/false, cons);
|
||||
if (res.hasMoreElements()) {
|
||||
LDAPEntry entry = res.next();
|
||||
return ObjectMapper.entryToObject(entry, ctx);
|
||||
}
|
||||
return null; // should never get here
|
||||
// Create DN by appending the name to the current context
|
||||
if (name.length() > 0) {
|
||||
if (base.length() > 0) {
|
||||
base = name + "," + base;
|
||||
}
|
||||
else {
|
||||
base = name;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
// Perform Base Search
|
||||
String[] attrs = null; // return all attrs
|
||||
LDAPSearchConstraints cons=ctx.getSearchConstraints();
|
||||
LDAPSearchResults res = m_ld.search( base, LDAPConnection.SCOPE_BASE, DEFAULT_FILTER, attrs, /*attrsOnly=*/false, cons);
|
||||
if (res.hasMoreElements()) {
|
||||
LDAPEntry entry = res.next();
|
||||
return ObjectMapper.entryToObject(entry, ctx);
|
||||
}
|
||||
return null; // should never get here
|
||||
|
||||
}
|
||||
catch (LDAPReferralException e) {
|
||||
throw new LdapReferralException(ctx, e);
|
||||
}
|
||||
catch (LDAPException e) {
|
||||
throw ExceptionMapper.getNamingException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (LDAPReferralException e) {
|
||||
throw new LdapReferralException(ctx, e);
|
||||
}
|
||||
catch (LDAPException e) {
|
||||
throw ExceptionMapper.getNamingException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read LDAP entry attributes
|
||||
*/
|
||||
Attributes readAttrs (LdapContextImpl ctx, String name, String[] attrs) throws NamingException{
|
||||
Debug.println(1, "READ ATTRS");
|
||||
String base = ctx.getDN();
|
||||
int scope = LDAPConnection.SCOPE_BASE;
|
||||
|
||||
connect(); // Lazy Connect
|
||||
/**
|
||||
* Read LDAP entry attributes
|
||||
*/
|
||||
Attributes readAttrs (LdapContextImpl ctx, String name, String[] attrs) throws NamingException{
|
||||
Debug.println(1, "READ ATTRS");
|
||||
String base = ctx.getDN();
|
||||
int scope = LDAPConnection.SCOPE_BASE;
|
||||
|
||||
connect(); // Lazy Connect
|
||||
|
||||
// Create DN by appending the name to the current context
|
||||
if (name.length() > 0) {
|
||||
if (base.length() > 0) {
|
||||
base = name + "," + base;
|
||||
}
|
||||
else {
|
||||
base = name;
|
||||
}
|
||||
}
|
||||
// Create DN by appending the name to the current context
|
||||
if (name.length() > 0) {
|
||||
if (base.length() > 0) {
|
||||
base = name + "," + base;
|
||||
}
|
||||
else {
|
||||
base = name;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
// Perform Search
|
||||
LDAPSearchConstraints cons=ctx.getSearchConstraints();
|
||||
LDAPSearchResults res = m_ld.search(base, scope, DEFAULT_FILTER, attrs, /*attrsOnly=*/false, cons);
|
||||
while (res.hasMoreElements()) {
|
||||
LDAPEntry entry = res.next();
|
||||
return new AttributesImpl(entry.getAttributeSet(),
|
||||
ctx.m_ctxEnv.getUserDefBinaryAttrs());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
catch (LDAPReferralException e) {
|
||||
throw new LdapReferralException(ctx, e);
|
||||
}
|
||||
catch (LDAPException e) {
|
||||
throw ExceptionMapper.getNamingException(e);
|
||||
}
|
||||
}
|
||||
try {
|
||||
// Perform Search
|
||||
LDAPSearchConstraints cons=ctx.getSearchConstraints();
|
||||
LDAPSearchResults res = m_ld.search(base, scope, DEFAULT_FILTER, attrs, /*attrsOnly=*/false, cons);
|
||||
while (res.hasMoreElements()) {
|
||||
LDAPEntry entry = res.next();
|
||||
return new AttributesImpl(entry.getAttributeSet(),
|
||||
ctx.m_ctxEnv.getUserDefBinaryAttrs());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
catch (LDAPReferralException e) {
|
||||
throw new LdapReferralException(ctx, e);
|
||||
}
|
||||
catch (LDAPException e) {
|
||||
throw ExceptionMapper.getNamingException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Modify LDAP entry attributes
|
||||
*/
|
||||
void modifyEntry(LdapContextImpl ctx, String name, LDAPModificationSet mods) throws NamingException{
|
||||
Debug.println(1, "MODIFY");
|
||||
String base = ctx.getDN();
|
||||
|
||||
if (mods.size() == 0) {
|
||||
return;
|
||||
}
|
||||
connect(); // Lazy Connect
|
||||
/**
|
||||
* Modify LDAP entry attributes
|
||||
*/
|
||||
void modifyEntry(LdapContextImpl ctx, String name, LDAPModificationSet mods) throws NamingException{
|
||||
Debug.println(1, "MODIFY");
|
||||
String base = ctx.getDN();
|
||||
|
||||
if (mods.size() == 0) {
|
||||
return;
|
||||
}
|
||||
connect(); // Lazy Connect
|
||||
|
||||
// Create DN by appending the name to the current context
|
||||
if (name.length() > 0) {
|
||||
if (base.length() > 0) {
|
||||
base = name + "," + base;
|
||||
}
|
||||
else {
|
||||
base = name;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
// Perform Modify
|
||||
m_ld.modify(base, mods);
|
||||
}
|
||||
catch (LDAPReferralException e) {
|
||||
throw new LdapReferralException(ctx, e);
|
||||
}
|
||||
catch (LDAPException e) {
|
||||
throw ExceptionMapper.getNamingException(e);
|
||||
}
|
||||
}
|
||||
// Create DN by appending the name to the current context
|
||||
if (name.length() > 0) {
|
||||
if (base.length() > 0) {
|
||||
base = name + "," + base;
|
||||
}
|
||||
else {
|
||||
base = name;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
// Perform Modify
|
||||
m_ld.modify(base, mods);
|
||||
}
|
||||
catch (LDAPReferralException e) {
|
||||
throw new LdapReferralException(ctx, e);
|
||||
}
|
||||
catch (LDAPException e) {
|
||||
throw ExceptionMapper.getNamingException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new LDAP entry
|
||||
*/
|
||||
LdapContextImpl addEntry(LdapContextImpl ctx, String name, LDAPAttributeSet attrs) throws NamingException{
|
||||
Debug.println(1, "ADD");
|
||||
String dn = ctx.getDN();
|
||||
|
||||
connect(); // Lazy Connect
|
||||
/**
|
||||
* Create a new LDAP entry
|
||||
*/
|
||||
LdapContextImpl addEntry(LdapContextImpl ctx, String name, LDAPAttributeSet attrs) throws NamingException{
|
||||
Debug.println(1, "ADD");
|
||||
String dn = ctx.getDN();
|
||||
|
||||
connect(); // Lazy Connect
|
||||
|
||||
// Create DN by appending the name to the current context
|
||||
if (name.length() == 0) {
|
||||
throw new IllegalArgumentException("Name can not be empty");
|
||||
}
|
||||
if (dn.length() > 0) {
|
||||
dn = name + "," + dn;
|
||||
}
|
||||
else {
|
||||
dn = name;
|
||||
}
|
||||
|
||||
try {
|
||||
// Add a new entry
|
||||
m_ld.add(new LDAPEntry(dn, attrs));
|
||||
return new LdapContextImpl(dn, ctx);
|
||||
}
|
||||
catch (LDAPReferralException e) {
|
||||
throw new LdapReferralException(ctx, e);
|
||||
}
|
||||
catch (LDAPException e) {
|
||||
throw ExceptionMapper.getNamingException(e);
|
||||
}
|
||||
}
|
||||
// Create DN by appending the name to the current context
|
||||
if (name.length() == 0) {
|
||||
throw new IllegalArgumentException("Name can not be empty");
|
||||
}
|
||||
if (dn.length() > 0) {
|
||||
dn = name + "," + dn;
|
||||
}
|
||||
else {
|
||||
dn = name;
|
||||
}
|
||||
|
||||
try {
|
||||
// Add a new entry
|
||||
m_ld.add(new LDAPEntry(dn, attrs));
|
||||
return new LdapContextImpl(dn, ctx);
|
||||
}
|
||||
catch (LDAPReferralException e) {
|
||||
throw new LdapReferralException(ctx, e);
|
||||
}
|
||||
catch (LDAPException e) {
|
||||
throw ExceptionMapper.getNamingException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a LDAP entry
|
||||
*/
|
||||
void delEntry(LdapContextImpl ctx, String name) throws NamingException{
|
||||
Debug.println(1, "DELETE");
|
||||
String dn = ctx.getDN();
|
||||
|
||||
connect(); // Lazy Connect
|
||||
/**
|
||||
* Delete a LDAP entry
|
||||
*/
|
||||
void delEntry(LdapContextImpl ctx, String name) throws NamingException{
|
||||
Debug.println(1, "DELETE");
|
||||
String dn = ctx.getDN();
|
||||
|
||||
connect(); // Lazy Connect
|
||||
|
||||
// Create DN by appending the name to the current context
|
||||
if (name.length() == 0) {
|
||||
throw new IllegalArgumentException("Name can not be empty");
|
||||
}
|
||||
if (dn.length() > 0) {
|
||||
dn = name + "," + dn;
|
||||
}
|
||||
else {
|
||||
dn = name;
|
||||
}
|
||||
|
||||
try {
|
||||
// Perform Delete
|
||||
m_ld.delete(dn);
|
||||
}
|
||||
catch (LDAPReferralException e) {
|
||||
throw new LdapReferralException(ctx, e);
|
||||
}
|
||||
catch (LDAPException e) {
|
||||
throw ExceptionMapper.getNamingException(e);
|
||||
}
|
||||
}
|
||||
// Create DN by appending the name to the current context
|
||||
if (name.length() == 0) {
|
||||
throw new IllegalArgumentException("Name can not be empty");
|
||||
}
|
||||
if (dn.length() > 0) {
|
||||
dn = name + "," + dn;
|
||||
}
|
||||
else {
|
||||
dn = name;
|
||||
}
|
||||
|
||||
try {
|
||||
// Perform Delete
|
||||
m_ld.delete(dn);
|
||||
}
|
||||
catch (LDAPReferralException e) {
|
||||
throw new LdapReferralException(ctx, e);
|
||||
}
|
||||
catch (LDAPException e) {
|
||||
throw ExceptionMapper.getNamingException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Chanage RDN for a LDAP entry
|
||||
*/
|
||||
void changeRDN(LdapContextImpl ctx, String name, String newRDN) throws NamingException{
|
||||
Debug.println(1, "RENAME");
|
||||
String dn = ctx.getDN();
|
||||
|
||||
connect(); // Lazy Connect
|
||||
/**
|
||||
* Chanage RDN for a LDAP entry
|
||||
*/
|
||||
void changeRDN(LdapContextImpl ctx, String name, String newRDN) throws NamingException{
|
||||
Debug.println(1, "RENAME");
|
||||
String dn = ctx.getDN();
|
||||
|
||||
connect(); // Lazy Connect
|
||||
|
||||
// Create DN by appending the name to the current context
|
||||
if (name.length() == 0 || newRDN.length() == 0) {
|
||||
throw new IllegalArgumentException("Name can not be empty");
|
||||
}
|
||||
if (dn.length() > 0) {
|
||||
dn = name + "," + dn;
|
||||
}
|
||||
else {
|
||||
dn = name;
|
||||
}
|
||||
// Create DN by appending the name to the current context
|
||||
if (name.length() == 0 || newRDN.length() == 0) {
|
||||
throw new IllegalArgumentException("Name can not be empty");
|
||||
}
|
||||
if (dn.length() > 0) {
|
||||
dn = name + "," + dn;
|
||||
}
|
||||
else {
|
||||
dn = name;
|
||||
}
|
||||
|
||||
try {
|
||||
// Rename
|
||||
m_ld.rename(dn, newRDN, ctx.m_ctxEnv.getDeleteOldRDNFlag());
|
||||
}
|
||||
catch (LDAPReferralException e) {
|
||||
throw new LdapReferralException(ctx, e);
|
||||
}
|
||||
catch (LDAPException e) {
|
||||
throw ExceptionMapper.getNamingException(e);
|
||||
}
|
||||
}
|
||||
try {
|
||||
// Rename
|
||||
m_ld.rename(dn, newRDN, ctx.m_ctxEnv.getDeleteOldRDNFlag());
|
||||
}
|
||||
catch (LDAPReferralException e) {
|
||||
throw new LdapReferralException(ctx, e);
|
||||
}
|
||||
catch (LDAPException e) {
|
||||
throw ExceptionMapper.getNamingException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Schema Operations
|
||||
*/
|
||||
DirContext getSchema(String name) throws NamingException {
|
||||
connect(); // Lazy Connect
|
||||
return new SchemaRoot(m_ld);
|
||||
}
|
||||
/**
|
||||
* Schema Operations
|
||||
*/
|
||||
DirContext getSchema(String name) throws NamingException {
|
||||
connect(); // Lazy Connect
|
||||
return new SchemaRoot(m_ld);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the event service
|
||||
*/
|
||||
EventService getEventService() throws NamingException {
|
||||
connect(); // Lazy Connect
|
||||
if (m_eventSvc == null) {
|
||||
m_eventSvc = new EventService(this);
|
||||
}
|
||||
return m_eventSvc;
|
||||
}
|
||||
EventService getEventService() throws NamingException {
|
||||
connect(); // Lazy Connect
|
||||
if (m_eventSvc == null) {
|
||||
m_eventSvc = new EventService(this);
|
||||
}
|
||||
return m_eventSvc;
|
||||
}
|
||||
}
|
||||
|
@ -33,63 +33,63 @@ import java.util.*;
|
||||
*/
|
||||
class NameClassPairEnum implements NamingEnumeration {
|
||||
|
||||
LDAPSearchResults m_res;
|
||||
LdapContextImpl m_ctx;
|
||||
Name m_ctxName;
|
||||
|
||||
public NameClassPairEnum(LDAPSearchResults res, LdapContextImpl ctx) throws NamingException{
|
||||
m_res = res;
|
||||
m_ctx = ctx;
|
||||
try {
|
||||
m_ctxName = LdapNameParser.getParser().parse(m_ctx.m_ctxDN);
|
||||
}
|
||||
catch ( NamingException e ) {
|
||||
throw ExceptionMapper.getNamingException(e);
|
||||
}
|
||||
}
|
||||
LDAPSearchResults m_res;
|
||||
LdapContextImpl m_ctx;
|
||||
Name m_ctxName;
|
||||
|
||||
public NameClassPairEnum(LDAPSearchResults res, LdapContextImpl ctx) throws NamingException{
|
||||
m_res = res;
|
||||
m_ctx = ctx;
|
||||
try {
|
||||
m_ctxName = LdapNameParser.getParser().parse(m_ctx.m_ctxDN);
|
||||
}
|
||||
catch ( NamingException e ) {
|
||||
throw ExceptionMapper.getNamingException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public Object next() throws NamingException{
|
||||
try {
|
||||
LDAPEntry entry = m_res.next();
|
||||
String name = LdapNameParser.getRelativeName(m_ctxName, entry.getDN());
|
||||
String className = ObjectMapper.getClassName(entry);
|
||||
return new NameClassPair(name, className, /*isRelative=*/true);
|
||||
public Object next() throws NamingException{
|
||||
try {
|
||||
LDAPEntry entry = m_res.next();
|
||||
String name = LdapNameParser.getRelativeName(m_ctxName, entry.getDN());
|
||||
String className = ObjectMapper.getClassName(entry);
|
||||
return new NameClassPair(name, className, /*isRelative=*/true);
|
||||
|
||||
}
|
||||
catch (LDAPReferralException e) {
|
||||
throw new LdapReferralException(m_ctx, e);
|
||||
}
|
||||
catch ( LDAPException e ) {
|
||||
throw ExceptionMapper.getNamingException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (LDAPReferralException e) {
|
||||
throw new LdapReferralException(m_ctx, e);
|
||||
}
|
||||
catch ( LDAPException e ) {
|
||||
throw ExceptionMapper.getNamingException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public Object nextElement() {
|
||||
try {
|
||||
return next();
|
||||
}
|
||||
catch ( Exception e ) {
|
||||
System.err.println( "Error in NameClassPairEnum.nextElement(): " + e.toString() );
|
||||
e.printStackTrace(System.err);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public Object nextElement() {
|
||||
try {
|
||||
return next();
|
||||
}
|
||||
catch ( Exception e ) {
|
||||
System.err.println( "Error in NameClassPairEnum.nextElement(): " + e.toString() );
|
||||
e.printStackTrace(System.err);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasMore() throws NamingException{
|
||||
return m_res.hasMoreElements();
|
||||
}
|
||||
public boolean hasMore() throws NamingException{
|
||||
return m_res.hasMoreElements();
|
||||
}
|
||||
|
||||
public boolean hasMoreElements() {
|
||||
return m_res.hasMoreElements();
|
||||
}
|
||||
public boolean hasMoreElements() {
|
||||
return m_res.hasMoreElements();
|
||||
}
|
||||
|
||||
public void close() throws NamingException{
|
||||
try {
|
||||
m_ctx.m_ldapSvc.getConnection().abandon(m_res);
|
||||
}
|
||||
catch (LDAPException e) {
|
||||
throw ExceptionMapper.getNamingException(e);
|
||||
}
|
||||
}
|
||||
public void close() throws NamingException{
|
||||
try {
|
||||
m_ctx.m_ldapSvc.getConnection().abandon(m_res);
|
||||
}
|
||||
catch (LDAPException e) {
|
||||
throw ExceptionMapper.getNamingException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -14,402 +14,402 @@ import com.netscape.jndi.ldap.common.Debug;
|
||||
*/
|
||||
public class ObjectMapper {
|
||||
|
||||
/**
|
||||
* Schema object classes for mapping java objects to ldap entries
|
||||
*/
|
||||
static final String OC_JAVAOBJECT = "javaObject"; // abstract oc
|
||||
static final String OC_SERIALOBJ = "javaSerializedObject";//aux oc
|
||||
static final String OC_REFERENCE = "javaNamingReference"; //aux oc
|
||||
static final String OC_REMOTEOBJ = "javaRemoteObject"; //aux oc
|
||||
static final String OC_CONTAINER = "javaContainer"; //structural oc
|
||||
/**
|
||||
* Schema object classes for mapping java objects to ldap entries
|
||||
*/
|
||||
static final String OC_JAVAOBJECT = "javaObject"; // abstract oc
|
||||
static final String OC_SERIALOBJ = "javaSerializedObject";//aux oc
|
||||
static final String OC_REFERENCE = "javaNamingReference"; //aux oc
|
||||
static final String OC_REMOTEOBJ = "javaRemoteObject"; //aux oc
|
||||
static final String OC_CONTAINER = "javaContainer"; //structural oc
|
||||
|
||||
/**
|
||||
* Schema attributes for mapping java objects to ldap entries
|
||||
*/
|
||||
static final String AT_CLASSNAME = "javaClassName"; //required
|
||||
static final String AT_CODEBASE = "javaCodeBase"; //optional
|
||||
static final String AT_SERIALDATA = "javaSerializedData"; //required
|
||||
static final String AT_REFADDR = "javaReferenceAddress"; //optional
|
||||
static final String AT_OBJFACTORY = "javaFactory"; //optional
|
||||
static final String AT_REMOTELOC = "javaRemoteLocation"; //required
|
||||
|
||||
//Default Object class for NameClassPair
|
||||
static final String DEFAULT_OBJCLASS = "javax.naming.directory.DirContext";
|
||||
|
||||
static Object entryToObject(LDAPEntry entry, LdapContextImpl ctx) throws NamingException {
|
||||
Object obj = entryToObject(entry);
|
||||
if (obj == null) {
|
||||
obj = new LdapContextImpl(entry.getDN(), ctx);
|
||||
}
|
||||
/**
|
||||
* Schema attributes for mapping java objects to ldap entries
|
||||
*/
|
||||
static final String AT_CLASSNAME = "javaClassName"; //required
|
||||
static final String AT_CODEBASE = "javaCodeBase"; //optional
|
||||
static final String AT_SERIALDATA = "javaSerializedData"; //required
|
||||
static final String AT_REFADDR = "javaReferenceAddress"; //optional
|
||||
static final String AT_OBJFACTORY = "javaFactory"; //optional
|
||||
static final String AT_REMOTELOC = "javaRemoteLocation"; //required
|
||||
|
||||
//Default Object class for NameClassPair
|
||||
static final String DEFAULT_OBJCLASS = "javax.naming.directory.DirContext";
|
||||
|
||||
static Object entryToObject(LDAPEntry entry, LdapContextImpl ctx) throws NamingException {
|
||||
Object obj = entryToObject(entry);
|
||||
if (obj == null) {
|
||||
obj = new LdapContextImpl(entry.getDN(), ctx);
|
||||
}
|
||||
|
||||
// SP is required to contact the NamingManager first to obtain an object
|
||||
try {
|
||||
String relName = LdapNameParser.getRelativeName(ctx.m_ctxDN, entry.getDN());
|
||||
Name nameObj = LdapNameParser.getParser().parse(relName);
|
||||
obj = NamingManager.getObjectInstance(obj, nameObj, ctx, ctx.getEnvironment());
|
||||
}
|
||||
catch (Exception ex) {
|
||||
if (ex instanceof NamingException) {
|
||||
throw (NamingException)ex;
|
||||
}
|
||||
NamingException nameEx = new NamingException("NamingManager.getObjectInstance failed");
|
||||
nameEx.setRootCause(ex);
|
||||
throw nameEx;
|
||||
}
|
||||
|
||||
return obj;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a Ldap entry into a java object
|
||||
*/
|
||||
static Object entryToObject(LDAPEntry entry) throws NamingException {
|
||||
|
||||
try {
|
||||
LDAPAttributeSet attrs = entry.getAttributeSet();
|
||||
|
||||
// TODO javaCodeBase to be processed
|
||||
|
||||
LDAPAttribute attr = null;
|
||||
if ((attr = attrs.getAttribute(AT_SERIALDATA)) != null) {
|
||||
byte[] serdata = (byte[])attr.getByteValues().nextElement();
|
||||
return deserializeObject(serdata);
|
||||
}
|
||||
|
||||
// Reference
|
||||
else if ((attr = attrs.getAttribute(AT_REFADDR)) != null) {
|
||||
return decodeRefObj(attrs);
|
||||
}
|
||||
|
||||
// RMI Object
|
||||
else if ((attr = attrs.getAttribute(AT_REMOTELOC)) != null) {
|
||||
String rmiURL = (String)attr.getByteValues().nextElement();
|
||||
return java.rmi.Naming.lookup(rmiURL);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
catch (Exception ex) {
|
||||
if (ex instanceof NamingException) {
|
||||
throw (NamingException)ex;
|
||||
}
|
||||
NamingException nameEx = new NamingException("NamingManager.getStateToStore failed");
|
||||
nameEx.setRootCause(ex);
|
||||
throw nameEx;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the className for NameClassPair from an entry
|
||||
*/
|
||||
static String getClassName(LDAPEntry entry) {
|
||||
LDAPAttributeSet attrs = entry.getAttributeSet();
|
||||
LDAPAttribute attrClass = attrs.getAttribute(AT_CLASSNAME);
|
||||
if (attrClass != null) {
|
||||
String className = (String)attrClass.getStringValues().nextElement();
|
||||
return className;
|
||||
}
|
||||
return DEFAULT_OBJCLASS;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert a java object with an optional set of attributes into a LDAP entry
|
||||
*/
|
||||
static LDAPAttributeSet objectToAttrSet(Object obj, String name, LdapContextImpl ctx, Attributes attrs) throws NamingException {
|
||||
|
||||
// SP is required to contact the NamingManager first to obtain a state object
|
||||
try {
|
||||
Name nameObj = LdapNameParser.getParser().parse(name);
|
||||
obj = NamingManager.getStateToBind(obj, nameObj, ctx, ctx.getEnvironment());
|
||||
}
|
||||
catch (Exception ex) {
|
||||
if (ex instanceof NamingException) {
|
||||
throw (NamingException)ex;
|
||||
}
|
||||
NamingException nameEx = new NamingException("NamingManager.getStateToStore failed");
|
||||
nameEx.setRootCause(ex);
|
||||
throw nameEx;
|
||||
}
|
||||
|
||||
if (attrs == null) {
|
||||
attrs = new BasicAttributes(/*ignoreCase=*/true);
|
||||
}
|
||||
|
||||
Attribute objectclass = attrs.get("objectClass");
|
||||
if (objectclass == null) {
|
||||
objectclass = new BasicAttribute("objectClass", "top");
|
||||
attrs.put(objectclass);
|
||||
}
|
||||
|
||||
// Root object class
|
||||
objectclass.add(OC_JAVAOBJECT);
|
||||
|
||||
if (obj instanceof Reference) {
|
||||
objectclass.add(OC_REFERENCE);
|
||||
char delimChar = ctx.m_ctxEnv.getRefSeparator();
|
||||
attrs = encodeRefObj(delimChar, (Reference)obj, attrs);
|
||||
}
|
||||
|
||||
else if (obj instanceof Referenceable) {
|
||||
objectclass.add(OC_REFERENCE);
|
||||
char delimChar = ctx.m_ctxEnv.getRefSeparator();
|
||||
attrs = encodeRefObj(delimChar, ((Referenceable)obj).getReference(), attrs);
|
||||
}
|
||||
|
||||
else if (obj instanceof java.rmi.Remote) {
|
||||
objectclass.add(OC_REMOTEOBJ);
|
||||
attrs = encodeRMIObj((java.rmi.Remote)obj, attrs);
|
||||
}
|
||||
|
||||
else if (obj instanceof Serializable) {
|
||||
objectclass.add(OC_SERIALOBJ);
|
||||
attrs = encodeSerialObj((Serializable)obj , attrs);
|
||||
}
|
||||
|
||||
else if (obj instanceof DirContext) {
|
||||
attrs = encodeDirCtxObj((DirContext)obj , attrs);
|
||||
}
|
||||
|
||||
else {
|
||||
throw new NamingException("Can not bind object of type " +
|
||||
obj.getClass().getName());
|
||||
}
|
||||
|
||||
return AttributesImpl.jndiAttrsToLdapAttrSet(attrs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserialized object, create object from a stream of bytes
|
||||
*/
|
||||
private static Object deserializeObject(byte[] byteBuf) throws NamingException {
|
||||
|
||||
ByteArrayInputStream bis = null;
|
||||
ObjectInputStream objis = null;
|
||||
|
||||
try {
|
||||
bis = new ByteArrayInputStream(byteBuf);
|
||||
objis = new ObjectInputStream(bis);
|
||||
return objis.readObject();
|
||||
}
|
||||
catch(Exception ex) {
|
||||
NamingException nameEx = new NamingException("Failed to deserialize object");
|
||||
nameEx.setRootCause(ex);
|
||||
throw nameEx;
|
||||
}
|
||||
finally {
|
||||
try {
|
||||
if (objis != null) {
|
||||
objis.close();
|
||||
}
|
||||
if (bis != null) {
|
||||
bis.close();
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {}
|
||||
// SP is required to contact the NamingManager first to obtain an object
|
||||
try {
|
||||
String relName = LdapNameParser.getRelativeName(ctx.m_ctxDN, entry.getDN());
|
||||
Name nameObj = LdapNameParser.getParser().parse(relName);
|
||||
obj = NamingManager.getObjectInstance(obj, nameObj, ctx, ctx.getEnvironment());
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
if (ex instanceof NamingException) {
|
||||
throw (NamingException)ex;
|
||||
}
|
||||
NamingException nameEx = new NamingException("NamingManager.getObjectInstance failed");
|
||||
nameEx.setRootCause(ex);
|
||||
throw nameEx;
|
||||
}
|
||||
|
||||
return obj;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a Ldap entry into a java object
|
||||
*/
|
||||
static Object entryToObject(LDAPEntry entry) throws NamingException {
|
||||
|
||||
try {
|
||||
LDAPAttributeSet attrs = entry.getAttributeSet();
|
||||
|
||||
// TODO javaCodeBase to be processed
|
||||
|
||||
LDAPAttribute attr = null;
|
||||
if ((attr = attrs.getAttribute(AT_SERIALDATA)) != null) {
|
||||
byte[] serdata = (byte[])attr.getByteValues().nextElement();
|
||||
return deserializeObject(serdata);
|
||||
}
|
||||
|
||||
// Reference
|
||||
else if ((attr = attrs.getAttribute(AT_REFADDR)) != null) {
|
||||
return decodeRefObj(attrs);
|
||||
}
|
||||
|
||||
// RMI Object
|
||||
else if ((attr = attrs.getAttribute(AT_REMOTELOC)) != null) {
|
||||
String rmiURL = (String)attr.getByteValues().nextElement();
|
||||
return java.rmi.Naming.lookup(rmiURL);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
catch (Exception ex) {
|
||||
if (ex instanceof NamingException) {
|
||||
throw (NamingException)ex;
|
||||
}
|
||||
NamingException nameEx = new NamingException("NamingManager.getStateToStore failed");
|
||||
nameEx.setRootCause(ex);
|
||||
throw nameEx;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the className for NameClassPair from an entry
|
||||
*/
|
||||
static String getClassName(LDAPEntry entry) {
|
||||
LDAPAttributeSet attrs = entry.getAttributeSet();
|
||||
LDAPAttribute attrClass = attrs.getAttribute(AT_CLASSNAME);
|
||||
if (attrClass != null) {
|
||||
String className = (String)attrClass.getStringValues().nextElement();
|
||||
return className;
|
||||
}
|
||||
return DEFAULT_OBJCLASS;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert a java object with an optional set of attributes into a LDAP entry
|
||||
*/
|
||||
static LDAPAttributeSet objectToAttrSet(Object obj, String name, LdapContextImpl ctx, Attributes attrs) throws NamingException {
|
||||
|
||||
// SP is required to contact the NamingManager first to obtain a state object
|
||||
try {
|
||||
Name nameObj = LdapNameParser.getParser().parse(name);
|
||||
obj = NamingManager.getStateToBind(obj, nameObj, ctx, ctx.getEnvironment());
|
||||
}
|
||||
catch (Exception ex) {
|
||||
if (ex instanceof NamingException) {
|
||||
throw (NamingException)ex;
|
||||
}
|
||||
NamingException nameEx = new NamingException("NamingManager.getStateToStore failed");
|
||||
nameEx.setRootCause(ex);
|
||||
throw nameEx;
|
||||
}
|
||||
|
||||
if (attrs == null) {
|
||||
attrs = new BasicAttributes(/*ignoreCase=*/true);
|
||||
}
|
||||
|
||||
Attribute objectclass = attrs.get("objectClass");
|
||||
if (objectclass == null) {
|
||||
objectclass = new BasicAttribute("objectClass", "top");
|
||||
attrs.put(objectclass);
|
||||
}
|
||||
|
||||
// Root object class
|
||||
objectclass.add(OC_JAVAOBJECT);
|
||||
|
||||
if (obj instanceof Reference) {
|
||||
objectclass.add(OC_REFERENCE);
|
||||
char delimChar = ctx.m_ctxEnv.getRefSeparator();
|
||||
attrs = encodeRefObj(delimChar, (Reference)obj, attrs);
|
||||
}
|
||||
|
||||
else if (obj instanceof Referenceable) {
|
||||
objectclass.add(OC_REFERENCE);
|
||||
char delimChar = ctx.m_ctxEnv.getRefSeparator();
|
||||
attrs = encodeRefObj(delimChar, ((Referenceable)obj).getReference(), attrs);
|
||||
}
|
||||
|
||||
else if (obj instanceof java.rmi.Remote) {
|
||||
objectclass.add(OC_REMOTEOBJ);
|
||||
attrs = encodeRMIObj((java.rmi.Remote)obj, attrs);
|
||||
}
|
||||
|
||||
else if (obj instanceof Serializable) {
|
||||
objectclass.add(OC_SERIALOBJ);
|
||||
attrs = encodeSerialObj((Serializable)obj , attrs);
|
||||
}
|
||||
|
||||
else if (obj instanceof DirContext) {
|
||||
attrs = encodeDirCtxObj((DirContext)obj , attrs);
|
||||
}
|
||||
|
||||
else {
|
||||
throw new NamingException("Can not bind object of type " +
|
||||
obj.getClass().getName());
|
||||
}
|
||||
|
||||
return AttributesImpl.jndiAttrsToLdapAttrSet(attrs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserialized object, create object from a stream of bytes
|
||||
*/
|
||||
private static Object deserializeObject(byte[] byteBuf) throws NamingException {
|
||||
|
||||
ByteArrayInputStream bis = null;
|
||||
ObjectInputStream objis = null;
|
||||
|
||||
try {
|
||||
bis = new ByteArrayInputStream(byteBuf);
|
||||
objis = new ObjectInputStream(bis);
|
||||
return objis.readObject();
|
||||
}
|
||||
catch(Exception ex) {
|
||||
NamingException nameEx = new NamingException("Failed to deserialize object");
|
||||
nameEx.setRootCause(ex);
|
||||
throw nameEx;
|
||||
}
|
||||
finally {
|
||||
try {
|
||||
if (objis != null) {
|
||||
objis.close();
|
||||
}
|
||||
if (bis != null) {
|
||||
bis.close();
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Serialize object, convert object to a stream of bytes
|
||||
*/
|
||||
private static byte[] serializeObject(Object obj) throws NamingException {
|
||||
/**
|
||||
* Serialize object, convert object to a stream of bytes
|
||||
*/
|
||||
private static byte[] serializeObject(Object obj) throws NamingException {
|
||||
|
||||
ByteArrayOutputStream bos = null;
|
||||
ObjectOutputStream objos = null;
|
||||
ByteArrayOutputStream bos = null;
|
||||
ObjectOutputStream objos = null;
|
||||
|
||||
try {
|
||||
bos = new ByteArrayOutputStream();
|
||||
objos = new ObjectOutputStream(bos);
|
||||
objos.writeObject(obj);
|
||||
objos.flush();
|
||||
try {
|
||||
bos = new ByteArrayOutputStream();
|
||||
objos = new ObjectOutputStream(bos);
|
||||
objos.writeObject(obj);
|
||||
objos.flush();
|
||||
return bos.toByteArray();
|
||||
}
|
||||
catch(Exception ex) {
|
||||
NamingException nameEx = new NamingException("Failed to serialize object");
|
||||
nameEx.setRootCause(ex);
|
||||
throw nameEx;
|
||||
}
|
||||
finally {
|
||||
try {
|
||||
if (objos != null) {
|
||||
objos.close();
|
||||
}
|
||||
if (bos != null) {
|
||||
bos.close();
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {}
|
||||
catch(Exception ex) {
|
||||
NamingException nameEx = new NamingException("Failed to serialize object");
|
||||
nameEx.setRootCause(ex);
|
||||
throw nameEx;
|
||||
}
|
||||
}
|
||||
finally {
|
||||
try {
|
||||
if (objos != null) {
|
||||
objos.close();
|
||||
}
|
||||
if (bos != null) {
|
||||
bos.close();
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode Jndi Reference Object
|
||||
*/
|
||||
private static Reference decodeRefObj(LDAPAttributeSet attrs) throws NamingException {
|
||||
try {
|
||||
/**
|
||||
* Decode Jndi Reference Object
|
||||
*/
|
||||
private static Reference decodeRefObj(LDAPAttributeSet attrs) throws NamingException {
|
||||
try {
|
||||
|
||||
LDAPAttribute attr = null;
|
||||
String className=null, factory = null, factoryLoc = null;
|
||||
if ((attr = attrs.getAttribute(AT_CLASSNAME)) == null ) {
|
||||
throw new NamingException("Bad Reference encoding, no attribute " + AT_CLASSNAME);
|
||||
}
|
||||
className = (String)attr.getStringValues().nextElement();
|
||||
|
||||
if ((attr = attrs.getAttribute(AT_OBJFACTORY)) != null ) {
|
||||
factory = (String)attr.getStringValues().nextElement();
|
||||
}
|
||||
if ((attr = attrs.getAttribute(AT_CODEBASE)) != null ) {
|
||||
factoryLoc = (String)attr.getStringValues().nextElement();
|
||||
}
|
||||
LDAPAttribute attr = null;
|
||||
String className=null, factory = null, factoryLoc = null;
|
||||
if ((attr = attrs.getAttribute(AT_CLASSNAME)) == null ) {
|
||||
throw new NamingException("Bad Reference encoding, no attribute " + AT_CLASSNAME);
|
||||
}
|
||||
className = (String)attr.getStringValues().nextElement();
|
||||
|
||||
if ((attr = attrs.getAttribute(AT_OBJFACTORY)) != null ) {
|
||||
factory = (String)attr.getStringValues().nextElement();
|
||||
}
|
||||
if ((attr = attrs.getAttribute(AT_CODEBASE)) != null ) {
|
||||
factoryLoc = (String)attr.getStringValues().nextElement();
|
||||
}
|
||||
|
||||
Reference ref = new Reference(className, factory, factoryLoc);
|
||||
|
||||
if ((attr = attrs.getAttribute(AT_REFADDR)) == null ) {
|
||||
return ref; // no refAddr
|
||||
}
|
||||
Reference ref = new Reference(className, factory, factoryLoc);
|
||||
|
||||
if ((attr = attrs.getAttribute(AT_REFADDR)) == null ) {
|
||||
return ref; // no refAddr
|
||||
}
|
||||
|
||||
for (Enumeration e = attr.getStringValues(); e.hasMoreElements();) {
|
||||
decodeRefAddr((String)e.nextElement(), ref);
|
||||
}
|
||||
|
||||
return ref;
|
||||
}
|
||||
catch (Exception ex) {
|
||||
if (ex instanceof NamingException) {
|
||||
throw (NamingException)ex;
|
||||
}
|
||||
NamingException nameEx = new NamingException("NamingManager.getStateToStore failed");
|
||||
nameEx.setRootCause(ex);
|
||||
throw nameEx;
|
||||
}
|
||||
}
|
||||
for (Enumeration e = attr.getStringValues(); e.hasMoreElements();) {
|
||||
decodeRefAddr((String)e.nextElement(), ref);
|
||||
}
|
||||
|
||||
return ref;
|
||||
}
|
||||
catch (Exception ex) {
|
||||
if (ex instanceof NamingException) {
|
||||
throw (NamingException)ex;
|
||||
}
|
||||
NamingException nameEx = new NamingException("NamingManager.getStateToStore failed");
|
||||
nameEx.setRootCause(ex);
|
||||
throw nameEx;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode RefAddr according to the <draft-ryan-java-schema-01.rev.txt>
|
||||
* StringRefAddr are encoded as #posNo#refType#refValue where posNo is the
|
||||
* refAddr position (index) inside a rerference. BynaryRefAddr is encoded
|
||||
* as #posNo#refType##data where data is the base64 encoding of the serialized
|
||||
* form of the entire BinaryRefAddr instance.
|
||||
*/
|
||||
/**
|
||||
* Decode RefAddr according to the <draft-ryan-java-schema-01.rev.txt>
|
||||
* StringRefAddr are encoded as #posNo#refType#refValue where posNo is the
|
||||
* refAddr position (index) inside a rerference. BynaryRefAddr is encoded
|
||||
* as #posNo#refType##data where data is the base64 encoding of the serialized
|
||||
* form of the entire BinaryRefAddr instance.
|
||||
*/
|
||||
private static void decodeRefAddr(String enc, Reference ref) throws NamingException{
|
||||
|
||||
if (enc.length() == 0) {
|
||||
throw new NamingException("Bad Reference encoding, empty refAddr");
|
||||
}
|
||||
|
||||
String delimChar = enc.substring(0,1);
|
||||
|
||||
StringTokenizer tok = new StringTokenizer(enc, delimChar);
|
||||
|
||||
int tokCount = tok.countTokens();
|
||||
if (tokCount != 3 && tokCount != 4) {
|
||||
Debug.println(3, "enc=" + enc + " delimChar="+delimChar + " tokCount="+tokCount);
|
||||
throw new NamingException("Bad Reference encoding");
|
||||
}
|
||||
|
||||
String type = null;
|
||||
int posn = -1;
|
||||
for (int i = 0; i < tokCount; i++) {
|
||||
String s = tok.nextToken();
|
||||
|
||||
if (i == 0) { // position
|
||||
try {
|
||||
posn = Integer.parseInt(s);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new NamingException("Bad Reference encoding, refAddr position not an initger");
|
||||
}
|
||||
}
|
||||
|
||||
else if (i == 1) { // type
|
||||
if (s.length() == 0) {
|
||||
throw new NamingException("Bad Reference encoding, empty refAddr type");
|
||||
}
|
||||
type = s;
|
||||
}
|
||||
|
||||
else if (i == 2) { // value for StringRefAddr, empty for BinaryRefAddr
|
||||
if (s.length() == 0 && tokCount != 4) { // should be empty for binary refs
|
||||
throw new NamingException("Bad Reference encoding, empty refAddr string value");
|
||||
}
|
||||
ref.add(posn, new StringRefAddr(type, s));
|
||||
}
|
||||
|
||||
else { // base64 encoding of the serialized BinaryRefAddr
|
||||
if (s.length() == 0) {
|
||||
throw new NamingException("Bad Reference encoding, empty refAddr binary value");
|
||||
}
|
||||
MimeBase64Decoder base64Dec = new MimeBase64Decoder();
|
||||
ByteBuf in = new ByteBuf(s), out = new ByteBuf();
|
||||
base64Dec.translate(in, out);
|
||||
base64Dec.eof(out);
|
||||
ref.add(posn, (RefAddr) deserializeObject(out.toBytes()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Encode Jndi Reference Object
|
||||
*/
|
||||
private static Attributes encodeRefObj(char delimChar, Reference ref, Attributes attrs) throws NamingException {
|
||||
|
||||
if (ref.getClassName() != null) {
|
||||
attrs.put(new BasicAttribute(AT_CLASSNAME, ref.getClassName()));
|
||||
}
|
||||
if (ref.getFactoryClassName() != null) {
|
||||
attrs.put(new BasicAttribute(AT_OBJFACTORY, ref.getFactoryClassName()));
|
||||
}
|
||||
if (ref.getFactoryClassLocation() != null) {
|
||||
attrs.put(new BasicAttribute(AT_CODEBASE, ref.getFactoryClassLocation()));
|
||||
}
|
||||
if (enc.length() == 0) {
|
||||
throw new NamingException("Bad Reference encoding, empty refAddr");
|
||||
}
|
||||
|
||||
String delimChar = enc.substring(0,1);
|
||||
|
||||
StringTokenizer tok = new StringTokenizer(enc, delimChar);
|
||||
|
||||
int tokCount = tok.countTokens();
|
||||
if (tokCount != 3 && tokCount != 4) {
|
||||
Debug.println(3, "enc=" + enc + " delimChar="+delimChar + " tokCount="+tokCount);
|
||||
throw new NamingException("Bad Reference encoding");
|
||||
}
|
||||
|
||||
String type = null;
|
||||
int posn = -1;
|
||||
for (int i = 0; i < tokCount; i++) {
|
||||
String s = tok.nextToken();
|
||||
|
||||
if (i == 0) { // position
|
||||
try {
|
||||
posn = Integer.parseInt(s);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new NamingException("Bad Reference encoding, refAddr position not an initger");
|
||||
}
|
||||
}
|
||||
|
||||
else if (i == 1) { // type
|
||||
if (s.length() == 0) {
|
||||
throw new NamingException("Bad Reference encoding, empty refAddr type");
|
||||
}
|
||||
type = s;
|
||||
}
|
||||
|
||||
else if (i == 2) { // value for StringRefAddr, empty for BinaryRefAddr
|
||||
if (s.length() == 0 && tokCount != 4) { // should be empty for binary refs
|
||||
throw new NamingException("Bad Reference encoding, empty refAddr string value");
|
||||
}
|
||||
ref.add(posn, new StringRefAddr(type, s));
|
||||
}
|
||||
|
||||
else { // base64 encoding of the serialized BinaryRefAddr
|
||||
if (s.length() == 0) {
|
||||
throw new NamingException("Bad Reference encoding, empty refAddr binary value");
|
||||
}
|
||||
MimeBase64Decoder base64Dec = new MimeBase64Decoder();
|
||||
ByteBuf in = new ByteBuf(s), out = new ByteBuf();
|
||||
base64Dec.translate(in, out);
|
||||
base64Dec.eof(out);
|
||||
ref.add(posn, (RefAddr) deserializeObject(out.toBytes()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(ref.size() > 0) {
|
||||
|
||||
/**
|
||||
* Encode Jndi Reference Object
|
||||
*/
|
||||
private static Attributes encodeRefObj(char delimChar, Reference ref, Attributes attrs) throws NamingException {
|
||||
|
||||
if (ref.getClassName() != null) {
|
||||
attrs.put(new BasicAttribute(AT_CLASSNAME, ref.getClassName()));
|
||||
}
|
||||
if (ref.getFactoryClassName() != null) {
|
||||
attrs.put(new BasicAttribute(AT_OBJFACTORY, ref.getFactoryClassName()));
|
||||
}
|
||||
if (ref.getFactoryClassLocation() != null) {
|
||||
attrs.put(new BasicAttribute(AT_CODEBASE, ref.getFactoryClassLocation()));
|
||||
}
|
||||
|
||||
if(ref.size() > 0) {
|
||||
BasicAttribute refAttr = new BasicAttribute(AT_REFADDR);
|
||||
for(int i = 0; i < ref.size(); i++) {
|
||||
refAttr.add(encodeRefAddr(delimChar, i, ref.get(i)));
|
||||
}
|
||||
attrs.put(refAttr);
|
||||
}
|
||||
return attrs;
|
||||
}
|
||||
refAttr.add(encodeRefAddr(delimChar, i, ref.get(i)));
|
||||
}
|
||||
attrs.put(refAttr);
|
||||
}
|
||||
return attrs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode RefAddr according to the <draft-ryan-java-schema-01.rev.txt>
|
||||
* StringRefAddr are encoded as #posNo#refType#refValue where posNo is the
|
||||
* refAddr position (index) inside a rerference. BynaryRefAddr is encoded
|
||||
* as #posNo#refType##data where data is the base64 encoding of the serialized
|
||||
* form of the entire BinaryRefAddr instance.
|
||||
/**
|
||||
* Encode RefAddr according to the <draft-ryan-java-schema-01.rev.txt>
|
||||
* StringRefAddr are encoded as #posNo#refType#refValue where posNo is the
|
||||
* refAddr position (index) inside a rerference. BynaryRefAddr is encoded
|
||||
* as #posNo#refType##data where data is the base64 encoding of the serialized
|
||||
* form of the entire BinaryRefAddr instance.
|
||||
|
||||
*/
|
||||
*/
|
||||
private static String encodeRefAddr(char delimChar, int idx, RefAddr refAddr) throws NamingException{
|
||||
|
||||
if(refAddr instanceof StringRefAddr) {
|
||||
|
||||
if(refAddr instanceof StringRefAddr) {
|
||||
|
||||
String content = (String) refAddr.getContent();
|
||||
if (content != null && content.length() > 0 && content.charAt(0) == delimChar) {
|
||||
throw new NamingException(
|
||||
"Can not encode StringRefAddr, value starts with the delimiter character " + delimChar);
|
||||
}
|
||||
return delimChar + idx +
|
||||
delimChar + refAddr.getType() +
|
||||
delimChar + content;
|
||||
}
|
||||
|
||||
else { // BinaryRefAdd
|
||||
|
||||
byte[] serialRefAddr = serializeObject(refAddr);
|
||||
MimeBase64Encoder base64 = new MimeBase64Encoder();
|
||||
ByteBuf in = new ByteBuf(), out = new ByteBuf();
|
||||
in.append(serialRefAddr);
|
||||
base64.translate(in, out);
|
||||
base64.eof(out);
|
||||
return delimChar + idx +
|
||||
delimChar + refAddr.getType() +
|
||||
delimChar + delimChar + out.toString();
|
||||
String content = (String) refAddr.getContent();
|
||||
if (content != null && content.length() > 0 && content.charAt(0) == delimChar) {
|
||||
throw new NamingException(
|
||||
"Can not encode StringRefAddr, value starts with the delimiter character " + delimChar);
|
||||
}
|
||||
return delimChar + idx +
|
||||
delimChar + refAddr.getType() +
|
||||
delimChar + content;
|
||||
}
|
||||
|
||||
else { // BinaryRefAdd
|
||||
|
||||
byte[] serialRefAddr = serializeObject(refAddr);
|
||||
MimeBase64Encoder base64 = new MimeBase64Encoder();
|
||||
ByteBuf in = new ByteBuf(), out = new ByteBuf();
|
||||
in.append(serialRefAddr);
|
||||
base64.translate(in, out);
|
||||
base64.eof(out);
|
||||
return delimChar + idx +
|
||||
delimChar + refAddr.getType() +
|
||||
delimChar + delimChar + out.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@ -419,55 +419,55 @@ public class ObjectMapper {
|
||||
*/
|
||||
|
||||
static Attributes encodeSerialObj(Serializable obj, Attributes attrs) throws NamingException{
|
||||
if (attrs.get(AT_CLASSNAME) == null) {
|
||||
attrs.put(new BasicAttribute(AT_CLASSNAME, obj.getClass().getName()));
|
||||
}
|
||||
attrs.put(new BasicAttribute(AT_SERIALDATA, serializeObject(obj)));
|
||||
return attrs;
|
||||
}
|
||||
|
||||
if (attrs.get(AT_CLASSNAME) == null) {
|
||||
attrs.put(new BasicAttribute(AT_CLASSNAME, obj.getClass().getName()));
|
||||
}
|
||||
attrs.put(new BasicAttribute(AT_SERIALDATA, serializeObject(obj)));
|
||||
return attrs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode RMI Object
|
||||
*/
|
||||
static Attributes encodeRMIObj(java.rmi.Remote obj, Attributes attrs) throws NamingException{
|
||||
if (attrs.get(AT_REMOTELOC) == null) {
|
||||
throw new NamingException(
|
||||
"Can not bind Remote object, " + AT_REMOTELOC + " not specified");
|
||||
}
|
||||
if (attrs.get(AT_CLASSNAME) == null) {
|
||||
attrs.put(new BasicAttribute(AT_CLASSNAME, obj.getClass().getName()));
|
||||
}
|
||||
return attrs;
|
||||
}
|
||||
static Attributes encodeRMIObj(java.rmi.Remote obj, Attributes attrs) throws NamingException{
|
||||
if (attrs.get(AT_REMOTELOC) == null) {
|
||||
throw new NamingException(
|
||||
"Can not bind Remote object, " + AT_REMOTELOC + " not specified");
|
||||
}
|
||||
if (attrs.get(AT_CLASSNAME) == null) {
|
||||
attrs.put(new BasicAttribute(AT_CLASSNAME, obj.getClass().getName()));
|
||||
}
|
||||
return attrs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode DirContext object (merege attributes)
|
||||
*/
|
||||
static Attributes encodeDirCtxObj(DirContext obj, Attributes attrs) throws NamingException{
|
||||
Attributes ctxAttrs = obj.getAttributes("");
|
||||
for (NamingEnumeration enum = ctxAttrs.getAll(); enum.hasMore();) {
|
||||
attrs.put((Attribute)enum.next());
|
||||
}
|
||||
return attrs;
|
||||
}
|
||||
static Attributes encodeDirCtxObj(DirContext obj, Attributes attrs) throws NamingException{
|
||||
Attributes ctxAttrs = obj.getAttributes("");
|
||||
for (NamingEnumeration enum = ctxAttrs.getAll(); enum.hasMore();) {
|
||||
attrs.put((Attribute)enum.next());
|
||||
}
|
||||
return attrs;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
byte[] serialRefAddr = { (byte)'a', (byte)'0', (byte)'A', (byte)0x10, (byte)0x7f, (byte)0xaa };
|
||||
MimeBase64Encoder base64 = new MimeBase64Encoder();
|
||||
MimeBase64Decoder base64Dec = new MimeBase64Decoder();
|
||||
ByteBuf in = new ByteBuf(), out = new ByteBuf();
|
||||
in.append(serialRefAddr);
|
||||
base64.translate(in, out);
|
||||
base64.eof(out);
|
||||
System.err.println("in="+in);
|
||||
System.err.println("out="+out);
|
||||
in = new ByteBuf(out.toString());
|
||||
out = new ByteBuf();
|
||||
base64Dec.translate(in, out);
|
||||
base64Dec.eof(out);
|
||||
System.err.println("in="+in);
|
||||
System.err.println("out="+out);
|
||||
|
||||
}
|
||||
byte[] serialRefAddr = { (byte)'a', (byte)'0', (byte)'A', (byte)0x10, (byte)0x7f, (byte)0xaa };
|
||||
MimeBase64Encoder base64 = new MimeBase64Encoder();
|
||||
MimeBase64Decoder base64Dec = new MimeBase64Decoder();
|
||||
ByteBuf in = new ByteBuf(), out = new ByteBuf();
|
||||
in.append(serialRefAddr);
|
||||
base64.translate(in, out);
|
||||
base64.eof(out);
|
||||
System.err.println("in="+in);
|
||||
System.err.println("out="+out);
|
||||
in = new ByteBuf(out.toString());
|
||||
out = new ByteBuf();
|
||||
base64Dec.translate(in, out);
|
||||
base64Dec.eof(out);
|
||||
System.err.println("in="+in);
|
||||
System.err.println("out="+out);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -31,249 +31,249 @@ import java.util.*;
|
||||
*/
|
||||
class ProviderUtils {
|
||||
|
||||
public static final String DEFAULT_FILTER = "(objectclass=*)";
|
||||
public static final String DEFAULT_FILTER = "(objectclass=*)";
|
||||
|
||||
static int jndiSearchScopeToLdap(int jndiScope) throws NamingException {
|
||||
int scope = -1;
|
||||
if (jndiScope == SearchControls.SUBTREE_SCOPE) {
|
||||
scope = LDAPConnection.SCOPE_SUB;
|
||||
}
|
||||
else if (jndiScope == SearchControls.ONELEVEL_SCOPE) {
|
||||
scope = LDAPConnection.SCOPE_ONE;
|
||||
}
|
||||
else if (jndiScope == SearchControls.OBJECT_SCOPE) {
|
||||
scope = LDAPConnection.SCOPE_BASE;
|
||||
}
|
||||
else {
|
||||
throw new InvalidSearchControlsException("Illegal value for the search scope");
|
||||
}
|
||||
return scope;
|
||||
}
|
||||
if (jndiScope == SearchControls.SUBTREE_SCOPE) {
|
||||
scope = LDAPConnection.SCOPE_SUB;
|
||||
}
|
||||
else if (jndiScope == SearchControls.ONELEVEL_SCOPE) {
|
||||
scope = LDAPConnection.SCOPE_ONE;
|
||||
}
|
||||
else if (jndiScope == SearchControls.OBJECT_SCOPE) {
|
||||
scope = LDAPConnection.SCOPE_BASE;
|
||||
}
|
||||
else {
|
||||
throw new InvalidSearchControlsException("Illegal value for the search scope");
|
||||
}
|
||||
return scope;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert Attribute List to a LDAP filter
|
||||
*
|
||||
* @return LDAP Filter
|
||||
* @throw NamingException
|
||||
* @param attrs An Attribute List
|
||||
*/
|
||||
static String attributesToFilter(Attributes attrs) throws NamingException{
|
||||
|
||||
if (attrs == null || attrs.size() == 0) {
|
||||
return DEFAULT_FILTER;
|
||||
}
|
||||
|
||||
String filter = "";
|
||||
|
||||
for (NamingEnumeration attrEnum = attrs.getAll(); attrEnum.hasMore();) {
|
||||
Attribute attrib = (Attribute) attrEnum.next();
|
||||
|
||||
//Has attributes any values
|
||||
if ( attrib.size() == 0) {
|
||||
// test only for presence of the attribute
|
||||
filter += "(" + attrib.getID() + "=*)";
|
||||
continue;
|
||||
}
|
||||
|
||||
// Add attribute values to the filter, ecsaping if necessary
|
||||
String attrValues = "";
|
||||
for (NamingEnumeration valEnum = attrib.getAll(); valEnum.hasMore();) {
|
||||
Object val = valEnum.next();
|
||||
if (val instanceof String) {
|
||||
attrValues += "(" + attrib.getID() + "=" + escapeString((String)val) +")";
|
||||
}
|
||||
else if (val instanceof byte[]) {
|
||||
attrValues += "(" + attrib.getID() + "=" + escapeBytes((byte[])val) +")";
|
||||
}
|
||||
else if (val == null) {
|
||||
//null is allowed value in Attribute.add(Object), accept it just in case
|
||||
attrValues += "(" + attrib.getID() + "=*)";
|
||||
}
|
||||
else {
|
||||
throw new NamingException(
|
||||
"Wrong Attribute value, expecting String or byte[]");
|
||||
}
|
||||
}
|
||||
filter += (attrib.size() > 1) ? ("(|" + attrValues + ")") : attrValues;
|
||||
}
|
||||
|
||||
return (attrs.size() > 1) ? ("(&" + filter + ")") : filter;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert Attribute List to a LDAP filter
|
||||
*
|
||||
* @return LDAP Filter
|
||||
* @throw NamingException
|
||||
* @param attrs An Attribute List
|
||||
*/
|
||||
static String attributesToFilter(Attributes attrs) throws NamingException{
|
||||
|
||||
if (attrs == null || attrs.size() == 0) {
|
||||
return DEFAULT_FILTER;
|
||||
}
|
||||
|
||||
String filter = "";
|
||||
|
||||
for (NamingEnumeration attrEnum = attrs.getAll(); attrEnum.hasMore();) {
|
||||
Attribute attrib = (Attribute) attrEnum.next();
|
||||
|
||||
//Has attributes any values
|
||||
if ( attrib.size() == 0) {
|
||||
// test only for presence of the attribute
|
||||
filter += "(" + attrib.getID() + "=*)";
|
||||
continue;
|
||||
}
|
||||
|
||||
// Add attribute values to the filter, ecsaping if necessary
|
||||
String attrValues = "";
|
||||
for (NamingEnumeration valEnum = attrib.getAll(); valEnum.hasMore();) {
|
||||
Object val = valEnum.next();
|
||||
if (val instanceof String) {
|
||||
attrValues += "(" + attrib.getID() + "=" + escapeString((String)val) +")";
|
||||
}
|
||||
else if (val instanceof byte[]) {
|
||||
attrValues += "(" + attrib.getID() + "=" + escapeBytes((byte[])val) +")";
|
||||
}
|
||||
else if (val == null) {
|
||||
//null is allowed value in Attribute.add(Object), accept it just in case
|
||||
attrValues += "(" + attrib.getID() + "=*)";
|
||||
}
|
||||
else {
|
||||
throw new NamingException(
|
||||
"Wrong Attribute value, expecting String or byte[]");
|
||||
}
|
||||
}
|
||||
filter += (attrib.size() > 1) ? ("(|" + attrValues + ")") : attrValues;
|
||||
}
|
||||
|
||||
return (attrs.size() > 1) ? ("(&" + filter + ")") : filter;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Expand filterExpr. Each occurrence of a variable "{n}", where n is a non-negative
|
||||
* integer, is replaced with a variable from the filterArgs array indexed by the 'n'.
|
||||
* FilterArgs can be Strings or byte[] and they are escaped according to the RFC2254
|
||||
*/
|
||||
static String expandFilterExpr(String filterExpr, Object[] filterArgs) throws InvalidSearchFilterException{
|
||||
StringTokenizer tok = new StringTokenizer(filterExpr, "{}", /*returnTokens=*/true);
|
||||
|
||||
if (tok.countTokens() == 1) {
|
||||
return filterExpr; // No escape characters
|
||||
}
|
||||
|
||||
StringBuffer out= new StringBuffer();
|
||||
boolean expectVarIdx = false, expectVarOff = false;
|
||||
Object arg= null;
|
||||
while (tok.hasMoreTokens()) {
|
||||
String s = tok.nextToken();
|
||||
|
||||
if (expectVarIdx) {
|
||||
expectVarIdx = false;
|
||||
try {
|
||||
int idx = Integer.parseInt(s);
|
||||
arg = filterArgs[idx];
|
||||
expectVarOff = true;
|
||||
}
|
||||
catch (IndexOutOfBoundsException e) {
|
||||
throw new InvalidSearchFilterException("Filter expression variable index out of bounds");
|
||||
}
|
||||
/**
|
||||
* Expand filterExpr. Each occurrence of a variable "{n}", where n is a non-negative
|
||||
* integer, is replaced with a variable from the filterArgs array indexed by the 'n'.
|
||||
* FilterArgs can be Strings or byte[] and they are escaped according to the RFC2254
|
||||
*/
|
||||
static String expandFilterExpr(String filterExpr, Object[] filterArgs) throws InvalidSearchFilterException{
|
||||
StringTokenizer tok = new StringTokenizer(filterExpr, "{}", /*returnTokens=*/true);
|
||||
|
||||
if (tok.countTokens() == 1) {
|
||||
return filterExpr; // No escape characters
|
||||
}
|
||||
|
||||
StringBuffer out= new StringBuffer();
|
||||
boolean expectVarIdx = false, expectVarOff = false;
|
||||
Object arg= null;
|
||||
while (tok.hasMoreTokens()) {
|
||||
String s = tok.nextToken();
|
||||
|
||||
if (expectVarIdx) {
|
||||
expectVarIdx = false;
|
||||
try {
|
||||
int idx = Integer.parseInt(s);
|
||||
arg = filterArgs[idx];
|
||||
expectVarOff = true;
|
||||
}
|
||||
catch (IndexOutOfBoundsException e) {
|
||||
throw new InvalidSearchFilterException("Filter expression variable index out of bounds");
|
||||
}
|
||||
|
||||
catch (Exception e) {
|
||||
throw new InvalidSearchFilterException("Invalid filter expression");
|
||||
}
|
||||
}
|
||||
|
||||
else if (expectVarOff) {
|
||||
expectVarOff = false;
|
||||
if (!s.equals("}")) {
|
||||
throw new InvalidSearchFilterException("Invalid filter expression");
|
||||
}
|
||||
if (arg instanceof String) {
|
||||
out.append(escapeString((String)arg));
|
||||
}
|
||||
else if (arg instanceof byte[]) {
|
||||
out.append(escapeBytes((byte[])arg));
|
||||
}
|
||||
else {
|
||||
throw new InvalidSearchFilterException("Invalid filter argument type");
|
||||
}
|
||||
arg = null;
|
||||
}
|
||||
|
||||
else if (s.equals("{")) {
|
||||
expectVarIdx = true;
|
||||
}
|
||||
else {
|
||||
out.append(s);
|
||||
}
|
||||
}
|
||||
if (expectVarIdx || expectVarOff) {
|
||||
throw new InvalidSearchFilterException("Invalid filter expression");
|
||||
}
|
||||
return out.toString();
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new InvalidSearchFilterException("Invalid filter expression");
|
||||
}
|
||||
}
|
||||
|
||||
else if (expectVarOff) {
|
||||
expectVarOff = false;
|
||||
if (!s.equals("}")) {
|
||||
throw new InvalidSearchFilterException("Invalid filter expression");
|
||||
}
|
||||
if (arg instanceof String) {
|
||||
out.append(escapeString((String)arg));
|
||||
}
|
||||
else if (arg instanceof byte[]) {
|
||||
out.append(escapeBytes((byte[])arg));
|
||||
}
|
||||
else {
|
||||
throw new InvalidSearchFilterException("Invalid filter argument type");
|
||||
}
|
||||
arg = null;
|
||||
}
|
||||
|
||||
else if (s.equals("{")) {
|
||||
expectVarIdx = true;
|
||||
}
|
||||
else {
|
||||
out.append(s);
|
||||
}
|
||||
}
|
||||
if (expectVarIdx || expectVarOff) {
|
||||
throw new InvalidSearchFilterException("Invalid filter expression");
|
||||
}
|
||||
return out.toString();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Escape a string according to the RFC 2254
|
||||
*/
|
||||
static String escapeString(String str) {
|
||||
String charToEscape = "\\*()\000";
|
||||
StringTokenizer tok = new StringTokenizer(str, charToEscape, /*returnTokens=*/true);
|
||||
|
||||
if (tok.countTokens() == 1) {
|
||||
return str; // No escape characters
|
||||
}
|
||||
|
||||
StringBuffer out= new StringBuffer();
|
||||
while (tok.hasMoreTokens()) {
|
||||
String s = tok.nextToken();
|
||||
|
||||
if (s.equals("*")) {
|
||||
out.append("\\2a");
|
||||
}
|
||||
else if (s.equals("(")) {
|
||||
out.append("\\28");
|
||||
}
|
||||
else if (s.equals(")")) {
|
||||
out.append("\\29");
|
||||
}
|
||||
else if (s.equals("\\")) {
|
||||
out.append("\\5c");
|
||||
}
|
||||
else if (s.equals("\000")) {
|
||||
out.append("\\00");
|
||||
}
|
||||
else {
|
||||
out.append(s);
|
||||
}
|
||||
}
|
||||
return out.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Escape a string according to the RFC 2254
|
||||
*/
|
||||
static String escapeString(String str) {
|
||||
String charToEscape = "\\*()\000";
|
||||
StringTokenizer tok = new StringTokenizer(str, charToEscape, /*returnTokens=*/true);
|
||||
|
||||
if (tok.countTokens() == 1) {
|
||||
return str; // No escape characters
|
||||
}
|
||||
|
||||
StringBuffer out= new StringBuffer();
|
||||
while (tok.hasMoreTokens()) {
|
||||
String s = tok.nextToken();
|
||||
|
||||
if (s.equals("*")) {
|
||||
out.append("\\2a");
|
||||
}
|
||||
else if (s.equals("(")) {
|
||||
out.append("\\28");
|
||||
}
|
||||
else if (s.equals(")")) {
|
||||
out.append("\\29");
|
||||
}
|
||||
else if (s.equals("\\")) {
|
||||
out.append("\\5c");
|
||||
}
|
||||
else if (s.equals("\000")) {
|
||||
out.append("\\00");
|
||||
}
|
||||
else {
|
||||
out.append(s);
|
||||
}
|
||||
}
|
||||
return out.toString();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Escape a byte array according to the RFC 2254
|
||||
*/
|
||||
static final String hexDigits="0123456789abcdef";
|
||||
|
||||
static String escapeBytes(byte[] bytes) {
|
||||
StringBuffer out = new StringBuffer("");
|
||||
for (int i=0; i < bytes.length; i++) {
|
||||
|
||||
/**
|
||||
* Escape a byte array according to the RFC 2254
|
||||
*/
|
||||
static final String hexDigits="0123456789abcdef";
|
||||
|
||||
static String escapeBytes(byte[] bytes) {
|
||||
StringBuffer out = new StringBuffer("");
|
||||
for (int i=0; i < bytes.length; i++) {
|
||||
|
||||
int low = bytes[i] & 0x0f;
|
||||
int high = (bytes[i] & 0xf0) >> 4;
|
||||
out.append("\\");
|
||||
out.append(hexDigits.charAt(high));
|
||||
out.append(hexDigits.charAt(low));
|
||||
}
|
||||
return out.toString();
|
||||
}
|
||||
int low = bytes[i] & 0x0f;
|
||||
int high = (bytes[i] & 0xf0) >> 4;
|
||||
out.append("\\");
|
||||
out.append(hexDigits.charAt(high));
|
||||
out.append(hexDigits.charAt(low));
|
||||
}
|
||||
return out.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* A method used only for testing
|
||||
*/
|
||||
private static void testAttributesToFilter() {
|
||||
try {
|
||||
System.out.println(attributesToFilter(null));
|
||||
|
||||
BasicAttributes attrs = new BasicAttributes(true);
|
||||
|
||||
System.out.println(attrs + " = " + attributesToFilter(attrs));
|
||||
|
||||
attrs.put (new BasicAttribute("attr1", "val1"));
|
||||
attrs.put (new BasicAttribute("attr2", "(val2)\\*x"));
|
||||
attrs.put (new BasicAttribute("attr3"));
|
||||
BasicAttribute attr4 = new BasicAttribute("attr4", "val41");
|
||||
attr4.add("val42");
|
||||
attrs.put(attr4);
|
||||
attrs.put("attr5", new byte[] { (byte)0x23, (byte)0x3, (byte)0x0, (byte)0xab, (byte)0xff});
|
||||
System.out.println(attrs + " = " +attributesToFilter(attrs));
|
||||
}
|
||||
catch (Exception e) {
|
||||
System.err.println(e);
|
||||
}
|
||||
}
|
||||
private static void testAttributesToFilter() {
|
||||
try {
|
||||
System.out.println(attributesToFilter(null));
|
||||
|
||||
BasicAttributes attrs = new BasicAttributes(true);
|
||||
|
||||
System.out.println(attrs + " = " + attributesToFilter(attrs));
|
||||
|
||||
attrs.put (new BasicAttribute("attr1", "val1"));
|
||||
attrs.put (new BasicAttribute("attr2", "(val2)\\*x"));
|
||||
attrs.put (new BasicAttribute("attr3"));
|
||||
BasicAttribute attr4 = new BasicAttribute("attr4", "val41");
|
||||
attr4.add("val42");
|
||||
attrs.put(attr4);
|
||||
attrs.put("attr5", new byte[] { (byte)0x23, (byte)0x3, (byte)0x0, (byte)0xab, (byte)0xff});
|
||||
System.out.println(attrs + " = " +attributesToFilter(attrs));
|
||||
}
|
||||
catch (Exception e) {
|
||||
System.err.println(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A method used only for testing
|
||||
*/
|
||||
private static void testFilterExpr() {
|
||||
try {
|
||||
String filterExpr = "(&(attr0={0})(attr1={1}))";
|
||||
Object [] args = new Object[] { "val*0", new byte[] { (byte)0xf0, (byte) 0x3a}};
|
||||
String filter = null;
|
||||
filter = expandFilterExpr(filterExpr, args);
|
||||
System.out.println(filterExpr + " -> " + filter);
|
||||
}
|
||||
catch (Exception e) {
|
||||
System.err.println(e);
|
||||
}
|
||||
}
|
||||
private static void testFilterExpr() {
|
||||
try {
|
||||
String filterExpr = "(&(attr0={0})(attr1={1}))";
|
||||
Object [] args = new Object[] { "val*0", new byte[] { (byte)0xf0, (byte) 0x3a}};
|
||||
String filter = null;
|
||||
filter = expandFilterExpr(filterExpr, args);
|
||||
System.out.println(filterExpr + " -> " + filter);
|
||||
}
|
||||
catch (Exception e) {
|
||||
System.err.println(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
/*testAttributesToFilter();
|
||||
String x = "012\0003";
|
||||
byte[] b = x.getBytes();
|
||||
for (int i=0; i < b.length; i++) {
|
||||
System.out.println(i+"="+b[i]);
|
||||
}*/
|
||||
testFilterExpr();
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
/*testAttributesToFilter();
|
||||
String x = "012\0003";
|
||||
byte[] b = x.getBytes();
|
||||
for (int i=0; i < b.length; i++) {
|
||||
System.out.println(i+"="+b[i]);
|
||||
}*/
|
||||
testFilterExpr();
|
||||
}
|
||||
}
|
||||
|
@ -31,92 +31,92 @@ import java.util.*;
|
||||
*/
|
||||
class SearchResultEnum implements NamingEnumeration {
|
||||
|
||||
LDAPSearchResults m_res;
|
||||
boolean m_returnObjs; // ReturningObjFlag in SearchControls
|
||||
LdapContextImpl m_ctx;
|
||||
Name m_ctxName;
|
||||
String[] m_userBinaryAttrs;
|
||||
LDAPConnection m_ld;
|
||||
|
||||
public SearchResultEnum(LDAPSearchResults res, boolean returnObjs, LdapContextImpl ctx) throws NamingException{
|
||||
m_res = res;
|
||||
m_returnObjs = returnObjs;
|
||||
m_ctx = ctx;
|
||||
m_userBinaryAttrs = ctx.m_ctxEnv.getUserDefBinaryAttrs();
|
||||
|
||||
m_ld = m_ctx.m_ldapSvc.getConnection();
|
||||
try {
|
||||
m_ctxName = LdapNameParser.getParser().parse(m_ctx.m_ctxDN);
|
||||
}
|
||||
catch ( NamingException e ) {
|
||||
throw ExceptionMapper.getNamingException(e);
|
||||
}
|
||||
}
|
||||
LDAPSearchResults m_res;
|
||||
boolean m_returnObjs; // ReturningObjFlag in SearchControls
|
||||
LdapContextImpl m_ctx;
|
||||
Name m_ctxName;
|
||||
String[] m_userBinaryAttrs;
|
||||
LDAPConnection m_ld;
|
||||
|
||||
public SearchResultEnum(LDAPSearchResults res, boolean returnObjs, LdapContextImpl ctx) throws NamingException{
|
||||
m_res = res;
|
||||
m_returnObjs = returnObjs;
|
||||
m_ctx = ctx;
|
||||
m_userBinaryAttrs = ctx.m_ctxEnv.getUserDefBinaryAttrs();
|
||||
|
||||
m_ld = m_ctx.m_ldapSvc.getConnection();
|
||||
try {
|
||||
m_ctxName = LdapNameParser.getParser().parse(m_ctx.m_ctxDN);
|
||||
}
|
||||
catch ( NamingException e ) {
|
||||
throw ExceptionMapper.getNamingException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public Object next() throws NamingException{
|
||||
try {
|
||||
LDAPEntry entry = m_res.next();
|
||||
String name = LdapNameParser.getRelativeName(m_ctxName, entry.getDN());
|
||||
Object obj = (m_returnObjs) ? ObjectMapper.entryToObject(entry, m_ctx) : null;
|
||||
Attributes attrs = new AttributesImpl(entry.getAttributeSet(), m_userBinaryAttrs);
|
||||
|
||||
// check for response controls
|
||||
LDAPControl[] ldapCtls = m_res.getResponseControls();
|
||||
if (ldapCtls != null) {
|
||||
// Parse raw controls
|
||||
Control[] ctls = new Control[ldapCtls.length];
|
||||
for (int i=0; i < ldapCtls.length; i++) {
|
||||
ctls[i] = NetscapeControlFactory.getControlInstance(ldapCtls[i]);
|
||||
if (ctls[i] == null) {
|
||||
throw new NamingException("Unsupported control " + ldapCtls[i].getID());
|
||||
public Object next() throws NamingException{
|
||||
try {
|
||||
LDAPEntry entry = m_res.next();
|
||||
String name = LdapNameParser.getRelativeName(m_ctxName, entry.getDN());
|
||||
Object obj = (m_returnObjs) ? ObjectMapper.entryToObject(entry, m_ctx) : null;
|
||||
Attributes attrs = new AttributesImpl(entry.getAttributeSet(), m_userBinaryAttrs);
|
||||
|
||||
// check for response controls
|
||||
LDAPControl[] ldapCtls = m_res.getResponseControls();
|
||||
if (ldapCtls != null) {
|
||||
// Parse raw controls
|
||||
Control[] ctls = new Control[ldapCtls.length];
|
||||
for (int i=0; i < ldapCtls.length; i++) {
|
||||
ctls[i] = NetscapeControlFactory.getControlInstance(ldapCtls[i]);
|
||||
if (ctls[i] == null) {
|
||||
throw new NamingException("Unsupported control " + ldapCtls[i].getID());
|
||||
}
|
||||
}
|
||||
|
||||
SearchResultWithControls searchRes =
|
||||
new SearchResultWithControls(name, obj, attrs);
|
||||
searchRes.setControls(ctls);
|
||||
|
||||
return searchRes;
|
||||
}
|
||||
else { // no controls
|
||||
return new SearchResult(name, obj, attrs);
|
||||
}
|
||||
|
||||
SearchResultWithControls searchRes =
|
||||
new SearchResultWithControls(name, obj, attrs);
|
||||
searchRes.setControls(ctls);
|
||||
|
||||
return searchRes;
|
||||
}
|
||||
else { // no controls
|
||||
return new SearchResult(name, obj, attrs);
|
||||
}
|
||||
|
||||
}
|
||||
catch (LDAPReferralException e) {
|
||||
throw new LdapReferralException(m_ctx, e);
|
||||
}
|
||||
catch ( LDAPException e ) {
|
||||
throw ExceptionMapper.getNamingException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (LDAPReferralException e) {
|
||||
throw new LdapReferralException(m_ctx, e);
|
||||
}
|
||||
catch ( LDAPException e ) {
|
||||
throw ExceptionMapper.getNamingException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public Object nextElement() {
|
||||
try {
|
||||
return next();
|
||||
}
|
||||
catch ( Exception e ) {
|
||||
System.err.println( "Error in SearchResultEnum.nextElement(): " + e.toString() );
|
||||
e.printStackTrace(System.err);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public Object nextElement() {
|
||||
try {
|
||||
return next();
|
||||
}
|
||||
catch ( Exception e ) {
|
||||
System.err.println( "Error in SearchResultEnum.nextElement(): " + e.toString() );
|
||||
e.printStackTrace(System.err);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasMore() throws NamingException {
|
||||
return m_res.hasMoreElements();
|
||||
}
|
||||
public boolean hasMore() throws NamingException {
|
||||
return m_res.hasMoreElements();
|
||||
}
|
||||
|
||||
public boolean hasMoreElements() {
|
||||
return m_res.hasMoreElements();
|
||||
}
|
||||
public boolean hasMoreElements() {
|
||||
return m_res.hasMoreElements();
|
||||
}
|
||||
|
||||
public void close() throws NamingException{
|
||||
try {
|
||||
m_ld.abandon(m_res);
|
||||
}
|
||||
catch (LDAPException e) {
|
||||
throw ExceptionMapper.getNamingException(e);
|
||||
}
|
||||
}
|
||||
public void close() throws NamingException{
|
||||
try {
|
||||
m_ld.abandon(m_res);
|
||||
}
|
||||
catch (LDAPException e) {
|
||||
throw ExceptionMapper.getNamingException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -26,226 +26,226 @@ public class DirContextAdapter implements DirContext {
|
||||
|
||||
/* Context Methods */
|
||||
|
||||
public Object addToEnvironment(String propName, Object propValue) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public Object addToEnvironment(String propName, Object propValue) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
public void bind(String name, Object obj) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public void bind(String name, Object obj) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
public void bind(Name name, Object obj) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public void bind(Name name, Object obj) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
public void close() throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public void close() throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
public String composeName(String name, String prefix) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public String composeName(String name, String prefix) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
public Name composeName(Name name, Name prefix) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public Name composeName(Name name, Name prefix) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
public Context createSubcontext(String name) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public Context createSubcontext(String name) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
public Context createSubcontext(Name name) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public Context createSubcontext(Name name) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
public void destroySubcontext(String name) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public void destroySubcontext(String name) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
public void destroySubcontext(Name name) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public void destroySubcontext(Name name) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
public Hashtable getEnvironment() throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public Hashtable getEnvironment() throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
public String getNameInNamespace() throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public String getNameInNamespace() throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
public NameParser getNameParser(String name) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public NameParser getNameParser(String name) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
public NameParser getNameParser(Name name) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public NameParser getNameParser(Name name) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
public NamingEnumeration list(String name) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public NamingEnumeration list(String name) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
public NamingEnumeration list(Name name) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public NamingEnumeration list(Name name) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
public NamingEnumeration listBindings(String name) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public NamingEnumeration listBindings(String name) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
public NamingEnumeration listBindings(Name name) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public NamingEnumeration listBindings(Name name) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
public Object lookup(String name) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public Object lookup(String name) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
public Object lookup(Name name) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public Object lookup(Name name) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
public Object lookupLink(String name) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public Object lookupLink(String name) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
public Object lookupLink(Name name) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public Object lookupLink(Name name) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
public void rebind(String name, Object obj) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public void rebind(String name, Object obj) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
public void rebind(Name name, Object obj) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public void rebind(Name name, Object obj) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
public Object removeFromEnvironment(String propName) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public Object removeFromEnvironment(String propName) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
public void rename(String oldName, String newName) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public void rename(String oldName, String newName) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
public void rename(Name oldName, Name newName) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public void rename(Name oldName, Name newName) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
public void unbind(String name) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public void unbind(String name) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
public void unbind(Name name) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public void unbind(Name name) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
|
||||
/* DirContext Methods */
|
||||
|
||||
public void bind(String name, Object obj, Attributes attrs) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public void bind(String name, Object obj, Attributes attrs) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
public void bind(Name name, Object obj, Attributes attrs) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public void bind(Name name, Object obj, Attributes attrs) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
public DirContext createSubcontext(String name, Attributes attrs) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public DirContext createSubcontext(String name, Attributes attrs) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
public DirContext createSubcontext(Name name, Attributes attrs) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public DirContext createSubcontext(Name name, Attributes attrs) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
public Attributes getAttributes(String name) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public Attributes getAttributes(String name) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
public Attributes getAttributes(String name, String[] attrIds) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public Attributes getAttributes(String name, String[] attrIds) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
public Attributes getAttributes(Name name) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public Attributes getAttributes(Name name) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
public Attributes getAttributes(Name name, String[] attrIds) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public Attributes getAttributes(Name name, String[] attrIds) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
public DirContext getSchema(String name) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public DirContext getSchema(String name) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
public DirContext getSchema(Name name) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public DirContext getSchema(Name name) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
public DirContext getSchemaClassDefinition(String name) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public DirContext getSchemaClassDefinition(String name) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
public DirContext getSchemaClassDefinition(Name name) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public DirContext getSchemaClassDefinition(Name name) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
public void modifyAttributes(String name, int mod_op, Attributes attrs) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public void modifyAttributes(String name, int mod_op, Attributes attrs) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
public void modifyAttributes(String name, ModificationItem[] mods) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public void modifyAttributes(String name, ModificationItem[] mods) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
public void modifyAttributes(Name name, int mod_op, Attributes attrs) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public void modifyAttributes(Name name, int mod_op, Attributes attrs) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
public void modifyAttributes(Name name, ModificationItem[] mods) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public void modifyAttributes(Name name, ModificationItem[] mods) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
public void rebind(String name, Object obj, Attributes attrs) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public void rebind(String name, Object obj, Attributes attrs) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
public void rebind(Name name, Object obj, Attributes attrs) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public void rebind(Name name, Object obj, Attributes attrs) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
public NamingEnumeration search(String name, String filter, SearchControls cons) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public NamingEnumeration search(String name, String filter, SearchControls cons) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
public NamingEnumeration search(String name, String filterExpr, Object[] filterArgs, SearchControls cons) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public NamingEnumeration search(String name, String filterExpr, Object[] filterArgs, SearchControls cons) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
public NamingEnumeration search(String name, Attributes matchingAttributes) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public NamingEnumeration search(String name, Attributes matchingAttributes) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
public NamingEnumeration search(String name, Attributes matchingAttributes, String[] attributesToReturn) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public NamingEnumeration search(String name, Attributes matchingAttributes, String[] attributesToReturn) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
public NamingEnumeration search(Name name, String filter, SearchControls cons) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public NamingEnumeration search(Name name, String filter, SearchControls cons) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
public NamingEnumeration search(Name name, String filterExpr, Object[] filterArgs, SearchControls cons) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public NamingEnumeration search(Name name, String filterExpr, Object[] filterArgs, SearchControls cons) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
public NamingEnumeration search(Name name, Attributes attrs) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public NamingEnumeration search(Name name, Attributes attrs) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
public NamingEnumeration search(Name name, Attributes matchingAttributes, String[] attributesToReturn) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public NamingEnumeration search(Name name, Attributes matchingAttributes, String[] attributesToReturn) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
}
|
||||
|
@ -30,191 +30,191 @@ import java.util.Hashtable;
|
||||
*/
|
||||
public class ExceptionMapper {
|
||||
|
||||
public static NamingException getNamingException(Exception origException) {
|
||||
|
||||
if (origException instanceof NamingException) {
|
||||
return (NamingException)origException;
|
||||
}
|
||||
|
||||
/**
|
||||
* LdapJDK exceptions
|
||||
*/
|
||||
else if (origException instanceof LDAPReferralException) {
|
||||
// Should never get here. The ldapjdk referral exceptions
|
||||
// should be explicitly captured by the ecode and converted
|
||||
// into jndi LdapReferralException instances.
|
||||
return new NamingException("Provider internal error, LDAPReferralException not captured");
|
||||
}
|
||||
|
||||
else if (origException instanceof LDAPException) {
|
||||
LDAPException ldapException = (LDAPException) origException;
|
||||
int resCode = ldapException.getLDAPResultCode();
|
||||
|
||||
if (resCode == LDAPException.OPERATION_ERROR) {
|
||||
NamingException nameEx = new NamingException(ldapException.toString());
|
||||
nameEx.setRootCause(ldapException);
|
||||
return nameEx;
|
||||
}
|
||||
else if (resCode == LDAPException.PROTOCOL_ERROR) {
|
||||
return new CommunicationException(ldapException.toString());
|
||||
}
|
||||
else if (resCode == LDAPException.TIME_LIMIT_EXCEEDED) {
|
||||
return new TimeLimitExceededException(ldapException.toString());
|
||||
}
|
||||
else if (resCode == LDAPException.SIZE_LIMIT_EXCEEDED) {
|
||||
return new SizeLimitExceededException(ldapException.toString());
|
||||
}
|
||||
// COMPARE_FALSE should never happen, but is included here for completeness
|
||||
else if (resCode == LDAPException.COMPARE_FALSE) {
|
||||
NamingException nameEx = new NamingException(ldapException.toString());
|
||||
nameEx.setRootCause(ldapException);
|
||||
return nameEx;
|
||||
}
|
||||
// COMPARE_TRUE should never happen, but is included here for completeness
|
||||
else if (resCode == LDAPException.COMPARE_TRUE) {
|
||||
NamingException nameEx = new NamingException(ldapException.toString());
|
||||
nameEx.setRootCause(ldapException);
|
||||
return nameEx;
|
||||
}
|
||||
else if (resCode == LDAPException.AUTH_METHOD_NOT_SUPPORTED) {
|
||||
return new AuthenticationNotSupportedException(ldapException.toString());
|
||||
}
|
||||
else if (resCode == LDAPException.STRONG_AUTH_REQUIRED) {
|
||||
return new AuthenticationNotSupportedException(ldapException.toString());
|
||||
}
|
||||
else if (resCode == LDAPException.LDAP_PARTIAL_RESULTS) {
|
||||
return new PartialResultException(ldapException.toString());
|
||||
}
|
||||
// REFERRAL code should be in LDAPReferralException
|
||||
else if (resCode == LDAPException.REFERRAL) {
|
||||
LDAPReferralException referralEx = (LDAPReferralException)ldapException;
|
||||
// TODO create jndi LdapReferralException
|
||||
}
|
||||
else if (resCode == LDAPException.ADMIN_LIMIT_EXCEEDED) {
|
||||
return new LimitExceededException(ldapException.toString());
|
||||
}
|
||||
else if(resCode == LDAPException.UNAVAILABLE_CRITICAL_EXTENSION) {
|
||||
return new OperationNotSupportedException(ldapException.toString());
|
||||
}
|
||||
else if (resCode == LDAPException.CONFIDENTIALITY_REQUIRED) {
|
||||
return new AuthenticationNotSupportedException(
|
||||
"A secure connection is required for this operation");
|
||||
}
|
||||
// This shoud never propagate to the caller
|
||||
else if (resCode == LDAPException.SASL_BIND_IN_PROGRESS) {
|
||||
NamingException nameEx = new NamingException(ldapException.toString());
|
||||
nameEx.setRootCause(ldapException);
|
||||
return nameEx;
|
||||
}
|
||||
else if (resCode == LDAPException.NO_SUCH_ATTRIBUTE) {
|
||||
return new NoSuchAttributeException(ldapException.toString());
|
||||
}
|
||||
else if (resCode == LDAPException.UNDEFINED_ATTRIBUTE_TYPE) {
|
||||
return new InvalidAttributeIdentifierException(ldapException.toString());
|
||||
}
|
||||
else if (resCode == LDAPException.INAPPROPRIATE_MATCHING) {
|
||||
return new InvalidSearchFilterException(ldapException.toString());
|
||||
}
|
||||
else if (resCode == LDAPException.CONSTRAINT_VIOLATION) {
|
||||
return new InvalidSearchControlsException(ldapException.toString());
|
||||
}
|
||||
else if (resCode == LDAPException.ATTRIBUTE_OR_VALUE_EXISTS) {
|
||||
return new AttributeInUseException(ldapException.toString());
|
||||
}
|
||||
else if (resCode == LDAPException.INVALID_ATTRIBUTE_SYNTAX) {
|
||||
return new InvalidAttributeValueException(ldapException.toString());
|
||||
}
|
||||
else if (resCode == LDAPException.NO_SUCH_OBJECT) {
|
||||
return new NameNotFoundException(ldapException.toString());
|
||||
}
|
||||
else if (resCode == LDAPException.ALIAS_PROBLEM) {
|
||||
return new NamingException(ldapException.toString());
|
||||
}
|
||||
else if (resCode == LDAPException.INVALID_DN_SYNTAX) {
|
||||
return new InvalidNameException(ldapException.toString());
|
||||
}
|
||||
else if (resCode == LDAPException.IS_LEAF) {
|
||||
NamingException nameEx = new NamingException(ldapException.toString());
|
||||
nameEx.setRootCause(ldapException);
|
||||
return nameEx;
|
||||
}
|
||||
else if (resCode == LDAPException.ALIAS_DEREFERENCING_PROBLEM) {
|
||||
NamingException nameEx = new NamingException(ldapException.toString());
|
||||
nameEx.setRootCause(ldapException);
|
||||
return nameEx;
|
||||
}
|
||||
else if (resCode == LDAPException.INAPPROPRIATE_AUTHENTICATION) {
|
||||
//return new AuthenticationNotSupportedException(ldapException.toString());
|
||||
return new AuthenticationException(ldapException.toString());
|
||||
}
|
||||
else if (resCode == LDAPException.INVALID_CREDENTIALS) {
|
||||
return new AuthenticationException(ldapException.toString());
|
||||
}
|
||||
else if (resCode == LDAPException.INSUFFICIENT_ACCESS_RIGHTS) {
|
||||
return new NoPermissionException(ldapException.toString());
|
||||
}
|
||||
else if (resCode == LDAPException.BUSY) {
|
||||
return new ServiceUnavailableException(ldapException.toString());
|
||||
}
|
||||
else if (resCode == LDAPException.UNAVAILABLE) {
|
||||
return new ServiceUnavailableException(ldapException.toString());
|
||||
}
|
||||
else if (resCode == LDAPException.UNWILLING_TO_PERFORM) {
|
||||
return new OperationNotSupportedException(ldapException.toString());
|
||||
}
|
||||
else if (resCode == LDAPException.LOOP_DETECT) {
|
||||
NamingException nameEx = new NamingException(ldapException.toString());
|
||||
nameEx.setRootCause(ldapException);
|
||||
return nameEx;
|
||||
}
|
||||
else if (resCode == LDAPException.NAMING_VIOLATION) {
|
||||
return new InvalidNameException(ldapException.toString());
|
||||
}
|
||||
else if (resCode == LDAPException.OBJECT_CLASS_VIOLATION) {
|
||||
return new SchemaViolationException(ldapException.toString());
|
||||
}
|
||||
else if (resCode == LDAPException.NOT_ALLOWED_ON_NONLEAF) {
|
||||
return new ContextNotEmptyException(ldapException.toString());
|
||||
}
|
||||
else if (resCode == LDAPException.NOT_ALLOWED_ON_RDN) {
|
||||
return new SchemaViolationException(ldapException.toString());
|
||||
}
|
||||
else if (resCode == LDAPException.ENTRY_ALREADY_EXISTS) {
|
||||
return new NameAlreadyBoundException(ldapException.toString());
|
||||
}
|
||||
else if (resCode == LDAPException.OBJECT_CLASS_MODS_PROHIBITED) {
|
||||
return new SchemaViolationException(ldapException.toString());
|
||||
}
|
||||
else if (resCode == LDAPException.SERVER_DOWN) {
|
||||
return new CommunicationException(ldapException.toString());
|
||||
}
|
||||
else if (resCode == LDAPException.CONNECT_ERROR) {
|
||||
return new CommunicationException(ldapException.toString());
|
||||
}
|
||||
public static NamingException getNamingException(Exception origException) {
|
||||
|
||||
if (origException instanceof NamingException) {
|
||||
return (NamingException)origException;
|
||||
}
|
||||
|
||||
/**
|
||||
* LdapJDK exceptions
|
||||
*/
|
||||
else if (origException instanceof LDAPReferralException) {
|
||||
// Should never get here. The ldapjdk referral exceptions
|
||||
// should be explicitly captured by the ecode and converted
|
||||
// into jndi LdapReferralException instances.
|
||||
return new NamingException("Provider internal error, LDAPReferralException not captured");
|
||||
}
|
||||
|
||||
else if (origException instanceof LDAPException) {
|
||||
LDAPException ldapException = (LDAPException) origException;
|
||||
int resCode = ldapException.getLDAPResultCode();
|
||||
|
||||
if (resCode == LDAPException.OPERATION_ERROR) {
|
||||
NamingException nameEx = new NamingException(ldapException.toString());
|
||||
nameEx.setRootCause(ldapException);
|
||||
return nameEx;
|
||||
}
|
||||
else if (resCode == LDAPException.PROTOCOL_ERROR) {
|
||||
return new CommunicationException(ldapException.toString());
|
||||
}
|
||||
else if (resCode == LDAPException.TIME_LIMIT_EXCEEDED) {
|
||||
return new TimeLimitExceededException(ldapException.toString());
|
||||
}
|
||||
else if (resCode == LDAPException.SIZE_LIMIT_EXCEEDED) {
|
||||
return new SizeLimitExceededException(ldapException.toString());
|
||||
}
|
||||
// COMPARE_FALSE should never happen, but is included here for completeness
|
||||
else if (resCode == LDAPException.COMPARE_FALSE) {
|
||||
NamingException nameEx = new NamingException(ldapException.toString());
|
||||
nameEx.setRootCause(ldapException);
|
||||
return nameEx;
|
||||
}
|
||||
// COMPARE_TRUE should never happen, but is included here for completeness
|
||||
else if (resCode == LDAPException.COMPARE_TRUE) {
|
||||
NamingException nameEx = new NamingException(ldapException.toString());
|
||||
nameEx.setRootCause(ldapException);
|
||||
return nameEx;
|
||||
}
|
||||
else if (resCode == LDAPException.AUTH_METHOD_NOT_SUPPORTED) {
|
||||
return new AuthenticationNotSupportedException(ldapException.toString());
|
||||
}
|
||||
else if (resCode == LDAPException.STRONG_AUTH_REQUIRED) {
|
||||
return new AuthenticationNotSupportedException(ldapException.toString());
|
||||
}
|
||||
else if (resCode == LDAPException.LDAP_PARTIAL_RESULTS) {
|
||||
return new PartialResultException(ldapException.toString());
|
||||
}
|
||||
// REFERRAL code should be in LDAPReferralException
|
||||
else if (resCode == LDAPException.REFERRAL) {
|
||||
LDAPReferralException referralEx = (LDAPReferralException)ldapException;
|
||||
// TODO create jndi LdapReferralException
|
||||
}
|
||||
else if (resCode == LDAPException.ADMIN_LIMIT_EXCEEDED) {
|
||||
return new LimitExceededException(ldapException.toString());
|
||||
}
|
||||
else if(resCode == LDAPException.UNAVAILABLE_CRITICAL_EXTENSION) {
|
||||
return new OperationNotSupportedException(ldapException.toString());
|
||||
}
|
||||
else if (resCode == LDAPException.CONFIDENTIALITY_REQUIRED) {
|
||||
return new AuthenticationNotSupportedException(
|
||||
"A secure connection is required for this operation");
|
||||
}
|
||||
// This shoud never propagate to the caller
|
||||
else if (resCode == LDAPException.SASL_BIND_IN_PROGRESS) {
|
||||
NamingException nameEx = new NamingException(ldapException.toString());
|
||||
nameEx.setRootCause(ldapException);
|
||||
return nameEx;
|
||||
}
|
||||
else if (resCode == LDAPException.NO_SUCH_ATTRIBUTE) {
|
||||
return new NoSuchAttributeException(ldapException.toString());
|
||||
}
|
||||
else if (resCode == LDAPException.UNDEFINED_ATTRIBUTE_TYPE) {
|
||||
return new InvalidAttributeIdentifierException(ldapException.toString());
|
||||
}
|
||||
else if (resCode == LDAPException.INAPPROPRIATE_MATCHING) {
|
||||
return new InvalidSearchFilterException(ldapException.toString());
|
||||
}
|
||||
else if (resCode == LDAPException.CONSTRAINT_VIOLATION) {
|
||||
return new InvalidSearchControlsException(ldapException.toString());
|
||||
}
|
||||
else if (resCode == LDAPException.ATTRIBUTE_OR_VALUE_EXISTS) {
|
||||
return new AttributeInUseException(ldapException.toString());
|
||||
}
|
||||
else if (resCode == LDAPException.INVALID_ATTRIBUTE_SYNTAX) {
|
||||
return new InvalidAttributeValueException(ldapException.toString());
|
||||
}
|
||||
else if (resCode == LDAPException.NO_SUCH_OBJECT) {
|
||||
return new NameNotFoundException(ldapException.toString());
|
||||
}
|
||||
else if (resCode == LDAPException.ALIAS_PROBLEM) {
|
||||
return new NamingException(ldapException.toString());
|
||||
}
|
||||
else if (resCode == LDAPException.INVALID_DN_SYNTAX) {
|
||||
return new InvalidNameException(ldapException.toString());
|
||||
}
|
||||
else if (resCode == LDAPException.IS_LEAF) {
|
||||
NamingException nameEx = new NamingException(ldapException.toString());
|
||||
nameEx.setRootCause(ldapException);
|
||||
return nameEx;
|
||||
}
|
||||
else if (resCode == LDAPException.ALIAS_DEREFERENCING_PROBLEM) {
|
||||
NamingException nameEx = new NamingException(ldapException.toString());
|
||||
nameEx.setRootCause(ldapException);
|
||||
return nameEx;
|
||||
}
|
||||
else if (resCode == LDAPException.INAPPROPRIATE_AUTHENTICATION) {
|
||||
//return new AuthenticationNotSupportedException(ldapException.toString());
|
||||
return new AuthenticationException(ldapException.toString());
|
||||
}
|
||||
else if (resCode == LDAPException.INVALID_CREDENTIALS) {
|
||||
return new AuthenticationException(ldapException.toString());
|
||||
}
|
||||
else if (resCode == LDAPException.INSUFFICIENT_ACCESS_RIGHTS) {
|
||||
return new NoPermissionException(ldapException.toString());
|
||||
}
|
||||
else if (resCode == LDAPException.BUSY) {
|
||||
return new ServiceUnavailableException(ldapException.toString());
|
||||
}
|
||||
else if (resCode == LDAPException.UNAVAILABLE) {
|
||||
return new ServiceUnavailableException(ldapException.toString());
|
||||
}
|
||||
else if (resCode == LDAPException.UNWILLING_TO_PERFORM) {
|
||||
return new OperationNotSupportedException(ldapException.toString());
|
||||
}
|
||||
else if (resCode == LDAPException.LOOP_DETECT) {
|
||||
NamingException nameEx = new NamingException(ldapException.toString());
|
||||
nameEx.setRootCause(ldapException);
|
||||
return nameEx;
|
||||
}
|
||||
else if (resCode == LDAPException.NAMING_VIOLATION) {
|
||||
return new InvalidNameException(ldapException.toString());
|
||||
}
|
||||
else if (resCode == LDAPException.OBJECT_CLASS_VIOLATION) {
|
||||
return new SchemaViolationException(ldapException.toString());
|
||||
}
|
||||
else if (resCode == LDAPException.NOT_ALLOWED_ON_NONLEAF) {
|
||||
return new ContextNotEmptyException(ldapException.toString());
|
||||
}
|
||||
else if (resCode == LDAPException.NOT_ALLOWED_ON_RDN) {
|
||||
return new SchemaViolationException(ldapException.toString());
|
||||
}
|
||||
else if (resCode == LDAPException.ENTRY_ALREADY_EXISTS) {
|
||||
return new NameAlreadyBoundException(ldapException.toString());
|
||||
}
|
||||
else if (resCode == LDAPException.OBJECT_CLASS_MODS_PROHIBITED) {
|
||||
return new SchemaViolationException(ldapException.toString());
|
||||
}
|
||||
else if (resCode == LDAPException.SERVER_DOWN) {
|
||||
return new CommunicationException(ldapException.toString());
|
||||
}
|
||||
else if (resCode == LDAPException.CONNECT_ERROR) {
|
||||
return new CommunicationException(ldapException.toString());
|
||||
}
|
||||
|
||||
else {
|
||||
// All other result codes
|
||||
// 71 AFFECTS_MULTIPLE_DSAS
|
||||
// 80 OTHER
|
||||
// 89 PARAM_ERROR
|
||||
// 92 LDAP_NOT_SUPPORTED
|
||||
// 93 CONTROL_NOT_FOUND
|
||||
// 94 NO_RESULTS_RETURNED
|
||||
// 95 MORE_RESULTS_TO_RETURN
|
||||
// 96 CLIENT_LOOP referral
|
||||
// 97 REFERRAL_LIMIT_EXCEEDED referral
|
||||
else {
|
||||
// All other result codes
|
||||
// 71 AFFECTS_MULTIPLE_DSAS
|
||||
// 80 OTHER
|
||||
// 89 PARAM_ERROR
|
||||
// 92 LDAP_NOT_SUPPORTED
|
||||
// 93 CONTROL_NOT_FOUND
|
||||
// 94 NO_RESULTS_RETURNED
|
||||
// 95 MORE_RESULTS_TO_RETURN
|
||||
// 96 CLIENT_LOOP referral
|
||||
// 97 REFERRAL_LIMIT_EXCEEDED referral
|
||||
|
||||
NamingException nameEx = new NamingException(ldapException.toString());
|
||||
nameEx.setRootCause(ldapException);
|
||||
return nameEx;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* All other Exceptions
|
||||
*/
|
||||
NamingException nameEx = new NamingException(origException.toString());
|
||||
nameEx.setRootCause(origException);
|
||||
return nameEx;
|
||||
}
|
||||
NamingException nameEx = new NamingException(ldapException.toString());
|
||||
nameEx.setRootCause(ldapException);
|
||||
return nameEx;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* All other Exceptions
|
||||
*/
|
||||
NamingException nameEx = new NamingException(origException.toString());
|
||||
nameEx.setRootCause(origException);
|
||||
return nameEx;
|
||||
}
|
||||
}
|
||||
|
@ -26,65 +26,65 @@ import java.util.Hashtable;
|
||||
public class LdapContextAdapter extends DirContextAdapter implements EventDirContext, LdapContext {
|
||||
|
||||
/* LdapContext methods */
|
||||
public ExtendedResponse extendedOperation(ExtendedRequest req)throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public ExtendedResponse extendedOperation(ExtendedRequest req)throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
public Control[] getRequestControls() throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public Control[] getRequestControls() throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
public Control[] getResponseControls() throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public Control[] getResponseControls() throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
public Control[] getConnectControls() throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public Control[] getConnectControls() throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
public LdapContext newInstance(Control[] reqCtls) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
public void reconnect(Control[] reqCtls) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public void reconnect(Control[] reqCtls) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
public void setRequestControls(Control[] reqCtls) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
/**
|
||||
* Naming Event methods
|
||||
*/
|
||||
public void addNamingListener(String target, int scope, NamingListener l) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
/**
|
||||
* Naming Event methods
|
||||
*/
|
||||
public void addNamingListener(String target, int scope, NamingListener l) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
public void addNamingListener(Name target, int scope, NamingListener l) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public void addNamingListener(Name target, int scope, NamingListener l) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
public void addNamingListener(String target, String filter, SearchControls ctls, NamingListener l)throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public void addNamingListener(String target, String filter, SearchControls ctls, NamingListener l)throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
public void addNamingListener(Name target, String filter, SearchControls ctls, NamingListener l)throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public void addNamingListener(Name target, String filter, SearchControls ctls, NamingListener l)throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
public void addNamingListener(String target, String filter, Object[] filtrArgs, SearchControls ctls, NamingListener l)throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public void addNamingListener(String target, String filter, Object[] filtrArgs, SearchControls ctls, NamingListener l)throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
public void addNamingListener(Name target, String filter, Object[] filtrArgs, SearchControls ctls, NamingListener l)throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public void addNamingListener(Name target, String filter, Object[] filtrArgs, SearchControls ctls, NamingListener l)throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
public void removeNamingListener(NamingListener l) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public void removeNamingListener(NamingListener l) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
public boolean targetMustExist() {
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -37,368 +37,368 @@ import java.util.*;
|
||||
*/
|
||||
public class ShareableEnv implements Cloneable{
|
||||
|
||||
/**
|
||||
* A special value that denotes a removed propety. Because shared property tables
|
||||
* are read-only, a shared property is deleted in the curent context by assigning
|
||||
* the REMOVED_PROPERTY value in the _modEnv table.
|
||||
*/
|
||||
private static final Object REMOVED_PROPERTY = new Object();
|
||||
/**
|
||||
* A special value that denotes a removed propety. Because shared property tables
|
||||
* are read-only, a shared property is deleted in the curent context by assigning
|
||||
* the REMOVED_PROPERTY value in the _modEnv table.
|
||||
*/
|
||||
private static final Object REMOVED_PROPERTY = new Object();
|
||||
|
||||
/**
|
||||
* A table of most recent environment modifications. These modifications are not
|
||||
* shared until the current context is cloned, which moves _privateEnv to
|
||||
* _sharedEnv
|
||||
*/
|
||||
protected Hashtable m_privateEnv;
|
||||
|
||||
/**
|
||||
* A set of environment propeties that have been changed in this Context and are
|
||||
* shared with one or more child contexts. Read-only access.
|
||||
*/
|
||||
protected Vector m_sharedEnv; // A vector of Hashtables
|
||||
|
||||
/**
|
||||
* Shared environment inherited from the parent context
|
||||
*/
|
||||
protected ShareableEnv m_parentEnv;
|
||||
|
||||
/**
|
||||
* Index into parent _sharedEnv list. Designates all environment chnages
|
||||
* in the parent context that are visible to this child context
|
||||
*/
|
||||
protected int m_parentSharedEnvIdx = -1;
|
||||
/**
|
||||
* A table of most recent environment modifications. These modifications are not
|
||||
* shared until the current context is cloned, which moves _privateEnv to
|
||||
* _sharedEnv
|
||||
*/
|
||||
protected Hashtable m_privateEnv;
|
||||
|
||||
/**
|
||||
* A set of environment propeties that have been changed in this Context and are
|
||||
* shared with one or more child contexts. Read-only access.
|
||||
*/
|
||||
protected Vector m_sharedEnv; // A vector of Hashtables
|
||||
|
||||
/**
|
||||
* Shared environment inherited from the parent context
|
||||
*/
|
||||
protected ShareableEnv m_parentEnv;
|
||||
|
||||
/**
|
||||
* Index into parent _sharedEnv list. Designates all environment chnages
|
||||
* in the parent context that are visible to this child context
|
||||
*/
|
||||
protected int m_parentSharedEnvIdx = -1;
|
||||
|
||||
/**
|
||||
* No-arg constructor is private
|
||||
*/
|
||||
private ShareableEnv() {}
|
||||
|
||||
/**
|
||||
* Constructor for non root Contexts
|
||||
*
|
||||
* @param parent A reference to the parent context environment
|
||||
* @param parentSharedEnvIdx index into parent's shared environemnt list
|
||||
*/
|
||||
public ShareableEnv(ShareableEnv parent, int parentSharedEnvIdx) {
|
||||
m_parentEnv = parent;
|
||||
m_parentSharedEnvIdx = parentSharedEnvIdx;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for the root context
|
||||
*
|
||||
* @param initialEnv a hashtable with environemnt properties
|
||||
*/
|
||||
public ShareableEnv(Hashtable initialEnv) {
|
||||
m_privateEnv = initialEnv;
|
||||
}
|
||||
/**
|
||||
* No-arg constructor is private
|
||||
*/
|
||||
private ShareableEnv() {}
|
||||
|
||||
/**
|
||||
* Constructor for non root Contexts
|
||||
*
|
||||
* @param parent A reference to the parent context environment
|
||||
* @param parentSharedEnvIdx index into parent's shared environemnt list
|
||||
*/
|
||||
public ShareableEnv(ShareableEnv parent, int parentSharedEnvIdx) {
|
||||
m_parentEnv = parent;
|
||||
m_parentSharedEnvIdx = parentSharedEnvIdx;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for the root context
|
||||
*
|
||||
* @param initialEnv a hashtable with environemnt properties
|
||||
*/
|
||||
public ShareableEnv(Hashtable initialEnv) {
|
||||
m_privateEnv = initialEnv;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the property value.
|
||||
*
|
||||
/**
|
||||
* Set the property value.
|
||||
*
|
||||
* @return the previous value of the specified property,
|
||||
* or <code>null</code> if it did not exist before.
|
||||
* @param prop property name
|
||||
* @param val property value
|
||||
*/
|
||||
public Object setProperty(String prop, Object val) {
|
||||
|
||||
// Need the current value to be returned
|
||||
Object oldVal = getProperty(prop);
|
||||
|
||||
// Lazy create _privateEnv table
|
||||
if (m_privateEnv == null) {
|
||||
m_privateEnv = new Hashtable(5);
|
||||
}
|
||||
* or <code>null</code> if it did not exist before.
|
||||
* @param prop property name
|
||||
* @param val property value
|
||||
*/
|
||||
public Object setProperty(String prop, Object val) {
|
||||
|
||||
// Need the current value to be returned
|
||||
Object oldVal = getProperty(prop);
|
||||
|
||||
// Lazy create _privateEnv table
|
||||
if (m_privateEnv == null) {
|
||||
m_privateEnv = new Hashtable(5);
|
||||
}
|
||||
|
||||
// Add/Modify property
|
||||
m_privateEnv.put(prop, val);
|
||||
|
||||
return oldVal;
|
||||
}
|
||||
// Add/Modify property
|
||||
m_privateEnv.put(prop, val);
|
||||
|
||||
return oldVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the property value.
|
||||
*
|
||||
* @return the object associated with the property name
|
||||
* or <code>null</code> if property is not found
|
||||
* @param prop property name
|
||||
*/
|
||||
public Object getProperty(String prop) {
|
||||
|
||||
// First check most recent modifications
|
||||
if (m_privateEnv != null) {
|
||||
Object val = m_privateEnv.get(prop);
|
||||
if (val != null) {
|
||||
return (val == REMOVED_PROPERTY) ? null : val;
|
||||
}
|
||||
}
|
||||
|
||||
// Then try shared properties
|
||||
if (m_sharedEnv != null) {
|
||||
return getSharedProperty(m_sharedEnv.size()-1, prop);
|
||||
}
|
||||
else {
|
||||
return getSharedProperty(-1, prop);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Get the property value.
|
||||
*
|
||||
* @return the object associated with the property name
|
||||
* or <code>null</code> if property is not found
|
||||
* @param prop property name
|
||||
*/
|
||||
public Object getProperty(String prop) {
|
||||
|
||||
// First check most recent modifications
|
||||
if (m_privateEnv != null) {
|
||||
Object val = m_privateEnv.get(prop);
|
||||
if (val != null) {
|
||||
return (val == REMOVED_PROPERTY) ? null : val;
|
||||
}
|
||||
}
|
||||
|
||||
// Then try shared properties
|
||||
if (m_sharedEnv != null) {
|
||||
return getSharedProperty(m_sharedEnv.size()-1, prop);
|
||||
}
|
||||
else {
|
||||
return getSharedProperty(-1, prop);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the property value for the specified _sharedEnv index
|
||||
*
|
||||
* @return the object associated with the property name
|
||||
* @param envIdx start index in the shared environment list
|
||||
* @param prop property name
|
||||
*/
|
||||
private Object getSharedProperty(int envIdx, String prop) {
|
||||
|
||||
// Check first the frozen updtates list
|
||||
if (envIdx >= 0) {
|
||||
for (int i= envIdx; i >= 0; i--) {
|
||||
Hashtable tab = (Hashtable) m_sharedEnv.elementAt(i);
|
||||
Object val = tab.get(prop);
|
||||
if (val != null) {
|
||||
return (val == REMOVED_PROPERTY) ? null : val;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check the parent env context
|
||||
if (m_parentSharedEnvIdx >= 0) {
|
||||
return m_parentEnv.getSharedProperty(m_parentSharedEnvIdx, prop);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* Get the property value for the specified _sharedEnv index
|
||||
*
|
||||
* @return the object associated with the property name
|
||||
* @param envIdx start index in the shared environment list
|
||||
* @param prop property name
|
||||
*/
|
||||
private Object getSharedProperty(int envIdx, String prop) {
|
||||
|
||||
// Check first the frozen updtates list
|
||||
if (envIdx >= 0) {
|
||||
for (int i= envIdx; i >= 0; i--) {
|
||||
Hashtable tab = (Hashtable) m_sharedEnv.elementAt(i);
|
||||
Object val = tab.get(prop);
|
||||
if (val != null) {
|
||||
return (val == REMOVED_PROPERTY) ? null : val;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check the parent env context
|
||||
if (m_parentSharedEnvIdx >= 0) {
|
||||
return m_parentEnv.getSharedProperty(m_parentSharedEnvIdx, prop);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove property
|
||||
*
|
||||
* @return the previous value of the specified property,
|
||||
* or <code>null</code> if it did not exist before.
|
||||
* @param prop property name
|
||||
*/
|
||||
public Object removeProperty(String prop) {
|
||||
|
||||
Object val = null;
|
||||
// Is this a shared property ?
|
||||
if (m_sharedEnv != null) {
|
||||
val = getSharedProperty(m_sharedEnv.size()-1, prop);
|
||||
}
|
||||
else {
|
||||
val = getSharedProperty(-1, prop);
|
||||
}
|
||||
|
||||
if (val == null) { // Not a shared property, remove if physically
|
||||
if (m_privateEnv != null) {
|
||||
return m_privateEnv.remove(prop);
|
||||
}
|
||||
}
|
||||
else { //A shared property, hide it
|
||||
setProperty(prop, REMOVED_PROPERTY);
|
||||
}
|
||||
return val;
|
||||
}
|
||||
/**
|
||||
* Remove property
|
||||
*
|
||||
* @return the previous value of the specified property,
|
||||
* or <code>null</code> if it did not exist before.
|
||||
* @param prop property name
|
||||
*/
|
||||
public Object removeProperty(String prop) {
|
||||
|
||||
Object val = null;
|
||||
// Is this a shared property ?
|
||||
if (m_sharedEnv != null) {
|
||||
val = getSharedProperty(m_sharedEnv.size()-1, prop);
|
||||
}
|
||||
else {
|
||||
val = getSharedProperty(-1, prop);
|
||||
}
|
||||
|
||||
if (val == null) { // Not a shared property, remove if physically
|
||||
if (m_privateEnv != null) {
|
||||
return m_privateEnv.remove(prop);
|
||||
}
|
||||
}
|
||||
else { //A shared property, hide it
|
||||
setProperty(prop, REMOVED_PROPERTY);
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a table of all properties. First read all properties from the parent env,
|
||||
* then merge the local updates. Notice that the data is processed in reverse order
|
||||
* than in the getProperty method.
|
||||
*
|
||||
* @return a hashtable containing all properties visible in this context
|
||||
*/
|
||||
public Hashtable getAllProperties() {
|
||||
Hashtable res = null;
|
||||
|
||||
// First copy shared properties
|
||||
if (m_sharedEnv != null) {
|
||||
res = getAllSharedProperties(m_sharedEnv.size()-1);
|
||||
}
|
||||
else {
|
||||
res = getAllSharedProperties(-1);
|
||||
}
|
||||
/**
|
||||
* Create a table of all properties. First read all properties from the parent env,
|
||||
* then merge the local updates. Notice that the data is processed in reverse order
|
||||
* than in the getProperty method.
|
||||
*
|
||||
* @return a hashtable containing all properties visible in this context
|
||||
*/
|
||||
public Hashtable getAllProperties() {
|
||||
Hashtable res = null;
|
||||
|
||||
// First copy shared properties
|
||||
if (m_sharedEnv != null) {
|
||||
res = getAllSharedProperties(m_sharedEnv.size()-1);
|
||||
}
|
||||
else {
|
||||
res = getAllSharedProperties(-1);
|
||||
}
|
||||
|
||||
if (res == null) {
|
||||
res = new Hashtable(51);
|
||||
}
|
||||
|
||||
// Then apply private env
|
||||
if (m_privateEnv != null) {
|
||||
Hashtable tab = m_privateEnv;
|
||||
for (Enumeration e = tab.keys(); e.hasMoreElements();) {
|
||||
Object key = e.nextElement();
|
||||
Object val = tab.get(key);
|
||||
if (val != REMOVED_PROPERTY) {
|
||||
res.put(key, val);
|
||||
}
|
||||
else {
|
||||
res.remove(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (res == null) {
|
||||
res = new Hashtable(51);
|
||||
}
|
||||
|
||||
// Then apply private env
|
||||
if (m_privateEnv != null) {
|
||||
Hashtable tab = m_privateEnv;
|
||||
for (Enumeration e = tab.keys(); e.hasMoreElements();) {
|
||||
Object key = e.nextElement();
|
||||
Object val = tab.get(key);
|
||||
if (val != REMOVED_PROPERTY) {
|
||||
res.put(key, val);
|
||||
}
|
||||
else {
|
||||
res.remove(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a table of all shared properties for the given envIdx. First read all
|
||||
* properties from the parent env, then merge the local environment.
|
||||
*
|
||||
* @return a hashtable containing all properties visible for the shared environment index
|
||||
* @param envIdx start index in the shared environment list
|
||||
*/
|
||||
private Hashtable getAllSharedProperties(int envIdx) {
|
||||
Hashtable res = null;
|
||||
|
||||
// First copy parent env
|
||||
if (m_parentEnv != null) {
|
||||
res = m_parentEnv.getAllSharedProperties(m_parentSharedEnvIdx);
|
||||
}
|
||||
|
||||
if (res == null) {
|
||||
res = new Hashtable(51);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a table of all shared properties for the given envIdx. First read all
|
||||
* properties from the parent env, then merge the local environment.
|
||||
*
|
||||
* @return a hashtable containing all properties visible for the shared environment index
|
||||
* @param envIdx start index in the shared environment list
|
||||
*/
|
||||
private Hashtable getAllSharedProperties(int envIdx) {
|
||||
Hashtable res = null;
|
||||
|
||||
// First copy parent env
|
||||
if (m_parentEnv != null) {
|
||||
res = m_parentEnv.getAllSharedProperties(m_parentSharedEnvIdx);
|
||||
}
|
||||
|
||||
if (res == null) {
|
||||
res = new Hashtable(51);
|
||||
}
|
||||
|
||||
// Then copy _sharedEnv (older entries are processed before newer ones)
|
||||
if (envIdx >= 0) {
|
||||
for (int i= 0; i <= envIdx; i++) {
|
||||
Hashtable tab = (Hashtable) m_sharedEnv.elementAt(i);
|
||||
for (Enumeration e = tab.keys(); e.hasMoreElements();) {
|
||||
Object key = e.nextElement();
|
||||
Object val = tab.get(key);
|
||||
if (val != REMOVED_PROPERTY) {
|
||||
res.put(key, val);
|
||||
}
|
||||
else {
|
||||
res.remove(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
// Then copy _sharedEnv (older entries are processed before newer ones)
|
||||
if (envIdx >= 0) {
|
||||
for (int i= 0; i <= envIdx; i++) {
|
||||
Hashtable tab = (Hashtable) m_sharedEnv.elementAt(i);
|
||||
for (Enumeration e = tab.keys(); e.hasMoreElements();) {
|
||||
Object key = e.nextElement();
|
||||
Object val = tab.get(key);
|
||||
if (val != REMOVED_PROPERTY) {
|
||||
res.put(key, val);
|
||||
}
|
||||
else {
|
||||
res.remove(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Freeze all environment changes changes in the current context. The "Freeze" is
|
||||
* done by moving the _privateEnv table to _sharedEnv vector.
|
||||
*/
|
||||
protected void freezeUpdates() {
|
||||
if (m_privateEnv != null) {
|
||||
// Lazy create _sharedEnv vector
|
||||
if (m_sharedEnv == null) {
|
||||
m_sharedEnv = new Vector();
|
||||
}
|
||||
m_sharedEnv.addElement(m_privateEnv);
|
||||
m_privateEnv = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clone ShareableEnv
|
||||
*
|
||||
* @return A "clone" of the current context environment
|
||||
*/
|
||||
public Object clone() {
|
||||
|
||||
// First freeze updates for this context
|
||||
freezeUpdates();
|
||||
|
||||
// If the context has been modified, then it is the parent of the clone
|
||||
if (m_sharedEnv != null) {
|
||||
return new ShareableEnv(this, m_sharedEnv.size()-1);
|
||||
}
|
||||
|
||||
// No changes has been done to the inherited parent context. Pass the parent
|
||||
// context to the clone
|
||||
else {
|
||||
return new ShareableEnv(m_parentEnv, m_parentSharedEnvIdx);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Freeze all environment changes changes in the current context. The "Freeze" is
|
||||
* done by moving the _privateEnv table to _sharedEnv vector.
|
||||
*/
|
||||
protected void freezeUpdates() {
|
||||
if (m_privateEnv != null) {
|
||||
// Lazy create _sharedEnv vector
|
||||
if (m_sharedEnv == null) {
|
||||
m_sharedEnv = new Vector();
|
||||
}
|
||||
m_sharedEnv.addElement(m_privateEnv);
|
||||
m_privateEnv = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clone ShareableEnv
|
||||
*
|
||||
* @return A "clone" of the current context environment
|
||||
*/
|
||||
public Object clone() {
|
||||
|
||||
// First freeze updates for this context
|
||||
freezeUpdates();
|
||||
|
||||
// If the context has been modified, then it is the parent of the clone
|
||||
if (m_sharedEnv != null) {
|
||||
return new ShareableEnv(this, m_sharedEnv.size()-1);
|
||||
}
|
||||
|
||||
// No changes has been done to the inherited parent context. Pass the parent
|
||||
// context to the clone
|
||||
else {
|
||||
return new ShareableEnv(m_parentEnv, m_parentSharedEnvIdx);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return string representation of the object
|
||||
*
|
||||
* @return a string representation of the object
|
||||
*/
|
||||
public String toString() {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
buf.append("ShareableEnv private=");
|
||||
if (m_privateEnv != null) {
|
||||
buf.append("(");
|
||||
buf.append(m_privateEnv.size());
|
||||
buf.append(")");
|
||||
}
|
||||
buf.append(" shared=");
|
||||
if (m_sharedEnv != null) {
|
||||
for (int i=0; i < m_sharedEnv.size(); i++) {
|
||||
Hashtable tab = (Hashtable) m_sharedEnv.elementAt(i);
|
||||
buf.append("(");
|
||||
buf.append(tab.size());
|
||||
buf.append(")");
|
||||
}
|
||||
}
|
||||
buf.append(" parentIdx=");
|
||||
buf.append(m_parentSharedEnvIdx);
|
||||
|
||||
return buf.toString();
|
||||
}
|
||||
/**
|
||||
* Return string representation of the object
|
||||
*
|
||||
* @return a string representation of the object
|
||||
*/
|
||||
public String toString() {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
buf.append("ShareableEnv private=");
|
||||
if (m_privateEnv != null) {
|
||||
buf.append("(");
|
||||
buf.append(m_privateEnv.size());
|
||||
buf.append(")");
|
||||
}
|
||||
buf.append(" shared=");
|
||||
if (m_sharedEnv != null) {
|
||||
for (int i=0; i < m_sharedEnv.size(); i++) {
|
||||
Hashtable tab = (Hashtable) m_sharedEnv.elementAt(i);
|
||||
buf.append("(");
|
||||
buf.append(tab.size());
|
||||
buf.append(")");
|
||||
}
|
||||
}
|
||||
buf.append(" parentIdx=");
|
||||
buf.append(m_parentSharedEnvIdx);
|
||||
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test program
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
|
||||
ShareableEnv c0 = new ShareableEnv(null, -1); // c=context 0=level 0=index
|
||||
System.err.println("c0.getProperty(p1)=" + c0.getProperty("p1"));
|
||||
System.err.println("c0.getAllProperties()=" + c0.getAllProperties());
|
||||
System.err.println("c0.setProperty(p1,vxxx)=" + c0.setProperty("p1", "vxxx"));
|
||||
System.err.println("c0.setProperty(p2,v2)=" + c0.setProperty("p2", "v2"));
|
||||
System.err.println("c0.setProperty(p3,v3)=" + c0.setProperty("p3", "v3"));
|
||||
System.err.println("c0.setProperty(p1,v1)=" + c0.setProperty("p1", "v1"));
|
||||
System.err.println("c0.getAllProperties()=" + c0.getAllProperties());
|
||||
|
||||
System.err.println("---");
|
||||
ShareableEnv c01 = (ShareableEnv)c0.clone();
|
||||
System.err.println("c01.getProperty(p1)=" + c01.getProperty("p1"));
|
||||
System.err.println("c01.getAllProperties()=" + c01.getAllProperties());
|
||||
System.err.println("c01.setProperty(p1,v1a)=" + c01.setProperty("p1", "v1a"));
|
||||
System.err.println("c01.getProperty(p1)=" + c01.getProperty("p1"));
|
||||
System.err.println("c01.removeProperty(p2)=" + c01.removeProperty("p2"));
|
||||
System.err.println("c01.getProperty(p2)=" + c01.getProperty("p2"));
|
||||
System.err.println("c01.setProperty(p11,v11a)=" + c01.setProperty("p11", "v11a"));
|
||||
System.err.println("c01.getAllProperties()=" + c01.getAllProperties());
|
||||
/**
|
||||
* Test program
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
|
||||
ShareableEnv c0 = new ShareableEnv(null, -1); // c=context 0=level 0=index
|
||||
System.err.println("c0.getProperty(p1)=" + c0.getProperty("p1"));
|
||||
System.err.println("c0.getAllProperties()=" + c0.getAllProperties());
|
||||
System.err.println("c0.setProperty(p1,vxxx)=" + c0.setProperty("p1", "vxxx"));
|
||||
System.err.println("c0.setProperty(p2,v2)=" + c0.setProperty("p2", "v2"));
|
||||
System.err.println("c0.setProperty(p3,v3)=" + c0.setProperty("p3", "v3"));
|
||||
System.err.println("c0.setProperty(p1,v1)=" + c0.setProperty("p1", "v1"));
|
||||
System.err.println("c0.getAllProperties()=" + c0.getAllProperties());
|
||||
|
||||
System.err.println("---");
|
||||
ShareableEnv c01 = (ShareableEnv)c0.clone();
|
||||
System.err.println("c01.getProperty(p1)=" + c01.getProperty("p1"));
|
||||
System.err.println("c01.getAllProperties()=" + c01.getAllProperties());
|
||||
System.err.println("c01.setProperty(p1,v1a)=" + c01.setProperty("p1", "v1a"));
|
||||
System.err.println("c01.getProperty(p1)=" + c01.getProperty("p1"));
|
||||
System.err.println("c01.removeProperty(p2)=" + c01.removeProperty("p2"));
|
||||
System.err.println("c01.getProperty(p2)=" + c01.getProperty("p2"));
|
||||
System.err.println("c01.setProperty(p11,v11a)=" + c01.setProperty("p11", "v11a"));
|
||||
System.err.println("c01.getAllProperties()=" + c01.getAllProperties());
|
||||
|
||||
System.err.println("---");
|
||||
ShareableEnv c02 = (ShareableEnv)c0.clone();
|
||||
System.err.println("c02.getProperty(p1)=" + c02.getProperty("p1"));
|
||||
System.err.println("c02.getAllProperties()=" + c02.getAllProperties());
|
||||
System.err.println("---");
|
||||
ShareableEnv c02 = (ShareableEnv)c0.clone();
|
||||
System.err.println("c02.getProperty(p1)=" + c02.getProperty("p1"));
|
||||
System.err.println("c02.getAllProperties()=" + c02.getAllProperties());
|
||||
|
||||
System.err.println("---");
|
||||
ShareableEnv c011 = (ShareableEnv)c01.clone();
|
||||
System.err.println("c011.getProperty(p1)=" + c011.getProperty("p1"));
|
||||
System.err.println("c011.getAllProperties()=" + c011.getAllProperties());
|
||||
System.err.println("c011.setProperty(p1,v11b)=" + c011.setProperty("p1", "v11b"));
|
||||
System.err.println("c011.getProperty(p1)=" + c011.getProperty("p1"));
|
||||
System.err.println("c011.getAllProperties()=" + c011.getAllProperties());
|
||||
System.err.println("---");
|
||||
ShareableEnv c011 = (ShareableEnv)c01.clone();
|
||||
System.err.println("c011.getProperty(p1)=" + c011.getProperty("p1"));
|
||||
System.err.println("c011.getAllProperties()=" + c011.getAllProperties());
|
||||
System.err.println("c011.setProperty(p1,v11b)=" + c011.setProperty("p1", "v11b"));
|
||||
System.err.println("c011.getProperty(p1)=" + c011.getProperty("p1"));
|
||||
System.err.println("c011.getAllProperties()=" + c011.getAllProperties());
|
||||
|
||||
System.err.println("---");
|
||||
System.err.println("c01.getAllProperties()=" + c01.getAllProperties());
|
||||
System.err.println("c01.removeProperty(p11)=" + c01.removeProperty("p11"));
|
||||
System.err.println("c01.getAllProperties()=" + c01.getAllProperties());
|
||||
System.err.println("c011.getAllProperties()=" + c011.getAllProperties());
|
||||
System.err.println("---");
|
||||
System.err.println("c01.getAllProperties()=" + c01.getAllProperties());
|
||||
System.err.println("c01.removeProperty(p11)=" + c01.removeProperty("p11"));
|
||||
System.err.println("c01.getAllProperties()=" + c01.getAllProperties());
|
||||
System.err.println("c011.getAllProperties()=" + c011.getAllProperties());
|
||||
|
||||
System.err.println("---");
|
||||
ShareableEnv c012 = (ShareableEnv)c01.clone();
|
||||
System.err.println("c012.getAllProperties()=" + c012.getAllProperties());
|
||||
System.err.println("c012.getProperty(p1)=" + c012.getProperty("p1"));
|
||||
|
||||
System.err.println("---");
|
||||
System.err.println("c0="+c0);
|
||||
System.err.println("c01="+c01);
|
||||
System.err.println("c02="+c02);
|
||||
System.err.println("c011="+c011);
|
||||
System.err.println("c012="+c012);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
System.err.println("---");
|
||||
ShareableEnv c012 = (ShareableEnv)c01.clone();
|
||||
System.err.println("c012.getAllProperties()=" + c012.getAllProperties());
|
||||
System.err.println("c012.getProperty(p1)=" + c012.getProperty("p1"));
|
||||
|
||||
System.err.println("---");
|
||||
System.err.println("c0="+c0);
|
||||
System.err.println("c01="+c01);
|
||||
System.err.println("c02="+c02);
|
||||
System.err.println("c011="+c011);
|
||||
System.err.println("c012="+c012);
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -28,182 +28,260 @@ import java.util.*;
|
||||
|
||||
public class SchemaAttribute extends SchemaElement {
|
||||
|
||||
LDAPAttributeSchema m_ldapAttribute;
|
||||
|
||||
// Attribute IDs that are exposed through Netscape LdapJDK
|
||||
private static String[] m_allAttrIds = {NUMERICOID, NAME, DESC, SYNTAX, SINGLEVALUE };
|
||||
|
||||
public SchemaAttribute(LDAPAttributeSchema ldapAttribute, SchemaManager schemaManager) {
|
||||
super(schemaManager);
|
||||
m_ldapAttribute = ldapAttribute;
|
||||
m_path = ATTRDEF + "/" + m_ldapAttribute.getName();
|
||||
}
|
||||
LDAPAttributeSchema m_ldapAttribute;
|
||||
|
||||
// Attribute IDs that are exposed through Netscape LdapJDK
|
||||
private static String[] m_allAttrIds = {NUMERICOID, NAME, DESC, OBSOLETE,
|
||||
SUP, EQUALITY, ORDERING, SUBSTRING,
|
||||
SYNTAX, SINGLEVALUE, COLLECTIVE,
|
||||
NOUSERMOD, USAGE
|
||||
};
|
||||
|
||||
public SchemaAttribute(LDAPAttributeSchema ldapAttribute, SchemaManager schemaManager) {
|
||||
super(schemaManager);
|
||||
m_ldapAttribute = ldapAttribute;
|
||||
m_path = ATTRDEF + "/" + m_ldapAttribute.getName();
|
||||
}
|
||||
|
||||
public SchemaAttribute(Attributes attrs, SchemaManager schemaManager) throws NamingException {
|
||||
super(schemaManager);
|
||||
m_ldapAttribute = parseDefAttributes(attrs);
|
||||
m_path = ATTRDEF + "/" + m_ldapAttribute.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse Definition Attributes for a LDAP attribute
|
||||
*/
|
||||
static LDAPAttributeSchema parseDefAttributes(Attributes attrs) throws NamingException {
|
||||
String name="", oid="", desc="";
|
||||
int syntax=-1;
|
||||
boolean singleValued = false;
|
||||
public SchemaAttribute(Attributes attrs, SchemaManager schemaManager) throws NamingException {
|
||||
super(schemaManager);
|
||||
m_ldapAttribute = parseDefAttributes(attrs);
|
||||
m_path = ATTRDEF + "/" + m_ldapAttribute.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse Definition Attributes for a LDAP attribute
|
||||
*/
|
||||
static LDAPAttributeSchema parseDefAttributes(Attributes attrs) throws NamingException {
|
||||
String name=null, oid=null, desc=null, syntax=null, usage=null, sup=null;
|
||||
String equality=null, ordering=null, substring=null;
|
||||
boolean singleValued=false, collective=false, obsolete=false, noUserMod=false;
|
||||
|
||||
for (Enumeration attrEnum = attrs.getAll(); attrEnum.hasMoreElements(); ) {
|
||||
Attribute attr = (Attribute) attrEnum.nextElement();
|
||||
String attrName = attr.getID();
|
||||
if (attrName.equals(NAME)) {
|
||||
for (Enumeration valEnum = attr.getAll(); valEnum.hasMoreElements(); ) {
|
||||
name = (String)valEnum.nextElement();
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (attrName.equals(NUMERICOID)) {
|
||||
for (Enumeration valEnum = attr.getAll(); valEnum.hasMoreElements(); ) {
|
||||
oid = (String)valEnum.nextElement();
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (attrName.equals(SYNTAX)) {
|
||||
for (Enumeration valEnum = attr.getAll(); valEnum.hasMoreElements(); ) {
|
||||
String syntaxString = (String)valEnum.nextElement();
|
||||
syntax = syntaxStringToInt(syntaxString);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (attrName.equals(DESC)) {
|
||||
for (Enumeration valEnum = attr.getAll(); valEnum.hasMoreElements(); ) {
|
||||
desc = (String)valEnum.nextElement();
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (attrName.equals(SINGLEVALUE)) {
|
||||
for (Enumeration valEnum = attr.getAll(); valEnum.hasMoreElements(); ) {
|
||||
String flag = (String)valEnum.nextElement();
|
||||
if (flag.equals("true")) {
|
||||
singleValued = true;
|
||||
}
|
||||
else if (flag.equals("false")) {
|
||||
singleValued = false;
|
||||
}
|
||||
else {
|
||||
throw new InvalidAttributeValueException(attrName);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (attrName.equals(OBSOLETE) || attrName.equals(SUP) || attrName.equals(USAGE) ||
|
||||
attrName.equals(EQUALITY) || attrName.equals(ORDERING) || attrName.equals(SUBSTRING) ||
|
||||
attrName.equals(COLLECTIVE) || attrName.equals(NOUSERMOD)) {
|
||||
; //ignore
|
||||
}
|
||||
else {
|
||||
throw new NamingException("Invalid schema attribute type for attribute definition " + attrName);
|
||||
}
|
||||
}
|
||||
|
||||
if (name.length() == 0 || oid.length() == 0 || syntax == -1) {
|
||||
throw new NamingException("Incomplete schema attribute definition");
|
||||
}
|
||||
|
||||
return new LDAPAttributeSchema(name, oid, desc, syntax, singleValued);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Exctract specified attributes from the ldapObjectClass
|
||||
*/
|
||||
Attributes extractAttributeIds(String[] attrIds) throws NamingException{
|
||||
Attributes attrs = new BasicAttributes();
|
||||
for (int i = 0; i < attrIds.length; i++) {
|
||||
if (attrIds[i].equals(NUMERICOID)) {
|
||||
attrs.put(new BasicAttribute(NUMERICOID, m_ldapAttribute.getOID()));
|
||||
}
|
||||
else if (attrIds[i].equals(NAME)) {
|
||||
attrs.put(new BasicAttribute(NAME, m_ldapAttribute.getName()));
|
||||
}
|
||||
else if (attrIds[i].equals(DESC)) {
|
||||
attrs.put(new BasicAttribute(DESC, m_ldapAttribute.getDescription()));
|
||||
}
|
||||
else if (attrIds[i].equals(SYNTAX)) {
|
||||
attrs.put(new BasicAttribute(SYNTAX, syntaxIntToString(m_ldapAttribute.getSyntax())));
|
||||
}
|
||||
else if (attrIds[i].equals(SINGLEVALUE)) {
|
||||
attrs.put(new BasicAttribute(SINGLEVALUE,
|
||||
(m_ldapAttribute.isSingleValued() ? "true" : "false")));
|
||||
}
|
||||
else {
|
||||
// ignore other attrIds as not supported by Netscape LdapJDK APIs
|
||||
}
|
||||
}
|
||||
return attrs;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* DirContext Attribute Operations
|
||||
*/
|
||||
for (Enumeration attrEnum = attrs.getAll(); attrEnum.hasMoreElements(); ) {
|
||||
Attribute attr = (Attribute) attrEnum.nextElement();
|
||||
String attrName = attr.getID();
|
||||
if (attrName.equals(NAME)) {
|
||||
name = getSchemaAttrValue(attr);
|
||||
}
|
||||
else if (attrName.equals(NUMERICOID)) {
|
||||
oid = getSchemaAttrValue(attr);
|
||||
}
|
||||
else if (attrName.equals(SYNTAX)) {
|
||||
syntax = getSchemaAttrValue(attr);
|
||||
}
|
||||
else if (attrName.equals(DESC)) {
|
||||
desc = getSchemaAttrValue(attr);
|
||||
}
|
||||
else if (attrName.equals(SINGLEVALUE)) {
|
||||
singleValued = parseTrueFalseValue(attr);
|
||||
}
|
||||
else if (attrName.equals(SUP)) {
|
||||
sup = getSchemaAttrValue(attr);
|
||||
}
|
||||
else if (attrName.equals(USAGE)) {
|
||||
usage = getSchemaAttrValue(attr);
|
||||
}
|
||||
else if (attrName.equals(OBSOLETE)) {
|
||||
obsolete = parseTrueFalseValue(attr);
|
||||
}
|
||||
else if (attrName.equals(COLLECTIVE)) {
|
||||
collective = parseTrueFalseValue(attr);
|
||||
}
|
||||
else if (attrName.equals(NOUSERMOD)) {
|
||||
noUserMod = parseTrueFalseValue(attr);
|
||||
}
|
||||
else if (attrName.equals(EQUALITY)) {
|
||||
equality = getSchemaAttrValue(attr);
|
||||
}
|
||||
else if (attrName.equals(ORDERING)) {
|
||||
ordering = getSchemaAttrValue(attr);
|
||||
}
|
||||
else if (attrName.equals(SUBSTRING)) {
|
||||
substring = getSchemaAttrValue(attr);
|
||||
}
|
||||
|
||||
public Attributes getAttributes(String name) throws NamingException {
|
||||
if (name.length() != 0) { // no subcontexts
|
||||
throw new NameNotFoundException(name); // no such object
|
||||
}
|
||||
return extractAttributeIds(m_allAttrIds);
|
||||
}
|
||||
else {
|
||||
throw new NamingException("Invalid schema attribute type for attribute definition " + attrName);
|
||||
}
|
||||
}
|
||||
|
||||
LDAPAttributeSchema attrSchema = new LDAPAttributeSchema(name, oid, desc, syntax, singleValued, sup, null);
|
||||
|
||||
if (obsolete) {
|
||||
attrSchema.setQualifier(OBSOLETE, "");
|
||||
}
|
||||
if (collective) {
|
||||
attrSchema.setQualifier(COLLECTIVE, "");
|
||||
}
|
||||
if (noUserMod) {
|
||||
attrSchema.setQualifier(NOUSERMOD, "");
|
||||
}
|
||||
if (equality != null) {
|
||||
attrSchema.setQualifier(EQUALITY, equality);
|
||||
}
|
||||
if (ordering != null) {
|
||||
attrSchema.setQualifier(ORDERING, ordering);
|
||||
}
|
||||
if (substring != null) {
|
||||
attrSchema.setQualifier(SUBSTRING, substring);
|
||||
}
|
||||
if (usage != null) {
|
||||
attrSchema.setQualifier(USAGE, usage);
|
||||
}
|
||||
|
||||
return attrSchema;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Exctract specified attributes from the ldapObjectClass
|
||||
*/
|
||||
Attributes extractAttributeIds(String[] attrIds) throws NamingException{
|
||||
Attributes attrs = new BasicAttributes();
|
||||
String val = null, multiVal[]=null;
|
||||
for (int i = 0; i < attrIds.length; i++) {
|
||||
if (attrIds[i].equals(NUMERICOID)) {
|
||||
val = m_ldapAttribute.getOID();
|
||||
if (val != null) {
|
||||
attrs.put(new BasicAttribute(NUMERICOID, val));
|
||||
}
|
||||
}
|
||||
else if (attrIds[i].equals(NAME)) {
|
||||
val = m_ldapAttribute.getName();
|
||||
if (val != null) {
|
||||
attrs.put(new BasicAttribute(NAME, val));
|
||||
}
|
||||
}
|
||||
else if (attrIds[i].equals(DESC)) {
|
||||
val = m_ldapAttribute.getDescription();
|
||||
if (val != null) {
|
||||
attrs.put(new BasicAttribute(DESC, val));
|
||||
}
|
||||
}
|
||||
else if (attrIds[i].equals(SYNTAX)) {
|
||||
val = m_ldapAttribute.getSyntaxString();
|
||||
if (val != null) {
|
||||
attrs.put(new BasicAttribute(SYNTAX, val));
|
||||
}
|
||||
}
|
||||
else if (attrIds[i].equals(SINGLEVALUE)) {
|
||||
if (m_ldapAttribute.isSingleValued()) {
|
||||
attrs.put(new BasicAttribute(SINGLEVALUE, "true"));
|
||||
}
|
||||
}
|
||||
else if (attrIds[i].equals(SUP)) {
|
||||
val = m_ldapAttribute.getSuperior();
|
||||
if (val != null) {
|
||||
attrs.put(new BasicAttribute(SUP, val));
|
||||
}
|
||||
}
|
||||
else if (attrIds[i].equals(USAGE)) {
|
||||
multiVal = m_ldapAttribute.getQualifier(USAGE);
|
||||
if (multiVal != null) {
|
||||
attrs.put(new BasicAttribute(USAGE, multiVal));
|
||||
}
|
||||
}
|
||||
else if (attrIds[i].equals(OBSOLETE)) {
|
||||
if (m_ldapAttribute.getQualifier(OBSOLETE) != null) {
|
||||
attrs.put(new BasicAttribute(OBSOLETE, "true"));
|
||||
}
|
||||
}
|
||||
else if (attrIds[i].equals(COLLECTIVE)) {
|
||||
if (m_ldapAttribute.getQualifier(COLLECTIVE) != null) {
|
||||
attrs.put(new BasicAttribute(COLLECTIVE, "true"));
|
||||
}
|
||||
}
|
||||
else if (attrIds[i].equals(NOUSERMOD)) {
|
||||
if (m_ldapAttribute.getQualifier(NOUSERMOD) != null) {
|
||||
attrs.put(new BasicAttribute(NOUSERMOD, "true"));
|
||||
}
|
||||
}
|
||||
else if (attrIds[i].equals(EQUALITY)) {
|
||||
multiVal = m_ldapAttribute.getQualifier(EQUALITY);
|
||||
if (multiVal != null) {
|
||||
attrs.put(new BasicAttribute(EQUALITY, multiVal));
|
||||
}
|
||||
}
|
||||
else if (attrIds[i].equals(ORDERING)) {
|
||||
multiVal = m_ldapAttribute.getQualifier(ORDERING);
|
||||
if (multiVal != null) {
|
||||
attrs.put(new BasicAttribute(ORDERING, multiVal));
|
||||
}
|
||||
}
|
||||
else if (attrIds[i].equals(SUBSTRING)) {
|
||||
multiVal = m_ldapAttribute.getQualifier(SUBSTRING);
|
||||
if (multiVal != null) {
|
||||
attrs.put(new BasicAttribute(SUBSTRING, multiVal));
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new NamingException("Invalid schema attribute type for attribute definition " + attrIds[i]);
|
||||
}
|
||||
}
|
||||
return attrs;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* DirContext Attribute Operations
|
||||
*/
|
||||
|
||||
public Attributes getAttributes(String name, String[] attrIds) throws NamingException {
|
||||
if (name.length() != 0) { // no subcontexts
|
||||
throw new NameNotFoundException(name); // no such object
|
||||
}
|
||||
return extractAttributeIds(attrIds);
|
||||
}
|
||||
public Attributes getAttributes(String name) throws NamingException {
|
||||
if (name.length() != 0) { // no subcontexts
|
||||
throw new NameNotFoundException(name); // no such object
|
||||
}
|
||||
return extractAttributeIds(m_allAttrIds);
|
||||
}
|
||||
|
||||
public Attributes getAttributes(Name name) throws NamingException {
|
||||
return getAttributes(name.toString());
|
||||
}
|
||||
public Attributes getAttributes(String name, String[] attrIds) throws NamingException {
|
||||
if (name.length() != 0) { // no subcontexts
|
||||
throw new NameNotFoundException(name); // no such object
|
||||
}
|
||||
return extractAttributeIds(attrIds);
|
||||
}
|
||||
|
||||
public Attributes getAttributes(Name name, String[] attrIds) throws NamingException {
|
||||
return getAttributes(name.toString(), attrIds);
|
||||
}
|
||||
public Attributes getAttributes(Name name) throws NamingException {
|
||||
return getAttributes(name.toString());
|
||||
}
|
||||
|
||||
public void modifyAttributes(String name, int mod_op, Attributes attrs) throws NamingException {
|
||||
if (name.length() != 0) { // no subcontexts
|
||||
throw new NameNotFoundException(name); // no such object
|
||||
}
|
||||
Attributes modAttrs = extractAttributeIds(m_allAttrIds);
|
||||
modifySchemaElementAttrs(modAttrs, mod_op, attrs);
|
||||
LDAPAttributeSchema modLdapAttribute = parseDefAttributes(modAttrs);
|
||||
m_schemaMgr.modifyAttribute(m_ldapAttribute, modLdapAttribute);
|
||||
m_ldapAttribute = modLdapAttribute;
|
||||
}
|
||||
public Attributes getAttributes(Name name, String[] attrIds) throws NamingException {
|
||||
return getAttributes(name.toString(), attrIds);
|
||||
}
|
||||
|
||||
public void modifyAttributes(String name, ModificationItem[] mods) throws NamingException {
|
||||
if (name.length() != 0) { // no subcontexts
|
||||
throw new NameNotFoundException(name); // no such object
|
||||
}
|
||||
Attributes modAttrs = extractAttributeIds(m_allAttrIds);
|
||||
modifySchemaElementAttrs(modAttrs, mods);
|
||||
LDAPAttributeSchema modLdapAttribute = parseDefAttributes(modAttrs);
|
||||
m_schemaMgr.modifyAttribute(m_ldapAttribute, modLdapAttribute);
|
||||
m_ldapAttribute = modLdapAttribute;
|
||||
}
|
||||
public void modifyAttributes(String name, int mod_op, Attributes attrs) throws NamingException {
|
||||
if (name.length() != 0) { // no subcontexts
|
||||
throw new NameNotFoundException(name); // no such object
|
||||
}
|
||||
Attributes modAttrs = extractAttributeIds(m_allAttrIds);
|
||||
modifySchemaElementAttrs(modAttrs, mod_op, attrs);
|
||||
LDAPAttributeSchema modLdapAttribute = parseDefAttributes(modAttrs);
|
||||
m_schemaMgr.modifyAttribute(m_ldapAttribute, modLdapAttribute);
|
||||
m_ldapAttribute = modLdapAttribute;
|
||||
}
|
||||
|
||||
public void modifyAttributes(Name name, int mod_op, Attributes attrs) throws NamingException {
|
||||
modifyAttributes(name.toString(), mod_op, attrs);
|
||||
}
|
||||
public void modifyAttributes(String name, ModificationItem[] mods) throws NamingException {
|
||||
if (name.length() != 0) { // no subcontexts
|
||||
throw new NameNotFoundException(name); // no such object
|
||||
}
|
||||
Attributes modAttrs = extractAttributeIds(m_allAttrIds);
|
||||
modifySchemaElementAttrs(modAttrs, mods);
|
||||
LDAPAttributeSchema modLdapAttribute = parseDefAttributes(modAttrs);
|
||||
m_schemaMgr.modifyAttribute(m_ldapAttribute, modLdapAttribute);
|
||||
m_ldapAttribute = modLdapAttribute;
|
||||
}
|
||||
|
||||
public void modifyAttributes(Name name, ModificationItem[] mods) throws NamingException {
|
||||
modifyAttributes(name.toString(), mods);
|
||||
}
|
||||
|
||||
/**
|
||||
* Search operations are not implemented because of complexity. Ir will require
|
||||
* to implement the full LDAP search filter sematics in the client. (The search
|
||||
* filter sematics is implemented by the Directory server).
|
||||
*/
|
||||
|
||||
public void modifyAttributes(Name name, int mod_op, Attributes attrs) throws NamingException {
|
||||
modifyAttributes(name.toString(), mod_op, attrs);
|
||||
}
|
||||
|
||||
public void modifyAttributes(Name name, ModificationItem[] mods) throws NamingException {
|
||||
modifyAttributes(name.toString(), mods);
|
||||
}
|
||||
|
||||
/**
|
||||
* Search operations are not implemented because of complexity. Ir will require
|
||||
* to implement the full LDAP search filter sematics in the client. (The search
|
||||
* filter sematics is implemented by the Directory server).
|
||||
*/
|
||||
|
||||
}
|
||||
|
@ -28,70 +28,70 @@ import java.util.*;
|
||||
|
||||
public class SchemaAttributeContainer extends SchemaElementContainer {
|
||||
|
||||
public SchemaAttributeContainer(SchemaManager schemaMgr) throws NamingException{
|
||||
super(schemaMgr, ATTRDEF);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ldap entry operations
|
||||
*/
|
||||
public SchemaAttributeContainer(SchemaManager schemaMgr) throws NamingException{
|
||||
super(schemaMgr, ATTRDEF);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ldap entry operations
|
||||
*/
|
||||
|
||||
public DirContext createSchemaElement(String name, Attributes attrs) throws NamingException {
|
||||
if (name.length() == 0) {
|
||||
throw new NamingException("Empty name for schema objectclass");
|
||||
}
|
||||
LDAPAttributeSchema attr = SchemaAttribute.parseDefAttributes(attrs);
|
||||
m_schemaMgr.createAttribute(attr);
|
||||
return new SchemaAttribute(attr, m_schemaMgr);
|
||||
public DirContext createSchemaElement(String name, Attributes attrs) throws NamingException {
|
||||
if (name.length() == 0) {
|
||||
throw new NamingException("Empty name for schema objectclass");
|
||||
}
|
||||
LDAPAttributeSchema attr = SchemaAttribute.parseDefAttributes(attrs);
|
||||
m_schemaMgr.createAttribute(attr);
|
||||
return new SchemaAttribute(attr, m_schemaMgr);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void removeSchemaElement(String name) throws NamingException {
|
||||
if (name.length() == 0) {
|
||||
throw new NamingException("Can not delete schema object container");
|
||||
}
|
||||
m_schemaMgr.removeAttribute(name);
|
||||
}
|
||||
public void removeSchemaElement(String name) throws NamingException {
|
||||
if (name.length() == 0) {
|
||||
throw new NamingException("Can not delete schema object container");
|
||||
}
|
||||
m_schemaMgr.removeAttribute(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* List Operations
|
||||
*/
|
||||
/**
|
||||
* List Operations
|
||||
*/
|
||||
|
||||
public NamingEnumeration getNameList(String name) throws NamingException {
|
||||
SchemaDirContext schemaObj = (SchemaDirContext)lookup(name);
|
||||
if (schemaObj == this) {
|
||||
return new SchemaElementNameEnum(m_schemaMgr.getAttributeNames());
|
||||
}
|
||||
else {
|
||||
throw new NotContextException(name);
|
||||
}
|
||||
}
|
||||
public NamingEnumeration getNameList(String name) throws NamingException {
|
||||
SchemaDirContext schemaObj = (SchemaDirContext)lookup(name);
|
||||
if (schemaObj == this) {
|
||||
return new SchemaElementNameEnum(m_schemaMgr.getAttributeNames());
|
||||
}
|
||||
else {
|
||||
throw new NotContextException(name);
|
||||
}
|
||||
}
|
||||
|
||||
public NamingEnumeration getBindingsList(String name) throws NamingException {
|
||||
SchemaDirContext schemaObj = (SchemaDirContext)lookup(name);
|
||||
if (schemaObj == this) {
|
||||
return new SchemaElementBindingEnum(m_schemaMgr.getAttributes(), m_schemaMgr);
|
||||
}
|
||||
else {
|
||||
throw new NotContextException(name);
|
||||
}
|
||||
}
|
||||
public NamingEnumeration getBindingsList(String name) throws NamingException {
|
||||
SchemaDirContext schemaObj = (SchemaDirContext)lookup(name);
|
||||
if (schemaObj == this) {
|
||||
return new SchemaElementBindingEnum(m_schemaMgr.getAttributes(), m_schemaMgr);
|
||||
}
|
||||
else {
|
||||
throw new NotContextException(name);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Lookup Operations
|
||||
*/
|
||||
/**
|
||||
* Lookup Operations
|
||||
*/
|
||||
|
||||
public Object lookupSchemaElement(String name) throws NamingException {
|
||||
if (name.length() == 0) {
|
||||
return this;
|
||||
}
|
||||
|
||||
// No caching; Always create a new object
|
||||
LDAPAttributeSchema attr = m_schemaMgr.getAttribute(name);
|
||||
if (attr == null) {
|
||||
throw new NameNotFoundException(name);
|
||||
}
|
||||
return new SchemaAttribute(attr, m_schemaMgr);
|
||||
public Object lookupSchemaElement(String name) throws NamingException {
|
||||
if (name.length() == 0) {
|
||||
return this;
|
||||
}
|
||||
|
||||
// No caching; Always create a new object
|
||||
LDAPAttributeSchema attr = m_schemaMgr.getAttribute(name);
|
||||
if (attr == null) {
|
||||
throw new NameNotFoundException(name);
|
||||
}
|
||||
return new SchemaAttribute(attr, m_schemaMgr);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -29,132 +29,132 @@ import java.util.*;
|
||||
|
||||
public class SchemaDirContext extends DirContextAdapter {
|
||||
|
||||
public static final String CLASSDEF = "ClassDefinition";
|
||||
public static final String ATTRDEF = "AttributeDefinition";
|
||||
public static final String MRULEDEF = "MatchingRule";
|
||||
|
||||
public static final String CLASSDEF = "ClassDefinition";
|
||||
public static final String ATTRDEF = "AttributeDefinition";
|
||||
public static final String MRULEDEF = "MatchingRule";
|
||||
|
||||
|
||||
String m_path;
|
||||
String m_path;
|
||||
|
||||
public void close() throws NamingException {
|
||||
; //NOP
|
||||
}
|
||||
public void close() throws NamingException {
|
||||
; //NOP
|
||||
}
|
||||
|
||||
/**
|
||||
* Name operations
|
||||
*/
|
||||
/**
|
||||
* Name operations
|
||||
*/
|
||||
|
||||
public String composeName(String name, String prefix) throws NamingException {
|
||||
return name + "," + prefix;
|
||||
}
|
||||
public String composeName(String name, String prefix) throws NamingException {
|
||||
return name + "," + prefix;
|
||||
}
|
||||
|
||||
public Name composeName(Name name, Name prefix) throws NamingException {
|
||||
String compoundName = composeName(name.toString(), prefix.toString());
|
||||
return SchemaNameParser.getParser().parse(compoundName);
|
||||
}
|
||||
public Name composeName(Name name, Name prefix) throws NamingException {
|
||||
String compoundName = composeName(name.toString(), prefix.toString());
|
||||
return SchemaNameParser.getParser().parse(compoundName);
|
||||
}
|
||||
|
||||
public String getNameInNamespace() throws NamingException {
|
||||
return new String(m_path);
|
||||
}
|
||||
public String getNameInNamespace() throws NamingException {
|
||||
return new String(m_path);
|
||||
}
|
||||
|
||||
public NameParser getNameParser(String name) throws NamingException {
|
||||
return SchemaNameParser.getParser();
|
||||
}
|
||||
public NameParser getNameParser(String name) throws NamingException {
|
||||
return SchemaNameParser.getParser();
|
||||
}
|
||||
|
||||
public NameParser getNameParser(Name name) throws NamingException {
|
||||
return SchemaNameParser.getParser();
|
||||
}
|
||||
public NameParser getNameParser(Name name) throws NamingException {
|
||||
return SchemaNameParser.getParser();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Naming Bind operations
|
||||
*/
|
||||
|
||||
/**
|
||||
* Naming Bind operations
|
||||
*/
|
||||
|
||||
public void bind(String name, Object obj) throws NamingException {
|
||||
if (obj instanceof DirContext) {
|
||||
createSubcontext(name, ((DirContext)obj).getAttributes(""));
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException("Can not bind this type of object");
|
||||
}
|
||||
}
|
||||
public void bind(String name, Object obj) throws NamingException {
|
||||
if (obj instanceof DirContext) {
|
||||
createSubcontext(name, ((DirContext)obj).getAttributes(""));
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException("Can not bind this type of object");
|
||||
}
|
||||
}
|
||||
|
||||
public void bind(Name name, Object obj) throws NamingException {
|
||||
bind(name.toString(), obj);
|
||||
}
|
||||
public void bind(Name name, Object obj) throws NamingException {
|
||||
bind(name.toString(), obj);
|
||||
}
|
||||
|
||||
public void rebind(String name, Object obj) throws NamingException {
|
||||
try {
|
||||
bind(name, obj);
|
||||
}
|
||||
catch (NameAlreadyBoundException ex) {
|
||||
unbind(name);
|
||||
bind(name, obj);
|
||||
}
|
||||
}
|
||||
public void rebind(String name, Object obj) throws NamingException {
|
||||
try {
|
||||
bind(name, obj);
|
||||
}
|
||||
catch (NameAlreadyBoundException ex) {
|
||||
unbind(name);
|
||||
bind(name, obj);
|
||||
}
|
||||
}
|
||||
|
||||
public void rebind(Name name, Object obj) throws NamingException {
|
||||
rebind(name.toString(), obj);
|
||||
}
|
||||
public void rebind(Name name, Object obj) throws NamingException {
|
||||
rebind(name.toString(), obj);
|
||||
}
|
||||
|
||||
public void rename(String oldName, String newName) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public void rename(String oldName, String newName) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
public void rename(Name oldName, Name newName) throws NamingException {
|
||||
rename(oldName.toString(), newName.toString());
|
||||
}
|
||||
public void rename(Name oldName, Name newName) throws NamingException {
|
||||
rename(oldName.toString(), newName.toString());
|
||||
}
|
||||
|
||||
public void unbind(String name) throws NamingException {
|
||||
// In ldap every entry is naming context
|
||||
destroySubcontext(name);
|
||||
}
|
||||
public void unbind(String name) throws NamingException {
|
||||
// In ldap every entry is naming context
|
||||
destroySubcontext(name);
|
||||
}
|
||||
|
||||
public void unbind(Name name) throws NamingException {
|
||||
// In ldap every entry is naming context
|
||||
destroySubcontext(name);
|
||||
}
|
||||
public void unbind(Name name) throws NamingException {
|
||||
// In ldap every entry is naming context
|
||||
destroySubcontext(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Empty enumeration for list operations
|
||||
*/
|
||||
class EmptyNamingEnumeration implements NamingEnumeration {
|
||||
/**
|
||||
* Empty enumeration for list operations
|
||||
*/
|
||||
class EmptyNamingEnumeration implements NamingEnumeration {
|
||||
|
||||
public Object next() throws NamingException{
|
||||
throw new NoSuchElementException("EmptyNamingEnumeration");
|
||||
}
|
||||
public Object next() throws NamingException{
|
||||
throw new NoSuchElementException("EmptyNamingEnumeration");
|
||||
}
|
||||
|
||||
public Object nextElement() {
|
||||
throw new NoSuchElementException("EmptyNamingEnumeration");
|
||||
}
|
||||
public Object nextElement() {
|
||||
throw new NoSuchElementException("EmptyNamingEnumeration");
|
||||
}
|
||||
|
||||
public boolean hasMore() throws NamingException{
|
||||
return false;
|
||||
}
|
||||
public boolean hasMore() throws NamingException{
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean hasMoreElements() {
|
||||
return false;
|
||||
}
|
||||
public boolean hasMoreElements() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void close() {}
|
||||
}
|
||||
|
||||
static class SchemaObjectSubordinateNamePair {
|
||||
SchemaDirContext schemaObj;
|
||||
String subordinateName;
|
||||
|
||||
public SchemaObjectSubordinateNamePair(SchemaDirContext object, String subordinateName) {
|
||||
this.schemaObj = object;
|
||||
this.subordinateName = subordinateName;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuffer str = new StringBuffer("SchemaObjectSubordinateNamePair{obj:");
|
||||
str.append(((schemaObj == null) ? "null" : schemaObj.toString()));
|
||||
str.append(" name:");
|
||||
str.append(subordinateName);
|
||||
str.append("}");
|
||||
return str.toString();
|
||||
}
|
||||
}
|
||||
public void close() {}
|
||||
}
|
||||
|
||||
static class SchemaObjectSubordinateNamePair {
|
||||
SchemaDirContext schemaObj;
|
||||
String subordinateName;
|
||||
|
||||
public SchemaObjectSubordinateNamePair(SchemaDirContext object, String subordinateName) {
|
||||
this.schemaObj = object;
|
||||
this.subordinateName = subordinateName;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuffer str = new StringBuffer("SchemaObjectSubordinateNamePair{obj:");
|
||||
str.append(((schemaObj == null) ? "null" : schemaObj.toString()));
|
||||
str.append(" name:");
|
||||
str.append(subordinateName);
|
||||
str.append("}");
|
||||
return str.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -30,8 +30,8 @@ public class SchemaElement extends SchemaDirContext {
|
||||
|
||||
SchemaManager m_schemaMgr;
|
||||
|
||||
// Attributes used to define schema elements
|
||||
static final String NUMERICOID = "NUMERICOID";
|
||||
// Attributes used to define schema elements
|
||||
static final String NUMERICOID = "NUMERICOID";
|
||||
static final String NAME = "NAME";
|
||||
static final String DESC = "DESC";
|
||||
static final String SYNTAX = "SYNTAX";
|
||||
@ -39,9 +39,9 @@ public class SchemaElement extends SchemaDirContext {
|
||||
static final String MUST = "MUST";
|
||||
static final String MAY = "MAY";
|
||||
static final String SINGLEVALUE = "SINGLE-VALUE";
|
||||
|
||||
// These attribute definition properties are not supported by LdapJDK and DS
|
||||
// Accept them for the appropriate schema element, but ignore them
|
||||
|
||||
// These attribute definition properties are not supported by LdapJDK and DS
|
||||
// Accept them for the appropriate schema element, but ignore them
|
||||
static final String OBSOLETE = "OBSOLETE";
|
||||
static final String EQUALITY = "EQUALITY";
|
||||
static final String ORDERING = "ORDERING";
|
||||
@ -54,161 +54,193 @@ public class SchemaElement extends SchemaDirContext {
|
||||
static final String AUXILIARY = "AUXILIARY";
|
||||
|
||||
|
||||
// Syntax string recognized by Netscape LdapJDK
|
||||
// Syntax string recognized by Netscape LdapJDK
|
||||
static final String cisString = "1.3.6.1.4.1.1466.115.121.1.15";
|
||||
static final String binaryString = "1.3.6.1.4.1.1466.115.121.1.5";
|
||||
static final String telephoneString = "1.3.6.1.4.1.1466.115.121.1.50";
|
||||
static final String cesString = "1.3.6.1.4.1.1466.115.121.1.26";
|
||||
static final String intString = "1.3.6.1.4.1.1466.115.121.1.27";
|
||||
static final String dnString = "1.3.6.1.4.1.1466.115.121.1.12";
|
||||
|
||||
SchemaElement(SchemaManager schemaMgr) {
|
||||
m_schemaMgr = schemaMgr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Map a syntax oid string to a constant recognized by LdapJDK
|
||||
*/
|
||||
static int syntaxStringToInt(String syntax) throws NamingException{
|
||||
if (syntax.equals(cisString)) {
|
||||
return LDAPSchemaElement.cis;
|
||||
}
|
||||
else if (syntax.equals(cesString)) {
|
||||
return LDAPSchemaElement.ces;
|
||||
}
|
||||
else if (syntax.equals(telephoneString)) {
|
||||
return LDAPSchemaElement.telephone;
|
||||
}
|
||||
else if (syntax.equals(intString)) {
|
||||
return LDAPSchemaElement.integer;
|
||||
}
|
||||
else if (syntax.equals(dnString)) {
|
||||
return LDAPSchemaElement.dn;
|
||||
}
|
||||
else if (syntax.equals(binaryString)) {
|
||||
return LDAPSchemaElement.binary;
|
||||
}
|
||||
else {
|
||||
throw new InvalidAttributeValueException(syntax);
|
||||
}
|
||||
}
|
||||
|
||||
SchemaElement(SchemaManager schemaMgr) {
|
||||
m_schemaMgr = schemaMgr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Map a syntax oid string to a constant recognized by LdapJDK
|
||||
*/
|
||||
static int syntaxStringToInt(String syntax) throws NamingException{
|
||||
if (syntax.equals(cisString)) {
|
||||
return LDAPSchemaElement.cis;
|
||||
}
|
||||
else if (syntax.equals(cesString)) {
|
||||
return LDAPSchemaElement.ces;
|
||||
}
|
||||
else if (syntax.equals(telephoneString)) {
|
||||
return LDAPSchemaElement.telephone;
|
||||
}
|
||||
else if (syntax.equals(intString)) {
|
||||
return LDAPSchemaElement.integer;
|
||||
}
|
||||
else if (syntax.equals(dnString)) {
|
||||
return LDAPSchemaElement.dn;
|
||||
}
|
||||
else if (syntax.equals(binaryString)) {
|
||||
return LDAPSchemaElement.binary;
|
||||
}
|
||||
else {
|
||||
throw new InvalidAttributeValueException(syntax);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Map a syntax identifier to a oid string
|
||||
*/
|
||||
static String syntaxIntToString(int syntax) throws NamingException{
|
||||
if (syntax == LDAPSchemaElement.cis) {
|
||||
return cisString;
|
||||
}
|
||||
else if (syntax == LDAPSchemaElement.ces) {
|
||||
return cesString;
|
||||
}
|
||||
else if (syntax == LDAPSchemaElement.telephone) {
|
||||
return telephoneString;
|
||||
}
|
||||
else if (syntax == LDAPSchemaElement.integer) {
|
||||
return intString;
|
||||
}
|
||||
else if (syntax == LDAPSchemaElement.dn) {
|
||||
return dnString;
|
||||
}
|
||||
else if (syntax == LDAPSchemaElement.binary) {
|
||||
return binaryString;
|
||||
}
|
||||
else {
|
||||
throw new InvalidAttributeValueException("Interanal error, unexpected syntax value " + syntax);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Map a syntax identifier to a oid string
|
||||
*/
|
||||
static String syntaxIntToString(int syntax) throws NamingException{
|
||||
if (syntax == LDAPSchemaElement.cis) {
|
||||
return cisString;
|
||||
}
|
||||
else if (syntax == LDAPSchemaElement.ces) {
|
||||
return cesString;
|
||||
}
|
||||
else if (syntax == LDAPSchemaElement.telephone) {
|
||||
return telephoneString;
|
||||
}
|
||||
else if (syntax == LDAPSchemaElement.integer) {
|
||||
return intString;
|
||||
}
|
||||
else if (syntax == LDAPSchemaElement.dn) {
|
||||
return dnString;
|
||||
}
|
||||
else if (syntax == LDAPSchemaElement.binary) {
|
||||
return binaryString;
|
||||
}
|
||||
else {
|
||||
throw new InvalidAttributeValueException("Interanal error, unexpected syntax value " + syntax);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert string vector to an array
|
||||
*/
|
||||
static String[] vectorToStringAry(Vector v) {
|
||||
String[] ary = new String[v.size()];
|
||||
for(int i=0; i<v.size(); i++) {
|
||||
ary[i] = (String) v.elementAt(i);
|
||||
}
|
||||
return ary;
|
||||
}
|
||||
/**
|
||||
* Convert string vector to an array
|
||||
*/
|
||||
static String[] vectorToStringAry(Vector v) {
|
||||
String[] ary = new String[v.size()];
|
||||
for(int i=0; i<v.size(); i++) {
|
||||
ary[i] = (String) v.elementAt(i);
|
||||
}
|
||||
return ary;
|
||||
}
|
||||
|
||||
/**
|
||||
* List Operations
|
||||
*/
|
||||
/**
|
||||
* List Operations
|
||||
*/
|
||||
|
||||
public NamingEnumeration list(String name) throws NamingException {
|
||||
return new EmptyNamingEnumeration();
|
||||
}
|
||||
public NamingEnumeration list(String name) throws NamingException {
|
||||
return new EmptyNamingEnumeration();
|
||||
}
|
||||
|
||||
public NamingEnumeration list(Name name) throws NamingException {
|
||||
return new EmptyNamingEnumeration();
|
||||
}
|
||||
public NamingEnumeration list(Name name) throws NamingException {
|
||||
return new EmptyNamingEnumeration();
|
||||
}
|
||||
|
||||
public NamingEnumeration listBindings(String name) throws NamingException {
|
||||
return new EmptyNamingEnumeration();
|
||||
}
|
||||
public NamingEnumeration listBindings(String name) throws NamingException {
|
||||
return new EmptyNamingEnumeration();
|
||||
}
|
||||
|
||||
public NamingEnumeration listBindings(Name name) throws NamingException {
|
||||
return new EmptyNamingEnumeration();
|
||||
}
|
||||
public NamingEnumeration listBindings(Name name) throws NamingException {
|
||||
return new EmptyNamingEnumeration();
|
||||
}
|
||||
|
||||
/**
|
||||
* Modify the current set of the schema element's attributes
|
||||
*/
|
||||
void modifySchemaElementAttrs (Attributes attrs, ModificationItem[] jndiMods) throws NamingException{
|
||||
LDAPModificationSet mods = new LDAPModificationSet();
|
||||
for (int i=0; i < jndiMods.length; i++) {
|
||||
int modop = jndiMods[i].getModificationOp();
|
||||
Attribute attr = jndiMods[i].getAttribute();
|
||||
Attributes modAttrs = new BasicAttributes(/*ignorecase=*/true);
|
||||
modAttrs.put(attr);
|
||||
void modifySchemaElementAttrs (Attributes attrs, ModificationItem[] jndiMods) throws NamingException{
|
||||
LDAPModificationSet mods = new LDAPModificationSet();
|
||||
for (int i=0; i < jndiMods.length; i++) {
|
||||
int modop = jndiMods[i].getModificationOp();
|
||||
Attribute attr = jndiMods[i].getAttribute();
|
||||
Attributes modAttrs = new BasicAttributes(/*ignorecase=*/true);
|
||||
modAttrs.put(attr);
|
||||
modifySchemaElementAttrs(attrs, modop, modAttrs);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Modify the current set of the schema element's attributes
|
||||
*/
|
||||
void modifySchemaElementAttrs (Attributes attrs, int modop, Attributes modAttrs) throws NamingException{
|
||||
LDAPModificationSet mods = new LDAPModificationSet();
|
||||
for (NamingEnumeration attrEnum = modAttrs.getAll(); attrEnum.hasMore();) {
|
||||
Attribute attr = (Attribute)attrEnum.next();
|
||||
if (modop == DirContext.ADD_ATTRIBUTE) {
|
||||
Attribute curAttr = attrs.get(attr.getID());
|
||||
if (curAttr == null) {
|
||||
attrs.put(attr);
|
||||
void modifySchemaElementAttrs (Attributes attrs, int modop, Attributes modAttrs) throws NamingException{
|
||||
LDAPModificationSet mods = new LDAPModificationSet();
|
||||
for (NamingEnumeration attrEnum = modAttrs.getAll(); attrEnum.hasMore();) {
|
||||
Attribute attr = (Attribute)attrEnum.next();
|
||||
if (modop == DirContext.ADD_ATTRIBUTE) {
|
||||
Attribute curAttr = attrs.get(attr.getID());
|
||||
if (curAttr == null) {
|
||||
attrs.put(attr);
|
||||
}
|
||||
else {
|
||||
for (NamingEnumeration vals = attr.getAll(); vals.hasMore();) {
|
||||
curAttr.add(vals.nextElement());
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (modop == DirContext.REPLACE_ATTRIBUTE) {
|
||||
attrs.put(attr);
|
||||
}
|
||||
else if (modop == DirContext.REMOVE_ATTRIBUTE) {
|
||||
Attribute curAttr = attrs.get(attr.getID());
|
||||
if (curAttr == null) {
|
||||
throw new NoSuchAttributeException(attr.getID());
|
||||
for (NamingEnumeration vals = attr.getAll(); vals.hasMore();) {
|
||||
curAttr.add(vals.nextElement());
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (modop == DirContext.REPLACE_ATTRIBUTE) {
|
||||
attrs.put(attr);
|
||||
}
|
||||
else if (modop == DirContext.REMOVE_ATTRIBUTE) {
|
||||
Attribute curAttr = attrs.get(attr.getID());
|
||||
if (curAttr == null) {
|
||||
throw new NoSuchAttributeException(attr.getID());
|
||||
}
|
||||
else if (attr.size() == 0) { // remove the attr
|
||||
attrs.remove(attr.getID());
|
||||
}
|
||||
else {
|
||||
for (NamingEnumeration vals = attr.getAll(); vals.hasMore();) {
|
||||
String val = (String) vals.nextElement();
|
||||
curAttr.remove(val);
|
||||
// Schema definition Values are case insensitive
|
||||
curAttr.remove(val.toLowerCase());
|
||||
}
|
||||
if (curAttr.size() == 0) { // remove attr if no values left
|
||||
attrs.remove(attr.getID());
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException("Illegal Attribute Modification Operation");
|
||||
}
|
||||
}
|
||||
}
|
||||
for (NamingEnumeration vals = attr.getAll(); vals.hasMore();) {
|
||||
String val = (String) vals.nextElement();
|
||||
curAttr.remove(val);
|
||||
// Schema definition Values are case insensitive
|
||||
curAttr.remove(val.toLowerCase());
|
||||
}
|
||||
if (curAttr.size() == 0) { // remove attr if no values left
|
||||
attrs.remove(attr.getID());
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException("Illegal Attribute Modification Operation");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse value for a schema attribute. Return true if the value is
|
||||
* "true", return false if the value is "false" or absent
|
||||
*/
|
||||
static boolean parseTrueFalseValue(Attribute attr) throws NamingException{
|
||||
|
||||
for (NamingEnumeration valEnum = attr.getAll(); valEnum.hasMore(); ) {
|
||||
String flag = (String)valEnum.nextElement();
|
||||
if (flag.equals("true")) {
|
||||
return true;
|
||||
}
|
||||
else if (flag.equals("false")) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
throw new InvalidAttributeValueException(attr.getID() +
|
||||
" value must be \"true\", \"false\" or absent");
|
||||
}
|
||||
}
|
||||
return false; // no values
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a string value for a schema attribute
|
||||
*/
|
||||
static String getSchemaAttrValue(Attribute attr) throws NamingException {
|
||||
for (Enumeration valEnum = attr.getAll(); valEnum.hasMoreElements(); ) {
|
||||
return (String)valEnum.nextElement();
|
||||
}
|
||||
throw new InvalidAttributeValueException(attr.getID() + " must have a value");
|
||||
}
|
||||
}
|
||||
|
@ -27,47 +27,47 @@ import java.util.*;
|
||||
|
||||
class SchemaElementBindingEnum implements NamingEnumeration {
|
||||
|
||||
/**
|
||||
* Enumeration of schema name-object bindings packaged into Binding object.
|
||||
*/
|
||||
Enumeration m_schemaElementEnum;
|
||||
|
||||
SchemaManager m_schemaMgr;
|
||||
/**
|
||||
* Enumeration of schema name-object bindings packaged into Binding object.
|
||||
*/
|
||||
Enumeration m_schemaElementEnum;
|
||||
|
||||
SchemaManager m_schemaMgr;
|
||||
|
||||
static final String _className = "javax.naming.directory.DirContext"; // for class name is bindings
|
||||
static final String _className = "javax.naming.directory.DirContext"; // for class name is bindings
|
||||
|
||||
public SchemaElementBindingEnum(Enumeration schemaElementEnum, SchemaManager schemaMgr) {
|
||||
m_schemaElementEnum = schemaElementEnum;
|
||||
m_schemaMgr = schemaMgr;
|
||||
}
|
||||
public SchemaElementBindingEnum(Enumeration schemaElementEnum, SchemaManager schemaMgr) {
|
||||
m_schemaElementEnum = schemaElementEnum;
|
||||
m_schemaMgr = schemaMgr;
|
||||
}
|
||||
|
||||
public Object next() throws NamingException{
|
||||
return nextElement();
|
||||
}
|
||||
public Object next() throws NamingException{
|
||||
return nextElement();
|
||||
}
|
||||
|
||||
public Object nextElement() {
|
||||
DirContext obj = null;
|
||||
LDAPSchemaElement schemaElement = (LDAPSchemaElement) m_schemaElementEnum.nextElement();
|
||||
if (schemaElement instanceof LDAPObjectClassSchema) {
|
||||
obj = new SchemaObjectClass((LDAPObjectClassSchema) schemaElement, m_schemaMgr);
|
||||
}
|
||||
else if (schemaElement instanceof LDAPAttributeSchema) {
|
||||
obj = new SchemaAttribute((LDAPAttributeSchema) schemaElement, m_schemaMgr);
|
||||
}
|
||||
else if (schemaElement instanceof LDAPMatchingRuleSchema) {
|
||||
obj = new SchemaMatchingRule((LDAPMatchingRuleSchema) schemaElement, m_schemaMgr);
|
||||
}
|
||||
return new Binding(schemaElement.getName(), _className, obj, /*isRelative=*/true);
|
||||
}
|
||||
public Object nextElement() {
|
||||
DirContext obj = null;
|
||||
LDAPSchemaElement schemaElement = (LDAPSchemaElement) m_schemaElementEnum.nextElement();
|
||||
if (schemaElement instanceof LDAPObjectClassSchema) {
|
||||
obj = new SchemaObjectClass((LDAPObjectClassSchema) schemaElement, m_schemaMgr);
|
||||
}
|
||||
else if (schemaElement instanceof LDAPAttributeSchema) {
|
||||
obj = new SchemaAttribute((LDAPAttributeSchema) schemaElement, m_schemaMgr);
|
||||
}
|
||||
else if (schemaElement instanceof LDAPMatchingRuleSchema) {
|
||||
obj = new SchemaMatchingRule((LDAPMatchingRuleSchema) schemaElement, m_schemaMgr);
|
||||
}
|
||||
return new Binding(schemaElement.getName(), _className, obj, /*isRelative=*/true);
|
||||
}
|
||||
|
||||
public boolean hasMore() throws NamingException{
|
||||
return m_schemaElementEnum.hasMoreElements();
|
||||
}
|
||||
public boolean hasMore() throws NamingException{
|
||||
return m_schemaElementEnum.hasMoreElements();
|
||||
}
|
||||
|
||||
public boolean hasMoreElements() {
|
||||
return m_schemaElementEnum.hasMoreElements();
|
||||
}
|
||||
public boolean hasMoreElements() {
|
||||
return m_schemaElementEnum.hasMoreElements();
|
||||
}
|
||||
|
||||
public void close() {}
|
||||
public void close() {}
|
||||
}
|
||||
|
||||
|
@ -28,21 +28,21 @@ import java.util.*;
|
||||
|
||||
public abstract class SchemaElementContainer extends SchemaDirContext {
|
||||
|
||||
SchemaManager m_schemaMgr;
|
||||
|
||||
public SchemaElementContainer(SchemaManager schemaMgr, String path) throws NamingException{
|
||||
m_schemaMgr = schemaMgr;
|
||||
m_path = path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new SchemaElement. Called by craeteSubcontext
|
||||
*/
|
||||
SchemaManager m_schemaMgr;
|
||||
|
||||
public SchemaElementContainer(SchemaManager schemaMgr, String path) throws NamingException{
|
||||
m_schemaMgr = schemaMgr;
|
||||
m_path = path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new SchemaElement. Called by craeteSubcontext
|
||||
*/
|
||||
abstract DirContext createSchemaElement(String name, Attributes attrs) throws NamingException;
|
||||
|
||||
/**
|
||||
* Delete a new SchemaElement. Called by destroySubcontext
|
||||
*/
|
||||
/**
|
||||
* Delete a new SchemaElement. Called by destroySubcontext
|
||||
*/
|
||||
abstract void removeSchemaElement(String name) throws NamingException;
|
||||
|
||||
/**
|
||||
@ -62,174 +62,174 @@ public abstract class SchemaElementContainer extends SchemaDirContext {
|
||||
abstract Object lookupSchemaElement(String name) throws NamingException;
|
||||
|
||||
|
||||
/**
|
||||
* Attribute Operations
|
||||
*/
|
||||
public Attributes getAttributes(String name) throws NamingException {
|
||||
|
||||
SchemaDirContext schemaElement = (SchemaDirContext)lookup(name);
|
||||
if (schemaElement == this) {
|
||||
throw new OperationNotSupportedException("No Attributes for " + m_path);
|
||||
}
|
||||
else {
|
||||
return schemaElement.getAttributes("");
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Attribute Operations
|
||||
*/
|
||||
public Attributes getAttributes(String name) throws NamingException {
|
||||
|
||||
SchemaDirContext schemaElement = (SchemaDirContext)lookup(name);
|
||||
if (schemaElement == this) {
|
||||
throw new OperationNotSupportedException("No Attributes for " + m_path);
|
||||
}
|
||||
else {
|
||||
return schemaElement.getAttributes("");
|
||||
}
|
||||
}
|
||||
|
||||
public Attributes getAttributes(String name, String[] attrIds) throws NamingException {
|
||||
SchemaDirContext schemaElement = (SchemaDirContext)lookup(name);
|
||||
if (schemaElement == this) {
|
||||
throw new OperationNotSupportedException("No Attributes for " + m_path);
|
||||
}
|
||||
else {
|
||||
return schemaElement.getAttributes("", attrIds);
|
||||
}
|
||||
}
|
||||
public Attributes getAttributes(String name, String[] attrIds) throws NamingException {
|
||||
SchemaDirContext schemaElement = (SchemaDirContext)lookup(name);
|
||||
if (schemaElement == this) {
|
||||
throw new OperationNotSupportedException("No Attributes for " + m_path);
|
||||
}
|
||||
else {
|
||||
return schemaElement.getAttributes("", attrIds);
|
||||
}
|
||||
}
|
||||
|
||||
public Attributes getAttributes(Name name) throws NamingException {
|
||||
return getAttributes(name.toString());
|
||||
}
|
||||
public Attributes getAttributes(Name name) throws NamingException {
|
||||
return getAttributes(name.toString());
|
||||
}
|
||||
|
||||
public Attributes getAttributes(Name name, String[] attrIds) throws NamingException {
|
||||
return getAttributes(name.toString(), attrIds);
|
||||
}
|
||||
public Attributes getAttributes(Name name, String[] attrIds) throws NamingException {
|
||||
return getAttributes(name.toString(), attrIds);
|
||||
}
|
||||
|
||||
public void modifyAttributes(String name, int mod_op, Attributes attrs) throws NamingException {
|
||||
SchemaDirContext schemaElement = (SchemaDirContext)lookup(name);
|
||||
if (schemaElement == this) {
|
||||
throw new OperationNotSupportedException("No Attributes for " + m_path);
|
||||
}
|
||||
else {
|
||||
schemaElement.modifyAttributes("", mod_op, attrs);
|
||||
}
|
||||
}
|
||||
public void modifyAttributes(String name, int mod_op, Attributes attrs) throws NamingException {
|
||||
SchemaDirContext schemaElement = (SchemaDirContext)lookup(name);
|
||||
if (schemaElement == this) {
|
||||
throw new OperationNotSupportedException("No Attributes for " + m_path);
|
||||
}
|
||||
else {
|
||||
schemaElement.modifyAttributes("", mod_op, attrs);
|
||||
}
|
||||
}
|
||||
|
||||
public void modifyAttributes(String name, ModificationItem[] mods) throws NamingException {
|
||||
SchemaDirContext schemaElement = (SchemaDirContext)lookup(name);
|
||||
if (schemaElement == this) {
|
||||
throw new OperationNotSupportedException("No Attributes for " + m_path);
|
||||
}
|
||||
else {
|
||||
schemaElement.modifyAttributes("", mods);
|
||||
}
|
||||
}
|
||||
public void modifyAttributes(String name, ModificationItem[] mods) throws NamingException {
|
||||
SchemaDirContext schemaElement = (SchemaDirContext)lookup(name);
|
||||
if (schemaElement == this) {
|
||||
throw new OperationNotSupportedException("No Attributes for " + m_path);
|
||||
}
|
||||
else {
|
||||
schemaElement.modifyAttributes("", mods);
|
||||
}
|
||||
}
|
||||
|
||||
public void modifyAttributes(Name name, int mod_op, Attributes attrs) throws NamingException {
|
||||
modifyAttributes(name.toString(), mod_op, attrs);
|
||||
}
|
||||
public void modifyAttributes(Name name, int mod_op, Attributes attrs) throws NamingException {
|
||||
modifyAttributes(name.toString(), mod_op, attrs);
|
||||
}
|
||||
|
||||
public void modifyAttributes(Name name, ModificationItem[] mods) throws NamingException {
|
||||
modifyAttributes(name.toString(), mods);
|
||||
}
|
||||
public void modifyAttributes(Name name, ModificationItem[] mods) throws NamingException {
|
||||
modifyAttributes(name.toString(), mods);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ldap entry operations
|
||||
*/
|
||||
/**
|
||||
* Ldap entry operations
|
||||
*/
|
||||
|
||||
public Context createSubcontext(String name) throws NamingException {
|
||||
// Directory entry must have attributes
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public Context createSubcontext(String name) throws NamingException {
|
||||
// Directory entry must have attributes
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
public Context createSubcontext(Name name) throws NamingException {
|
||||
// Directory entry must have attributes
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public Context createSubcontext(Name name) throws NamingException {
|
||||
// Directory entry must have attributes
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
public DirContext createSubcontext(String name, Attributes attrs) throws NamingException {
|
||||
return createSchemaElement(name, attrs);
|
||||
}
|
||||
public DirContext createSubcontext(String name, Attributes attrs) throws NamingException {
|
||||
return createSchemaElement(name, attrs);
|
||||
}
|
||||
|
||||
public DirContext createSubcontext(Name name, Attributes attrs) throws NamingException {
|
||||
return createSubcontext(name.toString(), attrs);
|
||||
}
|
||||
public DirContext createSubcontext(Name name, Attributes attrs) throws NamingException {
|
||||
return createSubcontext(name.toString(), attrs);
|
||||
}
|
||||
|
||||
public void destroySubcontext(String name) throws NamingException {
|
||||
removeSchemaElement(name);
|
||||
}
|
||||
public void destroySubcontext(String name) throws NamingException {
|
||||
removeSchemaElement(name);
|
||||
}
|
||||
|
||||
public void destroySubcontext(Name name) throws NamingException {
|
||||
destroySubcontext(name.toString());
|
||||
}
|
||||
public void destroySubcontext(Name name) throws NamingException {
|
||||
destroySubcontext(name.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Naming Bind operations
|
||||
*/
|
||||
/**
|
||||
* Naming Bind operations
|
||||
*/
|
||||
|
||||
public void bind(String name, Object obj) throws NamingException {
|
||||
if (obj instanceof DirContext) {
|
||||
createSubcontext(name, ((DirContext)obj).getAttributes(""));
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException("Can not bind this type of object");
|
||||
}
|
||||
}
|
||||
public void bind(String name, Object obj) throws NamingException {
|
||||
if (obj instanceof DirContext) {
|
||||
createSubcontext(name, ((DirContext)obj).getAttributes(""));
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException("Can not bind this type of object");
|
||||
}
|
||||
}
|
||||
|
||||
public void bind(Name name, Object obj) throws NamingException {
|
||||
bind(name.toString(), obj);
|
||||
}
|
||||
public void bind(Name name, Object obj) throws NamingException {
|
||||
bind(name.toString(), obj);
|
||||
}
|
||||
|
||||
public void rebind(String name, Object obj) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public void rebind(String name, Object obj) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
public void rebind(Name name, Object obj) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public void rebind(Name name, Object obj) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
public void rename(String oldName, String newName) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public void rename(String oldName, String newName) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
public void rename(Name oldName, Name newName) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public void rename(Name oldName, Name newName) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
public void unbind(String name) throws NamingException {
|
||||
destroySubcontext(name);
|
||||
}
|
||||
public void unbind(String name) throws NamingException {
|
||||
destroySubcontext(name);
|
||||
}
|
||||
|
||||
public void unbind(Name name) throws NamingException {
|
||||
destroySubcontext(name);
|
||||
}
|
||||
public void unbind(Name name) throws NamingException {
|
||||
destroySubcontext(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* List Operations
|
||||
*/
|
||||
/**
|
||||
* List Operations
|
||||
*/
|
||||
|
||||
public NamingEnumeration list(String name) throws NamingException {
|
||||
public NamingEnumeration list(String name) throws NamingException {
|
||||
return getNameList(name);
|
||||
}
|
||||
}
|
||||
|
||||
public NamingEnumeration list(Name name) throws NamingException {
|
||||
return list(name.toString());
|
||||
}
|
||||
public NamingEnumeration list(Name name) throws NamingException {
|
||||
return list(name.toString());
|
||||
}
|
||||
|
||||
public NamingEnumeration listBindings(String name) throws NamingException {
|
||||
return getBindingsList(name);
|
||||
}
|
||||
public NamingEnumeration listBindings(String name) throws NamingException {
|
||||
return getBindingsList(name);
|
||||
}
|
||||
|
||||
public NamingEnumeration listBindings(Name name) throws NamingException {
|
||||
return listBindings(name.toString());
|
||||
}
|
||||
public NamingEnumeration listBindings(Name name) throws NamingException {
|
||||
return listBindings(name.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Lookup Operations
|
||||
*/
|
||||
/**
|
||||
* Lookup Operations
|
||||
*/
|
||||
|
||||
public Object lookup(String name) throws NamingException {
|
||||
return lookupSchemaElement(name);
|
||||
}
|
||||
public Object lookup(String name) throws NamingException {
|
||||
return lookupSchemaElement(name);
|
||||
}
|
||||
|
||||
public Object lookup(Name name) throws NamingException {
|
||||
return lookup(name.toString());
|
||||
}
|
||||
public Object lookup(Name name) throws NamingException {
|
||||
return lookup(name.toString());
|
||||
}
|
||||
|
||||
public Object lookupLink(String name) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public Object lookupLink(String name) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
public Object lookupLink(Name name) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public Object lookupLink(Name name) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
}
|
||||
|
@ -27,34 +27,34 @@ import java.util.*;
|
||||
|
||||
class SchemaElementNameEnum implements NamingEnumeration {
|
||||
|
||||
/**
|
||||
* Enumeration of schema object names packaged into NameClassPair.
|
||||
* The class in NameClassPair is DirContext
|
||||
*/
|
||||
Enumeration m_nameEnum;
|
||||
|
||||
static final String _className = "javax.naming.directory.DirContext"; // for class name is bindings";
|
||||
/**
|
||||
* Enumeration of schema object names packaged into NameClassPair.
|
||||
* The class in NameClassPair is DirContext
|
||||
*/
|
||||
Enumeration m_nameEnum;
|
||||
|
||||
static final String _className = "javax.naming.directory.DirContext"; // for class name is bindings";
|
||||
|
||||
public SchemaElementNameEnum(Enumeration nameEnum) {
|
||||
m_nameEnum = nameEnum;
|
||||
}
|
||||
public SchemaElementNameEnum(Enumeration nameEnum) {
|
||||
m_nameEnum = nameEnum;
|
||||
}
|
||||
|
||||
public Object next() throws NamingException{
|
||||
return nextElement();
|
||||
}
|
||||
public Object next() throws NamingException{
|
||||
return nextElement();
|
||||
}
|
||||
|
||||
public Object nextElement() {
|
||||
String name = (String) m_nameEnum.nextElement();
|
||||
return new NameClassPair(name, _className, /*isRelative=*/true);
|
||||
}
|
||||
public Object nextElement() {
|
||||
String name = (String) m_nameEnum.nextElement();
|
||||
return new NameClassPair(name, _className, /*isRelative=*/true);
|
||||
}
|
||||
|
||||
public boolean hasMore() throws NamingException{
|
||||
return m_nameEnum.hasMoreElements();
|
||||
}
|
||||
public boolean hasMore() throws NamingException{
|
||||
return m_nameEnum.hasMoreElements();
|
||||
}
|
||||
|
||||
public boolean hasMoreElements() {
|
||||
return m_nameEnum.hasMoreElements();
|
||||
}
|
||||
public boolean hasMoreElements() {
|
||||
return m_nameEnum.hasMoreElements();
|
||||
}
|
||||
|
||||
public void close() {}
|
||||
public void close() {}
|
||||
}
|
||||
|
@ -31,226 +31,226 @@ import com.netscape.jndi.ldap.common.*;
|
||||
*/
|
||||
class SchemaManager {
|
||||
|
||||
/**
|
||||
* LdapJDK main schema object
|
||||
*/
|
||||
private LDAPSchema m_schema;
|
||||
|
||||
/**
|
||||
* LDAP Connection object
|
||||
*/
|
||||
private LDAPConnection m_ld;
|
||||
|
||||
/**
|
||||
* Flag whether schema needs to be loaded by calling fetchSchema()
|
||||
*/
|
||||
private boolean m_isLoaded;
|
||||
|
||||
/**
|
||||
* Flag whether schema objects have been modified in the Directory (add, remove)
|
||||
* but the change has not been propagated to the cached m_schema object
|
||||
*/
|
||||
private boolean m_isObjectClassDirty, m_isAttributeDirty, m_isMatchingRuleDirty;
|
||||
|
||||
/**
|
||||
* Must constract with LDAP Connection
|
||||
*/
|
||||
private SchemaManager() {}
|
||||
|
||||
/**
|
||||
* Connstructor
|
||||
*/
|
||||
public SchemaManager(LDAPConnection ld) {
|
||||
m_ld = ld;
|
||||
m_isLoaded = false;
|
||||
m_isObjectClassDirty = m_isAttributeDirty = m_isMatchingRuleDirty = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the schema
|
||||
*/
|
||||
void load() throws NamingException {
|
||||
try {
|
||||
m_schema = new LDAPSchema();
|
||||
m_schema.fetchSchema(m_ld);
|
||||
m_isLoaded = true;
|
||||
m_isObjectClassDirty = m_isAttributeDirty = m_isMatchingRuleDirty = false;
|
||||
}
|
||||
catch (LDAPException e) {
|
||||
throw ExceptionMapper.getNamingException(e);
|
||||
}
|
||||
}
|
||||
|
||||
LDAPObjectClassSchema getObjectClass(String name) throws NamingException {
|
||||
if (!m_isLoaded || m_isObjectClassDirty) {
|
||||
load();
|
||||
}
|
||||
return m_schema.getObjectClass(name);
|
||||
}
|
||||
/**
|
||||
* LdapJDK main schema object
|
||||
*/
|
||||
private LDAPSchema m_schema;
|
||||
|
||||
/**
|
||||
* LDAP Connection object
|
||||
*/
|
||||
private LDAPConnection m_ld;
|
||||
|
||||
/**
|
||||
* Flag whether schema needs to be loaded by calling fetchSchema()
|
||||
*/
|
||||
private boolean m_isLoaded;
|
||||
|
||||
/**
|
||||
* Flag whether schema objects have been modified in the Directory (add, remove)
|
||||
* but the change has not been propagated to the cached m_schema object
|
||||
*/
|
||||
private boolean m_isObjectClassDirty, m_isAttributeDirty, m_isMatchingRuleDirty;
|
||||
|
||||
/**
|
||||
* Must constract with LDAP Connection
|
||||
*/
|
||||
private SchemaManager() {}
|
||||
|
||||
/**
|
||||
* Connstructor
|
||||
*/
|
||||
public SchemaManager(LDAPConnection ld) {
|
||||
m_ld = ld;
|
||||
m_isLoaded = false;
|
||||
m_isObjectClassDirty = m_isAttributeDirty = m_isMatchingRuleDirty = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the schema
|
||||
*/
|
||||
void load() throws NamingException {
|
||||
try {
|
||||
m_schema = new LDAPSchema();
|
||||
m_schema.fetchSchema(m_ld);
|
||||
m_isLoaded = true;
|
||||
m_isObjectClassDirty = m_isAttributeDirty = m_isMatchingRuleDirty = false;
|
||||
}
|
||||
catch (LDAPException e) {
|
||||
throw ExceptionMapper.getNamingException(e);
|
||||
}
|
||||
}
|
||||
|
||||
LDAPObjectClassSchema getObjectClass(String name) throws NamingException {
|
||||
if (!m_isLoaded || m_isObjectClassDirty) {
|
||||
load();
|
||||
}
|
||||
return m_schema.getObjectClass(name);
|
||||
}
|
||||
|
||||
LDAPAttributeSchema getAttribute(String name) throws NamingException {
|
||||
if (!m_isLoaded || m_isAttributeDirty) {
|
||||
load();
|
||||
}
|
||||
return m_schema.getAttribute(name);
|
||||
}
|
||||
LDAPAttributeSchema getAttribute(String name) throws NamingException {
|
||||
if (!m_isLoaded || m_isAttributeDirty) {
|
||||
load();
|
||||
}
|
||||
return m_schema.getAttribute(name);
|
||||
}
|
||||
|
||||
LDAPMatchingRuleSchema getMatchingRule(String name) throws NamingException {
|
||||
if (!m_isLoaded || m_isMatchingRuleDirty) {
|
||||
load();
|
||||
}
|
||||
return m_schema.getMatchingRule(name);
|
||||
}
|
||||
LDAPMatchingRuleSchema getMatchingRule(String name) throws NamingException {
|
||||
if (!m_isLoaded || m_isMatchingRuleDirty) {
|
||||
load();
|
||||
}
|
||||
return m_schema.getMatchingRule(name);
|
||||
}
|
||||
|
||||
|
||||
Enumeration getObjectClassNames() throws NamingException {
|
||||
if (!m_isLoaded || m_isObjectClassDirty) {
|
||||
load();
|
||||
}
|
||||
return m_schema.getObjectClassNames();
|
||||
}
|
||||
Enumeration getObjectClassNames() throws NamingException {
|
||||
if (!m_isLoaded || m_isObjectClassDirty) {
|
||||
load();
|
||||
}
|
||||
return m_schema.getObjectClassNames();
|
||||
}
|
||||
|
||||
Enumeration getAttributeNames() throws NamingException {
|
||||
if (!m_isLoaded || m_isAttributeDirty) {
|
||||
load();
|
||||
}
|
||||
return m_schema.getAttributeNames();
|
||||
}
|
||||
Enumeration getAttributeNames() throws NamingException {
|
||||
if (!m_isLoaded || m_isAttributeDirty) {
|
||||
load();
|
||||
}
|
||||
return m_schema.getAttributeNames();
|
||||
}
|
||||
|
||||
Enumeration getMatchingRuleNames() throws NamingException {
|
||||
if (!m_isLoaded || m_isMatchingRuleDirty) {
|
||||
load();
|
||||
}
|
||||
return m_schema.getMatchingRuleNames();
|
||||
}
|
||||
Enumeration getMatchingRuleNames() throws NamingException {
|
||||
if (!m_isLoaded || m_isMatchingRuleDirty) {
|
||||
load();
|
||||
}
|
||||
return m_schema.getMatchingRuleNames();
|
||||
}
|
||||
|
||||
Enumeration getObjectClasses() throws NamingException {
|
||||
if (!m_isLoaded || m_isObjectClassDirty) {
|
||||
load();
|
||||
}
|
||||
return m_schema.getObjectClasses();
|
||||
}
|
||||
Enumeration getObjectClasses() throws NamingException {
|
||||
if (!m_isLoaded || m_isObjectClassDirty) {
|
||||
load();
|
||||
}
|
||||
return m_schema.getObjectClasses();
|
||||
}
|
||||
|
||||
Enumeration getAttributes() throws NamingException {
|
||||
if (!m_isLoaded || m_isAttributeDirty) {
|
||||
load();
|
||||
}
|
||||
return m_schema.getAttributes();
|
||||
}
|
||||
Enumeration getAttributes() throws NamingException {
|
||||
if (!m_isLoaded || m_isAttributeDirty) {
|
||||
load();
|
||||
}
|
||||
return m_schema.getAttributes();
|
||||
}
|
||||
|
||||
Enumeration getMatchingRules() throws NamingException {
|
||||
if (!m_isLoaded || m_isMatchingRuleDirty) {
|
||||
load();
|
||||
}
|
||||
return m_schema.getMatchingRules();
|
||||
}
|
||||
Enumeration getMatchingRules() throws NamingException {
|
||||
if (!m_isLoaded || m_isMatchingRuleDirty) {
|
||||
load();
|
||||
}
|
||||
return m_schema.getMatchingRules();
|
||||
}
|
||||
|
||||
void createObjectClass(LDAPObjectClassSchema objclass) throws NamingException {
|
||||
try {
|
||||
objclass.add(m_ld);
|
||||
m_isObjectClassDirty = true;
|
||||
}
|
||||
catch (LDAPException e) {
|
||||
throw ExceptionMapper.getNamingException(e);
|
||||
}
|
||||
}
|
||||
void createObjectClass(LDAPObjectClassSchema objclass) throws NamingException {
|
||||
try {
|
||||
objclass.add(m_ld);
|
||||
m_isObjectClassDirty = true;
|
||||
}
|
||||
catch (LDAPException e) {
|
||||
throw ExceptionMapper.getNamingException(e);
|
||||
}
|
||||
}
|
||||
|
||||
void createAttribute(LDAPAttributeSchema attr) throws NamingException {
|
||||
try {
|
||||
attr.add(m_ld);
|
||||
m_isAttributeDirty = true;
|
||||
}
|
||||
catch (LDAPException e) {
|
||||
throw ExceptionMapper.getNamingException(e);
|
||||
}
|
||||
}
|
||||
void createAttribute(LDAPAttributeSchema attr) throws NamingException {
|
||||
try {
|
||||
attr.add(m_ld);
|
||||
m_isAttributeDirty = true;
|
||||
}
|
||||
catch (LDAPException e) {
|
||||
throw ExceptionMapper.getNamingException(e);
|
||||
}
|
||||
}
|
||||
|
||||
void createMatchingRule(LDAPMatchingRuleSchema mrule) throws NamingException {
|
||||
try {
|
||||
mrule.add(m_ld);
|
||||
m_isMatchingRuleDirty = true;
|
||||
}
|
||||
catch (LDAPException e) {
|
||||
throw ExceptionMapper.getNamingException(e);
|
||||
}
|
||||
}
|
||||
void createMatchingRule(LDAPMatchingRuleSchema mrule) throws NamingException {
|
||||
try {
|
||||
mrule.add(m_ld);
|
||||
m_isMatchingRuleDirty = true;
|
||||
}
|
||||
catch (LDAPException e) {
|
||||
throw ExceptionMapper.getNamingException(e);
|
||||
}
|
||||
}
|
||||
|
||||
void removeObjectClass(String name) throws NamingException {
|
||||
LDAPObjectClassSchema objclass = getObjectClass(name);
|
||||
|
||||
if (objclass == null) {
|
||||
throw new NameNotFoundException(name);
|
||||
}
|
||||
|
||||
try {
|
||||
objclass.remove(m_ld);
|
||||
m_isObjectClassDirty = true;
|
||||
}
|
||||
catch (LDAPException e) {
|
||||
throw ExceptionMapper.getNamingException(e);
|
||||
}
|
||||
}
|
||||
void removeObjectClass(String name) throws NamingException {
|
||||
LDAPObjectClassSchema objclass = getObjectClass(name);
|
||||
|
||||
if (objclass == null) {
|
||||
throw new NameNotFoundException(name);
|
||||
}
|
||||
|
||||
try {
|
||||
objclass.remove(m_ld);
|
||||
m_isObjectClassDirty = true;
|
||||
}
|
||||
catch (LDAPException e) {
|
||||
throw ExceptionMapper.getNamingException(e);
|
||||
}
|
||||
}
|
||||
|
||||
void removeAttribute(String name) throws NamingException {
|
||||
LDAPAttributeSchema attr = getAttribute(name);
|
||||
|
||||
if (attr == null) {
|
||||
throw new NameNotFoundException(name);
|
||||
}
|
||||
void removeAttribute(String name) throws NamingException {
|
||||
LDAPAttributeSchema attr = getAttribute(name);
|
||||
|
||||
if (attr == null) {
|
||||
throw new NameNotFoundException(name);
|
||||
}
|
||||
|
||||
try {
|
||||
attr.remove(m_ld);
|
||||
m_isAttributeDirty = true;
|
||||
}
|
||||
catch (LDAPException e) {
|
||||
throw ExceptionMapper.getNamingException(e);
|
||||
}
|
||||
}
|
||||
try {
|
||||
attr.remove(m_ld);
|
||||
m_isAttributeDirty = true;
|
||||
}
|
||||
catch (LDAPException e) {
|
||||
throw ExceptionMapper.getNamingException(e);
|
||||
}
|
||||
}
|
||||
|
||||
void removeMatchingRule(String name) throws NamingException {
|
||||
LDAPMatchingRuleSchema mrule = getMatchingRule(name);
|
||||
|
||||
if (mrule == null) {
|
||||
throw new NameNotFoundException(name);
|
||||
}
|
||||
void removeMatchingRule(String name) throws NamingException {
|
||||
LDAPMatchingRuleSchema mrule = getMatchingRule(name);
|
||||
|
||||
if (mrule == null) {
|
||||
throw new NameNotFoundException(name);
|
||||
}
|
||||
|
||||
try {
|
||||
mrule.remove(m_ld);
|
||||
m_isMatchingRuleDirty = true;
|
||||
}
|
||||
catch (LDAPException e) {
|
||||
throw ExceptionMapper.getNamingException(e);
|
||||
}
|
||||
}
|
||||
try {
|
||||
mrule.remove(m_ld);
|
||||
m_isMatchingRuleDirty = true;
|
||||
}
|
||||
catch (LDAPException e) {
|
||||
throw ExceptionMapper.getNamingException(e);
|
||||
}
|
||||
}
|
||||
|
||||
void modifyObjectClass(LDAPObjectClassSchema objclass, LDAPObjectClassSchema modObjClass) throws NamingException {
|
||||
try {
|
||||
objclass.modify(m_ld, modObjClass);
|
||||
m_isObjectClassDirty = true;
|
||||
}
|
||||
catch (LDAPException e) {
|
||||
throw ExceptionMapper.getNamingException(e);
|
||||
}
|
||||
}
|
||||
void modifyObjectClass(LDAPObjectClassSchema objclass, LDAPObjectClassSchema modObjClass) throws NamingException {
|
||||
try {
|
||||
objclass.modify(m_ld, modObjClass);
|
||||
m_isObjectClassDirty = true;
|
||||
}
|
||||
catch (LDAPException e) {
|
||||
throw ExceptionMapper.getNamingException(e);
|
||||
}
|
||||
}
|
||||
|
||||
void modifyAttribute(LDAPAttributeSchema attr, LDAPAttributeSchema modAttr) throws NamingException {
|
||||
try {
|
||||
attr.modify(m_ld, modAttr);
|
||||
m_isAttributeDirty = true;
|
||||
}
|
||||
catch (LDAPException e) {
|
||||
throw ExceptionMapper.getNamingException(e);
|
||||
}
|
||||
}
|
||||
void modifyAttribute(LDAPAttributeSchema attr, LDAPAttributeSchema modAttr) throws NamingException {
|
||||
try {
|
||||
attr.modify(m_ld, modAttr);
|
||||
m_isAttributeDirty = true;
|
||||
}
|
||||
catch (LDAPException e) {
|
||||
throw ExceptionMapper.getNamingException(e);
|
||||
}
|
||||
}
|
||||
|
||||
void modifyMatchingRule(LDAPMatchingRuleSchema mrule, LDAPMatchingRuleSchema modMRule) throws NamingException {
|
||||
try {
|
||||
mrule.modify(m_ld, modMRule);
|
||||
m_isMatchingRuleDirty = true;
|
||||
}
|
||||
catch (LDAPException e) {
|
||||
throw ExceptionMapper.getNamingException(e);
|
||||
}
|
||||
}
|
||||
void modifyMatchingRule(LDAPMatchingRuleSchema mrule, LDAPMatchingRuleSchema modMRule) throws NamingException {
|
||||
try {
|
||||
mrule.modify(m_ld, modMRule);
|
||||
m_isMatchingRuleDirty = true;
|
||||
}
|
||||
catch (LDAPException e) {
|
||||
throw ExceptionMapper.getNamingException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -30,179 +30,186 @@ public class SchemaMatchingRule extends SchemaElement {
|
||||
|
||||
|
||||
private static final String APPLIES = "APPLIES";
|
||||
|
||||
LDAPMatchingRuleSchema m_ldapMatchingRule;
|
||||
|
||||
// Attribute IDs that are exposed through Netscape LdapJDK
|
||||
private static String[] m_allAttrIds = {NUMERICOID, NAME, DESC, SYNTAX, APPLIES };
|
||||
|
||||
LDAPConnection m_ld;
|
||||
|
||||
public SchemaMatchingRule(LDAPMatchingRuleSchema ldapMatchingRule, SchemaManager schemaManager) {
|
||||
super(schemaManager);
|
||||
m_ldapMatchingRule = ldapMatchingRule;
|
||||
m_path = ATTRDEF + "/" + m_ldapMatchingRule.getName();
|
||||
}
|
||||
|
||||
LDAPMatchingRuleSchema m_ldapMatchingRule;
|
||||
|
||||
// Attribute IDs that are exposed through Netscape LdapJDK
|
||||
private static String[] m_allAttrIds = {NUMERICOID, NAME, DESC, OBSOLETE, SYNTAX, APPLIES };
|
||||
|
||||
LDAPConnection m_ld;
|
||||
|
||||
public SchemaMatchingRule(LDAPMatchingRuleSchema ldapMatchingRule, SchemaManager schemaManager) {
|
||||
super(schemaManager);
|
||||
m_ldapMatchingRule = ldapMatchingRule;
|
||||
m_path = ATTRDEF + "/" + m_ldapMatchingRule.getName();
|
||||
}
|
||||
|
||||
public SchemaMatchingRule(Attributes attrs, SchemaManager schemaManager) throws NamingException {
|
||||
super(schemaManager);
|
||||
m_ldapMatchingRule = parseDefAttributes(attrs);
|
||||
m_path = ATTRDEF + "/" + m_ldapMatchingRule.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse Definition Attributes for a LDAP matching rule
|
||||
*/
|
||||
static LDAPMatchingRuleSchema parseDefAttributes(Attributes attrs) throws NamingException {
|
||||
String name="", oid="", desc="";
|
||||
int syntax=-1;
|
||||
Vector applies = new Vector();
|
||||
public SchemaMatchingRule(Attributes attrs, SchemaManager schemaManager) throws NamingException {
|
||||
super(schemaManager);
|
||||
m_ldapMatchingRule = parseDefAttributes(attrs);
|
||||
m_path = ATTRDEF + "/" + m_ldapMatchingRule.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse Definition Attributes for a LDAP matching rule
|
||||
*/
|
||||
static LDAPMatchingRuleSchema parseDefAttributes(Attributes attrs) throws NamingException {
|
||||
String name=null, oid=null, desc=null, syntax=null;
|
||||
boolean obsolete = false;
|
||||
Vector applies = new Vector();
|
||||
|
||||
for (Enumeration attrEnum = attrs.getAll(); attrEnum.hasMoreElements(); ) {
|
||||
Attribute attr = (Attribute) attrEnum.nextElement();
|
||||
String attrName = attr.getID();
|
||||
if (attrName.equals(NAME)) {
|
||||
for (Enumeration valEnum = attr.getAll(); valEnum.hasMoreElements(); ) {
|
||||
name = (String)valEnum.nextElement();
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (attrName.equals(NUMERICOID)) {
|
||||
for (Enumeration valEnum = attr.getAll(); valEnum.hasMoreElements(); ) {
|
||||
oid = (String)valEnum.nextElement();
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (attrName.equals(SYNTAX)) {
|
||||
for (Enumeration valEnum = attr.getAll(); valEnum.hasMoreElements(); ) {
|
||||
String syntaxString = (String)valEnum.nextElement();
|
||||
syntax = syntaxStringToInt(syntaxString);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (attrName.equals(DESC)) {
|
||||
for (Enumeration valEnum = attr.getAll(); valEnum.hasMoreElements(); ) {
|
||||
desc = (String)valEnum.nextElement();
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (attrName.equals(APPLIES)) {
|
||||
for (Enumeration valEnum = attr.getAll(); valEnum.hasMoreElements(); ) {
|
||||
applies.addElement((String)valEnum.nextElement());
|
||||
}
|
||||
}
|
||||
else if (attrName.equals(OBSOLETE)) {
|
||||
; //ignore
|
||||
}
|
||||
else {
|
||||
throw new NamingException("Invalid schema attribute type for attribute definition " + attrName);
|
||||
}
|
||||
}
|
||||
|
||||
if (name.length() == 0 || oid.length() == 0 || syntax == -1) {
|
||||
throw new NamingException("Incomplete schema attribute definition");
|
||||
}
|
||||
|
||||
return new LDAPMatchingRuleSchema(name, oid, desc, vectorToStringAry(applies), syntax);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Exctract specified attributes from the ldapMatchingRule
|
||||
*/
|
||||
Attributes extractAttributeIds(String[] attrIds) throws NamingException{
|
||||
Attributes attrs = new BasicAttributes();
|
||||
for (int i = 0; i < attrIds.length; i++) {
|
||||
if (attrIds[i].equals(NUMERICOID)) {
|
||||
attrs.put(new BasicAttribute(NUMERICOID, m_ldapMatchingRule.getOID()));
|
||||
}
|
||||
else if (attrIds[i].equals(NAME)) {
|
||||
attrs.put(new BasicAttribute(NAME, m_ldapMatchingRule.getName()));
|
||||
}
|
||||
else if (attrIds[i].equals(DESC)) {
|
||||
attrs.put(new BasicAttribute(DESC, m_ldapMatchingRule.getDescription()));
|
||||
}
|
||||
else if (attrIds[i].equals(SYNTAX)) {
|
||||
attrs.put(new BasicAttribute(SYNTAX, syntaxIntToString(m_ldapMatchingRule.getSyntax())));
|
||||
}
|
||||
else if (attrIds[i].equals(APPLIES)) {
|
||||
String[] appliesToAttrs = m_ldapMatchingRule.getAttributes();
|
||||
if (appliesToAttrs != null && appliesToAttrs.length > 0) {
|
||||
BasicAttribute applies = new BasicAttribute(APPLIES);
|
||||
for (int a=0; a < appliesToAttrs.length; a++) {
|
||||
applies.add(appliesToAttrs[a]);
|
||||
}
|
||||
attrs.put(applies);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// ignore other attrIds as not supported by Netscape LdapJDK APIs
|
||||
}
|
||||
}
|
||||
return attrs;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* DirContext Attribute Operations
|
||||
*/
|
||||
for (Enumeration attrEnum = attrs.getAll(); attrEnum.hasMoreElements(); ) {
|
||||
Attribute attr = (Attribute) attrEnum.nextElement();
|
||||
String attrName = attr.getID();
|
||||
if (attrName.equals(NAME)) {
|
||||
name = getSchemaAttrValue(attr);
|
||||
}
|
||||
else if (attrName.equals(NUMERICOID)) {
|
||||
oid = getSchemaAttrValue(attr);
|
||||
}
|
||||
else if (attrName.equals(SYNTAX)) {
|
||||
syntax = getSchemaAttrValue(attr);
|
||||
}
|
||||
else if (attrName.equals(DESC)) {
|
||||
desc = getSchemaAttrValue(attr);
|
||||
}
|
||||
else if (attrName.equals(APPLIES)) {
|
||||
for (Enumeration valEnum = attr.getAll(); valEnum.hasMoreElements(); ) {
|
||||
applies.addElement((String)valEnum.nextElement());
|
||||
}
|
||||
}
|
||||
else if (attrName.equals(OBSOLETE)) {
|
||||
obsolete = parseTrueFalseValue(attr);
|
||||
}
|
||||
else {
|
||||
throw new NamingException("Invalid schema attribute type for matching rule definition " + attrName);
|
||||
}
|
||||
}
|
||||
|
||||
LDAPMatchingRuleSchema mrule = new LDAPMatchingRuleSchema(name, oid, desc, vectorToStringAry(applies), syntax);
|
||||
|
||||
if (obsolete) {
|
||||
mrule.setQualifier(OBSOLETE, "");
|
||||
}
|
||||
return mrule;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Exctract specified attributes from the ldapMatchingRule
|
||||
*/
|
||||
Attributes extractAttributeIds(String[] attrIds) throws NamingException{
|
||||
Attributes attrs = new BasicAttributes();
|
||||
String val = null;
|
||||
for (int i = 0; i < attrIds.length; i++) {
|
||||
if (attrIds[i].equals(NUMERICOID)) {
|
||||
val = m_ldapMatchingRule.getOID();
|
||||
if (val != null) {
|
||||
attrs.put(new BasicAttribute(NUMERICOID, val));
|
||||
}
|
||||
}
|
||||
else if (attrIds[i].equals(NAME)) {
|
||||
val = m_ldapMatchingRule.getName();
|
||||
if (val != null) {
|
||||
attrs.put(new BasicAttribute(NAME, val));
|
||||
}
|
||||
}
|
||||
else if (attrIds[i].equals(DESC)) {
|
||||
val = m_ldapMatchingRule.getDescription();
|
||||
if (val != null) {
|
||||
attrs.put(new BasicAttribute(DESC, val));
|
||||
}
|
||||
}
|
||||
else if (attrIds[i].equals(SYNTAX)) {
|
||||
val = m_ldapMatchingRule.getSyntaxString();
|
||||
if (val != null) {
|
||||
attrs.put(new BasicAttribute(SYNTAX, val));
|
||||
}
|
||||
}
|
||||
else if (attrIds[i].equals(APPLIES)) {
|
||||
String[] appliesToAttrs = m_ldapMatchingRule.getAttributes();
|
||||
if (appliesToAttrs != null && appliesToAttrs.length > 0) {
|
||||
BasicAttribute applies = new BasicAttribute(APPLIES);
|
||||
for (int a=0; a < appliesToAttrs.length; a++) {
|
||||
applies.add(appliesToAttrs[a]);
|
||||
}
|
||||
attrs.put(applies);
|
||||
}
|
||||
}
|
||||
else if (attrIds[i].equals(OBSOLETE)) {
|
||||
if (m_ldapMatchingRule.getQualifier(OBSOLETE)!= null) {
|
||||
attrs.put(new BasicAttribute(OBSOLETE, "true"));
|
||||
}
|
||||
}
|
||||
|
||||
public Attributes getAttributes(String name) throws NamingException {
|
||||
if (name.length() != 0) { // no subcontexts
|
||||
throw new NameNotFoundException(name); // no such object
|
||||
}
|
||||
return extractAttributeIds(m_allAttrIds);
|
||||
}
|
||||
else {
|
||||
throw new NamingException("Invalid schema attribute type for matching rule definition " + attrIds[i]);
|
||||
}
|
||||
}
|
||||
return attrs;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* DirContext Attribute Operations
|
||||
*/
|
||||
|
||||
public Attributes getAttributes(String name, String[] attrIds) throws NamingException {
|
||||
if (name.length() != 0) { // no subcontexts
|
||||
throw new NameNotFoundException(name); // no such object
|
||||
}
|
||||
return extractAttributeIds(attrIds);
|
||||
}
|
||||
public Attributes getAttributes(String name) throws NamingException {
|
||||
if (name.length() != 0) { // no subcontexts
|
||||
throw new NameNotFoundException(name); // no such object
|
||||
}
|
||||
return extractAttributeIds(m_allAttrIds);
|
||||
}
|
||||
|
||||
public Attributes getAttributes(Name name) throws NamingException {
|
||||
return getAttributes(name.toString());
|
||||
}
|
||||
public Attributes getAttributes(String name, String[] attrIds) throws NamingException {
|
||||
if (name.length() != 0) { // no subcontexts
|
||||
throw new NameNotFoundException(name); // no such object
|
||||
}
|
||||
return extractAttributeIds(attrIds);
|
||||
}
|
||||
|
||||
public Attributes getAttributes(Name name, String[] attrIds) throws NamingException {
|
||||
return getAttributes(name.toString(), attrIds);
|
||||
}
|
||||
public Attributes getAttributes(Name name) throws NamingException {
|
||||
return getAttributes(name.toString());
|
||||
}
|
||||
|
||||
public void modifyAttributes(String name, int mod_op, Attributes attrs) throws NamingException {
|
||||
if (name.length() != 0) { // no subcontexts
|
||||
throw new NameNotFoundException(name); // no such object
|
||||
}
|
||||
Attributes modAttrs = extractAttributeIds(m_allAttrIds);
|
||||
modifySchemaElementAttrs(modAttrs, mod_op, attrs);
|
||||
LDAPMatchingRuleSchema modLdapMatchingRule = parseDefAttributes(modAttrs);
|
||||
m_schemaMgr.modifyMatchingRule(m_ldapMatchingRule, modLdapMatchingRule);
|
||||
m_ldapMatchingRule = modLdapMatchingRule;
|
||||
}
|
||||
public Attributes getAttributes(Name name, String[] attrIds) throws NamingException {
|
||||
return getAttributes(name.toString(), attrIds);
|
||||
}
|
||||
|
||||
public void modifyAttributes(String name, ModificationItem[] mods) throws NamingException {
|
||||
if (name.length() != 0) { // no subcontexts
|
||||
throw new NameNotFoundException(name); // no such object
|
||||
}
|
||||
Attributes modAttrs = extractAttributeIds(m_allAttrIds);
|
||||
modifySchemaElementAttrs(modAttrs, mods);
|
||||
LDAPMatchingRuleSchema modLdapMatchingRule = parseDefAttributes(modAttrs);
|
||||
m_schemaMgr.modifyMatchingRule(m_ldapMatchingRule, modLdapMatchingRule);
|
||||
m_ldapMatchingRule = modLdapMatchingRule;
|
||||
}
|
||||
public void modifyAttributes(String name, int mod_op, Attributes attrs) throws NamingException {
|
||||
if (name.length() != 0) { // no subcontexts
|
||||
throw new NameNotFoundException(name); // no such object
|
||||
}
|
||||
Attributes modAttrs = extractAttributeIds(m_allAttrIds);
|
||||
modifySchemaElementAttrs(modAttrs, mod_op, attrs);
|
||||
LDAPMatchingRuleSchema modLdapMatchingRule = parseDefAttributes(modAttrs);
|
||||
m_schemaMgr.modifyMatchingRule(m_ldapMatchingRule, modLdapMatchingRule);
|
||||
m_ldapMatchingRule = modLdapMatchingRule;
|
||||
}
|
||||
|
||||
public void modifyAttributes(Name name, int mod_op, Attributes attrs) throws NamingException {
|
||||
modifyAttributes(name.toString(), mod_op, attrs);
|
||||
}
|
||||
public void modifyAttributes(String name, ModificationItem[] mods) throws NamingException {
|
||||
if (name.length() != 0) { // no subcontexts
|
||||
throw new NameNotFoundException(name); // no such object
|
||||
}
|
||||
Attributes modAttrs = extractAttributeIds(m_allAttrIds);
|
||||
modifySchemaElementAttrs(modAttrs, mods);
|
||||
LDAPMatchingRuleSchema modLdapMatchingRule = parseDefAttributes(modAttrs);
|
||||
m_schemaMgr.modifyMatchingRule(m_ldapMatchingRule, modLdapMatchingRule);
|
||||
m_ldapMatchingRule = modLdapMatchingRule;
|
||||
}
|
||||
|
||||
public void modifyAttributes(Name name, ModificationItem[] mods) throws NamingException {
|
||||
modifyAttributes(name.toString(), mods);
|
||||
}
|
||||
|
||||
/**
|
||||
* Search operations are not implemented because of complexity. Ir will require
|
||||
* to implement the full LDAP search filter sematics in the client. (The search
|
||||
* filter sematics is implemented by the Directory server).
|
||||
*/
|
||||
public void modifyAttributes(Name name, int mod_op, Attributes attrs) throws NamingException {
|
||||
modifyAttributes(name.toString(), mod_op, attrs);
|
||||
}
|
||||
|
||||
public void modifyAttributes(Name name, ModificationItem[] mods) throws NamingException {
|
||||
modifyAttributes(name.toString(), mods);
|
||||
}
|
||||
|
||||
/**
|
||||
* Search operations are not implemented because of complexity. Ir will require
|
||||
* to implement the full LDAP search filter sematics in the client. (The search
|
||||
* filter sematics is implemented by the Directory server).
|
||||
*/
|
||||
|
||||
}
|
||||
|
@ -28,70 +28,70 @@ import java.util.*;
|
||||
|
||||
public class SchemaMatchingRuleContainer extends SchemaElementContainer {
|
||||
|
||||
public SchemaMatchingRuleContainer(SchemaManager schemaMgr) throws NamingException{
|
||||
super(schemaMgr, MRULEDEF);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ldap entry operations
|
||||
*/
|
||||
public SchemaMatchingRuleContainer(SchemaManager schemaMgr) throws NamingException{
|
||||
super(schemaMgr, MRULEDEF);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ldap entry operations
|
||||
*/
|
||||
|
||||
public DirContext createSchemaElement(String name, Attributes attrs) throws NamingException {
|
||||
if (name.length() == 0) {
|
||||
throw new NamingException("Empty name for schema objectclass");
|
||||
}
|
||||
LDAPMatchingRuleSchema mrule = SchemaMatchingRule.parseDefAttributes(attrs);
|
||||
m_schemaMgr.createMatchingRule(mrule);
|
||||
return new SchemaMatchingRule(mrule, m_schemaMgr);
|
||||
public DirContext createSchemaElement(String name, Attributes attrs) throws NamingException {
|
||||
if (name.length() == 0) {
|
||||
throw new NamingException("Empty name for schema objectclass");
|
||||
}
|
||||
LDAPMatchingRuleSchema mrule = SchemaMatchingRule.parseDefAttributes(attrs);
|
||||
m_schemaMgr.createMatchingRule(mrule);
|
||||
return new SchemaMatchingRule(mrule, m_schemaMgr);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void removeSchemaElement(String name) throws NamingException {
|
||||
if (name.length() == 0) {
|
||||
throw new NamingException("Can not delete schema object container");
|
||||
}
|
||||
m_schemaMgr.removeMatchingRule(name);
|
||||
}
|
||||
public void removeSchemaElement(String name) throws NamingException {
|
||||
if (name.length() == 0) {
|
||||
throw new NamingException("Can not delete schema object container");
|
||||
}
|
||||
m_schemaMgr.removeMatchingRule(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* List Operations
|
||||
*/
|
||||
/**
|
||||
* List Operations
|
||||
*/
|
||||
|
||||
public NamingEnumeration getNameList(String name) throws NamingException {
|
||||
SchemaDirContext schemaObj = (SchemaDirContext)lookup(name);
|
||||
if (schemaObj == this) {
|
||||
return new SchemaElementNameEnum(m_schemaMgr.getMatchingRuleNames());
|
||||
}
|
||||
else {
|
||||
throw new NotContextException(name);
|
||||
}
|
||||
}
|
||||
public NamingEnumeration getNameList(String name) throws NamingException {
|
||||
SchemaDirContext schemaObj = (SchemaDirContext)lookup(name);
|
||||
if (schemaObj == this) {
|
||||
return new SchemaElementNameEnum(m_schemaMgr.getMatchingRuleNames());
|
||||
}
|
||||
else {
|
||||
throw new NotContextException(name);
|
||||
}
|
||||
}
|
||||
|
||||
public NamingEnumeration getBindingsList(String name) throws NamingException {
|
||||
SchemaDirContext schemaObj = (SchemaDirContext)lookup(name);
|
||||
if (schemaObj == this) {
|
||||
return new SchemaElementBindingEnum(m_schemaMgr.getMatchingRules(), m_schemaMgr);
|
||||
}
|
||||
else {
|
||||
throw new NotContextException(name);
|
||||
}
|
||||
}
|
||||
public NamingEnumeration getBindingsList(String name) throws NamingException {
|
||||
SchemaDirContext schemaObj = (SchemaDirContext)lookup(name);
|
||||
if (schemaObj == this) {
|
||||
return new SchemaElementBindingEnum(m_schemaMgr.getMatchingRules(), m_schemaMgr);
|
||||
}
|
||||
else {
|
||||
throw new NotContextException(name);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Lookup Operations
|
||||
*/
|
||||
/**
|
||||
* Lookup Operations
|
||||
*/
|
||||
|
||||
public Object lookupSchemaElement(String name) throws NamingException {
|
||||
if (name.length() == 0) {
|
||||
return this;
|
||||
}
|
||||
|
||||
// No caching; Always create a new object
|
||||
LDAPAttributeSchema mrule = m_schemaMgr.getMatchingRule(name);
|
||||
if (mrule == null) {
|
||||
throw new NameNotFoundException(name);
|
||||
}
|
||||
return new SchemaAttribute(mrule, m_schemaMgr);
|
||||
public Object lookupSchemaElement(String name) throws NamingException {
|
||||
if (name.length() == 0) {
|
||||
return this;
|
||||
}
|
||||
|
||||
// No caching; Always create a new object
|
||||
LDAPMatchingRuleSchema mrule = m_schemaMgr.getMatchingRule(name);
|
||||
if (mrule == null) {
|
||||
throw new NameNotFoundException(name);
|
||||
}
|
||||
return new SchemaMatchingRule(mrule, m_schemaMgr);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,9 +23,9 @@ import javax.naming.*;
|
||||
|
||||
class SchemaNameParser implements NameParser {
|
||||
|
||||
private static SchemaNameParser m_parser;
|
||||
|
||||
// A table with compound name syntax properties
|
||||
private static SchemaNameParser m_parser;
|
||||
|
||||
// A table with compound name syntax properties
|
||||
static Properties nameSyntax;
|
||||
static {
|
||||
nameSyntax = new Properties();
|
||||
@ -34,18 +34,18 @@ class SchemaNameParser implements NameParser {
|
||||
nameSyntax.put("jndi.syntax.ignorecase", "true");
|
||||
}
|
||||
|
||||
// Can not be constructed
|
||||
private SchemaNameParser() {}
|
||||
|
||||
// Shared instance must be used
|
||||
public static SchemaNameParser getParser() {
|
||||
if (m_parser == null) {
|
||||
m_parser = new SchemaNameParser();
|
||||
}
|
||||
return m_parser;
|
||||
}
|
||||
|
||||
// implements parse
|
||||
// Can not be constructed
|
||||
private SchemaNameParser() {}
|
||||
|
||||
// Shared instance must be used
|
||||
public static SchemaNameParser getParser() {
|
||||
if (m_parser == null) {
|
||||
m_parser = new SchemaNameParser();
|
||||
}
|
||||
return m_parser;
|
||||
}
|
||||
|
||||
// implements parse
|
||||
public Name parse(String name) throws NamingException {
|
||||
return new CompoundName(name, nameSyntax);
|
||||
}
|
||||
|
@ -28,192 +28,233 @@ import java.util.*;
|
||||
|
||||
public class SchemaObjectClass extends SchemaElement {
|
||||
|
||||
LDAPObjectClassSchema m_ldapObjectClass;
|
||||
|
||||
// Attribute IDs that are exposed through Netscape LdapJDK
|
||||
private static String[] m_allAttrIds = {NUMERICOID, NAME, DESC, SUP, MUST, MAY };
|
||||
|
||||
public SchemaObjectClass(LDAPObjectClassSchema ldapObjectClass, SchemaManager schemaManager) {
|
||||
super(schemaManager);
|
||||
m_ldapObjectClass = ldapObjectClass;
|
||||
m_path = CLASSDEF + "/" + m_ldapObjectClass.getName();
|
||||
}
|
||||
LDAPObjectClassSchema m_ldapObjectClass;
|
||||
|
||||
// Attribute IDs that are exposed through Netscape LdapJDK
|
||||
private static String[] m_allAttrIds = {NUMERICOID, NAME, DESC, OBSOLETE, SUP,
|
||||
ABSTRACT, STRUCTURAL, AUXILIARY, MUST, MAY };
|
||||
|
||||
public SchemaObjectClass(LDAPObjectClassSchema ldapObjectClass, SchemaManager schemaManager) {
|
||||
super(schemaManager);
|
||||
m_ldapObjectClass = ldapObjectClass;
|
||||
m_path = CLASSDEF + "/" + m_ldapObjectClass.getName();
|
||||
}
|
||||
|
||||
public SchemaObjectClass(Attributes attrs, SchemaManager schemaManager) throws NamingException {
|
||||
super(schemaManager);
|
||||
m_ldapObjectClass = parseDefAttributes(attrs);
|
||||
m_path = CLASSDEF + "/" + m_ldapObjectClass.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse Definition Attributes for a LDAP objectcalss
|
||||
*/
|
||||
static LDAPObjectClassSchema parseDefAttributes(Attributes attrs) throws NamingException {
|
||||
String name="", oid="", desc="", sup="";
|
||||
Vector must=new Vector(), may=new Vector();
|
||||
public SchemaObjectClass(Attributes attrs, SchemaManager schemaManager) throws NamingException {
|
||||
super(schemaManager);
|
||||
m_ldapObjectClass = parseDefAttributes(attrs);
|
||||
m_path = CLASSDEF + "/" + m_ldapObjectClass.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse Definition Attributes for a LDAP objectcalss
|
||||
*/
|
||||
static LDAPObjectClassSchema parseDefAttributes(Attributes attrs) throws NamingException {
|
||||
String name=null, oid=null, desc=null, sup=null;
|
||||
boolean obsolete=false, abs=false, structural = false, aux = false;
|
||||
Vector must=new Vector(), may=new Vector();
|
||||
|
||||
for (Enumeration attrEnum = attrs.getAll(); attrEnum.hasMoreElements(); ) {
|
||||
Attribute attr = (Attribute) attrEnum.nextElement();
|
||||
String attrName = attr.getID();
|
||||
if (attrName.equals(NAME)) {
|
||||
for (Enumeration valEnum = attr.getAll(); valEnum.hasMoreElements(); ) {
|
||||
name = (String)valEnum.nextElement();
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (attrName.equals(NUMERICOID)) {
|
||||
for (Enumeration valEnum = attr.getAll(); valEnum.hasMoreElements(); ) {
|
||||
oid = (String)valEnum.nextElement();
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (attrName.equals(SUP)) {
|
||||
for (Enumeration valEnum = attr.getAll(); valEnum.hasMoreElements(); ) {
|
||||
sup = (String)valEnum.nextElement();
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (attrName.equals(DESC)) {
|
||||
for (Enumeration valEnum = attr.getAll(); valEnum.hasMoreElements(); ) {
|
||||
desc = (String)valEnum.nextElement();
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (attrName.equals(MAY)) {
|
||||
for (Enumeration valEnum = attr.getAll(); valEnum.hasMoreElements(); ) {
|
||||
may.addElement((String)valEnum.nextElement());
|
||||
}
|
||||
}
|
||||
else if (attrName.equals(MUST)) {
|
||||
for (Enumeration valEnum = attr.getAll(); valEnum.hasMoreElements(); ) {
|
||||
must.addElement((String)valEnum.nextElement());
|
||||
}
|
||||
}
|
||||
else if (attrName.equals(OBSOLETE) || attrName.equals(ABSTRACT) ||
|
||||
attrName.equals(STRUCTURAL) || attrName.equals(AUXILIARY)) {
|
||||
; //ignore
|
||||
}
|
||||
else {
|
||||
throw new NamingException("Invalid schema attribute type for object class definition " + attrName);
|
||||
}
|
||||
}
|
||||
|
||||
if (name.length() == 0 || oid.length() == 0 || sup.length() == 0 ||
|
||||
(must.size() == 0 && may.size() == 0)) {
|
||||
|
||||
throw new NamingException("Incomplete schema object class definition");
|
||||
}
|
||||
|
||||
return new LDAPObjectClassSchema(name, oid, sup, desc,
|
||||
vectorToStringAry(must),
|
||||
vectorToStringAry(may));
|
||||
}
|
||||
|
||||
/**
|
||||
* Exctract specified attributes from the ldapObjectClass
|
||||
*/
|
||||
Attributes extractAttributeIds(String[] attrIds) {
|
||||
Attributes attrs = new BasicAttributes();
|
||||
for (int i = 0; i < attrIds.length; i++) {
|
||||
if (attrIds[i].equals(NUMERICOID)) {
|
||||
attrs.put(new BasicAttribute(NUMERICOID, m_ldapObjectClass.getOID()));
|
||||
}
|
||||
else if (attrIds[i].equals(NAME)) {
|
||||
attrs.put(new BasicAttribute(NAME, m_ldapObjectClass.getName()));
|
||||
}
|
||||
else if (attrIds[i].equals(DESC)) {
|
||||
attrs.put(new BasicAttribute(DESC, m_ldapObjectClass.getDescription()));
|
||||
}
|
||||
else if (attrIds[i].equals(SUP)) {
|
||||
attrs.put(new BasicAttribute(SUP, m_ldapObjectClass.getSuperior()));
|
||||
}
|
||||
else if (attrIds[i].equals(MAY)) {
|
||||
BasicAttribute optional = new BasicAttribute(MAY);
|
||||
for (Enumeration e = m_ldapObjectClass.getOptionalAttributes(); e.hasMoreElements();) {
|
||||
optional.add(e.nextElement());
|
||||
}
|
||||
if (optional.size() != 0) {
|
||||
attrs.put(optional);
|
||||
}
|
||||
}
|
||||
else if (attrIds[i].equals(MUST)) {
|
||||
BasicAttribute required = new BasicAttribute(MUST);
|
||||
for (Enumeration e = m_ldapObjectClass.getRequiredAttributes(); e.hasMoreElements();) {
|
||||
required.add(e.nextElement());
|
||||
}
|
||||
if (required.size() != 0) {
|
||||
attrs.put(required);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// ignore other attrIds as not supported by Netscape LdapJDK APIs
|
||||
}
|
||||
}
|
||||
for (Enumeration attrEnum = attrs.getAll(); attrEnum.hasMoreElements(); ) {
|
||||
Attribute attr = (Attribute) attrEnum.nextElement();
|
||||
String attrName = attr.getID();
|
||||
if (attrName.equals(NAME)) {
|
||||
name = getSchemaAttrValue(attr);
|
||||
}
|
||||
else if (attrName.equals(NUMERICOID)) {
|
||||
oid = getSchemaAttrValue(attr);
|
||||
}
|
||||
else if (attrName.equals(SUP)) {
|
||||
sup = getSchemaAttrValue(attr);
|
||||
}
|
||||
else if (attrName.equals(DESC)) {
|
||||
desc = getSchemaAttrValue(attr);
|
||||
}
|
||||
else if (attrName.equals(MAY)) {
|
||||
for (Enumeration valEnum = attr.getAll(); valEnum.hasMoreElements(); ) {
|
||||
may.addElement((String)valEnum.nextElement());
|
||||
}
|
||||
}
|
||||
else if (attrName.equals(MUST)) {
|
||||
for (Enumeration valEnum = attr.getAll(); valEnum.hasMoreElements(); ) {
|
||||
must.addElement((String)valEnum.nextElement());
|
||||
}
|
||||
}
|
||||
else if (attrName.equals(OBSOLETE)) {
|
||||
obsolete = parseTrueFalseValue(attr);
|
||||
}
|
||||
else if (attrName.equals(ABSTRACT)) {
|
||||
abs = parseTrueFalseValue(attr);
|
||||
}
|
||||
else if (attrName.equals(STRUCTURAL)) {
|
||||
structural = parseTrueFalseValue(attr);
|
||||
}
|
||||
else if (attrName.equals(AUXILIARY)) {
|
||||
aux = parseTrueFalseValue(attr);
|
||||
}
|
||||
else {
|
||||
throw new NamingException("Invalid schema attribute type for object class definition " + attrName);
|
||||
}
|
||||
}
|
||||
|
||||
LDAPObjectClassSchema objectClass =
|
||||
new LDAPObjectClassSchema(name, oid, sup, desc,
|
||||
vectorToStringAry(must),
|
||||
vectorToStringAry(may));
|
||||
|
||||
return attrs;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* DirContext Attribute Operations
|
||||
*/
|
||||
if (obsolete) {
|
||||
objectClass.setQualifier(OBSOLETE, "");
|
||||
}
|
||||
if (abs) {
|
||||
objectClass.setQualifier(ABSTRACT, "");
|
||||
}
|
||||
if (structural) {
|
||||
objectClass.setQualifier(STRUCTURAL, "");
|
||||
}
|
||||
if (aux) {
|
||||
objectClass.setQualifier(AUXILIARY, "");
|
||||
}
|
||||
|
||||
return objectClass;
|
||||
}
|
||||
|
||||
/**
|
||||
* Exctract specified attributes from the ldapObjectClass
|
||||
*/
|
||||
Attributes extractAttributeIds(String[] attrIds) throws NamingException{
|
||||
Attributes attrs = new BasicAttributes();
|
||||
String val = null, multiVal[]=null;
|
||||
for (int i = 0; i < attrIds.length; i++) {
|
||||
if (attrIds[i].equals(NUMERICOID)) {
|
||||
val = m_ldapObjectClass.getOID();
|
||||
if (val != null) {
|
||||
attrs.put(new BasicAttribute(NUMERICOID, val));
|
||||
}
|
||||
}
|
||||
else if (attrIds[i].equals(NAME)) {
|
||||
val = m_ldapObjectClass.getName();
|
||||
if (val != null) {
|
||||
attrs.put(new BasicAttribute(NAME, val));
|
||||
}
|
||||
}
|
||||
else if (attrIds[i].equals(DESC)) {
|
||||
val = m_ldapObjectClass.getDescription();
|
||||
if (val != null) {
|
||||
attrs.put(new BasicAttribute(DESC, val));
|
||||
}
|
||||
}
|
||||
else if (attrIds[i].equals(SUP)) {
|
||||
val = m_ldapObjectClass.getSuperior();
|
||||
if (val != null) {
|
||||
attrs.put(new BasicAttribute(SUP, val));
|
||||
}
|
||||
}
|
||||
else if (attrIds[i].equals(MAY)) {
|
||||
BasicAttribute optional = new BasicAttribute(MAY);
|
||||
for (Enumeration e = m_ldapObjectClass.getOptionalAttributes(); e.hasMoreElements();) {
|
||||
optional.add(e.nextElement());
|
||||
}
|
||||
if (optional.size() != 0) {
|
||||
attrs.put(optional);
|
||||
}
|
||||
}
|
||||
else if (attrIds[i].equals(MUST)) {
|
||||
BasicAttribute required = new BasicAttribute(MUST);
|
||||
for (Enumeration e = m_ldapObjectClass.getRequiredAttributes(); e.hasMoreElements();) {
|
||||
required.add(e.nextElement());
|
||||
}
|
||||
if (required.size() != 0) {
|
||||
attrs.put(required);
|
||||
}
|
||||
}
|
||||
else if (attrIds[i].equals(OBSOLETE)) {
|
||||
if (m_ldapObjectClass.getQualifier(OBSOLETE)!= null) {
|
||||
attrs.put(new BasicAttribute(OBSOLETE, "true"));
|
||||
}
|
||||
}
|
||||
else if (attrIds[i].equals(ABSTRACT)) {
|
||||
if (m_ldapObjectClass.getQualifier(ABSTRACT)!= null) {
|
||||
attrs.put(new BasicAttribute(ABSTRACT, "true"));
|
||||
}
|
||||
}
|
||||
else if (attrIds[i].equals(STRUCTURAL)) {
|
||||
if (m_ldapObjectClass.getQualifier(STRUCTURAL)!= null) {
|
||||
attrs.put(new BasicAttribute(STRUCTURAL, "true"));
|
||||
}
|
||||
}
|
||||
else if (attrIds[i].equals(AUXILIARY)) {
|
||||
if (m_ldapObjectClass.getQualifier(AUXILIARY)!= null) {
|
||||
attrs.put(new BasicAttribute(AUXILIARY, "true"));
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new NamingException("Invalid schema attribute type for object class definition " + attrIds[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public Attributes getAttributes(String name) throws NamingException {
|
||||
if (name.length() != 0) { // no subcontexts
|
||||
throw new NameNotFoundException(name); // no such object
|
||||
}
|
||||
return extractAttributeIds(m_allAttrIds);
|
||||
}
|
||||
return attrs;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* DirContext Attribute Operations
|
||||
*/
|
||||
|
||||
public Attributes getAttributes(String name, String[] attrIds) throws NamingException {
|
||||
if (name.length() != 0) { // no subcontexts
|
||||
throw new NameNotFoundException(name); // no such object
|
||||
}
|
||||
return extractAttributeIds(attrIds);
|
||||
}
|
||||
public Attributes getAttributes(String name) throws NamingException {
|
||||
if (name.length() != 0) { // no subcontexts
|
||||
throw new NameNotFoundException(name); // no such object
|
||||
}
|
||||
return extractAttributeIds(m_allAttrIds);
|
||||
}
|
||||
|
||||
public Attributes getAttributes(Name name) throws NamingException {
|
||||
return getAttributes(name.toString());
|
||||
}
|
||||
public Attributes getAttributes(String name, String[] attrIds) throws NamingException {
|
||||
if (name.length() != 0) { // no subcontexts
|
||||
throw new NameNotFoundException(name); // no such object
|
||||
}
|
||||
return extractAttributeIds(attrIds);
|
||||
}
|
||||
|
||||
public Attributes getAttributes(Name name, String[] attrIds) throws NamingException {
|
||||
return getAttributes(name.toString(), attrIds);
|
||||
}
|
||||
public Attributes getAttributes(Name name) throws NamingException {
|
||||
return getAttributes(name.toString());
|
||||
}
|
||||
|
||||
public void modifyAttributes(String name, int mod_op, Attributes attrs) throws NamingException {
|
||||
if (name.length() != 0) { // no subcontexts
|
||||
throw new NameNotFoundException(name); // no such object
|
||||
}
|
||||
Attributes modAttrs = extractAttributeIds(m_allAttrIds);
|
||||
modifySchemaElementAttrs(modAttrs, mod_op, attrs);
|
||||
LDAPObjectClassSchema modLdapObjectClass = parseDefAttributes(modAttrs);
|
||||
m_schemaMgr.modifyObjectClass(m_ldapObjectClass, modLdapObjectClass);
|
||||
m_ldapObjectClass = modLdapObjectClass;
|
||||
}
|
||||
public Attributes getAttributes(Name name, String[] attrIds) throws NamingException {
|
||||
return getAttributes(name.toString(), attrIds);
|
||||
}
|
||||
|
||||
public void modifyAttributes(String name, ModificationItem[] mods) throws NamingException {
|
||||
if (name.length() != 0) { // no subcontexts
|
||||
throw new NameNotFoundException(name); // no such object
|
||||
}
|
||||
Attributes modAttrs = extractAttributeIds(m_allAttrIds);
|
||||
modifySchemaElementAttrs(modAttrs, mods);
|
||||
LDAPObjectClassSchema modLdapObjectClass = parseDefAttributes(modAttrs);
|
||||
m_schemaMgr.modifyObjectClass(m_ldapObjectClass, modLdapObjectClass);
|
||||
m_ldapObjectClass = modLdapObjectClass;
|
||||
}
|
||||
public void modifyAttributes(String name, int mod_op, Attributes attrs) throws NamingException {
|
||||
if (name.length() != 0) { // no subcontexts
|
||||
throw new NameNotFoundException(name); // no such object
|
||||
}
|
||||
Attributes modAttrs = extractAttributeIds(m_allAttrIds);
|
||||
modifySchemaElementAttrs(modAttrs, mod_op, attrs);
|
||||
LDAPObjectClassSchema modLdapObjectClass = parseDefAttributes(modAttrs);
|
||||
m_schemaMgr.modifyObjectClass(m_ldapObjectClass, modLdapObjectClass);
|
||||
m_ldapObjectClass = modLdapObjectClass;
|
||||
}
|
||||
|
||||
public void modifyAttributes(Name name, int mod_op, Attributes attrs) throws NamingException {
|
||||
modifyAttributes(name.toString(), mod_op, attrs);
|
||||
}
|
||||
public void modifyAttributes(String name, ModificationItem[] mods) throws NamingException {
|
||||
if (name.length() != 0) { // no subcontexts
|
||||
throw new NameNotFoundException(name); // no such object
|
||||
}
|
||||
Attributes modAttrs = extractAttributeIds(m_allAttrIds);
|
||||
modifySchemaElementAttrs(modAttrs, mods);
|
||||
LDAPObjectClassSchema modLdapObjectClass = parseDefAttributes(modAttrs);
|
||||
m_schemaMgr.modifyObjectClass(m_ldapObjectClass, modLdapObjectClass);
|
||||
m_ldapObjectClass = modLdapObjectClass;
|
||||
}
|
||||
|
||||
public void modifyAttributes(Name name, ModificationItem[] mods) throws NamingException {
|
||||
modifyAttributes(name.toString(), mods);
|
||||
}
|
||||
|
||||
/**
|
||||
* Search operations are not implemented because of complexity. Ir will require
|
||||
* to implement the full LDAP search filter sematics in the client. (The search
|
||||
* filter sematics is implemented by the Directory server).
|
||||
*/
|
||||
public void modifyAttributes(Name name, int mod_op, Attributes attrs) throws NamingException {
|
||||
modifyAttributes(name.toString(), mod_op, attrs);
|
||||
}
|
||||
|
||||
public void modifyAttributes(Name name, ModificationItem[] mods) throws NamingException {
|
||||
modifyAttributes(name.toString(), mods);
|
||||
}
|
||||
|
||||
/**
|
||||
* Search operations are not implemented because of complexity. Ir will require
|
||||
* to implement the full LDAP search filter sematics in the client. (The search
|
||||
* filter sematics is implemented by the Directory server).
|
||||
*/
|
||||
|
||||
}
|
||||
|
@ -28,70 +28,70 @@ import java.util.*;
|
||||
|
||||
public class SchemaObjectClassContainer extends SchemaElementContainer {
|
||||
|
||||
public SchemaObjectClassContainer(SchemaManager schemaMgr) throws NamingException{
|
||||
super(schemaMgr, CLASSDEF);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ldap entry operations
|
||||
*/
|
||||
public SchemaObjectClassContainer(SchemaManager schemaMgr) throws NamingException{
|
||||
super(schemaMgr, CLASSDEF);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ldap entry operations
|
||||
*/
|
||||
|
||||
public DirContext createSchemaElement(String name, Attributes attrs) throws NamingException {
|
||||
if (name.length() == 0) {
|
||||
throw new NamingException("Empty name for schema objectclass");
|
||||
}
|
||||
LDAPObjectClassSchema objclass = SchemaObjectClass.parseDefAttributes(attrs);
|
||||
m_schemaMgr.createObjectClass(objclass);
|
||||
return new SchemaObjectClass(objclass, m_schemaMgr);
|
||||
public DirContext createSchemaElement(String name, Attributes attrs) throws NamingException {
|
||||
if (name.length() == 0) {
|
||||
throw new NamingException("Empty name for schema objectclass");
|
||||
}
|
||||
LDAPObjectClassSchema objclass = SchemaObjectClass.parseDefAttributes(attrs);
|
||||
m_schemaMgr.createObjectClass(objclass);
|
||||
return new SchemaObjectClass(objclass, m_schemaMgr);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void removeSchemaElement(String name) throws NamingException {
|
||||
if (name.length() == 0) {
|
||||
throw new NamingException("Can not delete schema object container");
|
||||
}
|
||||
m_schemaMgr.removeObjectClass(name);
|
||||
}
|
||||
public void removeSchemaElement(String name) throws NamingException {
|
||||
if (name.length() == 0) {
|
||||
throw new NamingException("Can not delete schema object container");
|
||||
}
|
||||
m_schemaMgr.removeObjectClass(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* List Operations
|
||||
*/
|
||||
/**
|
||||
* List Operations
|
||||
*/
|
||||
|
||||
public NamingEnumeration getNameList(String name) throws NamingException {
|
||||
SchemaDirContext schemaObj = (SchemaDirContext)lookup(name);
|
||||
if (schemaObj == this) {
|
||||
return new SchemaElementNameEnum(m_schemaMgr.getObjectClassNames());
|
||||
}
|
||||
else {
|
||||
throw new NotContextException(name);
|
||||
}
|
||||
}
|
||||
public NamingEnumeration getNameList(String name) throws NamingException {
|
||||
SchemaDirContext schemaObj = (SchemaDirContext)lookup(name);
|
||||
if (schemaObj == this) {
|
||||
return new SchemaElementNameEnum(m_schemaMgr.getObjectClassNames());
|
||||
}
|
||||
else {
|
||||
throw new NotContextException(name);
|
||||
}
|
||||
}
|
||||
|
||||
public NamingEnumeration getBindingsList(String name) throws NamingException {
|
||||
SchemaDirContext schemaObj = (SchemaDirContext)lookup(name);
|
||||
if (schemaObj == this) {
|
||||
return new SchemaElementBindingEnum(m_schemaMgr.getObjectClasses(), m_schemaMgr);
|
||||
}
|
||||
else {
|
||||
throw new NotContextException(name);
|
||||
}
|
||||
}
|
||||
public NamingEnumeration getBindingsList(String name) throws NamingException {
|
||||
SchemaDirContext schemaObj = (SchemaDirContext)lookup(name);
|
||||
if (schemaObj == this) {
|
||||
return new SchemaElementBindingEnum(m_schemaMgr.getObjectClasses(), m_schemaMgr);
|
||||
}
|
||||
else {
|
||||
throw new NotContextException(name);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Lookup Operations
|
||||
*/
|
||||
/**
|
||||
* Lookup Operations
|
||||
*/
|
||||
|
||||
public Object lookupSchemaElement(String name) throws NamingException {
|
||||
if (name.length() == 0) {
|
||||
return this;
|
||||
}
|
||||
|
||||
// No caching; Always create a new object
|
||||
LDAPObjectClassSchema objclass = m_schemaMgr.getObjectClass(name);
|
||||
if (objclass == null) {
|
||||
throw new NameNotFoundException(name);
|
||||
}
|
||||
return new SchemaObjectClass(objclass, m_schemaMgr);
|
||||
public Object lookupSchemaElement(String name) throws NamingException {
|
||||
if (name.length() == 0) {
|
||||
return this;
|
||||
}
|
||||
|
||||
// No caching; Always create a new object
|
||||
LDAPObjectClassSchema objclass = m_schemaMgr.getObjectClass(name);
|
||||
if (objclass == null) {
|
||||
throw new NameNotFoundException(name);
|
||||
}
|
||||
return new SchemaObjectClass(objclass, m_schemaMgr);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -28,333 +28,333 @@ import java.util.*;
|
||||
|
||||
public class SchemaRoot extends SchemaDirContext {
|
||||
|
||||
static final String m_className = "javax.naming.directory.DirContext"; // for class name is bindings
|
||||
|
||||
SchemaDirContext m_classContainer, m_attrContainer, m_matchRuleContainer;
|
||||
|
||||
SchemaManager m_schemaMgr;
|
||||
|
||||
public SchemaRoot(LDAPConnection ld) throws NamingException{
|
||||
m_path = "";
|
||||
m_schemaMgr = new SchemaManager(ld);
|
||||
m_classContainer = new SchemaObjectClassContainer(m_schemaMgr);
|
||||
m_attrContainer = new SchemaAttributeContainer(m_schemaMgr);
|
||||
m_matchRuleContainer = new SchemaMatchingRuleContainer(m_schemaMgr);
|
||||
}
|
||||
static final String m_className = "javax.naming.directory.DirContext"; // for class name is bindings
|
||||
|
||||
SchemaDirContext m_classContainer, m_attrContainer, m_matchRuleContainer;
|
||||
|
||||
SchemaManager m_schemaMgr;
|
||||
|
||||
public SchemaRoot(LDAPConnection ld) throws NamingException{
|
||||
m_path = "";
|
||||
m_schemaMgr = new SchemaManager(ld);
|
||||
m_classContainer = new SchemaObjectClassContainer(m_schemaMgr);
|
||||
m_attrContainer = new SchemaAttributeContainer(m_schemaMgr);
|
||||
m_matchRuleContainer = new SchemaMatchingRuleContainer(m_schemaMgr);
|
||||
}
|
||||
|
||||
SchemaObjectSubordinateNamePair resolveSchemaObject(String name) throws NamingException{
|
||||
|
||||
SchemaDirContext obj = null;
|
||||
|
||||
if (name.length() == 0) {
|
||||
obj = this;
|
||||
}
|
||||
else if (name.startsWith(CLASSDEF) || name.startsWith(CLASSDEF.toLowerCase())) {
|
||||
name = name.substring(CLASSDEF.length());
|
||||
obj = m_classContainer;
|
||||
}
|
||||
else if (name.startsWith(ATTRDEF) || name.startsWith(ATTRDEF.toLowerCase())) {
|
||||
name = name.substring(ATTRDEF.length());
|
||||
obj = m_attrContainer;
|
||||
}
|
||||
else if (name.startsWith(MRULEDEF) || name.startsWith(MRULEDEF.toLowerCase())) {
|
||||
name = name.substring(MRULEDEF.length());
|
||||
obj = m_matchRuleContainer;
|
||||
|
||||
}
|
||||
else {
|
||||
throw new NameNotFoundException(name);
|
||||
}
|
||||
|
||||
if (name.length() > 1 && name.startsWith("/")) {
|
||||
name = name.substring(1);
|
||||
}
|
||||
return new SchemaObjectSubordinateNamePair(obj, name);
|
||||
}
|
||||
|
||||
SchemaObjectSubordinateNamePair resolveSchemaObject(String name) throws NamingException{
|
||||
|
||||
SchemaDirContext obj = null;
|
||||
|
||||
if (name.length() == 0) {
|
||||
obj = this;
|
||||
}
|
||||
else if (name.startsWith(CLASSDEF) || name.startsWith(CLASSDEF.toLowerCase())) {
|
||||
name = name.substring(CLASSDEF.length());
|
||||
obj = m_classContainer;
|
||||
}
|
||||
else if (name.startsWith(ATTRDEF) || name.startsWith(ATTRDEF.toLowerCase())) {
|
||||
name = name.substring(ATTRDEF.length());
|
||||
obj = m_attrContainer;
|
||||
}
|
||||
else if (name.startsWith(MRULEDEF) || name.startsWith(MRULEDEF.toLowerCase())) {
|
||||
name = name.substring(MRULEDEF.length());
|
||||
obj = m_matchRuleContainer;
|
||||
|
||||
}
|
||||
else {
|
||||
throw new NameNotFoundException(name);
|
||||
}
|
||||
|
||||
if (name.length() > 1 && name.startsWith("/")) {
|
||||
name = name.substring(1);
|
||||
}
|
||||
return new SchemaObjectSubordinateNamePair(obj, name);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Attribute Operations
|
||||
*/
|
||||
/**
|
||||
* Attribute Operations
|
||||
*/
|
||||
|
||||
public Attributes getAttributes(String name) throws NamingException {
|
||||
SchemaObjectSubordinateNamePair objNamePair = resolveSchemaObject(name);
|
||||
if (objNamePair.schemaObj == this) {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
else {
|
||||
return objNamePair.schemaObj.getAttributes(objNamePair.subordinateName);
|
||||
}
|
||||
}
|
||||
public Attributes getAttributes(String name) throws NamingException {
|
||||
SchemaObjectSubordinateNamePair objNamePair = resolveSchemaObject(name);
|
||||
if (objNamePair.schemaObj == this) {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
else {
|
||||
return objNamePair.schemaObj.getAttributes(objNamePair.subordinateName);
|
||||
}
|
||||
}
|
||||
|
||||
public Attributes getAttributes(String name, String[] attrIds) throws NamingException {
|
||||
SchemaObjectSubordinateNamePair objNamePair = resolveSchemaObject(name);
|
||||
if (objNamePair.schemaObj == this) {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
else {
|
||||
return objNamePair.schemaObj.getAttributes(objNamePair.subordinateName, attrIds);
|
||||
}
|
||||
}
|
||||
public Attributes getAttributes(String name, String[] attrIds) throws NamingException {
|
||||
SchemaObjectSubordinateNamePair objNamePair = resolveSchemaObject(name);
|
||||
if (objNamePair.schemaObj == this) {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
else {
|
||||
return objNamePair.schemaObj.getAttributes(objNamePair.subordinateName, attrIds);
|
||||
}
|
||||
}
|
||||
|
||||
public Attributes getAttributes(Name name) throws NamingException {
|
||||
return getAttributes(name.toString());
|
||||
}
|
||||
public Attributes getAttributes(Name name) throws NamingException {
|
||||
return getAttributes(name.toString());
|
||||
}
|
||||
|
||||
public Attributes getAttributes(Name name, String[] attrIds) throws NamingException {
|
||||
return getAttributes(name.toString(), attrIds);
|
||||
}
|
||||
public Attributes getAttributes(Name name, String[] attrIds) throws NamingException {
|
||||
return getAttributes(name.toString(), attrIds);
|
||||
}
|
||||
|
||||
public void modifyAttributes(String name, int mod_op, Attributes attrs) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public void modifyAttributes(String name, int mod_op, Attributes attrs) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
public void modifyAttributes(String name, ModificationItem[] mods) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public void modifyAttributes(String name, ModificationItem[] mods) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
public void modifyAttributes(Name name, int mod_op, Attributes attrs) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public void modifyAttributes(Name name, int mod_op, Attributes attrs) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
public void modifyAttributes(Name name, ModificationItem[] mods) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public void modifyAttributes(Name name, ModificationItem[] mods) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
/**
|
||||
* Ldap entry operations
|
||||
*/
|
||||
/**
|
||||
* Ldap entry operations
|
||||
*/
|
||||
|
||||
public Context createSubcontext(String name) throws NamingException {
|
||||
// Directory entry must have attributes
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public Context createSubcontext(String name) throws NamingException {
|
||||
// Directory entry must have attributes
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
public Context createSubcontext(Name name) throws NamingException {
|
||||
// Directory entry must have attributes
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public Context createSubcontext(Name name) throws NamingException {
|
||||
// Directory entry must have attributes
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
public DirContext createSubcontext(String name, Attributes attrs) throws NamingException {
|
||||
SchemaObjectSubordinateNamePair objNamePair = resolveSchemaObject(name);
|
||||
if (objNamePair.schemaObj == this) {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
else {
|
||||
return objNamePair.schemaObj.createSubcontext(objNamePair.subordinateName, attrs);
|
||||
}
|
||||
}
|
||||
public DirContext createSubcontext(String name, Attributes attrs) throws NamingException {
|
||||
SchemaObjectSubordinateNamePair objNamePair = resolveSchemaObject(name);
|
||||
if (objNamePair.schemaObj == this) {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
else {
|
||||
return objNamePair.schemaObj.createSubcontext(objNamePair.subordinateName, attrs);
|
||||
}
|
||||
}
|
||||
|
||||
public DirContext createSubcontext(Name name, Attributes attrs) throws NamingException {
|
||||
return createSubcontext(name.toString(), attrs);
|
||||
}
|
||||
public DirContext createSubcontext(Name name, Attributes attrs) throws NamingException {
|
||||
return createSubcontext(name.toString(), attrs);
|
||||
}
|
||||
|
||||
public void destroySubcontext(String name) throws NamingException {
|
||||
SchemaObjectSubordinateNamePair objNamePair = resolveSchemaObject(name);
|
||||
if (objNamePair.schemaObj == this) {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
else {
|
||||
objNamePair.schemaObj.destroySubcontext(objNamePair.subordinateName);
|
||||
}
|
||||
}
|
||||
public void destroySubcontext(String name) throws NamingException {
|
||||
SchemaObjectSubordinateNamePair objNamePair = resolveSchemaObject(name);
|
||||
if (objNamePair.schemaObj == this) {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
else {
|
||||
objNamePair.schemaObj.destroySubcontext(objNamePair.subordinateName);
|
||||
}
|
||||
}
|
||||
|
||||
public void destroySubcontext(Name name) throws NamingException {
|
||||
destroySubcontext(name.toString());
|
||||
}
|
||||
public void destroySubcontext(Name name) throws NamingException {
|
||||
destroySubcontext(name.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Naming Bind operations
|
||||
*/
|
||||
/**
|
||||
* Naming Bind operations
|
||||
*/
|
||||
|
||||
public void bind(String name, Object obj) throws NamingException {
|
||||
if (obj instanceof DirContext) {
|
||||
createSubcontext(name, ((DirContext)obj).getAttributes(""));
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException("Can not bind this type of object");
|
||||
}
|
||||
}
|
||||
public void bind(String name, Object obj) throws NamingException {
|
||||
if (obj instanceof DirContext) {
|
||||
createSubcontext(name, ((DirContext)obj).getAttributes(""));
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException("Can not bind this type of object");
|
||||
}
|
||||
}
|
||||
|
||||
public void bind(Name name, Object obj) throws NamingException {
|
||||
bind(name.toString(), obj);
|
||||
}
|
||||
public void bind(Name name, Object obj) throws NamingException {
|
||||
bind(name.toString(), obj);
|
||||
}
|
||||
|
||||
public void rebind(String name, Object obj) throws NamingException {
|
||||
unbind(name);
|
||||
bind(name, obj);
|
||||
}
|
||||
public void rebind(String name, Object obj) throws NamingException {
|
||||
unbind(name);
|
||||
bind(name, obj);
|
||||
}
|
||||
|
||||
public void rebind(Name name, Object obj) throws NamingException {
|
||||
rebind(name.toString(), obj);
|
||||
}
|
||||
public void rebind(Name name, Object obj) throws NamingException {
|
||||
rebind(name.toString(), obj);
|
||||
}
|
||||
|
||||
public void rename(String oldName, String newName) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public void rename(String oldName, String newName) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
public void rename(Name oldName, Name newName) throws NamingException {
|
||||
rename(oldName.toString(), newName.toString());
|
||||
}
|
||||
public void rename(Name oldName, Name newName) throws NamingException {
|
||||
rename(oldName.toString(), newName.toString());
|
||||
}
|
||||
|
||||
public void unbind(String name) throws NamingException {
|
||||
// In ldap every entry is naming context
|
||||
destroySubcontext(name);
|
||||
}
|
||||
public void unbind(String name) throws NamingException {
|
||||
// In ldap every entry is naming context
|
||||
destroySubcontext(name);
|
||||
}
|
||||
|
||||
public void unbind(Name name) throws NamingException {
|
||||
// In ldap every entry is naming context
|
||||
destroySubcontext(name);
|
||||
}
|
||||
public void unbind(Name name) throws NamingException {
|
||||
// In ldap every entry is naming context
|
||||
destroySubcontext(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* List Operations
|
||||
*/
|
||||
/**
|
||||
* List Operations
|
||||
*/
|
||||
|
||||
public NamingEnumeration list(String name) throws NamingException {
|
||||
SchemaObjectSubordinateNamePair objNamePair = resolveSchemaObject(name);
|
||||
if (objNamePair.schemaObj == this) {
|
||||
return new SchemaRootNameClassPairEnum();
|
||||
}
|
||||
else {
|
||||
return objNamePair.schemaObj.list(objNamePair.subordinateName);
|
||||
}
|
||||
}
|
||||
public NamingEnumeration list(String name) throws NamingException {
|
||||
SchemaObjectSubordinateNamePair objNamePair = resolveSchemaObject(name);
|
||||
if (objNamePair.schemaObj == this) {
|
||||
return new SchemaRootNameClassPairEnum();
|
||||
}
|
||||
else {
|
||||
return objNamePair.schemaObj.list(objNamePair.subordinateName);
|
||||
}
|
||||
}
|
||||
|
||||
public NamingEnumeration list(Name name) throws NamingException {
|
||||
return list(name.toString());
|
||||
}
|
||||
public NamingEnumeration list(Name name) throws NamingException {
|
||||
return list(name.toString());
|
||||
}
|
||||
|
||||
public NamingEnumeration listBindings(String name) throws NamingException {
|
||||
SchemaObjectSubordinateNamePair objNamePair = resolveSchemaObject(name);
|
||||
if (objNamePair.schemaObj == this) {
|
||||
return new SchemaRootBindingEnum();
|
||||
}
|
||||
else {
|
||||
return objNamePair.schemaObj.listBindings(objNamePair.subordinateName);
|
||||
}
|
||||
public NamingEnumeration listBindings(String name) throws NamingException {
|
||||
SchemaObjectSubordinateNamePair objNamePair = resolveSchemaObject(name);
|
||||
if (objNamePair.schemaObj == this) {
|
||||
return new SchemaRootBindingEnum();
|
||||
}
|
||||
else {
|
||||
return objNamePair.schemaObj.listBindings(objNamePair.subordinateName);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public NamingEnumeration listBindings(Name name) throws NamingException {
|
||||
return listBindings(name.toString());
|
||||
}
|
||||
public NamingEnumeration listBindings(Name name) throws NamingException {
|
||||
return listBindings(name.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Lookup Operations
|
||||
*/
|
||||
/**
|
||||
* Lookup Operations
|
||||
*/
|
||||
|
||||
public Object lookup(String name) throws NamingException {
|
||||
SchemaObjectSubordinateNamePair objNamePair = resolveSchemaObject(name);
|
||||
if (objNamePair.schemaObj == this) {
|
||||
return this;
|
||||
}
|
||||
else {
|
||||
return objNamePair.schemaObj.lookup(objNamePair.subordinateName);
|
||||
}
|
||||
public Object lookup(String name) throws NamingException {
|
||||
SchemaObjectSubordinateNamePair objNamePair = resolveSchemaObject(name);
|
||||
if (objNamePair.schemaObj == this) {
|
||||
return this;
|
||||
}
|
||||
else {
|
||||
return objNamePair.schemaObj.lookup(objNamePair.subordinateName);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public Object lookup(Name name) throws NamingException {
|
||||
return lookup(name.toString());
|
||||
}
|
||||
public Object lookup(Name name) throws NamingException {
|
||||
return lookup(name.toString());
|
||||
}
|
||||
|
||||
public Object lookupLink(String name) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public Object lookupLink(String name) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
public Object lookupLink(Name name) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
public Object lookupLink(Name name) throws NamingException {
|
||||
throw new OperationNotSupportedException();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test program
|
||||
*/
|
||||
public static void main(String args[]) {
|
||||
try {
|
||||
String name = args[0];
|
||||
System.out.println((new SchemaRoot(null)).resolveSchemaObject(name));
|
||||
}
|
||||
catch (Exception e) {
|
||||
System.err.println(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* NamigEnumeration of NameClassPairs
|
||||
*/
|
||||
class SchemaRootNameClassPairEnum implements NamingEnumeration {
|
||||
public static void main(String args[]) {
|
||||
try {
|
||||
String name = args[0];
|
||||
System.out.println((new SchemaRoot(null)).resolveSchemaObject(name));
|
||||
}
|
||||
catch (Exception e) {
|
||||
System.err.println(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* NamigEnumeration of NameClassPairs
|
||||
*/
|
||||
class SchemaRootNameClassPairEnum implements NamingEnumeration {
|
||||
|
||||
private int m_idx = -1;
|
||||
private int m_idx = -1;
|
||||
|
||||
public Object next() {
|
||||
return nextElement();
|
||||
}
|
||||
public Object next() {
|
||||
return nextElement();
|
||||
}
|
||||
|
||||
public Object nextElement() {
|
||||
m_idx++;
|
||||
if (m_idx == 0 ) {
|
||||
return new NameClassPair(CLASSDEF, m_className);
|
||||
}
|
||||
else if (m_idx == 1) {
|
||||
return new NameClassPair(ATTRDEF, m_className);
|
||||
}
|
||||
else if (m_idx == 2) {
|
||||
return new NameClassPair(MRULEDEF, m_className);
|
||||
}
|
||||
else {
|
||||
throw new NoSuchElementException("SchemaRootEnumerator");
|
||||
}
|
||||
|
||||
}
|
||||
public Object nextElement() {
|
||||
m_idx++;
|
||||
if (m_idx == 0 ) {
|
||||
return new NameClassPair(CLASSDEF, m_className);
|
||||
}
|
||||
else if (m_idx == 1) {
|
||||
return new NameClassPair(ATTRDEF, m_className);
|
||||
}
|
||||
else if (m_idx == 2) {
|
||||
return new NameClassPair(MRULEDEF, m_className);
|
||||
}
|
||||
else {
|
||||
throw new NoSuchElementException("SchemaRootEnumerator");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public boolean hasMore() {
|
||||
return hasMoreElements();
|
||||
}
|
||||
public boolean hasMore() {
|
||||
return hasMoreElements();
|
||||
}
|
||||
|
||||
public boolean hasMoreElements() {
|
||||
return m_idx < 2;
|
||||
}
|
||||
public boolean hasMoreElements() {
|
||||
return m_idx < 2;
|
||||
}
|
||||
|
||||
public void close() {}
|
||||
}
|
||||
public void close() {}
|
||||
}
|
||||
|
||||
/**
|
||||
* NamingEnumeration of Bindings
|
||||
*/
|
||||
class SchemaRootBindingEnum implements NamingEnumeration {
|
||||
class SchemaRootBindingEnum implements NamingEnumeration {
|
||||
|
||||
private int m_idx = -1;
|
||||
private int m_idx = -1;
|
||||
|
||||
public Object next() {
|
||||
return nextElement();
|
||||
}
|
||||
public Object next() {
|
||||
return nextElement();
|
||||
}
|
||||
|
||||
public Object nextElement() {
|
||||
m_idx++;
|
||||
if (m_idx == 0 ) {
|
||||
return new Binding(CLASSDEF, m_className, m_classContainer);
|
||||
}
|
||||
else if (m_idx == 1) {
|
||||
return new Binding(ATTRDEF, m_className, m_attrContainer);
|
||||
}
|
||||
else if (m_idx == 2) {
|
||||
return new Binding(MRULEDEF, m_className, m_matchRuleContainer);
|
||||
}
|
||||
else {
|
||||
throw new NoSuchElementException("SchemaRootEnumerator");
|
||||
}
|
||||
|
||||
}
|
||||
public Object nextElement() {
|
||||
m_idx++;
|
||||
if (m_idx == 0 ) {
|
||||
return new Binding(CLASSDEF, m_className, m_classContainer);
|
||||
}
|
||||
else if (m_idx == 1) {
|
||||
return new Binding(ATTRDEF, m_className, m_attrContainer);
|
||||
}
|
||||
else if (m_idx == 2) {
|
||||
return new Binding(MRULEDEF, m_className, m_matchRuleContainer);
|
||||
}
|
||||
else {
|
||||
throw new NoSuchElementException("SchemaRootEnumerator");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public boolean hasMore() {
|
||||
return hasMoreElements();
|
||||
}
|
||||
public boolean hasMore() {
|
||||
return hasMoreElements();
|
||||
}
|
||||
|
||||
public boolean hasMoreElements() {
|
||||
return m_idx < 2;
|
||||
}
|
||||
public boolean hasMoreElements() {
|
||||
return m_idx < 2;
|
||||
}
|
||||
|
||||
public void close() {}
|
||||
}
|
||||
public void close() {}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user