Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Haskell: LDAP Authentication

Tags:

haskell

I am trying to write a simple function that would bind to LDAP server and return a IO Bool value so that I can analyze the return in a conditional statement later. This little snippet below works and prints an error if bind fails but it is not what I need.

import LDAP.Init
import LDAP.Exceptions

auth :: IO ()
auth = do
  c <- ldapOpen "10.1.1.11" 3268
  let bnd =ldapSimpleBind c "[email protected]" "mypassword"
  catchLDAP bnd (\_ -> error "Wrong user name or password")

I get an error if I try to return anything but IO () by the function that deals with exception. I need it to return IO Bool.

'ldapSimpleBind' just throws an exception if unsuccessful and that's all. Catching exceptions will only allow me to return an IO () What I need is to return something meaningful so that I can do something useful with the return value. I am clearly missing something as the signature of catchLDAP in the docs is :: IO a -> (LDAPException -> IO a) -> IO a

What am I doing wrong? Thanks.

like image 442
r.sendecky Avatar asked Jul 02 '26 11:07

r.sendecky


1 Answers

Your bnd action doesn't return true when it succeeds, and the error handler just calls error,

So it seems that you could just let bnd' = bnd >> return true ,

then, catchLDAP bnd' $ \_ -> return false.

like image 138
user1891025 Avatar answered Jul 05 '26 05:07

user1891025



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!