github-advanced-security[bot] commented on code in PR #1036:
URL: https://github.com/apache/syncope/pull/1036#discussion_r2014451063


##########
fit/core-reference/src/test/java/org/apache/syncope/fit/AbstractITCase.java:
##########
@@ -786,120 +783,112 @@
                 (InputStream) response.getEntity(), response.getMediaType(), 
new BatchResponseItem());
     }
 
-    @SuppressWarnings({ "unchecked", "rawtypes", "UseOfObsoleteCollectionType" 
})
-    protected static InitialDirContext getLdapResourceDirContext(final String 
bindDn, final String bindPwd)
-            throws NamingException {
-        ResourceTO ldapRes = RESOURCE_SERVICE.read(RESOURCE_NAME_LDAP);
-        ConnInstanceTO ldapConn = 
CONNECTOR_SERVICE.read(ldapRes.getConnector(), Locale.ENGLISH.getLanguage());
-
-        Properties env = new Properties();
-        env.put(Context.INITIAL_CONTEXT_FACTORY, 
"com.sun.jndi.ldap.LdapCtxFactory");
-        env.put(Context.PROVIDER_URL, "ldap://"; + 
ldapConn.getConf("host").get().getValues().getFirst()
-                + ':' + ldapConn.getConf("port").get().getValues().getFirst() 
+ '/');
-        env.put(Context.SECURITY_AUTHENTICATION, "simple");
-        env.put(Context.SECURITY_PRINCIPAL,
-                bindDn == null ? 
ldapConn.getConf("principal").get().getValues().getFirst() : bindDn);
-        env.put(Context.SECURITY_CREDENTIALS,
-                bindPwd == null ? 
ldapConn.getConf("credentials").get().getValues().getFirst() : bindPwd);
-
-        return new InitialDirContext(env);
+    private static <T> T execOnLDAP(
+            final String bindDn,
+            final String bindPassword,
+            final ConnInstanceTO connInstance,
+            final ThrowingFunction<LDAPConnection, T> function) throws 
LDAPException {
+
+        try (LDAPConnection ldapConn = new LDAPConnection(
+                
connInstance.getConf("host").orElseThrow().getValues().getFirst().toString(),
+                
Integer.parseInt(connInstance.getConf("port").orElseThrow().getValues().getFirst().toString()),

Review Comment:
   ## Missing catch of NumberFormatException
   
   Potential uncaught 'java.lang.NumberFormatException'.
   
   [Show more 
details](https://github.com/apache/syncope/security/code-scanning/2203)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@syncope.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to