test_class.file: authentication/identity-store/identity-store-readonly/src/test/java/javax/security/identitystore/persistence/LdapIdentityStoreTest.java
test_class.identifier: LdapIdentityStoreTest
test_case.body: @Test
      public void callerGroups() throws IOException {
  
          // Test with locally installed LDAP
  
          // Set up the environment for creating the initial context
          Hashtable<String, Object> env = new Hashtable();
          env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
          env.put(Context.PROVIDER_URL, "ldap://localhost:7001");
  
          env.put(Context.SECURITY_AUTHENTICATION, "simple");
          env.put(Context.SECURITY_PRINCIPAL, "cn=Admin");
          env.put(Context.SECURITY_CREDENTIALS, "welcome1");
  
          // LDAP entry mapping
          LdapEntryMapping mapping = new LdapEntryMapping();
          mapping
              .getCallerMapping()
              .setDnPattern("uid={0},ou=people,ou=myrealm,dc=base_domain")
              .setGroupAttribute("wlsMemberOf");
  
          // Instantiate store
          LdapIdentityStore store = new LdapIdentityStore(env, mapping);
  
          // Get caller groups
          List<String> groups = store.getCallerGroups("jsmith");
          assertNotNull("Groups", groups);
          assertEquals("Groups count", 2, groups.size());
          assertTrue("Deployers", groups.contains("Deployers"));
          assertTrue("Operators", groups.contains("Operators"));
      }
test_case.class_method_signature: LdapIdentityStoreTest.callerGroups()
test_case.full_signature: @Test public void callerGroups()
test_case.identifier: callerGroups
test_case.invocations: put put put put put setGroupAttribute setDnPattern getCallerMapping getCallerGroups assertNotNull assertEquals size assertTrue contains assertTrue contains
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void callerGroups()
focal_class.declarator: contextEnv
focal_class.modifier: final private
focal_class.original_string: final private Hashtable<String, Object> contextEnv;
focal_class.type: Hashtable<String, Object>
focal_class.var_name: contextEnv
focal_class.declarator: entryMapping
focal_class.modifier: final private
focal_class.original_string: final private LdapEntryMapping entryMapping;
focal_class.type: LdapEntryMapping
focal_class.var_name: entryMapping
focal_class.file: authentication/identity-store/identity-store-readonly/src/main/java/javax/security/identitystore/persistence/LdapIdentityStore.java
focal_class.identifier: LdapIdentityStore
focal_class.class_method_signature: LdapIdentityStore.LdapIdentityStore(
          Hashtable<String, Object> contextEnvironment,
          LdapEntryMapping entryMapping)
focal_class.full_signature: public  LdapIdentityStore(
          Hashtable<String, Object> contextEnvironment,
          LdapEntryMapping entryMapping)
focal_class.identifier: LdapIdentityStore
focal_class.modifiers: public
focal_class.parameters: (
          Hashtable<String, Object> contextEnvironment,
          LdapEntryMapping entryMapping)
focal_class.signature:  LdapIdentityStore(
          Hashtable<String, Object> contextEnvironment,
          LdapEntryMapping entryMapping)
focal_class.class_method_signature: LdapIdentityStore.formatDn(String caller)
focal_class.full_signature:  String formatDn(String caller)
focal_class.identifier: formatDn
focal_class.parameters: (String caller)
focal_class.return: String
focal_class.signature: String formatDn(String caller)
focal_class.class_method_signature: LdapIdentityStore.validateUsernamePassword(UsernamePasswordCredential usernamePasswordCredential)
focal_class.full_signature: @Override protected CredentialValidationResult validateUsernamePassword(UsernamePasswordCredential usernamePasswordCredential)
focal_class.identifier: validateUsernamePassword
focal_class.modifiers: @Override protected
focal_class.parameters: (UsernamePasswordCredential usernamePasswordCredential)
focal_class.return: CredentialValidationResult
focal_class.signature: CredentialValidationResult validateUsernamePassword(UsernamePasswordCredential usernamePasswordCredential)
focal_class.class_method_signature: LdapIdentityStore.getCallerGroups(String callerName)
focal_class.full_signature: @Override public List<String> getCallerGroups(String callerName)
focal_class.identifier: getCallerGroups
focal_class.modifiers: @Override public
focal_class.parameters: (String callerName)
focal_class.return: List<String>
focal_class.signature: List<String> getCallerGroups(String callerName)
focal_class.class_method_signature: LdapIdentityStore.getCallerRoles(String callerName)
focal_class.full_signature: @Override public List<String> getCallerRoles(String callerName)
focal_class.identifier: getCallerRoles
focal_class.modifiers: @Override public
focal_class.parameters: (String callerName)
focal_class.return: List<String>
focal_class.signature: List<String> getCallerRoles(String callerName)
focal_class.superclass: extends AbstractIdentityStore
focal_method.body: @Override
      public List<String> getCallerGroups(String callerName) {
          LdapContext ctx = null;
  
          try {
              Hashtable<String, Object> env = new Hashtable<String, Object>(contextEnv);
  
              // Never use connection pool to prevent password caching
              env.put("com.sun.jndi.ldap.connect.pool", "false");
  
              ctx = new InitialLdapContext(env, null);
  
              // Get group attribute from caller entry
              String callerDn = formatDn(callerName);
              Attributes attributes = ctx.getAttributes(callerDn, new String[]{entryMapping.getCallerMapping().getGroupAttribute()});
              Attribute attribute = attributes.get(entryMapping.getCallerMapping().getGroupAttribute());
              NamingEnumeration<?> values = attribute.getAll();
              ArrayList<String> result = new ArrayList<>();
              while (values.hasMore()) {
                  String dn = (String)values.next();
                  LdapName ldapDN = new LdapName(dn);
                  List<Rdn> rdns = ldapDN.getRdns();
                  Rdn mostSpecificRdn = rdns.get(rdns.size() - 1);
                  result.add((String)mostSpecificRdn.getValue());
              }
              return result;
          } catch (Exception e) {
              // TODO: Add logging
              e.printStackTrace();
              return null;
          } finally {
              if (ctx != null) {
                  try {
                      ctx.close();
                  } catch (NamingException e) {
                  }
              }
          }
      }
focal_method.class_method_signature: LdapIdentityStore.getCallerGroups(String callerName)
focal_method.full_signature: @Override public List<String> getCallerGroups(String callerName)
focal_method.identifier: getCallerGroups
focal_method.invocations: put formatDn getAttributes getGroupAttribute getCallerMapping get getGroupAttribute getCallerMapping getAll hasMore next getRdns get size add getValue printStackTrace close
focal_method.modifiers: @Override public
focal_method.parameters: (String callerName)
focal_method.return: List<String>
focal_method.signature: List<String> getCallerGroups(String callerName)