Page 1 of 1

javac : cannot find symbol , PrincipalAdapter

PostPosted:Fri Jul 25, 2008 7:10 am
by skowit
Hello.
Now I used OpenKM login with LDAP ,I need to use User&group List (Full LDAP Integration).
I tried to create a new java file,It\'s implements PrincipalAdapter class.
My new java file , In getUsers and getRoles functions connect TO LDAP instead from file.
when i compiled java file. found the error this message :

UsersRolesPrincipalAdapterPKG.java:14: cannot find symbol
symbol: class PrincipalAdapter
public class UsersRolesPrincipalAdapterPKG implements PrincipalAdapter

How to debug this error,
thank you for the help

Ps, I\'am not good at english

Re:javac : cannot find symbol , PrincipalAdapter

PostPosted:Mon Jul 28, 2008 7:16 am
by pavila
Post the source code so I can help you.

Re:javac : cannot find symbol , PrincipalAdapter

PostPosted:Tue Jul 29, 2008 4:45 am
by skowit
My Source code..
Code: Select all
package es.git.openkm.core;

import java.io.*;

import java.util.*;
import javax.naming.*;
import javax.naming.Context;
import javax.naming.directory.*;
import javax.naming.NamingException;
import java.util.Collection;


import org.slf4j.Logger;

import org.slf4j.LoggerFactory;

public class UsersRolesPrincipalAdapterPKG implements PrincipalAdapter
{
  private static Logger log = LoggerFactory.getLogger(UsersRolesPrincipalAdapterPKG.class);


    public Collection getUsers() throws PrincipalAdapterException
    { 
      log.debug(\"getUsers()\");
      Hashtable env = new Hashtable();
      env.put(Context.INITIAL_CONTEXT_FACTORY,
         \"com.sun.jndi.ldap.LdapCtxFactory\");
      env.put(Context.PROVIDER_URL,
         \"ldap://xxx.xxx.xxx.xxx:389\");
      env.put(Context.SECURITY_PRINCIPAL, \"cn=Manager,dc=example,dc=com\");
      env.put(Context.SECURITY_CREDENTIALS, \"mypassword\");

      DirContext ctx;
      try {
         ctx = new InitialDirContext(env);
      } catch (NamingException e) {
         throw new RuntimeException(e);
      }

      LinkedList list = new LinkedList();
      NamingEnumeration results = null;
      try {
         SearchControls controls =
            new SearchControls();
         controls.setSearchScope(
            SearchControls.SUBTREE_SCOPE);
         results = ctx.search(
            \"ou=employee,dc=example,dc=com\", \"(objectclass=person)\", controls);

         while (results.hasMore()) {
            SearchResult searchResult =
               (SearchResult) results.next();
            Attributes attributes =
               searchResult.getAttributes();
            Attribute attr = attributes.get(\"uid\");
            String uid = (String) attr.get();
            list.add(uid);
         }
      } catch (NameNotFoundException e) {
         // The base context was not found.
         // Just clean up and exit.
      } catch (NamingException e) {
         throw new RuntimeException(e);
      } finally {
         if (results != null) {
            try {
               results.close();
            } catch (Exception e) {
               // Never mind this.
            }
         }
         if (ctx != null) {
            try {
               ctx.close();
            } catch (Exception e) {
               // Never mind this.
            }
         }
      }
      log.debug(\"getUsers: \"+list);	
      return list;
   }

    public Collection getRoles() throws PrincipalAdapterException 
    { 
      log.debug(\"getRoles()\");
      Hashtable env = new Hashtable();
      env.put(Context.INITIAL_CONTEXT_FACTORY,
         \"com.sun.jndi.ldap.LdapCtxFactory\");
      env.put(Context.PROVIDER_URL,
         \"ldap://xxx.xxx.xxx.xxx:389\");
      env.put(Context.SECURITY_PRINCIPAL, \"cn=Manager,dc=example,dc=com\");
      env.put(Context.SECURITY_CREDENTIALS, \"mypassword\");

      DirContext ctx;
      try {
         ctx = new InitialDirContext(env);
      } catch (NamingException e) {
         throw new RuntimeException(e);
      }

      LinkedList list = new LinkedList();
      NamingEnumeration results = null;
      try {
         SearchControls controls =
            new SearchControls();
         controls.setSearchScope(
            SearchControls.SUBTREE_SCOPE);
         results = ctx.search(
            \"ou=roles,dc=example,dc=com\", \"(objectclass=group)\", controls);

         while (results.hasMore()) {
            SearchResult searchResult =
               (SearchResult) results.next();
            Attributes attributes =
               searchResult.getAttributes();
            Attribute attr = attributes.get(\"cn\");
            String cn = (String) attr.get();
            list.add(cn);
         }
      } catch (NameNotFoundException e) {
         // The base context was not found.
         // Just clean up and exit.
      } catch (NamingException e) {
         throw new RuntimeException(e);
      } finally {
         if (results != null) {
            try {
               results.close();
            } catch (Exception e) {
               // Never mind this.
            }
         }
         if (ctx != null) {
            try {
               ctx.close();
            } catch (Exception e) {
               // Never mind this.
            }
         }
      }
      log.debug(\"getRoles: \"+list);
      return list;
   }
}

Re:javac : cannot find symbol , PrincipalAdapter

PostPosted:Tue Jul 29, 2008 6:03 am
by pavila
Which IDE do you use for java develop?

Re:javac : cannot find symbol , PrincipalAdapter

PostPosted:Thu Jul 31, 2008 5:33 am
by jllort
You\'ve missed some imports ?

Because if your class is on package es.git.openkm.core; ( file writen ) then you need some imports

import es.git.openkm.core.principal.PrincipalAdapter;
import es.git.openkm.core.principal.PrincipalAdapterException;

and you must implement the method getMails

public Collection<String> getMails(Collection<String> users)
throws PrincipalAdapterException {
// TODO Auto-generated method stub
return null;
}

Without it your code can compile correctly.

Have you take a look about actual developer guide, if not look it please, because I think it\'s not possible jboss-ide ( eclipse ) don\'t detects problems.