{"id":68228,"date":"2024-07-05T11:52:45","date_gmt":"2024-07-05T08:22:45","guid":{"rendered":"https:\/\/nabfollower.com\/blog\/how-can-you-implement-a-conditional-login-mechanism-between-ldap-and-local-database-using-spring-boot-5glm\/"},"modified":"2024-07-05T11:52:45","modified_gmt":"2024-07-05T08:22:45","slug":"how-can-you-implement-a-conditional-login-mechanism-between-ldap-and-local-database-using-spring-boot-5glm","status":"publish","type":"post","link":"https:\/\/nabfollower.com\/blog\/how-can-you-implement-a-conditional-login-mechanism-between-ldap-and-local-database-using-spring-boot-5glm\/","title":{"rendered":"\u0686\u06af\u0648\u0646\u0647 \u0645\u06cc \u062a\u0648\u0627\u0646\u06cc\u062f \u06cc\u06a9 \u0645\u06a9\u0627\u0646\u06cc\u0633\u0645 \u0648\u0631\u0648\u062f \u0634\u0631\u0637\u06cc \u0628\u06cc\u0646 LDAP \u0648 \u067e\u0627\u06cc\u06af\u0627\u0647 \u062f\u0627\u062f\u0647 \u0645\u062d\u0644\u06cc \u0628\u0627 \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0627\u0632 Spring Boot \u067e\u06cc\u0627\u062f\u0647 \u0633\u0627\u0632\u06cc \u06a9\u0646\u06cc\u062f."},"content":{"rendered":"<p>Summarize this content to 400 words in Persian Lang<br \/>\n            \u0627\u062c\u0631\u0627\u06cc \u06cc\u06a9 \u0645\u06a9\u0627\u0646\u06cc\u0632\u0645 \u0648\u0631\u0648\u062f \u0628\u0647 \u0633\u06cc\u0633\u062a\u0645 \u0634\u0631\u0637\u06cc \u062f\u0631 Spring Boot \u06a9\u0647 \u0628\u0647 \u0637\u0648\u0631 \u06cc\u06a9\u067e\u0627\u0631\u0686\u0647 \u0628\u06cc\u0646 \u0627\u062d\u0631\u0627\u0632 \u0647\u0648\u06cc\u062a LDAP \u0648 \u0627\u062d\u0631\u0627\u0632 \u0647\u0648\u06cc\u062a \u067e\u0627\u06cc\u06af\u0627\u0647 \u062f\u0627\u062f\u0647 \u0645\u062d\u0644\u06cc \u0628\u0631 \u0627\u0633\u0627\u0633 \u062f\u0631 \u062f\u0633\u062a\u0631\u0633 \u0628\u0648\u062f\u0646 \u0633\u0631\u0648\u0631 LDAP \u0633\u0648\u0626\u06cc\u0686 \u0645\u06cc \u06a9\u0646\u062f\u060c \u06cc\u06a9 \u062c\u0646\u0628\u0647 \u062d\u06cc\u0627\u062a\u06cc \u0628\u0631\u0627\u06cc \u0627\u0637\u0645\u06cc\u0646\u0627\u0646 \u0627\u0632 \u062f\u0633\u062a\u0631\u0633\u06cc \u0628\u062f\u0648\u0646 \u0648\u0642\u0641\u0647 \u0628\u0647 \u0628\u0631\u0646\u0627\u0645\u0647 \u0634\u0645\u0627 \u0627\u0633\u062a. <\/p>\n<p>\u0628\u0627 \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0627\u0632 \u0627\u06cc\u0646 \u0631\u0648\u06cc\u06a9\u0631\u062f \u0627\u062d\u0631\u0627\u0632 \u0647\u0648\u06cc\u062a \u067e\u0648\u06cc\u0627\u060c \u0645\u06cc\u200c\u062a\u0648\u0627\u0646\u06cc\u062f \u0642\u0627\u0628\u0644\u06cc\u062a \u0627\u0637\u0645\u06cc\u0646\u0627\u0646 \u0648 \u0627\u0646\u0639\u0637\u0627\u0641\u200c\u067e\u0630\u06cc\u0631\u06cc \u0633\u06cc\u0633\u062a\u0645 \u062e\u0648\u062f \u0631\u0627 \u0627\u0641\u0632\u0627\u06cc\u0634 \u062f\u0647\u06cc\u062f \u0648 \u062a\u062c\u0631\u0628\u0647 \u0648\u0631\u0648\u062f \u06cc\u06a9\u067e\u0627\u0631\u0686\u0647 \u0628\u0647 \u06a9\u0627\u0631\u0628\u0631\u0627\u0646 \u0631\u0627 \u062d\u062a\u06cc \u062f\u0631 \u0632\u0645\u0627\u0646 \u062e\u0631\u0627\u0628\u06cc \u0633\u0631\u0648\u0631 LDAP \u0641\u0631\u0627\u0647\u0645 \u06a9\u0646\u06cc\u062f.<\/p>\n<p>\u0628\u0631\u0627\u06cc \u067e\u06cc\u0627\u062f\u0647\u200c\u0633\u0627\u0632\u06cc \u0645\u06a9\u0627\u0646\u06cc\u0632\u0645 \u0648\u0631\u0648\u062f \u0645\u0634\u0631\u0648\u0637 \u06a9\u0647 \u0628\u0631\u0631\u0633\u06cc \u0645\u06cc\u200c\u06a9\u0646\u062f \u0622\u06cc\u0627 \u0633\u0631\u0648\u0631 LDAP \u062f\u0631 \u062f\u0633\u062a\u0631\u0633 \u0627\u0633\u062a \u0648 \u0628\u0631 \u0627\u0633\u0627\u0633 \u0622\u0646\u060c \u0628\u0627 \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0627\u0632 \u0633\u0631\u0648\u0631 LDAP \u0627\u062d\u0631\u0627\u0632 \u0647\u0648\u06cc\u062a \u0645\u06cc\u200c\u0634\u0648\u062f \u06cc\u0627 \u0628\u0647 \u067e\u0627\u06cc\u06af\u0627\u0647 \u062f\u0627\u062f\u0647 \u0645\u062d\u0644\u06cc PostgreSQL \u0628\u0631\u0645\u06cc\u200c\u06af\u0631\u062f\u062f\u060c \u0628\u0627\u06cc\u062f:<\/p>\n<p>\u062f\u0631 \u062f\u0633\u062a\u0631\u0633 \u0628\u0648\u062f\u0646 \u0633\u0631\u0648\u0631 LDAP \u0631\u0627 \u0628\u0631\u0631\u0633\u06cc \u06a9\u0646\u06cc\u062f: \u0645\u06a9\u0627\u0646\u06cc\u0632\u0645\u06cc \u0631\u0627 \u0628\u0631\u0627\u06cc \u0628\u0631\u0631\u0633\u06cc \u0627\u06cc\u0646\u06a9\u0647 \u0622\u06cc\u0627 \u0633\u0631\u0648\u0631 LDAP \u0642\u0627\u0628\u0644 \u062f\u0633\u062a\u0631\u0633\u06cc \u0627\u0633\u062a \u06cc\u0627 \u062e\u06cc\u0631\u060c \u0627\u062c\u0631\u0627 \u06a9\u0646\u06cc\u062f.<\/p>\n<p>\u062a\u0644\u0627\u0634 \u0628\u0631\u0627\u06cc \u0627\u062d\u0631\u0627\u0632 \u0647\u0648\u06cc\u062a LDAP: \u0627\u06af\u0631 \u0633\u0631\u0648\u0631 LDAP \u062f\u0631 \u062f\u0633\u062a\u0631\u0633 \u0627\u0633\u062a\u060c \u0628\u0627 \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0627\u0632 LDAP \u0627\u062d\u0631\u0627\u0632 \u0647\u0648\u06cc\u062a \u06a9\u0646\u06cc\u062f.<\/p>\n<p>\u0628\u0627\u0632\u06af\u0634\u062a \u0628\u0647 \u0627\u062d\u0631\u0627\u0632 \u0647\u0648\u06cc\u062a \u0645\u062d\u0644\u06cc: \u0627\u06af\u0631 \u0633\u0631\u0648\u0631 LDAP \u0642\u0627\u0628\u0644 \u062f\u0633\u062a\u0631\u0633\u06cc \u0646\u06cc\u0633\u062a\u060c \u0628\u0627 \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0627\u0632 \u0627\u0639\u062a\u0628\u0627\u0631\u0646\u0627\u0645\u0647 \u0647\u0627\u06cc \u0630\u062e\u06cc\u0631\u0647 \u0634\u062f\u0647 \u062f\u0631 \u067e\u0627\u06cc\u06af\u0627\u0647 \u062f\u0627\u062f\u0647 \u0645\u062d\u0644\u06cc PostgreSQL \u0627\u062d\u0631\u0627\u0632 \u0647\u0648\u06cc\u062a \u06a9\u0646\u06cc\u062f.<\/p>\n<p>\u062f\u0631 \u0627\u06cc\u0646\u062c\u0627 \u067e\u06cc\u0627\u062f\u0647 \u0633\u0627\u0632\u06cc \u06af\u0627\u0645 \u0628\u0647 \u06af\u0627\u0645 \u0627\u0633\u062a :<\/p>\n<p>  1. \u0627\u0641\u0632\u0648\u062f\u0646 \u0648\u0627\u0628\u0633\u062a\u06af\u06cc \u0647\u0627:<\/p>\n<p>\u062f\u0631 \u0627\u06cc\u0646\u062c\u0627 \u0645\u0646 Maven \u0631\u0627 \u0628\u0647 \u0639\u0646\u0648\u0627\u0646 \u0627\u0628\u0632\u0627\u0631 \u0633\u0627\u062e\u062a \u062f\u0631 \u0646\u0638\u0631 \u0645\u06cc\u200c\u06af\u06cc\u0631\u0645. \u0645\u0637\u0645\u0626\u0646 \u0634\u0648\u06cc\u062f \u06a9\u0647 \u0648\u0627\u0628\u0633\u062a\u06af\u06cc\u200c\u0647\u0627\u06cc \u0632\u06cc\u0631 \u0631\u0627 \u062f\u0631 \u062e\u0648\u062f \u062f\u0627\u0631\u06cc\u062fpom.xml\u0641\u0627\u06cc\u0644:<\/p>\n<p>org.springframework.bootspring-boot-starter-weborg.springframework.bootspring-boot-starter-data-jpaorg.postgresqlpostgresqlruntimeorg.springframework.bootspring-boot-starter-ldaporg.springframework.bootspring-boot-starter-actuator<\/p>\n<p>  2. \u0648\u06cc\u0698\u06af\u06cc \u0647\u0627\u06cc \u0628\u0631\u0646\u0627\u0645\u0647 \u0631\u0627 \u067e\u06cc\u06a9\u0631\u0628\u0646\u062f\u06cc \u06a9\u0646\u06cc\u062f<\/p>\n<p>\u0648\u06cc\u0698\u06af\u06cc \u0647\u0627\u06cc \u0644\u0627\u0632\u0645 \u0631\u0627 \u062f\u0631 application.properties \u062a\u0646\u0638\u06cc\u0645 \u06a9\u0646\u06cc\u062f:<\/p>\n<p># LDAP Server Configuration<br \/>\nldap.url=ldap:\/\/url:389<br \/>\nldap.admin.dn=cn=admin,dc=urdc,dc=urdc<br \/>\nldap.admin.password=ldappassword<br \/>\nldap.search.base=dc=cspurdc,dc=csp<\/p>\n<p># PostgreSQL Configuration<br \/>\nspring.datasource.url=jdbc:postgresql:\/\/localhost:5432\/yourdb<br \/>\nspring.datasource.username=yourusername<br \/>\nspring.datasource.password=yourpassword<br \/>\nspring.datasource.driver-class-name=org.postgresql.Driver<br \/>\nspring.jpa.hibernate.ddl-auto=update<\/p>\n<p># User Authentication Configuration<br \/>\nuser.samaccountname=username<br \/>\nuser.password=ldappassword<\/p>\n<p>    \u0648\u0627\u0631\u062f \u062d\u0627\u0644\u062a \u062a\u0645\u0627\u0645 \u0635\u0641\u062d\u0647 \u0634\u0648\u06cc\u062f<\/p>\n<p>    \u0627\u0632 \u062d\u0627\u0644\u062a \u062a\u0645\u0627\u0645 \u0635\u0641\u062d\u0647 \u062e\u0627\u0631\u062c \u0634\u0648\u06cc\u062f<\/p>\n<p>  3. Entity \u0648 Repository \u06a9\u0627\u0631\u0628\u0631 \u0628\u0631\u0627\u06cc PostgreSQL \u0627\u06cc\u062c\u0627\u062f \u06a9\u0646\u06cc\u062f<\/p>\n<p>\u06cc\u06a9 \u0645\u0648\u062c\u0648\u062f\u06cc\u062a \u06a9\u0627\u0631\u0628\u0631 \u0648 \u0645\u062e\u0632\u0646 \u0633\u0627\u062f\u0647 \u0628\u0631\u0627\u06cc \u067e\u0627\u06cc\u06af\u0627\u0647 \u062f\u0627\u062f\u0647 PostgreSQL \u062a\u0639\u0631\u06cc\u0641 \u06a9\u0646\u06cc\u062f. User.java<\/p>\n<p>package com.example.ldapauth.entity;<br \/>\nimport javax.persistence.Entity;<br \/>\nimport javax.persistence.GeneratedValue;<br \/>\nimport javax.persistence.GenerationType;<br \/>\nimport javax.persistence.Id;<br \/>\n@Entity<br \/>\npublic class User {<br \/>\n    @Id<br \/>\n    @GeneratedValue(strategy = GenerationType.AUTO)<br \/>\n    private Long id;<br \/>\n    private String username;<br \/>\n    private String password;<br \/>\n    \/\/ Getters and Setters<br \/>\n    public Long getId() {<br \/>\n        return id;<br \/>\n    }<br \/>\n    public void setId(Long id) {<br \/>\n        this.id = id;<br \/>\n    }<br \/>\n    public String getUsername() {<br \/>\n        return username;<br \/>\n    }<br \/>\n    public void setUsername(String username) {<br \/>\n        this.username = username;<br \/>\n    }<br \/>\n    public String getPassword() {<br \/>\n        return password;<br \/>\n    }<br \/>\n    public void setPassword(String password) {<br \/>\n        this.password = password;<br \/>\n    }<br \/>\n}<\/p>\n<p>    \u0648\u0627\u0631\u062f \u062d\u0627\u0644\u062a \u062a\u0645\u0627\u0645 \u0635\u0641\u062d\u0647 \u0634\u0648\u06cc\u062f<\/p>\n<p>    \u0627\u0632 \u062d\u0627\u0644\u062a \u062a\u0645\u0627\u0645 \u0635\u0641\u062d\u0647 \u062e\u0627\u0631\u062c \u0634\u0648\u06cc\u062f<\/p>\n<p>UserRepository.java<\/p>\n<p>package com.example.ldapauth.repository;<\/p>\n<p>import com.example.ldapauth.entity.User;<br \/>\nimport org.springframework.data.jpa.repository.JpaRepository;<br \/>\nimport org.springframework.stereotype.Repository;<\/p>\n<p>@Repository<br \/>\npublic interface UserRepository extends JpaRepository {<br \/>\n    User findByUsername(String username);<br \/>\n}<\/p>\n<p>    \u0648\u0627\u0631\u062f \u062d\u0627\u0644\u062a \u062a\u0645\u0627\u0645 \u0635\u0641\u062d\u0647 \u0634\u0648\u06cc\u062f<\/p>\n<p>    \u0627\u0632 \u062d\u0627\u0644\u062a \u062a\u0645\u0627\u0645 \u0635\u0641\u062d\u0647 \u062e\u0627\u0631\u062c \u0634\u0648\u06cc\u062f<\/p>\n<p>  4. \u0633\u0631\u0648\u06cc\u0633 \u0628\u0631\u0627\u06cc \u0627\u062d\u0631\u0627\u0632 \u0647\u0648\u06cc\u062a \u0645\u062d\u0644\u06cc<\/p>\n<p>\u0633\u0631\u0648\u06cc\u0633\u06cc \u0627\u0636\u0627\u0641\u0647 \u06a9\u0646\u06cc\u062f \u062a\u0627 \u0627\u062d\u0631\u0627\u0632 \u0647\u0648\u06cc\u062a \u067e\u0627\u06cc\u06af\u0627\u0647 \u062f\u0627\u062f\u0647 \u0645\u062d\u0644\u06cc \u0631\u0627 \u06a9\u0646\u062a\u0631\u0644 \u06a9\u0646\u062f.LocalAuthService.java<\/p>\n<p>package com.example.ldapauth.service;<\/p>\n<p>import com.example.ldapauth.entity.User;<br \/>\nimport com.example.ldapauth.repository.UserRepository;<br \/>\nimport org.springframework.beans.factory.annotation.Autowired;<br \/>\nimport org.springframework.stereotype.Service;<\/p>\n<p>@Service<br \/>\npublic class LocalAuthService {<\/p>\n<p>    @Autowired<br \/>\n    private UserRepository userRepository;<\/p>\n<p>    public boolean authenticate(String username, String password) {<br \/>\n        User user = userRepository.findByUsername(username);<br \/>\n        return user != null &amp;&amp; user.getPassword().equals(password);<br \/>\n    }<br \/>\n}<\/p>\n<p>    \u0648\u0627\u0631\u062f \u062d\u0627\u0644\u062a \u062a\u0645\u0627\u0645 \u0635\u0641\u062d\u0647 \u0634\u0648\u06cc\u062f<\/p>\n<p>    \u0627\u0632 \u062d\u0627\u0644\u062a \u062a\u0645\u0627\u0645 \u0635\u0641\u062d\u0647 \u062e\u0627\u0631\u062c \u0634\u0648\u06cc\u062f<\/p>\n<p>  5. LdapService \u0631\u0627 \u062a\u063a\u06cc\u06cc\u0631 \u062f\u0647\u06cc\u062f \u062a\u0627 \u0634\u0627\u0645\u0644 \u0628\u0631\u0631\u0633\u06cc \u0633\u0644\u0627\u0645\u062a \u0634\u0648\u062f:<\/p>\n<p>\u0631\u0648\u0634\u06cc \u0628\u0631\u0627\u06cc \u0628\u0631\u0631\u0633\u06cc \u062f\u0631 \u062f\u0633\u062a\u0631\u0633 \u0628\u0648\u062f\u0646 \u0633\u0631\u0648\u0631 LDAP \u0627\u0636\u0627\u0641\u0647 \u06a9\u0646\u06cc\u062f.LdapService.java<\/p>\n<p>package com.example.ldapauth.service;<\/p>\n<p>import org.springframework.beans.factory.annotation.Autowired;<br \/>\nimport org.springframework.beans.factory.annotation.Value;<br \/>\nimport org.springframework.ldap.support.LdapUtils;<br \/>\nimport org.springframework.stereotype.Service;<\/p>\n<p>import javax.naming.Context;<br \/>\nimport javax.naming.NamingEnumeration;<br \/>\nimport javax.naming.NamingException;<br \/>\nimport javax.naming.directory.*;<br \/>\nimport java.util.Hashtable;<\/p>\n<p>@Service<br \/>\npublic class LdapService {<\/p>\n<p>    @Autowired<br \/>\n    private DirContext ldapContext;<\/p>\n<p>    @Value(&#8220;${ldap.search.base}&#8221;)<br \/>\n    private String searchBase;<\/p>\n<p>    @Value(&#8220;${user.samaccountname}&#8221;)<br \/>\n    private String sAMAccountName;<\/p>\n<p>    @Value(&#8220;${user.password}&#8221;)<br \/>\n    private String userPassword;<\/p>\n<p>    public boolean isLdapAvailable() {<br \/>\n        try {<br \/>\n            \/\/ Try a no-op search to check server availability<br \/>\n            NamingEnumeration results = ldapContext.search(&#8220;&#8221;, &#8220;(objectClass=*)&#8221;, new SearchControls());<br \/>\n            return results != null;  \/\/ If this does not throw an exception, LDAP is available<br \/>\n        } catch (NamingException e) {<br \/>\n            return false; \/\/ LDAP is not available<br \/>\n        }<br \/>\n    }<\/p>\n<p>    public String getUserDn(String username) {<br \/>\n        try {<br \/>\n            String searchFilter = &#8220;(sAMAccountName=&#8221; + username + &#8220;)&#8221;;<br \/>\n            SearchControls searchControls = new SearchControls();<br \/>\n            searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);<br \/>\n            NamingEnumeration results = ldapContext.search(searchBase, searchFilter, searchControls);<\/p>\n<p>            if (results.hasMore()) {<br \/>\n                SearchResult searchResult = results.next();<br \/>\n                return searchResult.getNameInNamespace();<br \/>\n            }<br \/>\n        } catch (NamingException e) {<br \/>\n            e.printStackTrace();<br \/>\n        }<br \/>\n        return null;<br \/>\n    }<\/p>\n<p>    public boolean authenticateUser(String userDn, String password) {<br \/>\n        if (userDn == null) {<br \/>\n            System.out.println(&#8220;User authentication failed: User DN not found.&#8221;);<br \/>\n            return false;<br \/>\n        }<\/p>\n<p>        try {<br \/>\n            Hashtable env = new Hashtable();<br \/>\n            env.put(Context.INITIAL_CONTEXT_FACTORY, &#8220;com.sun.jndi.ldap.LdapCtxFactory&#8221;);<br \/>\n            env.put(Context.PROVIDER_URL, ldapContext.getEnvironment().get(Context.PROVIDER_URL).toString());<br \/>\n            env.put(Context.SECURITY_AUTHENTICATION, &#8220;simple&#8221;);<br \/>\n            env.put(Context.SECURITY_PRINCIPAL, userDn);<br \/>\n            env.put(Context.SECURITY_CREDENTIALS, password);<\/p>\n<p>            DirContext ctx = new InitialDirContext(env);<br \/>\n            ctx.close();<br \/>\n            System.out.println(&#8220;User authentication successful.&#8221;);<br \/>\n            return true;<br \/>\n        } catch (NamingException e) {<br \/>\n            System.out.println(&#8220;User authentication failed: &#8221; + e.getMessage());<br \/>\n            return false;<br \/>\n        }<br \/>\n    }<br \/>\n}<\/p>\n<p>    \u0648\u0627\u0631\u062f \u062d\u0627\u0644\u062a \u062a\u0645\u0627\u0645 \u0635\u0641\u062d\u0647 \u0634\u0648\u06cc\u062f<\/p>\n<p>    \u0627\u0632 \u062d\u0627\u0644\u062a \u062a\u0645\u0627\u0645 \u0635\u0641\u062d\u0647 \u062e\u0627\u0631\u062c \u0634\u0648\u06cc\u062f<\/p>\n<p>  6. \u06a9\u0646\u062a\u0631\u0644 \u06a9\u0646\u0646\u062f\u0647 \u0631\u0627 \u0628\u0631\u0627\u06cc \u067e\u06cc\u0627\u062f\u0647 \u0633\u0627\u0632\u06cc \u0648\u0631\u0648\u062f \u0634\u0631\u0637\u06cc \u062a\u063a\u06cc\u06cc\u0631 \u062f\u0647\u06cc\u062f<\/p>\n<p>LdapController.java<\/p>\n<p>package com.example.ldapauth.controller;<\/p>\n<p>import com.example.ldapauth.service.LdapService;<br \/>\nimport com.example.ldapauth.service.LocalAuthService;<br \/>\nimport org.springframework.beans.factory.annotation.Autowired;<br \/>\nimport org.springframework.web.bind.annotation.PostMapping;<br \/>\nimport org.springframework.web.bind.annotation.RequestParam;<br \/>\nimport org.springframework.web.bind.annotation.RestController;<\/p>\n<p>@RestController<br \/>\npublic class LdapController {<\/p>\n<p>    @Autowired<br \/>\n    private LdapService ldapService;<\/p>\n<p>    @Autowired<br \/>\n    private LocalAuthService localAuthService;<\/p>\n<p>    @PostMapping(&#8220;\/login&#8221;)<br \/>\n    public String performLogin(@RequestParam String username, @RequestParam String password) {<br \/>\n        if (ldapService.isLdapAvailable()) {<br \/>\n            String userDn = ldapService.getUserDn(username);<br \/>\n            boolean isAuthenticated = ldapService.authenticateUser(userDn, password);<br \/>\n            if (isAuthenticated) {<br \/>\n                return &#8220;LDAP authentication successful!&#8221;;<br \/>\n            }<br \/>\n        }<\/p>\n<p>        boolean isLocalAuthenticated = localAuthService.authenticate(username, password);<br \/>\n        if (isLocalAuthenticated) {<br \/>\n            return &#8220;Local authentication successful!&#8221;;<br \/>\n        }<\/p>\n<p>        return &#8220;Authentication failed!&#8221;;<br \/>\n    }<br \/>\n}<\/p>\n<p>    \u0648\u0627\u0631\u062f \u062d\u0627\u0644\u062a \u062a\u0645\u0627\u0645 \u0635\u0641\u062d\u0647 \u0634\u0648\u06cc\u062f<\/p>\n<p>    \u0627\u0632 \u062d\u0627\u0644\u062a \u062a\u0645\u0627\u0645 \u0635\u0641\u062d\u0647 \u062e\u0627\u0631\u062c \u0634\u0648\u06cc\u062f<\/p>\n<p>  \u062a\u0648\u0636\u06cc\u062d:<\/p>\n<p>\u0628\u0631\u0631\u0633\u06cc \u062f\u0631 \u062f\u0633\u062a\u0631\u0633 \u0628\u0648\u062f\u0646 LDAP: \u0631\u0648\u0634 isLdapAvailable \u062f\u0631 LdapService \u06cc\u06a9 \u062c\u0633\u062a\u062c\u0648\u06cc \u0633\u0627\u062e\u062a\u06af\u06cc LDAP \u0631\u0627 \u0628\u0631\u0627\u06cc \u0628\u0631\u0631\u0633\u06cc \u0627\u06cc\u0646\u06a9\u0647 \u0622\u06cc\u0627 \u0633\u0631\u0648\u0631 LDAP \u062f\u0631 \u062f\u0633\u062a\u0631\u0633 \u0627\u0633\u062a \u0627\u0646\u062c\u0627\u0645 \u0645\u06cc \u062f\u0647\u062f.<br \/>\n\u0645\u0646\u0637\u0642 \u0648\u0631\u0648\u062f \u0634\u0631\u0637\u06cc: \u062f\u0631 LdapController\u060c \u0646\u0642\u0637\u0647 \u067e\u0627\u06cc\u0627\u0646\u06cc \/login \u062f\u0631 \u062f\u0633\u062a\u0631\u0633 \u0628\u0648\u062f\u0646 LDAP \u0631\u0627 \u0628\u0631\u0631\u0633\u06cc \u0645\u06cc \u06a9\u0646\u062f.  \u0627\u06af\u0631 LDAP \u062f\u0631 \u062f\u0633\u062a\u0631\u0633 \u0628\u0627\u0634\u062f\u060c \u0633\u0639\u06cc \u0645\u06cc \u06a9\u0646\u062f \u06a9\u0627\u0631\u0628\u0631 \u0631\u0627 \u0628\u0627 LDAP \u0627\u062d\u0631\u0627\u0632 \u0647\u0648\u06cc\u062a \u06a9\u0646\u062f.  \u0627\u06af\u0631 \u0627\u062d\u0631\u0627\u0632 \u0647\u0648\u06cc\u062a LDAP \u0646\u0627\u0645\u0648\u0641\u0642 \u0628\u0627\u0634\u062f \u06cc\u0627 LDAP \u062f\u0631 \u062f\u0633\u062a\u0631\u0633 \u0646\u0628\u0627\u0634\u062f\u060c \u0628\u0627 \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0627\u0632 LocalAuthService \u0628\u0647 \u0627\u062d\u0631\u0627\u0632 \u0647\u0648\u06cc\u062a \u067e\u0627\u06cc\u06af\u0627\u0647 \u062f\u0627\u062f\u0647 PostgreSQL \u0645\u062d\u0644\u06cc \u0628\u0627\u0632\u0645\u06cc \u06af\u0631\u062f\u062f.<br \/>\n\u0627\u062d\u0631\u0627\u0632 \u0647\u0648\u06cc\u062a \u0645\u062d\u0644\u06cc: \u0627\u06af\u0631 LDAP \u062f\u0631 \u062f\u0633\u062a\u0631\u0633 \u0646\u0628\u0627\u0634\u062f \u06cc\u0627 \u06a9\u0627\u0631\u0628\u0631 \u062f\u0631 \u062a\u0623\u06cc\u06cc\u062f \u0627\u0639\u062a\u0628\u0627\u0631 LDAP \u0646\u0627\u0645\u0648\u0641\u0642 \u0628\u0627\u0634\u062f\u060c \u067e\u0627\u06cc\u06af\u0627\u0647 \u062f\u0627\u062f\u0647 \u0645\u062d\u0644\u06cc PostgreSQL \u0631\u0627 \u0628\u0631\u0627\u06cc \u0627\u0639\u062a\u0628\u0627\u0631 \u06a9\u0627\u0631\u0628\u0631 \u0628\u0627 \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0627\u0632 UserRepository \u0628\u0631\u0631\u0633\u06cc \u0645\u06cc \u06a9\u0646\u062f.<br \/>\n\u06a9\u0646\u062a\u0631\u0644\u0631 REST: @PostMapping \u062f\u0631 \u0646\u0642\u0637\u0647 \u067e\u0627\u06cc\u0627\u0646\u06cc \/login \u062f\u0631\u062e\u0648\u0627\u0633\u062a\u200c\u0647\u0627\u06cc \u0648\u0631\u0648\u062f \u0631\u0627 \u0645\u062f\u06cc\u0631\u06cc\u062a \u0645\u06cc\u200c\u06a9\u0646\u062f \u0648 \u0645\u0646\u0637\u0642 \u0634\u0631\u0637\u06cc \u0631\u0627 \u0628\u0631\u0627\u06cc \u0627\u062d\u0631\u0627\u0632 \u0647\u0648\u06cc\u062a \u0627\u0639\u0645\u0627\u0644 \u0645\u06cc\u200c\u06a9\u0646\u062f.<\/p>\n<p>\u0627\u06cc\u0646 \u062a\u0646\u0638\u06cc\u0645\u0627\u062a \u0645\u06a9\u0627\u0646\u06cc\u0632\u0645\u06cc \u0642\u0648\u06cc \u0628\u0631\u0627\u06cc \u062c\u0627\u0628\u062c\u0627\u06cc\u06cc \u0628\u06cc\u0646 LDAP \u0648 \u0627\u062d\u0631\u0627\u0632 \u0647\u0648\u06cc\u062a \u0645\u062d\u0644\u06cc \u0628\u0631 \u0627\u0633\u0627\u0633 \u062f\u0631 \u062f\u0633\u062a\u0631\u0633 \u0628\u0648\u062f\u0646 \u0633\u0631\u0648\u0631 LDAP \u0641\u0631\u0627\u0647\u0645 \u0645\u06cc \u06a9\u0646\u062f.<\/p>\n<p>\u0627\u0645\u06cc\u062f\u0648\u0627\u0631\u0645 \u0627\u06cc\u0646 \u0645\u0641\u06cc\u062f \u0628\u0648\u062f\u0647 \u0628\u0627\u0634\u0647 \u0628\u0686\u0647 \u0647\u0627  \u0644\u0637\u0641\u0627\u064b \u062a\u0648\u062c\u0647 \u062f\u0627\u0634\u062a\u0647 \u0628\u0627\u0634\u06cc\u062f \u06a9\u0647 \u0628\u0627\u06cc\u062f \u0686\u0646\u062f \u0686\u06cc\u0632 \u0631\u0627 \u0628\u0631 \u0627\u0633\u0627\u0633 \u0646\u06cc\u0627\u0632\u0647\u0627 \u0648 \u0645\u0646\u0637\u0642 \u062e\u0648\u062f \u062a\u063a\u06cc\u06cc\u0631 \u062f\u0647\u06cc\u062f.  \u0645\u0646 \u062f\u0631 \u0627\u06cc\u0646\u062c\u0627 \u0641\u0642\u0637 \u0627\u06cc\u062f\u0647 \u06a9\u0644\u06cc \u062f\u0627\u062f\u0647 \u0627\u0645. <\/p>\n<p>\u06a9\u062f \u0646\u0648\u06cc\u0633\u06cc \u0645\u0628\u0627\u0631\u06a9 \ud83d\ude42 <\/p>\n<p>\u0628\u0627 \u062a\u0634\u06a9\u0631\u060c\u062c\u0627\u0648\u0627\u0686\u0627\u0631\u062a\u0631\u06a9\u0627\u06cc\u0644\u0627\u0634 \u0646\u06cc\u0631\u0645\u0627\u0644\u0646\u0648\u0634\u062a\u0647 \u0634\u062f\u0647 \u062f\u0631 : 5 \u062c\u0648\u0644\u0627\u06cc 2024.<\/p>\n<div data-article-id=\"1912368\" id=\"article-body\">\n<p>\u0627\u062c\u0631\u0627\u06cc \u06cc\u06a9 \u0645\u06a9\u0627\u0646\u06cc\u0632\u0645 \u0648\u0631\u0648\u062f \u0628\u0647 \u0633\u06cc\u0633\u062a\u0645 \u0634\u0631\u0637\u06cc \u062f\u0631 Spring Boot \u06a9\u0647 \u0628\u0647 \u0637\u0648\u0631 \u06cc\u06a9\u067e\u0627\u0631\u0686\u0647 \u0628\u06cc\u0646 \u0627\u062d\u0631\u0627\u0632 \u0647\u0648\u06cc\u062a LDAP \u0648 \u0627\u062d\u0631\u0627\u0632 \u0647\u0648\u06cc\u062a \u067e\u0627\u06cc\u06af\u0627\u0647 \u062f\u0627\u062f\u0647 \u0645\u062d\u0644\u06cc \u0628\u0631 \u0627\u0633\u0627\u0633 \u062f\u0631 \u062f\u0633\u062a\u0631\u0633 \u0628\u0648\u062f\u0646 \u0633\u0631\u0648\u0631 LDAP \u0633\u0648\u0626\u06cc\u0686 \u0645\u06cc \u06a9\u0646\u062f\u060c \u06cc\u06a9 \u062c\u0646\u0628\u0647 \u062d\u06cc\u0627\u062a\u06cc \u0628\u0631\u0627\u06cc \u0627\u0637\u0645\u06cc\u0646\u0627\u0646 \u0627\u0632 \u062f\u0633\u062a\u0631\u0633\u06cc \u0628\u062f\u0648\u0646 \u0648\u0642\u0641\u0647 \u0628\u0647 \u0628\u0631\u0646\u0627\u0645\u0647 \u0634\u0645\u0627 \u0627\u0633\u062a. <\/p>\n<p>\u0628\u0627 \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0627\u0632 \u0627\u06cc\u0646 \u0631\u0648\u06cc\u06a9\u0631\u062f \u0627\u062d\u0631\u0627\u0632 \u0647\u0648\u06cc\u062a \u067e\u0648\u06cc\u0627\u060c \u0645\u06cc\u200c\u062a\u0648\u0627\u0646\u06cc\u062f \u0642\u0627\u0628\u0644\u06cc\u062a \u0627\u0637\u0645\u06cc\u0646\u0627\u0646 \u0648 \u0627\u0646\u0639\u0637\u0627\u0641\u200c\u067e\u0630\u06cc\u0631\u06cc \u0633\u06cc\u0633\u062a\u0645 \u062e\u0648\u062f \u0631\u0627 \u0627\u0641\u0632\u0627\u06cc\u0634 \u062f\u0647\u06cc\u062f \u0648 \u062a\u062c\u0631\u0628\u0647 \u0648\u0631\u0648\u062f \u06cc\u06a9\u067e\u0627\u0631\u0686\u0647 \u0628\u0647 \u06a9\u0627\u0631\u0628\u0631\u0627\u0646 \u0631\u0627 \u062d\u062a\u06cc \u062f\u0631 \u0632\u0645\u0627\u0646 \u062e\u0631\u0627\u0628\u06cc \u0633\u0631\u0648\u0631 LDAP \u0641\u0631\u0627\u0647\u0645 \u06a9\u0646\u06cc\u062f.<\/p>\n<p>\u0628\u0631\u0627\u06cc \u067e\u06cc\u0627\u062f\u0647\u200c\u0633\u0627\u0632\u06cc \u0645\u06a9\u0627\u0646\u06cc\u0632\u0645 \u0648\u0631\u0648\u062f \u0645\u0634\u0631\u0648\u0637 \u06a9\u0647 \u0628\u0631\u0631\u0633\u06cc \u0645\u06cc\u200c\u06a9\u0646\u062f \u0622\u06cc\u0627 \u0633\u0631\u0648\u0631 LDAP \u062f\u0631 \u062f\u0633\u062a\u0631\u0633 \u0627\u0633\u062a \u0648 \u0628\u0631 \u0627\u0633\u0627\u0633 \u0622\u0646\u060c \u0628\u0627 \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0627\u0632 \u0633\u0631\u0648\u0631 LDAP \u0627\u062d\u0631\u0627\u0632 \u0647\u0648\u06cc\u062a \u0645\u06cc\u200c\u0634\u0648\u062f \u06cc\u0627 \u0628\u0647 \u067e\u0627\u06cc\u06af\u0627\u0647 \u062f\u0627\u062f\u0647 \u0645\u062d\u0644\u06cc PostgreSQL \u0628\u0631\u0645\u06cc\u200c\u06af\u0631\u062f\u062f\u060c \u0628\u0627\u06cc\u062f:<\/p>\n<ol>\n<li>\n<strong>\u062f\u0631 \u062f\u0633\u062a\u0631\u0633 \u0628\u0648\u062f\u0646 \u0633\u0631\u0648\u0631 LDAP \u0631\u0627 \u0628\u0631\u0631\u0633\u06cc \u06a9\u0646\u06cc\u062f<\/strong>: \u0645\u06a9\u0627\u0646\u06cc\u0632\u0645\u06cc \u0631\u0627 \u0628\u0631\u0627\u06cc \u0628\u0631\u0631\u0633\u06cc \u0627\u06cc\u0646\u06a9\u0647 \u0622\u06cc\u0627 \u0633\u0631\u0648\u0631 LDAP \u0642\u0627\u0628\u0644 \u062f\u0633\u062a\u0631\u0633\u06cc \u0627\u0633\u062a \u06cc\u0627 \u062e\u06cc\u0631\u060c \u0627\u062c\u0631\u0627 \u06a9\u0646\u06cc\u062f.<\/li>\n<li>\n<strong>\u062a\u0644\u0627\u0634 \u0628\u0631\u0627\u06cc \u0627\u062d\u0631\u0627\u0632 \u0647\u0648\u06cc\u062a LDAP<\/strong>: \u0627\u06af\u0631 \u0633\u0631\u0648\u0631 LDAP \u062f\u0631 \u062f\u0633\u062a\u0631\u0633 \u0627\u0633\u062a\u060c \u0628\u0627 \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0627\u0632 LDAP \u0627\u062d\u0631\u0627\u0632 \u0647\u0648\u06cc\u062a \u06a9\u0646\u06cc\u062f.<\/li>\n<li>\n<strong>\u0628\u0627\u0632\u06af\u0634\u062a \u0628\u0647 \u0627\u062d\u0631\u0627\u0632 \u0647\u0648\u06cc\u062a \u0645\u062d\u0644\u06cc<\/strong>: \u0627\u06af\u0631 \u0633\u0631\u0648\u0631 LDAP \u0642\u0627\u0628\u0644 \u062f\u0633\u062a\u0631\u0633\u06cc \u0646\u06cc\u0633\u062a\u060c \u0628\u0627 \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0627\u0632 \u0627\u0639\u062a\u0628\u0627\u0631\u0646\u0627\u0645\u0647 \u0647\u0627\u06cc \u0630\u062e\u06cc\u0631\u0647 \u0634\u062f\u0647 \u062f\u0631 \u067e\u0627\u06cc\u06af\u0627\u0647 \u062f\u0627\u062f\u0647 \u0645\u062d\u0644\u06cc PostgreSQL \u0627\u062d\u0631\u0627\u0632 \u0647\u0648\u06cc\u062a \u06a9\u0646\u06cc\u062f.<\/li>\n<\/ol>\n<p><em>\u062f\u0631 \u0627\u06cc\u0646\u062c\u0627 \u067e\u06cc\u0627\u062f\u0647 \u0633\u0627\u0632\u06cc \u06af\u0627\u0645 \u0628\u0647 \u06af\u0627\u0645 \u0627\u0633\u062a<\/em> :<\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_85 counter-hierarchy ez-toc-counter-rtl ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">\u0641\u0647\u0631\u0633\u062a \u0645\u0637\u0627\u0644\u0628<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"\u062a\u063a\u06cc\u06cc\u0631 \u0648\u0636\u0639\u06cc\u062a \u0641\u0647\u0631\u0633\u062a \u0645\u0637\u0627\u0644\u0628\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/nabfollower.com\/blog\/how-can-you-implement-a-conditional-login-mechanism-between-ldap-and-local-database-using-spring-boot-5glm\/#1_%D8%A7%D9%81%D8%B2%D9%88%D8%AF%D9%86_%D9%88%D8%A7%D8%A8%D8%B3%D8%AA%DA%AF%DB%8C_%D9%87%D8%A7\" >1. \u0627\u0641\u0632\u0648\u062f\u0646 \u0648\u0627\u0628\u0633\u062a\u06af\u06cc \u0647\u0627:<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/nabfollower.com\/blog\/how-can-you-implement-a-conditional-login-mechanism-between-ldap-and-local-database-using-spring-boot-5glm\/#2_%D9%88%DB%8C%DA%98%DA%AF%DB%8C_%D9%87%D8%A7%DB%8C_%D8%A8%D8%B1%D9%86%D8%A7%D9%85%D9%87_%D8%B1%D8%A7_%D9%BE%DB%8C%DA%A9%D8%B1%D8%A8%D9%86%D8%AF%DB%8C_%DA%A9%D9%86%DB%8C%D8%AF\" >2. \u0648\u06cc\u0698\u06af\u06cc \u0647\u0627\u06cc \u0628\u0631\u0646\u0627\u0645\u0647 \u0631\u0627 \u067e\u06cc\u06a9\u0631\u0628\u0646\u062f\u06cc \u06a9\u0646\u06cc\u062f<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/nabfollower.com\/blog\/how-can-you-implement-a-conditional-login-mechanism-between-ldap-and-local-database-using-spring-boot-5glm\/#3_Entity_%D9%88_Repository_%DA%A9%D8%A7%D8%B1%D8%A8%D8%B1_%D8%A8%D8%B1%D8%A7%DB%8C_PostgreSQL_%D8%A7%DB%8C%D8%AC%D8%A7%D8%AF_%DA%A9%D9%86%DB%8C%D8%AF\" >3. Entity \u0648 Repository \u06a9\u0627\u0631\u0628\u0631 \u0628\u0631\u0627\u06cc PostgreSQL \u0627\u06cc\u062c\u0627\u062f \u06a9\u0646\u06cc\u062f<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/nabfollower.com\/blog\/how-can-you-implement-a-conditional-login-mechanism-between-ldap-and-local-database-using-spring-boot-5glm\/#4_%D8%B3%D8%B1%D9%88%DB%8C%D8%B3_%D8%A8%D8%B1%D8%A7%DB%8C_%D8%A7%D8%AD%D8%B1%D8%A7%D8%B2_%D9%87%D9%88%DB%8C%D8%AA_%D9%85%D8%AD%D9%84%DB%8C\" >4. \u0633\u0631\u0648\u06cc\u0633 \u0628\u0631\u0627\u06cc \u0627\u062d\u0631\u0627\u0632 \u0647\u0648\u06cc\u062a \u0645\u062d\u0644\u06cc<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/nabfollower.com\/blog\/how-can-you-implement-a-conditional-login-mechanism-between-ldap-and-local-database-using-spring-boot-5glm\/#5_LdapService_%D8%B1%D8%A7_%D8%AA%D8%BA%DB%8C%DB%8C%D8%B1_%D8%AF%D9%87%DB%8C%D8%AF_%D8%AA%D8%A7_%D8%B4%D8%A7%D9%85%D9%84_%D8%A8%D8%B1%D8%B1%D8%B3%DB%8C_%D8%B3%D9%84%D8%A7%D9%85%D8%AA_%D8%B4%D9%88%D8%AF\" >5. LdapService \u0631\u0627 \u062a\u063a\u06cc\u06cc\u0631 \u062f\u0647\u06cc\u062f \u062a\u0627 \u0634\u0627\u0645\u0644 \u0628\u0631\u0631\u0633\u06cc \u0633\u0644\u0627\u0645\u062a \u0634\u0648\u062f:<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/nabfollower.com\/blog\/how-can-you-implement-a-conditional-login-mechanism-between-ldap-and-local-database-using-spring-boot-5glm\/#6_%DA%A9%D9%86%D8%AA%D8%B1%D9%84_%DA%A9%D9%86%D9%86%D8%AF%D9%87_%D8%B1%D8%A7_%D8%A8%D8%B1%D8%A7%DB%8C_%D9%BE%DB%8C%D8%A7%D8%AF%D9%87_%D8%B3%D8%A7%D8%B2%DB%8C_%D9%88%D8%B1%D9%88%D8%AF_%D8%B4%D8%B1%D8%B7%DB%8C_%D8%AA%D8%BA%DB%8C%DB%8C%D8%B1_%D8%AF%D9%87%DB%8C%D8%AF\" >6. \u06a9\u0646\u062a\u0631\u0644 \u06a9\u0646\u0646\u062f\u0647 \u0631\u0627 \u0628\u0631\u0627\u06cc \u067e\u06cc\u0627\u062f\u0647 \u0633\u0627\u0632\u06cc \u0648\u0631\u0648\u062f \u0634\u0631\u0637\u06cc \u062a\u063a\u06cc\u06cc\u0631 \u062f\u0647\u06cc\u062f<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/nabfollower.com\/blog\/how-can-you-implement-a-conditional-login-mechanism-between-ldap-and-local-database-using-spring-boot-5glm\/#%D8%AA%D9%88%D8%B6%DB%8C%D8%AD\" >\u062a\u0648\u0636\u06cc\u062d:<\/a><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"1_%D8%A7%D9%81%D8%B2%D9%88%D8%AF%D9%86_%D9%88%D8%A7%D8%A8%D8%B3%D8%AA%DA%AF%DB%8C_%D9%87%D8%A7\"><\/span>\n<p>  1. \u0627\u0641\u0632\u0648\u062f\u0646 \u0648\u0627\u0628\u0633\u062a\u06af\u06cc \u0647\u0627:<br \/>\n<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>\u062f\u0631 \u0627\u06cc\u0646\u062c\u0627 \u0645\u0646 Maven \u0631\u0627 \u0628\u0647 \u0639\u0646\u0648\u0627\u0646 \u0627\u0628\u0632\u0627\u0631 \u0633\u0627\u062e\u062a \u062f\u0631 \u0646\u0638\u0631 \u0645\u06cc\u200c\u06af\u06cc\u0631\u0645. \u0645\u0637\u0645\u0626\u0646 \u0634\u0648\u06cc\u062f \u06a9\u0647 \u0648\u0627\u0628\u0633\u062a\u06af\u06cc\u200c\u0647\u0627\u06cc \u0632\u06cc\u0631 \u0631\u0627 \u062f\u0631 \u062e\u0648\u062f \u062f\u0627\u0631\u06cc\u062f<br \/>pom.xml<br \/>\u0641\u0627\u06cc\u0644:<\/p>\n<p><code><dependencies><!-- Spring Boot and Web --><dependency><groupid>org.springframework.boot<\/groupid><artifactid>spring-boot-starter-web<\/artifactid><\/dependency><!-- Spring Boot and Data JPA --><dependency><groupid>org.springframework.boot<\/groupid><artifactid>spring-boot-starter-data-jpa<\/artifactid><\/dependency><!-- PostgreSQL Driver --><dependency><groupid>org.postgresql<\/groupid><artifactid>postgresql<\/artifactid><scope>runtime<\/scope><\/dependency><!-- Spring Boot LDAP --><dependency><groupid>org.springframework.boot<\/groupid><artifactid>spring-boot-starter-ldap<\/artifactid><\/dependency><!-- Spring Boot Actuator (Optional) --><dependency><groupid>org.springframework.boot<\/groupid><artifactid>spring-boot-starter-actuator<\/artifactid><\/dependency><\/dependencies><\/code><\/p>\n<h2><span class=\"ez-toc-section\" id=\"2_%D9%88%DB%8C%DA%98%DA%AF%DB%8C_%D9%87%D8%A7%DB%8C_%D8%A8%D8%B1%D9%86%D8%A7%D9%85%D9%87_%D8%B1%D8%A7_%D9%BE%DB%8C%DA%A9%D8%B1%D8%A8%D9%86%D8%AF%DB%8C_%DA%A9%D9%86%DB%8C%D8%AF\"><\/span>\n<p>  2. \u0648\u06cc\u0698\u06af\u06cc \u0647\u0627\u06cc \u0628\u0631\u0646\u0627\u0645\u0647 \u0631\u0627 \u067e\u06cc\u06a9\u0631\u0628\u0646\u062f\u06cc \u06a9\u0646\u06cc\u062f<br \/>\n<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>\u0648\u06cc\u0698\u06af\u06cc \u0647\u0627\u06cc \u0644\u0627\u0632\u0645 \u0631\u0627 \u062f\u0631 application.properties \u062a\u0646\u0638\u06cc\u0645 \u06a9\u0646\u06cc\u062f:<\/p>\n<div class=\"highlight js-code-highlight\">\n<pre class=\"highlight plaintext\"><code># LDAP Server Configuration\nldap.url=ldap:\/\/url:389\nldap.admin.dn=cn=admin,dc=urdc,dc=urdc\nldap.admin.password=ldappassword\nldap.search.base=dc=cspurdc,dc=csp\n\n# PostgreSQL Configuration\nspring.datasource.url=jdbc:postgresql:\/\/localhost:5432\/yourdb\nspring.datasource.username=yourusername\nspring.datasource.password=yourpassword\nspring.datasource.driver-class-name=org.postgresql.Driver\nspring.jpa.hibernate.ddl-auto=update\n\n# User Authentication Configuration\nuser.samaccountname=username\nuser.password=ldappassword\n<\/code><\/pre>\n<div class=\"highlight__panel js-actions-panel\">\n<div class=\"highlight__panel-action js-fullscreen-code-action\">\n    <svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"><title>\u0648\u0627\u0631\u062f \u062d\u0627\u0644\u062a \u062a\u0645\u0627\u0645 \u0635\u0641\u062d\u0647 \u0634\u0648\u06cc\u062f<\/title>\n    <path d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\/>\n<\/svg><\/p>\n<p>    <svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"><title>\u0627\u0632 \u062d\u0627\u0644\u062a \u062a\u0645\u0627\u0645 \u0635\u0641\u062d\u0647 \u062e\u0627\u0631\u062c \u0634\u0648\u06cc\u062f<\/title>\n    <path d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\/>\n<\/svg><\/p>\n<\/div>\n<\/div>\n<\/div>\n<h2><span class=\"ez-toc-section\" id=\"3_Entity_%D9%88_Repository_%DA%A9%D8%A7%D8%B1%D8%A8%D8%B1_%D8%A8%D8%B1%D8%A7%DB%8C_PostgreSQL_%D8%A7%DB%8C%D8%AC%D8%A7%D8%AF_%DA%A9%D9%86%DB%8C%D8%AF\"><\/span>\n<p>  3. Entity \u0648 Repository \u06a9\u0627\u0631\u0628\u0631 \u0628\u0631\u0627\u06cc PostgreSQL \u0627\u06cc\u062c\u0627\u062f \u06a9\u0646\u06cc\u062f<br \/>\n<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>\u06cc\u06a9 \u0645\u0648\u062c\u0648\u062f\u06cc\u062a \u06a9\u0627\u0631\u0628\u0631 \u0648 \u0645\u062e\u0632\u0646 \u0633\u0627\u062f\u0647 \u0628\u0631\u0627\u06cc \u067e\u0627\u06cc\u06af\u0627\u0647 \u062f\u0627\u062f\u0647 PostgreSQL \u062a\u0639\u0631\u06cc\u0641 \u06a9\u0646\u06cc\u062f. <strong>User.java<\/strong><\/p>\n<div class=\"highlight js-code-highlight\">\n<pre class=\"highlight plaintext\"><code>package com.example.ldapauth.entity;\nimport javax.persistence.Entity;\nimport javax.persistence.GeneratedValue;\nimport javax.persistence.GenerationType;\nimport javax.persistence.Id;\n@Entity\npublic class User {\n    @Id\n    @GeneratedValue(strategy = GenerationType.AUTO)\n    private Long id;\n    private String username;\n    private String password;\n    \/\/ Getters and Setters\n    public Long getId() {\n        return id;\n    }\n    public void setId(Long id) {\n        this.id = id;\n    }\n    public String getUsername() {\n        return username;\n    }\n    public void setUsername(String username) {\n        this.username = username;\n    }\n    public String getPassword() {\n        return password;\n    }\n    public void setPassword(String password) {\n        this.password = password;\n    }\n}\n\n<\/code><\/pre>\n<div class=\"highlight__panel js-actions-panel\">\n<div class=\"highlight__panel-action js-fullscreen-code-action\">\n    <svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"><title>\u0648\u0627\u0631\u062f \u062d\u0627\u0644\u062a \u062a\u0645\u0627\u0645 \u0635\u0641\u062d\u0647 \u0634\u0648\u06cc\u062f<\/title>\n    <path d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\/>\n<\/svg><\/p>\n<p>    <svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"><title>\u0627\u0632 \u062d\u0627\u0644\u062a \u062a\u0645\u0627\u0645 \u0635\u0641\u062d\u0647 \u062e\u0627\u0631\u062c \u0634\u0648\u06cc\u062f<\/title>\n    <path d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\/>\n<\/svg><\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><strong>UserRepository.java<\/strong><\/p>\n<div class=\"highlight js-code-highlight\">\n<pre class=\"highlight plaintext\"><code>package com.example.ldapauth.repository;\n\nimport com.example.ldapauth.entity.User;\nimport org.springframework.data.jpa.repository.JpaRepository;\nimport org.springframework.stereotype.Repository;\n\n@Repository\npublic interface UserRepository extends JpaRepository<user long=\"\"> {\n    User findByUsername(String username);\n}\n<\/user><\/code><\/pre>\n<div class=\"highlight__panel js-actions-panel\">\n<div class=\"highlight__panel-action js-fullscreen-code-action\">\n    <svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"><title>\u0648\u0627\u0631\u062f \u062d\u0627\u0644\u062a \u062a\u0645\u0627\u0645 \u0635\u0641\u062d\u0647 \u0634\u0648\u06cc\u062f<\/title>\n    <path d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\/>\n<\/svg><\/p>\n<p>    <svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"><title>\u0627\u0632 \u062d\u0627\u0644\u062a \u062a\u0645\u0627\u0645 \u0635\u0641\u062d\u0647 \u062e\u0627\u0631\u062c \u0634\u0648\u06cc\u062f<\/title>\n    <path d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\/>\n<\/svg><\/p>\n<\/div>\n<\/div>\n<\/div>\n<h3><span class=\"ez-toc-section\" id=\"4_%D8%B3%D8%B1%D9%88%DB%8C%D8%B3_%D8%A8%D8%B1%D8%A7%DB%8C_%D8%A7%D8%AD%D8%B1%D8%A7%D8%B2_%D9%87%D9%88%DB%8C%D8%AA_%D9%85%D8%AD%D9%84%DB%8C\"><\/span>\n<p>  4. \u0633\u0631\u0648\u06cc\u0633 \u0628\u0631\u0627\u06cc \u0627\u062d\u0631\u0627\u0632 \u0647\u0648\u06cc\u062a \u0645\u062d\u0644\u06cc<br \/>\n<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\u0633\u0631\u0648\u06cc\u0633\u06cc \u0627\u0636\u0627\u0641\u0647 \u06a9\u0646\u06cc\u062f \u062a\u0627 \u0627\u062d\u0631\u0627\u0632 \u0647\u0648\u06cc\u062a \u067e\u0627\u06cc\u06af\u0627\u0647 \u062f\u0627\u062f\u0647 \u0645\u062d\u0644\u06cc \u0631\u0627 \u06a9\u0646\u062a\u0631\u0644 \u06a9\u0646\u062f.<br \/><strong>LocalAuthService.java<\/strong><\/p>\n<div class=\"highlight js-code-highlight\">\n<pre class=\"highlight plaintext\"><code>package com.example.ldapauth.service;\n\nimport com.example.ldapauth.entity.User;\nimport com.example.ldapauth.repository.UserRepository;\nimport org.springframework.beans.factory.annotation.Autowired;\nimport org.springframework.stereotype.Service;\n\n@Service\npublic class LocalAuthService {\n\n    @Autowired\n    private UserRepository userRepository;\n\n    public boolean authenticate(String username, String password) {\n        User user = userRepository.findByUsername(username);\n        return user != null &amp;&amp; user.getPassword().equals(password);\n    }\n}\n<\/code><\/pre>\n<div class=\"highlight__panel js-actions-panel\">\n<div class=\"highlight__panel-action js-fullscreen-code-action\">\n    <svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"><title>\u0648\u0627\u0631\u062f \u062d\u0627\u0644\u062a \u062a\u0645\u0627\u0645 \u0635\u0641\u062d\u0647 \u0634\u0648\u06cc\u062f<\/title>\n    <path d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\/>\n<\/svg><\/p>\n<p>    <svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"><title>\u0627\u0632 \u062d\u0627\u0644\u062a \u062a\u0645\u0627\u0645 \u0635\u0641\u062d\u0647 \u062e\u0627\u0631\u062c \u0634\u0648\u06cc\u062f<\/title>\n    <path d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\/>\n<\/svg><\/p>\n<\/div>\n<\/div>\n<\/div>\n<h2><span class=\"ez-toc-section\" id=\"5_LdapService_%D8%B1%D8%A7_%D8%AA%D8%BA%DB%8C%DB%8C%D8%B1_%D8%AF%D9%87%DB%8C%D8%AF_%D8%AA%D8%A7_%D8%B4%D8%A7%D9%85%D9%84_%D8%A8%D8%B1%D8%B1%D8%B3%DB%8C_%D8%B3%D9%84%D8%A7%D9%85%D8%AA_%D8%B4%D9%88%D8%AF\"><\/span>\n<p>  5. LdapService \u0631\u0627 \u062a\u063a\u06cc\u06cc\u0631 \u062f\u0647\u06cc\u062f \u062a\u0627 \u0634\u0627\u0645\u0644 \u0628\u0631\u0631\u0633\u06cc \u0633\u0644\u0627\u0645\u062a \u0634\u0648\u062f:<br \/>\n<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>\u0631\u0648\u0634\u06cc \u0628\u0631\u0627\u06cc \u0628\u0631\u0631\u0633\u06cc \u062f\u0631 \u062f\u0633\u062a\u0631\u0633 \u0628\u0648\u062f\u0646 \u0633\u0631\u0648\u0631 LDAP \u0627\u0636\u0627\u0641\u0647 \u06a9\u0646\u06cc\u062f.<br \/><strong>LdapService.java<\/strong><\/p>\n<div class=\"highlight js-code-highlight\">\n<pre class=\"highlight plaintext\"><code>package com.example.ldapauth.service;\n\nimport org.springframework.beans.factory.annotation.Autowired;\nimport org.springframework.beans.factory.annotation.Value;\nimport org.springframework.ldap.support.LdapUtils;\nimport org.springframework.stereotype.Service;\n\nimport javax.naming.Context;\nimport javax.naming.NamingEnumeration;\nimport javax.naming.NamingException;\nimport javax.naming.directory.*;\nimport java.util.Hashtable;\n\n@Service\npublic class LdapService {\n\n    @Autowired\n    private DirContext ldapContext;\n\n    @Value(\"${ldap.search.base}\")\n    private String searchBase;\n\n    @Value(\"${user.samaccountname}\")\n    private String sAMAccountName;\n\n    @Value(\"${user.password}\")\n    private String userPassword;\n\n    public boolean isLdapAvailable() {\n        try {\n            \/\/ Try a no-op search to check server availability\n            NamingEnumeration<searchresult> results = ldapContext.search(\"\", \"(objectClass=*)\", new SearchControls());\n            return results != null;  \/\/ If this does not throw an exception, LDAP is available\n        } catch (NamingException e) {\n            return false; \/\/ LDAP is not available\n        }\n    }\n\n    public String getUserDn(String username) {\n        try {\n            String searchFilter = \"(sAMAccountName=\" + username + \")\";\n            SearchControls searchControls = new SearchControls();\n            searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);\n            NamingEnumeration<searchresult> results = ldapContext.search(searchBase, searchFilter, searchControls);\n\n            if (results.hasMore()) {\n                SearchResult searchResult = results.next();\n                return searchResult.getNameInNamespace();\n            }\n        } catch (NamingException e) {\n            e.printStackTrace();\n        }\n        return null;\n    }\n\n    public boolean authenticateUser(String userDn, String password) {\n        if (userDn == null) {\n            System.out.println(\"User authentication failed: User DN not found.\");\n            return false;\n        }\n\n        try {\n            Hashtable<string string=\"\"> env = new Hashtable();\n            env.put(Context.INITIAL_CONTEXT_FACTORY, \"com.sun.jndi.ldap.LdapCtxFactory\");\n            env.put(Context.PROVIDER_URL, ldapContext.getEnvironment().get(Context.PROVIDER_URL).toString());\n            env.put(Context.SECURITY_AUTHENTICATION, \"simple\");\n            env.put(Context.SECURITY_PRINCIPAL, userDn);\n            env.put(Context.SECURITY_CREDENTIALS, password);\n\n            DirContext ctx = new InitialDirContext(env);\n            ctx.close();\n            System.out.println(\"User authentication successful.\");\n            return true;\n        } catch (NamingException e) {\n            System.out.println(\"User authentication failed: \" + e.getMessage());\n            return false;\n        }\n    }\n}\n<\/string><\/searchresult><\/searchresult><\/code><\/pre>\n<div class=\"highlight__panel js-actions-panel\">\n<div class=\"highlight__panel-action js-fullscreen-code-action\">\n    <svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"><title>\u0648\u0627\u0631\u062f \u062d\u0627\u0644\u062a \u062a\u0645\u0627\u0645 \u0635\u0641\u062d\u0647 \u0634\u0648\u06cc\u062f<\/title>\n    <path d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\/>\n<\/svg><\/p>\n<p>    <svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"><title>\u0627\u0632 \u062d\u0627\u0644\u062a \u062a\u0645\u0627\u0645 \u0635\u0641\u062d\u0647 \u062e\u0627\u0631\u062c \u0634\u0648\u06cc\u062f<\/title>\n    <path d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\/>\n<\/svg><\/p>\n<\/div>\n<\/div>\n<\/div>\n<h2><span class=\"ez-toc-section\" id=\"6_%DA%A9%D9%86%D8%AA%D8%B1%D9%84_%DA%A9%D9%86%D9%86%D8%AF%D9%87_%D8%B1%D8%A7_%D8%A8%D8%B1%D8%A7%DB%8C_%D9%BE%DB%8C%D8%A7%D8%AF%D9%87_%D8%B3%D8%A7%D8%B2%DB%8C_%D9%88%D8%B1%D9%88%D8%AF_%D8%B4%D8%B1%D8%B7%DB%8C_%D8%AA%D8%BA%DB%8C%DB%8C%D8%B1_%D8%AF%D9%87%DB%8C%D8%AF\"><\/span>\n<p>  6. \u06a9\u0646\u062a\u0631\u0644 \u06a9\u0646\u0646\u062f\u0647 \u0631\u0627 \u0628\u0631\u0627\u06cc \u067e\u06cc\u0627\u062f\u0647 \u0633\u0627\u0632\u06cc \u0648\u0631\u0648\u062f \u0634\u0631\u0637\u06cc \u062a\u063a\u06cc\u06cc\u0631 \u062f\u0647\u06cc\u062f<br \/>\n<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><strong>LdapController.java<\/strong><\/p>\n<div class=\"highlight js-code-highlight\">\n<pre class=\"highlight plaintext\"><code>package com.example.ldapauth.controller;\n\nimport com.example.ldapauth.service.LdapService;\nimport com.example.ldapauth.service.LocalAuthService;\nimport org.springframework.beans.factory.annotation.Autowired;\nimport org.springframework.web.bind.annotation.PostMapping;\nimport org.springframework.web.bind.annotation.RequestParam;\nimport org.springframework.web.bind.annotation.RestController;\n\n@RestController\npublic class LdapController {\n\n    @Autowired\n    private LdapService ldapService;\n\n    @Autowired\n    private LocalAuthService localAuthService;\n\n    @PostMapping(\"\/login\")\n    public String performLogin(@RequestParam String username, @RequestParam String password) {\n        if (ldapService.isLdapAvailable()) {\n            String userDn = ldapService.getUserDn(username);\n            boolean isAuthenticated = ldapService.authenticateUser(userDn, password);\n            if (isAuthenticated) {\n                return \"LDAP authentication successful!\";\n            }\n        }\n\n        boolean isLocalAuthenticated = localAuthService.authenticate(username, password);\n        if (isLocalAuthenticated) {\n            return \"Local authentication successful!\";\n        }\n\n        return \"Authentication failed!\";\n    }\n}\n<\/code><\/pre>\n<div class=\"highlight__panel js-actions-panel\">\n<div class=\"highlight__panel-action js-fullscreen-code-action\">\n    <svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"><title>\u0648\u0627\u0631\u062f \u062d\u0627\u0644\u062a \u062a\u0645\u0627\u0645 \u0635\u0641\u062d\u0647 \u0634\u0648\u06cc\u062f<\/title>\n    <path d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\/>\n<\/svg><\/p>\n<p>    <svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"><title>\u0627\u0632 \u062d\u0627\u0644\u062a \u062a\u0645\u0627\u0645 \u0635\u0641\u062d\u0647 \u062e\u0627\u0631\u062c \u0634\u0648\u06cc\u062f<\/title>\n    <path d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\/>\n<\/svg><\/p>\n<\/div>\n<\/div>\n<\/div>\n<h2><span class=\"ez-toc-section\" id=\"%D8%AA%D9%88%D8%B6%DB%8C%D8%AD\"><\/span>\n<p>  \u062a\u0648\u0636\u06cc\u062d:<br \/>\n<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<ol>\n<li>\u0628\u0631\u0631\u0633\u06cc \u062f\u0631 \u062f\u0633\u062a\u0631\u0633 \u0628\u0648\u062f\u0646 LDAP: \u0631\u0648\u0634 isLdapAvailable \u062f\u0631 LdapService \u06cc\u06a9 \u062c\u0633\u062a\u062c\u0648\u06cc \u0633\u0627\u062e\u062a\u06af\u06cc LDAP \u0631\u0627 \u0628\u0631\u0627\u06cc \u0628\u0631\u0631\u0633\u06cc \u0627\u06cc\u0646\u06a9\u0647 \u0622\u06cc\u0627 \u0633\u0631\u0648\u0631 LDAP \u062f\u0631 \u062f\u0633\u062a\u0631\u0633 \u0627\u0633\u062a \u0627\u0646\u062c\u0627\u0645 \u0645\u06cc \u062f\u0647\u062f.<\/li>\n<li>\u0645\u0646\u0637\u0642 \u0648\u0631\u0648\u062f \u0634\u0631\u0637\u06cc: \u062f\u0631 LdapController\u060c \u0646\u0642\u0637\u0647 \u067e\u0627\u06cc\u0627\u0646\u06cc \/login \u062f\u0631 \u062f\u0633\u062a\u0631\u0633 \u0628\u0648\u062f\u0646 LDAP \u0631\u0627 \u0628\u0631\u0631\u0633\u06cc \u0645\u06cc \u06a9\u0646\u062f.  \u0627\u06af\u0631 LDAP \u062f\u0631 \u062f\u0633\u062a\u0631\u0633 \u0628\u0627\u0634\u062f\u060c \u0633\u0639\u06cc \u0645\u06cc \u06a9\u0646\u062f \u06a9\u0627\u0631\u0628\u0631 \u0631\u0627 \u0628\u0627 LDAP \u0627\u062d\u0631\u0627\u0632 \u0647\u0648\u06cc\u062a \u06a9\u0646\u062f.  \u0627\u06af\u0631 \u0627\u062d\u0631\u0627\u0632 \u0647\u0648\u06cc\u062a LDAP \u0646\u0627\u0645\u0648\u0641\u0642 \u0628\u0627\u0634\u062f \u06cc\u0627 LDAP \u062f\u0631 \u062f\u0633\u062a\u0631\u0633 \u0646\u0628\u0627\u0634\u062f\u060c \u0628\u0627 \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0627\u0632 LocalAuthService \u0628\u0647 \u0627\u062d\u0631\u0627\u0632 \u0647\u0648\u06cc\u062a \u067e\u0627\u06cc\u06af\u0627\u0647 \u062f\u0627\u062f\u0647 PostgreSQL \u0645\u062d\u0644\u06cc \u0628\u0627\u0632\u0645\u06cc \u06af\u0631\u062f\u062f.<\/li>\n<li>\u0627\u062d\u0631\u0627\u0632 \u0647\u0648\u06cc\u062a \u0645\u062d\u0644\u06cc: \u0627\u06af\u0631 LDAP \u062f\u0631 \u062f\u0633\u062a\u0631\u0633 \u0646\u0628\u0627\u0634\u062f \u06cc\u0627 \u06a9\u0627\u0631\u0628\u0631 \u062f\u0631 \u062a\u0623\u06cc\u06cc\u062f \u0627\u0639\u062a\u0628\u0627\u0631 LDAP \u0646\u0627\u0645\u0648\u0641\u0642 \u0628\u0627\u0634\u062f\u060c \u067e\u0627\u06cc\u06af\u0627\u0647 \u062f\u0627\u062f\u0647 \u0645\u062d\u0644\u06cc PostgreSQL \u0631\u0627 \u0628\u0631\u0627\u06cc \u0627\u0639\u062a\u0628\u0627\u0631 \u06a9\u0627\u0631\u0628\u0631 \u0628\u0627 \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0627\u0632 UserRepository \u0628\u0631\u0631\u0633\u06cc \u0645\u06cc \u06a9\u0646\u062f.<\/li>\n<li>\u06a9\u0646\u062a\u0631\u0644\u0631 REST: @PostMapping \u062f\u0631 \u0646\u0642\u0637\u0647 \u067e\u0627\u06cc\u0627\u0646\u06cc \/login \u062f\u0631\u062e\u0648\u0627\u0633\u062a\u200c\u0647\u0627\u06cc \u0648\u0631\u0648\u062f \u0631\u0627 \u0645\u062f\u06cc\u0631\u06cc\u062a \u0645\u06cc\u200c\u06a9\u0646\u062f \u0648 \u0645\u0646\u0637\u0642 \u0634\u0631\u0637\u06cc \u0631\u0627 \u0628\u0631\u0627\u06cc \u0627\u062d\u0631\u0627\u0632 \u0647\u0648\u06cc\u062a \u0627\u0639\u0645\u0627\u0644 \u0645\u06cc\u200c\u06a9\u0646\u062f.<\/li>\n<\/ol>\n<p>\u0627\u06cc\u0646 \u062a\u0646\u0638\u06cc\u0645\u0627\u062a \u0645\u06a9\u0627\u0646\u06cc\u0632\u0645\u06cc \u0642\u0648\u06cc \u0628\u0631\u0627\u06cc \u062c\u0627\u0628\u062c\u0627\u06cc\u06cc \u0628\u06cc\u0646 LDAP \u0648 \u0627\u062d\u0631\u0627\u0632 \u0647\u0648\u06cc\u062a \u0645\u062d\u0644\u06cc \u0628\u0631 \u0627\u0633\u0627\u0633 \u062f\u0631 \u062f\u0633\u062a\u0631\u0633 \u0628\u0648\u062f\u0646 \u0633\u0631\u0648\u0631 LDAP \u0641\u0631\u0627\u0647\u0645 \u0645\u06cc \u06a9\u0646\u062f.<\/p>\n<p>\u0627\u0645\u06cc\u062f\u0648\u0627\u0631\u0645 \u0627\u06cc\u0646 \u0645\u0641\u06cc\u062f \u0628\u0648\u062f\u0647 \u0628\u0627\u0634\u0647 \u0628\u0686\u0647 \u0647\u0627  \u0644\u0637\u0641\u0627\u064b \u062a\u0648\u062c\u0647 \u062f\u0627\u0634\u062a\u0647 \u0628\u0627\u0634\u06cc\u062f \u06a9\u0647 \u0628\u0627\u06cc\u062f \u0686\u0646\u062f \u0686\u06cc\u0632 \u0631\u0627 \u0628\u0631 \u0627\u0633\u0627\u0633 \u0646\u06cc\u0627\u0632\u0647\u0627 \u0648 \u0645\u0646\u0637\u0642 \u062e\u0648\u062f \u062a\u063a\u06cc\u06cc\u0631 \u062f\u0647\u06cc\u062f.  \u0645\u0646 \u062f\u0631 \u0627\u06cc\u0646\u062c\u0627 \u0641\u0642\u0637 \u0627\u06cc\u062f\u0647 \u06a9\u0644\u06cc \u062f\u0627\u062f\u0647 \u0627\u0645. <\/p>\n<p>\u06a9\u062f \u0646\u0648\u06cc\u0633\u06cc \u0645\u0628\u0627\u0631\u06a9 \ud83d\ude42 <\/p>\n<p>\u0628\u0627 \u062a\u0634\u06a9\u0631\u060c<br \/>\u062c\u0627\u0648\u0627\u0686\u0627\u0631\u062a\u0631<br \/>\u06a9\u0627\u06cc\u0644\u0627\u0634 \u0646\u06cc\u0631\u0645\u0627\u0644<br \/>\u0646\u0648\u0634\u062a\u0647 \u0634\u062f\u0647 \u062f\u0631 : 5 \u062c\u0648\u0644\u0627\u06cc 2024.<\/p>\n<\/p><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Summarize this content to 400 words in Persian Lang \u0627\u062c\u0631\u0627\u06cc \u06cc\u06a9 \u0645\u06a9\u0627\u0646\u06cc\u0632\u0645 \u0648\u0631\u0648\u062f \u0628\u0647 \u0633\u06cc\u0633\u062a\u0645 \u0634\u0631\u0637\u06cc \u062f\u0631 Spring Boot \u06a9\u0647 \u0628\u0647 \u0637\u0648\u0631 \u06cc\u06a9\u067e\u0627\u0631\u0686\u0647 \u0628\u06cc\u0646 \u0627\u062d\u0631\u0627\u0632 \u0647\u0648\u06cc\u062a LDAP \u0648 \u0627\u062d\u0631\u0627\u0632 \u0647\u0648\u06cc\u062a \u067e\u0627\u06cc\u06af\u0627\u0647 \u062f\u0627\u062f\u0647 \u0645\u062d\u0644\u06cc \u0628\u0631 \u0627\u0633\u0627\u0633 \u062f\u0631 \u062f\u0633\u062a\u0631\u0633 \u0628\u0648\u062f\u0646 \u0633\u0631\u0648\u0631 LDAP \u0633\u0648\u0626\u06cc\u0686 \u0645\u06cc \u06a9\u0646\u062f\u060c \u06cc\u06a9 \u062c\u0646\u0628\u0647 \u062d\u06cc\u0627\u062a\u06cc \u0628\u0631\u0627\u06cc \u0627\u0637\u0645\u06cc\u0646\u0627\u0646 \u0627\u0632 \u062f\u0633\u062a\u0631\u0633\u06cc \u0628\u062f\u0648\u0646 \u0648\u0642\u0641\u0647 \u0628\u0647 \u0628\u0631\u0646\u0627\u0645\u0647 \u0634\u0645\u0627 &hellip;<\/p>\n","protected":false},"author":2,"featured_media":68229,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"fifu_image_url":"","fifu_image_alt":"","footnotes":""},"categories":[339],"tags":[],"class_list":["post-68228","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dev"],"_links":{"self":[{"href":"https:\/\/nabfollower.com\/blog\/wp-json\/wp\/v2\/posts\/68228","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nabfollower.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nabfollower.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nabfollower.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/nabfollower.com\/blog\/wp-json\/wp\/v2\/comments?post=68228"}],"version-history":[{"count":0,"href":"https:\/\/nabfollower.com\/blog\/wp-json\/wp\/v2\/posts\/68228\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/nabfollower.com\/blog\/wp-json\/wp\/v2\/media\/68229"}],"wp:attachment":[{"href":"https:\/\/nabfollower.com\/blog\/wp-json\/wp\/v2\/media?parent=68228"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nabfollower.com\/blog\/wp-json\/wp\/v2\/categories?post=68228"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nabfollower.com\/blog\/wp-json\/wp\/v2\/tags?post=68228"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}