authnScriptExample.groovy revision 4eb3558c40788d5427c0b570c1e1d7e6fbdc3108
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn ForteSTART_TIME = 9 // 9am
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn ForteEND_TIME = 17 // 5pm
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortelogger.message("Starting authentication groovy script")
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortelogger.message("User: " + username)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte// Log out current cookies in the request
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteif (logger.messageEnabled()) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cookies = requestData.getHeaders('Cookie')
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (cookie in cookies) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte logger.message('Cookie: ' + cookie)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteif (username != null) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte // Make REST call to the users endpoint if username is set.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte response = httpClient.get("http://localhost:8080/openam/json/users/" + username,[
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cookies : [],
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte headers : []
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte // Log out response from users REST call
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana logger.message("User REST Call. Status: " + response.getStatusCode() + ", Body: " + response.getEntity())
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortenow = new Date()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortelogger.message("Current time: " + now.getHours())
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteif (now.getHours() < START_TIME || now.getHours() > END_TIME) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte logger.error("Login forbidden outside work hours!")
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte authState = FAILED
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte} else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte logger.message("Authentication allowed!")
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte authState = SUCCESS
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}