packages feed

authenticate-ldap (empty) → 0.0.1

raw patch · 4 files changed

+115/−0 lines, 4 filesdep +LDAPdep +basedep +textsetup-changed

Dependencies added: LDAP, base, text

Files

+ LICENSE view
@@ -0,0 +1,25 @@+The following license covers this documentation, and the source code, except+where otherwise indicated.++Copyright 2008, Michael Snoyman. All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++* Redistributions of source code must retain the above copyright notice, this+  list of conditions and the following disclaimer.++* Redistributions in binary form must reproduce the above copyright notice,+  this list of conditions and the following disclaimer in the documentation+  and/or other materials provided with the distribution.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS "AS IS" AND ANY EXPRESS OR+IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO+EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,+OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF+LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE+OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF+ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Setup.lhs view
@@ -0,0 +1,7 @@+#!/usr/bin/env runhaskell++> module Main where+> import Distribution.Simple++> main :: IO ()+> main = defaultMain
+ Web/Authenticate/LDAP.hs view
@@ -0,0 +1,57 @@+{-# LANGUAGE OverloadedStrings #-}+-- | Module for using LDAP as an authentication service+-- +-- This code was written for yesod-auth-ldap, but maybe it can be used in any +-- given Haskell web framwork?+-- For now, the only usage examples will be Yesod specific. So you can find+-- them in the yesod-auth-ldap repo ++module Web.Authenticate.LDAP+  ( loginLDAP+  , LDAPAuthResult (..)+  ) where++import Data.Text (Text,unpack)+import LDAP+import Control.Exception++  +data LDAPAuthResult = Ok [LDAPEntry]+                    | NoSuchUser+                    | WrongPassword++instance Show LDAPAuthResult where+  show (Ok _            )         = "Login successful"+  show NoSuchUser                 = "Wrong username"+  show WrongPassword              = "Wrong password"+   +loginLDAP :: Text -> -- user's identifier+             String -> -- user's password+             String -> -- LDAPHost+             LDAPInt -> -- LDAP port+             String -> -- DN for initial bind+             String -> -- Password for initial bind+             Maybe String -> --  Base DN for user search, if any+             LDAPScope -> -- Scope of User search+             IO LDAPAuthResult+loginLDAP user pass ldapHost ldapPort' initDN initPassword searchDN ldapScope =+  do+   ldapOBJ <- ldapInit ldapHost ldapPort'+   initBindResult <- try (ldapSimpleBind ldapOBJ initDN initPassword) +                                                 :: IO (Either LDAPException ())+   case initBindResult of+     Left _ -> do -- Successful initial bind+       ldapOBJ' <- ldapInit ldapHost ldapPort'+       userBindResult <- try (ldapSimpleBind ldapOBJ' (unpack user) pass) +                                                 :: IO (Either LDAPException ())+       case userBindResult of+         Left _ -> do -- Successful user bind+           entry <- ldapSearch ldapOBJ  +                               searchDN +                               ldapScope+                               (Just ("sAMAccountName=" ++ (unpack user)))+                               LDAPAllUserAttrs+                               False+           return $ Ok entry+         Right _ -> return WrongPassword+     Right _ -> return NoSuchUser    
+ authenticate-ldap.cabal view
@@ -0,0 +1,26 @@+name:            authenticate-ldap+version:         0.0.1 +license:         BSD3+license-file:    LICENSE+author:          Michael Litchard +maintainer:      Michael Litchard +synopsis:        LDAP authentication for Haskell web applications.+description:     LDAP authentication for Haskell web applications. +category:        Web+stability:       Experimental +cabal-version:   >= 1.6+build-type:      Simple+homepage:        http://github.com:mlitchard/authenticate-ldap+++library+    build-depends:   base                          >= 4        && < 5+                   , text+                   , LDAP                          == 0.6.6+    exposed-modules: Web.Authenticate.LDAP+    ghc-options:     -Wall+++source-repository head+  type:     git+  location: git://github.com:mlitchard/authenticate-ldap/authenticate-ldap.git