NaNash
NaNash

Reputation: 473

Search for users by Forgerock ClientSDK tools

All. I'm trying to search for the users using ClientSDK tools of Forgerock OpenAM-12.0.0 by sunIdentityServerPPCommonNameSN. Look my code. I found out that I can search the users by AMIdentityRepository.searchIdentities of the filter argument. However, I don't find out the format. Please give me your help. Regard.

protected void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
                // TODO Auto-generated method stub
                try {
                        AuthContext ac = new AuthContext("/");
                AuthContext.IndexType indexType =
AuthContext.IndexType.MODULE_INSTANCE;
                String indexName = "DataStore";

                ac.login(indexType, indexName);

                Callback[] callback = ac.getRequirements();

                for (int i =0 ; i< callback.length ; i++) {
                    if (callback[i] instanceof NameCallback) {
                        NameCallback name = (NameCallback) callback[i];
                        name.setName("amAdmin");
                    } else if (callback[i] instanceof PasswordCallback) {
                        PasswordCallback pass = (PasswordCallback) callback[i];
                        String password = "adAdmin00";
                        pass.setPassword(password.toCharArray());
                    }

                }

                ac.submitRequirements(callback);

                        if(ac.getStatus() == AuthContext.Status.SUCCESS){
                                SSOToken token = ac.getSSOToken();
                                AMIdentityRepository amIr = new AMIdentityRepository(token, "/");

                                // I want to search for the users by sunIdentityServerPPCommonNameSN;
                                String filter = "sunIdentityServerPPCommonNameSN=*";
                IdSearchResults isr = amIr.searchIdentities(IdType.USER,
filter,
                        new IdSearchControl());
                Set<AMIdentity> results = isr.getSearchResults();

                if ((results != null) && !results.isEmpty()) {
                    IdSearchResults specialUsersResults =
                            amIr.getSpecialIdentities(IdType.USER);

results.removeAll(specialUsersResults.getSearchResults());

                    for (Iterator<AMIdentity> i = results.iterator();
i.hasNext(); ) {
                        AMIdentity amid = i.next();
                        System.out.println("dn: "+ amid.getDN());
                        System.out.println("realm: "+ amid.getRealm());
                        System.out.println("uid: "+ amid.getUniversalId());
                        System.out.println("type: "+ amid.getType());

                    }
                }
                        }
                } catch (AuthLoginException e) {
                        e.printStackTrace();
                } catch (L10NMessageImpl e) {
                        e.printStackTrace();
                } catch (IdRepoException e) {
                        e.printStackTrace();
                }
        }

Upvotes: 2

Views: 395

Answers (1)

Warren Strange
Warren Strange

Reputation: 785

You are strongly encouraged to use the ForgeRock REST APIs in preference to the Java SDK.

Have a look at the OpenAM developers guide http://openam.forgerock.org/doc/webhelp/dev-guide/rest-api-query-identity.html

The best alternative is to query the data store directly. For example, if you are using OpenDJ you could use the OpenDJ LDAP SDK, or the OpenDJ REST interface.

Upvotes: 1

Related Questions