Skip to content

Commit 19dcc60

Browse files
Completed authentication and tested inside docker-compose
1 parent 2c26bd0 commit 19dcc60

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

api/routes/routes.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,20 @@ import (
44
"net/http"
55

66
"github.com/PythonHacker24/linux-acl-management-backend/api/middleware"
7+
"github.com/PythonHacker24/linux-acl-management-backend/internal/auth"
78
"github.com/PythonHacker24/linux-acl-management-backend/internal/health"
89
)
910

11+
/* all routes for all features are registered here */
1012
func RegisterRoutes(mux *http.ServeMux) {
13+
14+
/* for monitoring the state of overall server and laclm backend */
1115
mux.Handle("GET /health", http.HandlerFunc(
1216
middleware.LoggingMiddleware(health.HealthHandler),
1317
))
18+
19+
/* for logging into the backend and creating a session */
20+
mux.Handle("POST /login", http.HandlerFunc(
21+
middleware.LoggingMiddleware(auth.LoginHandler),
22+
))
1423
}

config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ filesystem_servers:
3434
# authentication information
3535
authentication:
3636
ldap:
37-
tls: true
38-
address: "ldaps://openldap" # Use the service name from docker-compose
37+
tls: false
38+
address: "ldap://openldap:389" # Use the service name from docker-compose
3939
admin_dn: ${LACLM_LDAP_ADMIN_DN}
4040
admin_password: ${LACLM_LDAP_ADMIN_PASSWORD}
41-
search_base: "ou=users,dc=example,dc=com"
41+
search_base: "cn=Princeton Plainsboro Hospital,dc=myorg,dc=local"
4242

4343
backend_security:
4444
jwt_secret_token: ${JWT_SECRET_TOKEN}

internal/auth/ldap.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package auth
22

33
import (
4-
"os"
54
"crypto/tls"
65
"fmt"
76

@@ -29,7 +28,7 @@ func AuthenticateUser(username, password, searchbase string) bool {
2928
l, err = ldap.DialURL(ldapAddress, ldap.DialWithTLSConfig(&tls.Config{
3029

3130
/* true if using self-signed certs (not recommended) */
32-
InsecureSkipVerify: false,
31+
InsecureSkipVerify: true,
3332
}))
3433
} else {
3534
l, err = ldap.DialURL(ldapAddress)
@@ -43,12 +42,10 @@ func AuthenticateUser(username, password, searchbase string) bool {
4342
}
4443
defer l.Close()
4544

46-
/* securely fetch LDAP credentials from the environment */
47-
adminDN := os.Getenv("LDAP_ADMIN_DN")
48-
adminPassword := os.Getenv("LDAP_ADMIN_PASSWORD")
49-
5045
/* authenticating with the ldap server with admin */
51-
err = l.Bind(adminDN, adminPassword)
46+
err = l.Bind(config.BackendConfig.Authentication.LDAPConfig.AdminDN,
47+
config.BackendConfig.Authentication.LDAPConfig.AdminPassword,
48+
)
5249
if err != nil {
5350
zap.L().Error("Admin authentication failed",
5451
zap.Error(err),
@@ -62,7 +59,8 @@ func AuthenticateUser(username, password, searchbase string) bool {
6259
ldap.ScopeWholeSubtree, ldap.NeverDerefAliases, 0, 0, false,
6360

6461
/* Searching by username */
65-
fmt.Sprintf("(uid=%s)", username),
62+
/* for uid -> fmt.Sprintf("(uid=%s)", username), */
63+
fmt.Sprintf("(cn=%s)", username),
6664

6765
/* We only need the DN */
6866
[]string{"dn"},

0 commit comments

Comments
 (0)