Boa tarde a todos, sou newbie em java to aprendendo agora Flex + Java, bem vamos ao que interessa eu criei essa function
Ela funciona blz se eu for listar ela em um grid no Flex, mas eu queria saber como executa ela direto no java e pegar os dados dos campos no java mesmo.
public static List DadosUsuario(String LDAP_User) throws Exception
{
DirContext Context = null;
String Usuario = "user";
String Senha = "pass";
String entryDN = "DC=domain,DC=empresa,DC=com,DC=br";
String DOMINIO = "DOMAIN";
String HOST = "DOMAIN";
String PORTA = "389";
String lUrl = "LDAP://" + HOST + ":" + PORTA;
String lDn = Usuario + "@" + DOMINIO;
String Teste = "";
List listar = new ArrayList();
Hashtable lMapDadosUsuario = new Hashtable();
lMapDadosUsuario.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
lMapDadosUsuario.put(Context.SECURITY_AUTHENTICATION, "simple");
lMapDadosUsuario.put(Context.REFERRAL, "follow");
lMapDadosUsuario.put(Context.PROVIDER_URL, lUrl);
lMapDadosUsuario.put(Context.SECURITY_PRINCIPAL, lDn);
lMapDadosUsuario.put(Context.SECURITY_CREDENTIALS, Senha);
lMapDadosUsuario.put("java.naming.ldap.attributes.binary", "objectSid");
try
{
DirContext lAutenticacaoContexto = new InitialDirContext(lMapDadosUsuario);
NamingEnumeration results = null;
SearchControls search = new SearchControls();
search.setSearchScope(SearchControls.SUBTREE_SCOPE);
results = lAutenticacaoContexto.search(entryDN, "(&(objectClass=user)(sAMAccountName="+LDAP_User+"))", search);
while (results.hasMore())
{
LDAP_ActiveDirectory_VO registro = new LDAP_ActiveDirectory_VO();
SearchResult searchResult = (SearchResult) results.next();
Attributes attributes = searchResult.getAttributes();
registro.setdisplayName((String)attributes.get("displayName").get());
registro.setsAMAccountName((String)attributes.get("sAMAccountName").get());
registro.setmail((String)attributes.get("mail").get());
registro.setobjectSid(getSIDAsString((byte[]) attributes.get("objectSid").get()));
listar.add(registro);
}
lAutenticacaoContexto.close();
}
catch (Exception ldap_Excecao)
{
ldap_Excecao.printStackTrace();
throw ldap_Excecao;
}
return listar;
}
// Funcao retornar SID do usuario.
public static String getSIDAsString(byte[] SID)
{
// Add the 'S' prefix
StringBuilder strSID = new StringBuilder("S-");
// bytes[0] : in the array is the version (must be 1 but might
// change in the future)
strSID.append(SID[0]).append('-');
// bytes[2..7] : the Authority
StringBuilder tmpBuff = new StringBuilder();
for (int t=2; t<=7; t++) {
String hexString = Integer.toHexString(SID[t] & 0xFF);
tmpBuff.append(hexString);
}
strSID.append(Long.parseLong(tmpBuff.toString(),16));
// bytes[1] : the sub authorities count
int count = SID[1];
// bytes[8..end] : the sub authorities (these are Integers - notice
// the endian)
for (int i = 0; i < count; i++)
{
int currSubAuthOffset = i*4;
tmpBuff.setLength(0);
tmpBuff.append(String.format("%02X%02X%02X%02X",
(SID[11 + currSubAuthOffset]& 0xFF),
(SID[10 + currSubAuthOffset]& 0xFF),
(SID[9 + currSubAuthOffset]& 0xFF),
(SID[8 + currSubAuthOffset]& 0xFF)));
strSID.append('-').append(Long.parseLong(tmpBuff.toString(), 16));
}
// That's it - we have the SID
return strSID.toString();
}