How to get Primary Group details of a user from Active Directory

Hi ,
This is Viswanath. I want to know how can we retrieve the primary group of a user (Active Directory). I have searhed the entire forum but could not get the required information.
The reference link is which i have searched is : http://forum.java.sun.com/thread.jspa?threadID=581444
I got a sample .NET project where we can retrieve the primary group information :
refer to the link : http://dunnry.com/blog/DeterminingYourPrimaryGroupInActiveDirectoryUsingNET.aspx
you can download the sample project and build that in VS.NET 2003 and see the result. Please let me know if this kind of implementation is possible in java.
Kindly help me as i have to provide a solution to my client.
Regards,
Viswanath.
Edited by: sriganesh on Jun 22, 2008 10:36 AM
can anybody please share their thoughts on the above

To connect to the Active Directory you can do something like this:
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.NamingException;
import javax.naming.directory.DirContext;
import javax.naming.directory.InitialDirContext;
public class AD
public static void main(String[] args)
Hashtable environment = new Hashtable();
//Just change your user here
String myUser = "myUser";
//Just change your user password here
String myPassword = "myUser";
//Just change your domain name here
String myDomain = "myDomain";
//Host name or IP
String myActiveDirectoryServer = "192.168.0.20";
environment.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
environment.put(Context.PROVIDER_URL, "ldap://" + myActiveDirectoryServer + ":389");
environment.put(Context.SECURITY_AUTHENTICATION, "simple");
environment.put(Context.SECURITY_PRINCIPAL, "CN=" + myUser + ",CN=Users,DC=" + myDomain + ",DC=COM");
environment.put(Context.SECURITY_CREDENTIALS, myPassword);
try
DirContext context = new InitialDirContext(environment);
System.out.println("Exit!!");
catch (NamingException e)
e.printStackTrace();
Reddy Pathepuram
Inteligic Inc

Similar Messages

  • How to get the name of the selected user in Active Directory.

    Hi,
    I have added an vbs script to the Active Directory GUI, to do some actions on a selected user.
    When I right-click on a AD user, I choose my custom option, and a vbs script starts.
    So far so good, but in the script i would like to know the account (logonname) for that user.
    I can find many examples to do that with a script and a given parameter, but the parameter is in my case, the selected user in AD.
    Who can help ?
    Luc

    You just need to take the arguments and echo out the samaccountname (or do something else with it) - 
    Set wshArgs=WScript.Arguments
    Set adsUser=GetObject(wshArgs(0))
    MsgBox adsUser.samaccountname

  • LabVIEW 8.0:: How to get the group name of a user logged to a NI Security Domain?

    Hello all,
    I am using LabVIEW 8.0 PDS.
    I created a new local domain called "MyDomain" in the "NI Domain Account Manager" . I added a new User called "MyUser" and a new group called "Maintenance". I set "MyUser" to be a member of the "Maintenance" group. Then, I configured LabVIEW to invoke the login dialog at start-up in order to log "MyUser" with the correct password.
    I would like to get the group name of the current user logged programmatically in a VI. I tried with the VI Server >> Application >> Security properties and methods and also with the properties and methods of the NI Security Class but it seems to be not so simple as I believed at start.
    I do not find any informations or KB on this (all the documents I found deal with LV DSC or TestStand).
     The final goal is to be able to manage a list of user for my application. Each user is a member of a group ("Administrator", "Operator", "Maintenance") and depending on the group, the user can or cannot access to some parts of the application.
    Thanks for your help.
    Matthieu
    Eurilogic

    Re,
    Here is a screenshot of this functions...
    If you really own LV DSC 8.2 the best thing to do is to reinstall it.
    Regards, 
    Message Edité par Richard K. le 04-02-2007 04:00 AM
    Richard Keromen
    National Instruments France
    #adMrkt{text-align: center;font-size:11px; font-weight: bold;} #adMrkt a {text-decoration: none;} #adMrkt a:hover{font-size: 9px;} #adMrkt a span{display: none;} #adMrkt a:hover span{display: block;}
    >> Découvrez, en vidéo, les innovations technologiques réalisées en éco-conception
    Attachments:
    security.jpg ‏3841 KB

  • How to get the group name of a user

    Hi,
    I am using an openldap for user authentification. How can i retreive the groups name of a user ? I read that i must use the GroupManagerControl class.
    What is the way to specify the openldap authenticator using the above class ?
    Thanks for help.

    Re,
    Here is a screenshot of this functions...
    If you really own LV DSC 8.2 the best thing to do is to reinstall it.
    Regards, 
    Message Edité par Richard K. le 04-02-2007 04:00 AM
    Richard Keromen
    National Instruments France
    #adMrkt{text-align: center;font-size:11px; font-weight: bold;} #adMrkt a {text-decoration: none;} #adMrkt a:hover{font-size: 9px;} #adMrkt a span{display: none;} #adMrkt a:hover span{display: block;}
    >> Découvrez, en vidéo, les innovations technologiques réalisées en éco-conception
    Attachments:
    security.jpg ‏3841 KB

  • How to get the real name of a user from WFSYST-AGENT

    Hi,
    I am retrieving the WFSYST-AGENT value (which correspond to the US<user_id> of the agent responsible of a task) in a container variable in my workflow.
    I would like to get the real name of the user represented by WFSYST-AGENT. How should I do that ?
    Thanks in advance for your help.
    Thibault

    Hi,
    Take the user name and write a select for database table USER_ADDR fetching fields NAME_FIRST and NAME_LAST by passing BNAME = username.
    Regards,
    Jayesh

  • Get all users from Active Directory

    Dear All,
    I would like to retreive all USERS from the AD.
    I finaly could connect to an AD server but I couldn't perform the search.
    I got a javax.naming.NamingException: [LDAP: error code 1 - 000020D6: SvcErr: DSID-03100690, problem 5012 (DIR_ERROR), data 0
    --> Does it mean that my query is incorect.
    I think I am missing something obvious. but what?
    Can somebody please help me or point me to some working code sample.
    Thanks in advance.
    Karim.
    //======== Test Code =============
            String THIS_INIT_CONT_FAC="com.sun.jndi.ldap.LdapCtxFactory";
            String THIS_PROV_URL=url;
            String THIS_SEC_AUTH="simple";
            String THIS_SEARCHBASE="CN=Users, CN=domain, CN=com";
            String THIS_ATTRS[] = {"mail"};
    try {
    String THIS_FILTER="(objectClass=user)";
    System.out.println("Testing LDAP Program");
    System.out.println("************************************************************");
    String THIS_SEC_PRIN="";
    String THIS_SEC_CRED="";
    System.out.println("Cont Fac : " + THIS_INIT_CONT_FAC);
    System.out.println("LDAP Server : " + THIS_PROV_URL);
    System.out.println("Auth Method : " + THIS_SEC_AUTH);
    System.out.println("Search Base : " + THIS_SEARCHBASE);
    System.out.println("Filter : " + THIS_FILTER);
    System.out.println("Login : " + THIS_SEC_PRIN);
    System.out.println("Credentials : " + THIS_SEC_CRED);
    System.out.println("************************************************************");
    Hashtable env=new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY, THIS_INIT_CONT_FAC);
    env.put(Context.PROVIDER_URL, THIS_PROV_URL);
    env.put(Context.SECURITY_AUTHENTICATION, THIS_SEC_AUTH);
    env.put(Context.SECURITY_PRINCIPAL, THIS_SEC_PRIN);
    env.put(Context.SECURITY_CREDENTIALS, THIS_SEC_CRED);
    DirContext ctx = new InitialDirContext(env);
    System.out.println("LDAP TEST Login Successful!");
    SearchControls constraints = new SearchControls();
    constraints.setSearchScope(SearchControls.SUBTREE_SCOPE);
    NamingEnumeration results = ctx.search(THIS_SEARCHBASE,THIS_FILTER, constraints);
    int namecount=0;
    System.out.println("LDAP TEST Results : " + results);
    System.out.println("LDAP TEST Pre-Hit ! ");
    } catch(AuthenticationException ae) {
    ae.printStackTrace();
    System.out.println("Incorrect Password or UserName");
    return false;
    } catch(Exception e) {
    e.printStackTrace();
    System.out.println("Error accessing LDAP");
    return false;
    // ============ OUTPUT =====================
    Testing LDAP Program
    Cont Fac : com.sun.jndi.ldap.LdapCtxFactory
    LDAP Server : ldap://192.168.2.3:389/
    Auth Method : simple
    Search Base : CN=Users, CN=domain, CN=com
    Filter : (objectClass=user)
    Login :
    Credentials :
    LDAP TEST Login Successful!
    javax.naming.NamingException: [LDAP: error code 1 - 000020D6: SvcErr: DSID-03100690, problem 5012 (DIR_ERROR), data 0
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    If you want to list all the users then you don't need to perform a search. Just list them.
       private void list(String contextName)
          try
             // get enumeration of NameValuePairs
                NamingEnumeration contentsEnum = ctx.list(contextName);
             while (contentsEnum.hasMore())
                System.out.println(contentsEnum.next());
          catch (NamingException e)
             System.err.println("Problem listing context contents: " + e);
       }You will want to call this using something like this:
    list("CN=Users, CN=domain, CN=com");One caveat, there is a restriction on the number of results returned so this will still throw an LDAP exception if you have a lot of users.
    Not sure how to get around that. Never needed to look. Don't expect it is hard though.

  • How to get the last value edited by users from JTable?

    Hi.
    I have a JDialog that includes an editable JTable. This table is used to set up field caption and font for a report program. I found only when cursor is moved to another cell, the value in current cell being edited will be transferred to Table Model. So if the user don�t move cursor to another cell after editing the value of a cell but click OK button directly, Table Model cannot get the last value edited by the user, I wonder if there is a way to fire JTable to transfer the value being edited to Table model.
    By the way, I found if the TableCellEditor is using JCheckBox or JComboBox instead of JTextField, there is no this problem.
    Thank you for any reply.

    I guess you can make use of the following methods on your table model to inform it make it getValueAt bcos table data has changed.
    fireTableCellUpdated
    Notifies all listeners that the value of the cell at [row, column] has been updated.
    fireTableChanged
    Forwards the given notification event to all TableModelListeners that registered themselves as listeners for this table model.
    fireTableDataChanged
    Notifies all listeners that all cell values in the table's rows may have changed. The number of rows may also have changed and the JTable should redraw the table from scratch. The structure of the table (as in the order of the columns) is assumed to be the same.
    But when to call these methods??
    -- When OK button is pressed, do this as the first thing!!
    OR
    -- Call this on every key event!!
    regds,
    CA

  • ISR FORM how to get Employee Name based on Login User From R3

    hi,,
    I am working on ISR Adobe Forms.In the form I have to display the Employee Name,according to the portal logged in user.I have written a Function Module which fetches the Employee Name, based on Employee Code(PERNR) .I will be viewing the form in portal, so the current logged in user's PERNR should be passed to  the BADI.How can I do this?
    Regards,
    Rheema Rahael.

    Hi Rheema,
    Write the code, in the initialisation method of the BADi, to fetch the personnel number for the respective sy-uname from the communications infotype.
    Hope this helps.
    - anto.
    Message was edited by:
            Antony John Isacc

  • How to get the network details in flex4.5 web application

    How to get the network details in flex 4.5 web application
    similar to the nativeinterface in air application

    checkout this document for secure web application
    http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf6167e-7fff.html    

  • How to get the input details on the output screen in T code KCR0

    Hi All,
    How to get the input details on the output screen in T code KCR0, the issue is that we need to get the input details like Company code and payment date on the output screen while executing the report painter via t code KCR0.
    I tried to chane the settings via t code KCR6 but still didn't get the required output details.
    Regards,
    Ajay

    This is the asset accounting forum.  You should post your question in the proper forum.

  • How to get GL transactions detail

    How to get GL transactions detail to insert in 3rd party applicaton.? We need Journal Entry number, date, account number, debit and credit columns. We need detail table structure.
    Thanks
    Shafiq

    Hi
    About period balance.
    To have the amount of the balance of a certain account you need to run the following query (you need to know the CODE_COMBINATION_ID of the account, the SET_OF_BOOKS_ID of the company, the PERIOD_NAME and the functional currency used)
    select nvl(sum(bal.begin_balance_dr + bal_period_net_dr - bal.begin_balance_cr - bal.period_net_cr),0)
    from gl_balances bal,
    gl_code_combinations cc
    where cc.code_combination_id = bal.code_combination_id
    and bal.actual_flag = 'A'
    and cc.code_combination_id = <your ccid>
    and bal.period_name = <your period name>
    and bal.currency_code = <your func currency>
    and bal.set_of_books_id = <your sob id)
    Hope this helps.
    Octavio.

  • How to get SharePoint Groups using Javascript in SP2013 ?

    How to get SharePoint Groups using Javascript in SP2013 , not JSOM please

    Here is the code that worked for me:
    <script type="text/javascript">
    var requestUri = _spPageContextInfo.webAbsoluteUrl + "/_api/web/sitegroups";
      var requestHeaders = { "accept" : "application/json;odata=verbose" };
      $.ajax({
        url : requestUri,
        contentType : "application/json;odata=verbose",
        headers : requestHeaders,
        success : onSuccess,
        error : onError
      function onSuccess(data, request){
    var s='';
     for (var i = 0; i < data.d.results.length; i++)
    s +=data.d.results[i].LoginName+'\n';
        alert(s);
     function onError(error) {
        alert("error");
    </script>

  • HT4859 Does anyone know how to get my Mailbox details from iCloud Back-up? I have accidentally deleted lots of emails I needed to keep. Thanks

    Does anyone know how to get my Mailbox details from ICloud Back-up?
    I deleted some emails in error and need them back.Thanks

    The iCloud backup doesn't contain email.  If you deleted the email and it isn't in your trash folder, there is no way to recover it.

  • Getting a user's primary group from Active Directory

    I'm coding a java web app that should authenticate a user to Active Directory and return his primary group.
    Using JNDI apis I realized the first part (authentication) and functions well but still having problems with the second part (getting the user's primary group).
    Is there somebody who knows/gets some codes for getting this info from Active Directory using java?
    Thanks a lot.
    Regards.
    John.

    I'm coding a java web app that should authenticate a user to Active Directory and return his primary group.
    Using JNDI apis I realized the first part (authentication) and functions well but still having problems with the second part (getting the user's primary group).
    Is there somebody who knows/gets some codes for getting this info from Active Directory using java?
    Thanks a lot.
    Regards.
    John.

  • How to get work item details programatically ?

    Hi All,
    I have a list of work items (process instances) and I want to retrieve each item details such as: attachments, notes, id, ...
    All the items are filtered and represented as Fuego.Papi.Instance:
    Fuego.Papi.Instance[] inst = busProcess.getInstancesByFilter(filter : instFilter);
    But the work item details are inherited from Fuego.Lib.ProcessInstance. So, how to get the item details from inst[] ?
    Would appreciate any help, may be Dan will have an advise ?
    Regards,
    Kim

    If you have instances returned by your filter, you could extract variable information for each instance by doing something like this:
    for each inst in getInstancesByFilter(ps, filter : instF) do
        // here's how to get the value inside a primitive instance variable
        orderAmtObj as Object = getVar(inst, var : "orderAmount")
        // here's how to get the value of attributes inside a complex BPM Object instance variable
        //    - in this case this is an "order" object with two attributes (customerName and amount)
        orderObj as Object = (getVar(inst, var : "order"))
        xmlObject = Fuego.Xml.XMLObject(createXmlTextFor(DynamicXml, object : orderObj, topLevelTag : "xsi"))
        logMessage "The value of the order object's customer name is: " +
               selectString(xmlObject, xpath : "customerName")
        logMessage "The value of the order object's order amount is: " +
               selectNumber(xmlObject, xpath : "amount")
        // here's a rather uninspired way to retrieve who the participant is that was assigned the instance
        logMessage "The participant assigned to this instance is: " + inst.participantId
    endInside the above "for" loop, you could retrieve these predefined variables (this example assumes you use "inst" in your "for" loop):
        objRet as Any
        objRet = inst.getVar(var : "PREDEFINE_ACTIVITY")
        logMessage "Activity name = " + objRet using severity = DEBUGSubstitute "PREDEFINE_ACTIVITY" in the above logic to get this information:
    PREDEFINE_PRIORITY (priority)
    PREDEFINE_ACTIVITY_DEADLINE (activity.deadline)
    PREDEFINE_CREATION_TIME (creation.time)
    PREDEFINE_PROCESS_DEADLINE (deadline)
    PREDEFINE_DESCRIPTION (description)
    PREDEFINE_PROCESS (process)
    PREDEFINE_RECEIVED_TIME (receptionTime)
    PREDEFINE_PARTICIPANT (participant)
    PREDEFINE_COPY (id.copy)
    PREDEFINE_STATUS (status)
    Similarly, you might want to try to get instance information using the Fuego.Papi.VarDefinition object a try. Never used it, but the logic might be as simple as:
        logMessage "who created? = " + inst.getVar(Fuego.Papi.VarDefinition.CREATOR_ID) using severity = DEBUG
        logMessage "does it have attachments? = " + inst.getVar(Fuego.Papi.VarDefinition.HAS_ATTACHMENTS) using severity = DEBUG   
        logMessage "does it have notes? = " + inst.getVar(Fuego.Papi.VarDefinition.hasnotes) using severity = DEBUGDan

Maybe you are looking for