Skip to content

Instantly share code, notes, and snippets.

@jbarber
Created October 13, 2014 12:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbarber/eb25c94a5dc32212cd70 to your computer and use it in GitHub Desktop.
Save jbarber/eb25c94a5dc32212cd70 to your computer and use it in GitHub Desktop.
Shibboleth example login
(comment (defproject otrs "0.1.0-SNAPSHOT"
:description "Example of Shibboleth login to OTRS with htmlunit"
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.6.0"]
[net.sourceforge.htmlunit/htmlunit "2.15"]]))
(ns otrs.core
(:import (com.gargoylesoftware.htmlunit WebClient)))
(defn newClient
"Create new WebClient class with CSS and JavaScript disabled"
[] (let [wc (new WebClient)
opts (.getOptions wc )]
(do (.setCssEnabled opts false)
(.setJavaScriptEnabled opts false)
wc)))
(defn getPage
"Get a URL with a WebClient client"
[client url]
{:pre [(= (str (class client)) "class com.gargoylesoftware.htmlunit.WebClient")
(string? url)]}
(.getPage client url))
(defn shibboleth-auth
"Authenticate via shibboleth."
[client url username password]
{:pre [(= (str (class client)) "class com.gargoylesoftware.htmlunit.WebClient")
(string? url)
(string? username)
(string? password)]}
(let [
otrs (getPage client url)
password-form (first (.getForms otrs))
saml-form (do (.. password-form (getInputByName "j_username") (setValueAttribute username))
(.. password-form (getInputByName "j_password") (setValueAttribute password))
(.. password-form (getInputByValue "Login") (click)))]
(.. (first (.. saml-form getForms)) (getInputByValue "Continue") (click))))
(def client (newClient))
(def otrs "https://tickets.example.com/otrs/index.pl")
(def p (login client otrs "username@example.com" "sekretpassw0rd"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment