You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@directory.apache.org by Merve Temizer <me...@gmail.com> on 2012/09/11 14:54:22 UTC
Empty/Null Attribute
Hello,
I have some objectClasses and dc and ou attributes and their values, in an
entry in LDAP.
I try to read ou attribute but i cant get it with below code.
I can get dc value correctly.
I know i must control if it is null, but why might "ou" be null despite of
taking place in LDAP.
NamingEnumeration answer = ctx.search(searchBaseDn, filter, ctls);
try
{
while (answer.hasMore())
{
SearchResult sr = (SearchResult) answer.next();
OrganizationPojo organizationPojo = new OrganizationPojo();
organizationPojo.setOrgDc((String)sr.getAttributes().get("dc").get());
organizationPojo.setOrgOu((String)sr.getAttributes().get("ou").get());
Re: Empty/Null Attribute
Posted by Pierre-Arnaud Marcelot <pa...@marcelot.net>.
You could also try to use our Apache LDAP API instead of JNDI.
=> http://directory.apache.org/api/downloads.html
And, in code, what does 'ctls' look like? Can you show us the definition ?
Regards,
Piere-Arnaud
On 11 sept. 2012, at 16:35, Merve Temizer <me...@gmail.com> wrote:
> According to page
>
> http://docs.oracle.com/javase/jndi/tutorial/basics/directory/getattrs.html
>
> I have tried
>
> for (NamingEnumeration ae = sr.getAttributes().getAll(); ae.hasMore();) {
> Attribute attr = (Attribute)ae.next();
> System.out.println("attribute: " + attr.getID());
> /* Print each value */
> for (NamingEnumeration e = attr.getAll(); e.hasMore();
> System.out.println("value: " + e.next()));
> }
> Output:
>
> attribute: dc
> value: is
> attribute: objectClass
> value: extensibleObject
> value: organizationalUnit
> value: top
>
> Can not see ou attribute. Sorry for simple questions but i did what tutorial tells.
>
>
> 2012/9/11 Emmanuel Lécharny <el...@gmail.com>
> Le 9/11/12 2:54 PM, Merve Temizer a écrit :
>
> Hello,
>
> I have some objectClasses and dc and ou attributes and their values, in an
> entry in LDAP.
> I try to read ou attribute but i cant get it with below code.
> I can get dc value correctly.
> I know i must control if it is null, but why might "ou" be null despite of
> taking place in LDAP.
>
> NamingEnumeration answer = ctx.search(searchBaseDn, filter, ctls);
> try
> {
> while (answer.hasMore())
> {
> SearchResult sr = (SearchResult) answer.next();
> OrganizationPojo organizationPojo = new OrganizationPojo();
> organizationPojo.setOrgDc((String)sr.getAttributes().get("dc").get());
> organizationPojo.setOrgOu((String)sr.getAttributes().get("ou").get());
>
> http://docs.oracle.com/javase/jndi/tutorial/
>
> --
> Regards,
> Cordialement,
> Emmanuel Lécharny
> www.iktek.com
>
>
Re: Empty/Null Attribute
Posted by Emmanuel Lécharny <el...@gmail.com>.
Again, I stress out that this dev list is *not* the right list.
Please use the users@directry.apache.org mailing list.
Also the user mailing list is not the right place when someone is
learning how to use JNDI. We are a few people answering question on
these mailing lists, please avoid posting questions that are not
directly related to Apache Directory Server or its subprojects.
Many thanks ...
--
Regards,
Cordialement,
Emmanuel Lécharny
www.iktek.com
Re: Empty/Null Attribute
Posted by Pierre-Arnaud Marcelot <pa...@marcelot.net>.
No pb. ;)
Think about posting to the user's mailing list next time.
These kind of threads should be located there.
Regards,
Pierre-Arnaud
On 11 sept. 2012, at 17:03, Merve Temizer <me...@gmail.com> wrote:
> Sorry :( I hope next time be more careful :(
>
> 2012/9/11 Pierre-Arnaud Marcelot <pa...@marcelot.net>
> Hum... Hum... Don't you think there's something wrong here if you want to require the 'ou' attribute on you search results ?!?
>> String[] attrIDs = { "dc", "objectClass" };
>
>
> Regards,
> Pierre-Arnaud
>
> PS: Small hints:
> - To require no user attributes at all, you can use the '1.1' shortcut as attribute id.
> - To require all user attributes, you can use the '*' shortcut as attribute id.
> - To require all operational attributes, you can use the '+' shortcut as attribute it.
>
> On 11 sept. 2012, at 16:52, Merve Temizer <me...@gmail.com> wrote:
>
>> The method:
>>
>> public static List<OrganizationPojo> getOrganizations(String searchBaseDn){
>>
>> Hashtable env = new Hashtable();
>> env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
>> env.put(Context.PROVIDER_URL, "ldap://localhost:10389");
>> env.put(Context.SECURITY_AUTHENTICATION, "simple");
>> env.put(Context.SECURITY_PRINCIPAL,"uid=admin,ou=system"); // specify the username
>> env.put(Context.SECURITY_CREDENTIALS,"secret");// specify the password
>> // TODO code application logic here
>>
>> // entry's DN
>> List<OrganizationPojo> organizationPojoList = new ArrayList<OrganizationPojo>();
>> DirContext ctx = null;
>>
>>
>> try {
>> // get a handle to an Initial DirContext
>> ctx = new InitialDirContext(env);
>> String[] attrIDs = { "dc", "objectClass" };
>>
>> SearchControls ctls = new SearchControls();
>> ctls.setReturningAttributes(attrIDs);
>>
>> String filter = "(&(dc=*) (objectClass=organizationalUnit) (ou=*))";
>>
>> NamingEnumeration answer = ctx.search(searchBaseDn, filter, ctls);
>> try
>> {
>> while (answer.hasMore())
>> {
>> SearchResult sr = (SearchResult) answer.next();
>> OrganizationPojo organizationPojo = new OrganizationPojo();
>> organizationPojo.setOrgDn((String)sr.getNameInNamespace());
>> LdapName dn = new LdapName((String)sr.getNameInNamespace());
>> LdapName rdn = new LdapName((String)sr.getName());
>> for(int i=0;(i<rdn.size() && dn.size()>0);i++){
>> dn.remove(dn.size()-1);
>> }
>> for (NamingEnumeration ae = sr.getAttributes().getAll(); ae.hasMore();) {
>> Attribute attr = (Attribute)ae.next();
>> System.out.println("attribute: " + attr.getID());
>> /* Print each value */
>> for (NamingEnumeration e = attr.getAll(); e.hasMore();
>> System.out.println("value: " + e.next()));
>> }
>> organizationPojo.setOrgParentDn(dn.toString());
>> organizationPojo.setOrgDc((String)sr.getAttributes().get("dc").get());
>> organizationPojo.setOrgOu((String)sr.getAttributes().get("ou").get());
>>
>> organizationPojo.setOrgName((String)sr.getAttributes().get("orgName").get());
>> organizationPojo.setOrgPhone((String)sr.getAttributes().get("orgPhone").get());
>> organizationPojo.setOrgFax((String)sr.getAttributes().get("orgFax").get());
>> organizationPojo.setOrgContactName((String)sr.getAttributes().get("orgContactName").get());
>> organizationPojo.setOrgCountry((String)sr.getAttributes().get("orgCountry").get());
>> organizationPojo.setOrgCity((String)sr.getAttributes().get("orgCity").get());
>> organizationPojo.setOrgAddress((String)sr.getAttributes().get("orgAddress").get());
>>
>>
>> organizationPojoList.add(organizationPojo);
>> }
>> }
>> catch (NamingException e)
>> {
>> if (e instanceof javax.naming.PartialResultException)
>> {
>> // ignore
>> }
>> else
>> {
>> e.printStackTrace();
>> }
>> }
>> ctx.close();
>>
>>
>>
>> } catch (Exception e) {
>> System.err.println("Error: Search organizations:" + e);
>> }
>> return organizationPojoList;
>> }
>>
>>
>> 2012/9/11 Merve Temizer <me...@gmail.com>
>> According to page
>>
>> http://docs.oracle.com/javase/jndi/tutorial/basics/directory/getattrs.html
>>
>> I have tried
>>
>> for (NamingEnumeration ae = sr.getAttributes().getAll(); ae.hasMore();) {
>> Attribute attr = (Attribute)ae.next();
>> System.out.println("attribute: " + attr.getID());
>> /* Print each value */
>> for (NamingEnumeration e = attr.getAll(); e.hasMore();
>> System.out.println("value: " + e.next()));
>> }
>> Output:
>>
>> attribute: dc
>> value: is
>> attribute: objectClass
>> value: extensibleObject
>> value: organizationalUnit
>> value: top
>>
>> Can not see ou attribute. Sorry for simple questions but i did what tutorial tells.
>>
>>
>> 2012/9/11 Emmanuel Lécharny <el...@gmail.com>
>> Le 9/11/12 2:54 PM, Merve Temizer a écrit :
>>
>> Hello,
>>
>> I have some objectClasses and dc and ou attributes and their values, in an
>> entry in LDAP.
>> I try to read ou attribute but i cant get it with below code.
>> I can get dc value correctly.
>> I know i must control if it is null, but why might "ou" be null despite of
>> taking place in LDAP.
>>
>> NamingEnumeration answer = ctx.search(searchBaseDn, filter, ctls);
>> try
>> {
>> while (answer.hasMore())
>> {
>> SearchResult sr = (SearchResult) answer.next();
>> OrganizationPojo organizationPojo = new OrganizationPojo();
>> organizationPojo.setOrgDc((String)sr.getAttributes().get("dc").get());
>> organizationPojo.setOrgOu((String)sr.getAttributes().get("ou").get());
>>
>> http://docs.oracle.com/javase/jndi/tutorial/
>>
>> --
>> Regards,
>> Cordialement,
>> Emmanuel Lécharny
>> www.iktek.com
>>
>>
>>
>
>
Re: Empty/Null Attribute
Posted by Merve Temizer <me...@gmail.com>.
Sorry :( I hope next time be more careful :(
2012/9/11 Pierre-Arnaud Marcelot <pa...@marcelot.net>
> Hum... Hum... Don't you think there's something wrong here if you want to
> require the 'ou' attribute on you search results ?!?
>
> String[] attrIDs = { "dc", "objectClass" };
>
>
> Regards,
> Pierre-Arnaud
>
> PS: Small hints:
> - To require no user attributes at all, you can use the '1.1' shortcut as
> attribute id.
> - To require all user attributes, you can use the '*' shortcut as
> attribute id.
> - To require all operational attributes, you can use the '+' shortcut as
> attribute it.
>
> On 11 sept. 2012, at 16:52, Merve Temizer <me...@gmail.com> wrote:
>
> The method:
>
> public static List<OrganizationPojo> getOrganizations(String searchBaseDn){
> Hashtable env = new Hashtable();
> env.put(Context.INITIAL_CONTEXT_FACTORY,
> "com.sun.jndi.ldap.LdapCtxFactory");
> env.put(Context.PROVIDER_URL, "ldap://localhost:10389");
> env.put(Context.SECURITY_AUTHENTICATION, "simple");
> env.put(Context.SECURITY_PRINCIPAL,"uid=admin,ou=system"); //
> specify the username
> env.put(Context.SECURITY_CREDENTIALS,"secret");// specify the
> password
> // TODO code application logic here
>
> // entry's DN
> List<OrganizationPojo> organizationPojoList = new
> ArrayList<OrganizationPojo>();
> DirContext ctx = null;
>
> try {
> // get a handle to an Initial DirContext
> ctx = new InitialDirContext(env);
> String[] attrIDs = { "dc", "objectClass" };
>
> SearchControls ctls = new SearchControls();
> ctls.setReturningAttributes(attrIDs);
>
> String filter = "(&(dc=*) (objectClass=organizationalUnit) (ou=*))";
>
> NamingEnumeration answer = ctx.search(searchBaseDn, filter, ctls);
> try
> {
> while (answer.hasMore())
> {
> SearchResult sr = (SearchResult) answer.next();
> OrganizationPojo organizationPojo = new OrganizationPojo();
> organizationPojo.setOrgDn((String)sr.getNameInNamespace());
> LdapName dn = new LdapName((String)sr.getNameInNamespace());
> LdapName rdn = new LdapName((String)sr.getName());
> for(int i=0;(i<rdn.size() && dn.size()>0);i++){
> dn.remove(dn.size()-1);
> }
> for (NamingEnumeration ae = sr.getAttributes().getAll();
> ae.hasMore();) {
> Attribute attr = (Attribute)ae.next();
> System.out.println("attribute: " + attr.getID());
> /* Print each value */
> for (NamingEnumeration e = attr.getAll(); e.hasMore();
> System.out.println("value: " + e.next()));
> }
> organizationPojo.setOrgParentDn(dn.toString());
>
> organizationPojo.setOrgDc((String)sr.getAttributes().get("dc").get());
>
> organizationPojo.setOrgOu((String)sr.getAttributes().get("ou").get());
>
>
> organizationPojo.setOrgName((String)sr.getAttributes().get("orgName").get());
>
> organizationPojo.setOrgPhone((String)sr.getAttributes().get("orgPhone").get());
>
> organizationPojo.setOrgFax((String)sr.getAttributes().get("orgFax").get());
>
> organizationPojo.setOrgContactName((String)sr.getAttributes().get("orgContactName").get());
>
> organizationPojo.setOrgCountry((String)sr.getAttributes().get("orgCountry").get());
>
> organizationPojo.setOrgCity((String)sr.getAttributes().get("orgCity").get());
>
> organizationPojo.setOrgAddress((String)sr.getAttributes().get("orgAddress").get());
>
>
> organizationPojoList.add(organizationPojo);
> }
> }
> catch (NamingException e)
> {
> if (e instanceof javax.naming.PartialResultException)
> {
> // ignore
> }
> else
> {
> e.printStackTrace();
> }
> }
> ctx.close();
>
>
> } catch (Exception e) {
> System.err.println("Error: Search organizations:" + e);
> }
> return organizationPojoList;
> }
>
> 2012/9/11 Merve Temizer <me...@gmail.com>
>
>> According to page
>>
>> http://docs.oracle.com/javase/jndi/tutorial/basics/directory/getattrs.html
>>
>> I have tried
>>
>> for (NamingEnumeration ae = sr.getAttributes().getAll(); ae.hasMore();) {
>> Attribute attr = (Attribute)ae.next();
>> System.out.println("attribute: " + attr.getID());
>> /* Print each value */
>> for (NamingEnumeration e = attr.getAll(); e.hasMore();
>> System.out.println("value: " + e.next()));
>> }
>> Output:
>>
>> attribute: dc
>> value: is
>> attribute: objectClass
>> value: extensibleObject
>> value: organizationalUnit
>> value: top
>>
>> Can not see ou attribute. Sorry for simple questions but i did what
>> tutorial tells.
>>
>>
>> 2012/9/11 Emmanuel Lécharny <el...@gmail.com>
>>
>>> Le 9/11/12 2:54 PM, Merve Temizer a écrit :
>>>
>>> Hello,
>>>>
>>>> I have some objectClasses and dc and ou attributes and their values, in
>>>> an
>>>> entry in LDAP.
>>>> I try to read ou attribute but i cant get it with below code.
>>>> I can get dc value correctly.
>>>> I know i must control if it is null, but why might "ou" be null despite
>>>> of
>>>> taking place in LDAP.
>>>>
>>>> NamingEnumeration answer = ctx.search(searchBaseDn, filter, ctls);
>>>> try
>>>> {
>>>> while (answer.hasMore())
>>>> {
>>>> SearchResult sr = (SearchResult) answer.next();
>>>> OrganizationPojo organizationPojo = new OrganizationPojo();
>>>> organizationPojo.setOrgDc((**String)sr.getAttributes().get(**
>>>> "dc").get());
>>>> organizationPojo.setOrgOu((**String)sr.getAttributes().get(**
>>>> "ou").get());
>>>>
>>>> http://docs.oracle.com/javase/**jndi/tutorial/<http://docs.oracle.com/javase/jndi/tutorial/>
>>>
>>> --
>>> Regards,
>>> Cordialement,
>>> Emmanuel Lécharny
>>> www.iktek.com
>>>
>>>
>>
>
>
Re: Empty/Null Attribute
Posted by Pierre-Arnaud Marcelot <pa...@marcelot.net>.
Hum... Hum... Don't you think there's something wrong here if you want to require the 'ou' attribute on you search results ?!?
> String[] attrIDs = { "dc", "objectClass" };
Regards,
Pierre-Arnaud
PS: Small hints:
- To require no user attributes at all, you can use the '1.1' shortcut as attribute id.
- To require all user attributes, you can use the '*' shortcut as attribute id.
- To require all operational attributes, you can use the '+' shortcut as attribute it.
On 11 sept. 2012, at 16:52, Merve Temizer <me...@gmail.com> wrote:
> The method:
>
> public static List<OrganizationPojo> getOrganizations(String searchBaseDn){
>
> Hashtable env = new Hashtable();
> env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
> env.put(Context.PROVIDER_URL, "ldap://localhost:10389");
> env.put(Context.SECURITY_AUTHENTICATION, "simple");
> env.put(Context.SECURITY_PRINCIPAL,"uid=admin,ou=system"); // specify the username
> env.put(Context.SECURITY_CREDENTIALS,"secret");// specify the password
> // TODO code application logic here
>
> // entry's DN
> List<OrganizationPojo> organizationPojoList = new ArrayList<OrganizationPojo>();
> DirContext ctx = null;
>
>
> try {
> // get a handle to an Initial DirContext
> ctx = new InitialDirContext(env);
> String[] attrIDs = { "dc", "objectClass" };
>
> SearchControls ctls = new SearchControls();
> ctls.setReturningAttributes(attrIDs);
>
> String filter = "(&(dc=*) (objectClass=organizationalUnit) (ou=*))";
>
> NamingEnumeration answer = ctx.search(searchBaseDn, filter, ctls);
> try
> {
> while (answer.hasMore())
> {
> SearchResult sr = (SearchResult) answer.next();
> OrganizationPojo organizationPojo = new OrganizationPojo();
> organizationPojo.setOrgDn((String)sr.getNameInNamespace());
> LdapName dn = new LdapName((String)sr.getNameInNamespace());
> LdapName rdn = new LdapName((String)sr.getName());
> for(int i=0;(i<rdn.size() && dn.size()>0);i++){
> dn.remove(dn.size()-1);
> }
> for (NamingEnumeration ae = sr.getAttributes().getAll(); ae.hasMore();) {
> Attribute attr = (Attribute)ae.next();
> System.out.println("attribute: " + attr.getID());
> /* Print each value */
> for (NamingEnumeration e = attr.getAll(); e.hasMore();
> System.out.println("value: " + e.next()));
> }
> organizationPojo.setOrgParentDn(dn.toString());
> organizationPojo.setOrgDc((String)sr.getAttributes().get("dc").get());
> organizationPojo.setOrgOu((String)sr.getAttributes().get("ou").get());
>
> organizationPojo.setOrgName((String)sr.getAttributes().get("orgName").get());
> organizationPojo.setOrgPhone((String)sr.getAttributes().get("orgPhone").get());
> organizationPojo.setOrgFax((String)sr.getAttributes().get("orgFax").get());
> organizationPojo.setOrgContactName((String)sr.getAttributes().get("orgContactName").get());
> organizationPojo.setOrgCountry((String)sr.getAttributes().get("orgCountry").get());
> organizationPojo.setOrgCity((String)sr.getAttributes().get("orgCity").get());
> organizationPojo.setOrgAddress((String)sr.getAttributes().get("orgAddress").get());
>
>
> organizationPojoList.add(organizationPojo);
> }
> }
> catch (NamingException e)
> {
> if (e instanceof javax.naming.PartialResultException)
> {
> // ignore
> }
> else
> {
> e.printStackTrace();
> }
> }
> ctx.close();
>
>
>
> } catch (Exception e) {
> System.err.println("Error: Search organizations:" + e);
> }
> return organizationPojoList;
> }
>
>
> 2012/9/11 Merve Temizer <me...@gmail.com>
> According to page
>
> http://docs.oracle.com/javase/jndi/tutorial/basics/directory/getattrs.html
>
> I have tried
>
> for (NamingEnumeration ae = sr.getAttributes().getAll(); ae.hasMore();) {
> Attribute attr = (Attribute)ae.next();
> System.out.println("attribute: " + attr.getID());
> /* Print each value */
> for (NamingEnumeration e = attr.getAll(); e.hasMore();
> System.out.println("value: " + e.next()));
> }
> Output:
>
> attribute: dc
> value: is
> attribute: objectClass
> value: extensibleObject
> value: organizationalUnit
> value: top
>
> Can not see ou attribute. Sorry for simple questions but i did what tutorial tells.
>
>
> 2012/9/11 Emmanuel Lécharny <el...@gmail.com>
> Le 9/11/12 2:54 PM, Merve Temizer a écrit :
>
> Hello,
>
> I have some objectClasses and dc and ou attributes and their values, in an
> entry in LDAP.
> I try to read ou attribute but i cant get it with below code.
> I can get dc value correctly.
> I know i must control if it is null, but why might "ou" be null despite of
> taking place in LDAP.
>
> NamingEnumeration answer = ctx.search(searchBaseDn, filter, ctls);
> try
> {
> while (answer.hasMore())
> {
> SearchResult sr = (SearchResult) answer.next();
> OrganizationPojo organizationPojo = new OrganizationPojo();
> organizationPojo.setOrgDc((String)sr.getAttributes().get("dc").get());
> organizationPojo.setOrgOu((String)sr.getAttributes().get("ou").get());
>
> http://docs.oracle.com/javase/jndi/tutorial/
>
> --
> Regards,
> Cordialement,
> Emmanuel Lécharny
> www.iktek.com
>
>
>
Re: Empty/Null Attribute
Posted by Merve Temizer <me...@gmail.com>.
The method:
public static List<OrganizationPojo> getOrganizations(String searchBaseDn){
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://localhost:10389");
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL,"uid=admin,ou=system"); //
specify the username
env.put(Context.SECURITY_CREDENTIALS,"secret");// specify the
password
// TODO code application logic here
// entry's DN
List<OrganizationPojo> organizationPojoList = new
ArrayList<OrganizationPojo>();
DirContext ctx = null;
try {
// get a handle to an Initial DirContext
ctx = new InitialDirContext(env);
String[] attrIDs = { "dc", "objectClass" };
SearchControls ctls = new SearchControls();
ctls.setReturningAttributes(attrIDs);
String filter = "(&(dc=*) (objectClass=organizationalUnit) (ou=*))";
NamingEnumeration answer = ctx.search(searchBaseDn, filter, ctls);
try
{
while (answer.hasMore())
{
SearchResult sr = (SearchResult) answer.next();
OrganizationPojo organizationPojo = new OrganizationPojo();
organizationPojo.setOrgDn((String)sr.getNameInNamespace());
LdapName dn = new LdapName((String)sr.getNameInNamespace());
LdapName rdn = new LdapName((String)sr.getName());
for(int i=0;(i<rdn.size() && dn.size()>0);i++){
dn.remove(dn.size()-1);
}
for (NamingEnumeration ae = sr.getAttributes().getAll();
ae.hasMore();) {
Attribute attr = (Attribute)ae.next();
System.out.println("attribute: " + attr.getID());
/* Print each value */
for (NamingEnumeration e = attr.getAll(); e.hasMore();
System.out.println("value: " + e.next()));
}
organizationPojo.setOrgParentDn(dn.toString());
organizationPojo.setOrgDc((String)sr.getAttributes().get("dc").get());
organizationPojo.setOrgOu((String)sr.getAttributes().get("ou").get());
organizationPojo.setOrgName((String)sr.getAttributes().get("orgName").get());
organizationPojo.setOrgPhone((String)sr.getAttributes().get("orgPhone").get());
organizationPojo.setOrgFax((String)sr.getAttributes().get("orgFax").get());
organizationPojo.setOrgContactName((String)sr.getAttributes().get("orgContactName").get());
organizationPojo.setOrgCountry((String)sr.getAttributes().get("orgCountry").get());
organizationPojo.setOrgCity((String)sr.getAttributes().get("orgCity").get());
organizationPojo.setOrgAddress((String)sr.getAttributes().get("orgAddress").get());
organizationPojoList.add(organizationPojo);
}
}
catch (NamingException e)
{
if (e instanceof javax.naming.PartialResultException)
{
// ignore
}
else
{
e.printStackTrace();
}
}
ctx.close();
} catch (Exception e) {
System.err.println("Error: Search organizations:" + e);
}
return organizationPojoList;
}
2012/9/11 Merve Temizer <me...@gmail.com>
> According to page
>
> http://docs.oracle.com/javase/jndi/tutorial/basics/directory/getattrs.html
>
> I have tried
>
> for (NamingEnumeration ae = sr.getAttributes().getAll(); ae.hasMore();) {
> Attribute attr = (Attribute)ae.next();
> System.out.println("attribute: " + attr.getID());
> /* Print each value */
> for (NamingEnumeration e = attr.getAll(); e.hasMore();
> System.out.println("value: " + e.next()));
> }
> Output:
>
> attribute: dc
> value: is
> attribute: objectClass
> value: extensibleObject
> value: organizationalUnit
> value: top
>
> Can not see ou attribute. Sorry for simple questions but i did what
> tutorial tells.
>
>
> 2012/9/11 Emmanuel Lécharny <el...@gmail.com>
>
>> Le 9/11/12 2:54 PM, Merve Temizer a écrit :
>>
>> Hello,
>>>
>>> I have some objectClasses and dc and ou attributes and their values, in
>>> an
>>> entry in LDAP.
>>> I try to read ou attribute but i cant get it with below code.
>>> I can get dc value correctly.
>>> I know i must control if it is null, but why might "ou" be null despite
>>> of
>>> taking place in LDAP.
>>>
>>> NamingEnumeration answer = ctx.search(searchBaseDn, filter, ctls);
>>> try
>>> {
>>> while (answer.hasMore())
>>> {
>>> SearchResult sr = (SearchResult) answer.next();
>>> OrganizationPojo organizationPojo = new OrganizationPojo();
>>> organizationPojo.setOrgDc((**String)sr.getAttributes().get(**
>>> "dc").get());
>>> organizationPojo.setOrgOu((**String)sr.getAttributes().get(**
>>> "ou").get());
>>>
>>> http://docs.oracle.com/javase/**jndi/tutorial/<http://docs.oracle.com/javase/jndi/tutorial/>
>>
>> --
>> Regards,
>> Cordialement,
>> Emmanuel Lécharny
>> www.iktek.com
>>
>>
>
Re: Empty/Null Attribute
Posted by Merve Temizer <me...@gmail.com>.
According to page
http://docs.oracle.com/javase/jndi/tutorial/basics/directory/getattrs.html
I have tried
for (NamingEnumeration ae = sr.getAttributes().getAll(); ae.hasMore();) {
Attribute attr = (Attribute)ae.next();
System.out.println("attribute: " + attr.getID());
/* Print each value */
for (NamingEnumeration e = attr.getAll(); e.hasMore();
System.out.println("value: " + e.next()));
}
Output:
attribute: dc
value: is
attribute: objectClass
value: extensibleObject
value: organizationalUnit
value: top
Can not see ou attribute. Sorry for simple questions but i did what
tutorial tells.
2012/9/11 Emmanuel Lécharny <el...@gmail.com>
> Le 9/11/12 2:54 PM, Merve Temizer a écrit :
>
> Hello,
>>
>> I have some objectClasses and dc and ou attributes and their values, in an
>> entry in LDAP.
>> I try to read ou attribute but i cant get it with below code.
>> I can get dc value correctly.
>> I know i must control if it is null, but why might "ou" be null despite of
>> taking place in LDAP.
>>
>> NamingEnumeration answer = ctx.search(searchBaseDn, filter, ctls);
>> try
>> {
>> while (answer.hasMore())
>> {
>> SearchResult sr = (SearchResult) answer.next();
>> OrganizationPojo organizationPojo = new OrganizationPojo();
>> organizationPojo.setOrgDc((**String)sr.getAttributes().get(**
>> "dc").get());
>> organizationPojo.setOrgOu((**String)sr.getAttributes().get(**
>> "ou").get());
>>
>> http://docs.oracle.com/javase/**jndi/tutorial/<http://docs.oracle.com/javase/jndi/tutorial/>
>
> --
> Regards,
> Cordialement,
> Emmanuel Lécharny
> www.iktek.com
>
>
Re: Empty/Null Attribute
Posted by Emmanuel Lécharny <el...@gmail.com>.
Le 9/11/12 2:54 PM, Merve Temizer a écrit :
> Hello,
>
> I have some objectClasses and dc and ou attributes and their values, in an
> entry in LDAP.
> I try to read ou attribute but i cant get it with below code.
> I can get dc value correctly.
> I know i must control if it is null, but why might "ou" be null despite of
> taking place in LDAP.
>
> NamingEnumeration answer = ctx.search(searchBaseDn, filter, ctls);
> try
> {
> while (answer.hasMore())
> {
> SearchResult sr = (SearchResult) answer.next();
> OrganizationPojo organizationPojo = new OrganizationPojo();
> organizationPojo.setOrgDc((String)sr.getAttributes().get("dc").get());
> organizationPojo.setOrgOu((String)sr.getAttributes().get("ou").get());
>
http://docs.oracle.com/javase/jndi/tutorial/
--
Regards,
Cordialement,
Emmanuel Lécharny
www.iktek.com