Having a significant issue, I've been stuck for days trying to figure out how to make my login app functional. I need it to send the username and password to Spring Boot for validation. Although I have the basic setup in place using Spring Boot's loginForm, I'm quite new to programming with Spring Boot as I was previously working with NodeJS. My aim is to authenticate users via LDAP in the backend using Spring Security instead of Pure Java (which would be simpler). This involves handling HTTP Requests (Endpoints).
Here's what I currently have:
// WebSecurityConfiguration
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.anyRequest().fullyAuthenticated()
.and()
.formLogin()
.loginPage("/test").permitAll()
.usernameParameter("_username_")
.passwordParameter("_password_")
.and()
.csrf()
.csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse());
}
@Override
public void configure(AuthenticationManagerBuilder auth) throws Exception {
auth
.ldapAuthentication()
.userDnPatterns("uid={0},ou=people")
.groupSearchBase("ou=groups")
.contextSource()
.url("ldap://localhost:8389/dc=springframework,dc=org")
.and()
.passwordCompare()
.passwordEncoder(new LdapShaPasswordEncoder())
.passwordAttribute("userPassword");
}
@Bean
public DefaultSpringSecurityContextSource contextSource() {
return new DefaultSpringSecurityContextSource(Arrays.asList("ldap://localhost:8389/"), "dc=springframework,cd=org");
}
I opted to use Gradle due to company standards, so here's the build.gradle:
// build.gradle
plugins {
id 'org.springframework.boot' version '2.1.2.RELEASE'
id 'java'
}
apply plugin: 'io.spring.dependency-management'
group = 'net.company'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-ldap'
// other dependencies...
}
Below is my current app.component.ts where I imported HttpClientModule and added it to imports:
// app.component.ts
import {Component} from '@angular/core';
import {HttpClient} from '@angular/common/http';
// rest of the code...
// login.component.html
<div id="container"
fxLayout="column"
fxLayoutAlign="start center">
<div class="spacer" fxFlex="10%"></div>
<div id="login" fxFlex="25%"
fxLayout="column"
fxLayoutAlign="start center">
<h1 id="loginTitle" fxFlex="35%">LOGIN</h1>
// form structure...
</div>
// more template code...
</div>
For those requiring information on LDAP configurations, refer to application.properties:
// application.properties
spring.ldap.embedded.ldif=classpath:test-server.ldif
spring.ldap.embedded.base-dn=dc=springframework,dc=org
spring.ldap.embedded.port=8389
server.servlet.context-path=/
server.port=8082
If more details or files are needed, feel free to reach out. I'll update this post once a solution is found for better understanding by beginners.