267f3657df2e592dbc1397077658ca7426f0da74Phill CunningtonSTART_TIME = 9 // 9am
267f3657df2e592dbc1397077658ca7426f0da74Phill CunningtonEND_TIME = 17 // 5pm
267f3657df2e592dbc1397077658ca7426f0da74Phill Cunnington
267f3657df2e592dbc1397077658ca7426f0da74Phill Cunningtonlogger.message("Starting authentication groovy script")
267f3657df2e592dbc1397077658ca7426f0da74Phill Cunningtonlogger.message("User: " + username)
267f3657df2e592dbc1397077658ca7426f0da74Phill Cunnington
267f3657df2e592dbc1397077658ca7426f0da74Phill Cunnington// Log out current cookies in the request
267f3657df2e592dbc1397077658ca7426f0da74Phill Cunningtonif (logger.messageEnabled()) {
267f3657df2e592dbc1397077658ca7426f0da74Phill Cunnington cookies = requestData.getHeaders('Cookie')
267f3657df2e592dbc1397077658ca7426f0da74Phill Cunnington for (cookie in cookies) {
267f3657df2e592dbc1397077658ca7426f0da74Phill Cunnington logger.message('Cookie: ' + cookie)
267f3657df2e592dbc1397077658ca7426f0da74Phill Cunnington }
267f3657df2e592dbc1397077658ca7426f0da74Phill Cunnington}
267f3657df2e592dbc1397077658ca7426f0da74Phill Cunnington
267f3657df2e592dbc1397077658ca7426f0da74Phill Cunningtonif (username != null) {
267f3657df2e592dbc1397077658ca7426f0da74Phill Cunnington // Make REST call to the users endpoint if username is set.
4eb3558c40788d5427c0b570c1e1d7e6fbdc3108Rich Riley response = httpClient.get("http://localhost:8080/openam/json/users/" + username,[
4eb3558c40788d5427c0b570c1e1d7e6fbdc3108Rich Riley cookies : [],
4eb3558c40788d5427c0b570c1e1d7e6fbdc3108Rich Riley headers : []
4eb3558c40788d5427c0b570c1e1d7e6fbdc3108Rich Riley ]);
267f3657df2e592dbc1397077658ca7426f0da74Phill Cunnington // Log out response from users REST call
267f3657df2e592dbc1397077658ca7426f0da74Phill Cunnington logger.message("User REST Call. Status: " + response.getStatusCode() + ", Body: " + response.getEntity())
267f3657df2e592dbc1397077658ca7426f0da74Phill Cunnington}
267f3657df2e592dbc1397077658ca7426f0da74Phill Cunnington
267f3657df2e592dbc1397077658ca7426f0da74Phill Cunningtonnow = new Date()
267f3657df2e592dbc1397077658ca7426f0da74Phill Cunningtonlogger.message("Current time: " + now.getHours())
267f3657df2e592dbc1397077658ca7426f0da74Phill Cunningtonif (now.getHours() < START_TIME || now.getHours() > END_TIME) {
267f3657df2e592dbc1397077658ca7426f0da74Phill Cunnington logger.error("Login forbidden outside work hours!")
267f3657df2e592dbc1397077658ca7426f0da74Phill Cunnington authState = FAILED
267f3657df2e592dbc1397077658ca7426f0da74Phill Cunnington} else {
267f3657df2e592dbc1397077658ca7426f0da74Phill Cunnington logger.message("Authentication allowed!")
267f3657df2e592dbc1397077658ca7426f0da74Phill Cunnington authState = SUCCESS
267f3657df2e592dbc1397077658ca7426f0da74Phill Cunnington}