CAS 6.3.x or 6.1.x with custom SMS

79 views
Skip to first unread message

mohammad almodallal

unread,
Jul 1, 2021, 4:16:06 AM7/1/21
to CAS Community
Hi,

 anyone could help on how to send SMS for OTP using a custom java or script on CAS 6.3.x or 6.1.x?

thanks

Stewart

unread,
Jul 2, 2021, 10:06:17 AM7/2/21
to CAS Community, mohammad almodallal
Hi Mohammad,

Here are the settings that work for us under 6.1.6 (with sensitive information redacted).  I've included the groovy script we use too...we send messages via Flowroute (a voip provider).  I hope this helps.

Regards,

Stewart

cas.authn.mfa.simple.order=0
cas.authn.mfa.simple.timeToKillInSeconds=60
cas.authn.mfa.simple.tokenLength=6
cas.authn.mfa.simple.mail.from=nor...@mydomain.com
cas.authn.mfa.simple.mail.text=Your one-time authorization token is: %s
cas.authn.mfa.simple.mail.subject=Authorization Token
cas.authn.mfa.simple.sms.from=12125551212
cas.authn.mfa.simple.sms.text=Your one-time authorization token is: %s
cas.authn.mfa.simple.sms.attributeName=mobile
cas.smsProvider.groovy.location=file:/etc/cas/sendSms.groovy

--- sendSms.groovy ---
@Grab(group = 'org.codehaus.groovy.modules.http-builder', module = 'http-builder', v ersion = '0.7.1')
import java.util.*
  import groovyx.net.http.RESTClient
import static groovyx.net.http.ContentType.JSON
import groovy.json.JsonSlurper

class smsSender {
  def run(Object[] args) {
    def from = args[0]
    def to = args[1]
    def message = args[2]
    def logger = args[3]

    logger.debug("Sending message ${message} to ${to} from ${from}")
    RESTClient client = new RESTClient("https://api.flowroute.com/v2/".toString())
    def jsonObj = new JsonSlurper().parseText('{"to": "${to}", "from": "${from}", "body": "${message}"
    }
    ')
    def path = "messages"
    client.auth.basic("XXXXXX", "<long key here> ")
    def response = client.post(
      path: path,
      contentType: JSON,
      requestContentType: JSON,
      body: jsonObj,
    )

    return response.status

  }
}

Emilian Mitocariu

unread,
Aug 1, 2022, 9:16:52 AMAug 1
to CAS Community, Stewart, mohammad almodallal
Hi Steward,

Did you add a dependency when building CAS for that @Grab( line in the groovy script? Because when I add that line in my groovy script (no other code, just that line) CAS fails to start with error "java.lang.ClassNotFoundException: org.apache.ivy.util.MessageLogger".

A search for that error point to `org.apache.ivy` being needed.

Stewart

unread,
Aug 1, 2022, 4:11:48 PMAug 1
to Emilian Mitocariu, CAS Community, mohammad almodallal
Hi Emilian,

I don't have any specific ivy dependencies configured.  I'd expect that to come with a full groovy install.  What version of groovy are you using? 

Regards,

Stewart

Emilian Mitocariu

unread,
Aug 2, 2022, 9:03:56 AMAug 2
to CAS Community, Stewart, CAS Community, mohammad almodallal, Emilian Mitocariu
I didn't install groovy directly on my server, CAS (version 6.5.6 in my case) comes with jars for groovy 3.0.9

Here's a list of all the groovy related jars that came with my CAS build:
 - groovy-3.0.9.jar
 - groovy-datetime-3.0.9.jar
 - groovy-extensions-1.1.0.jar
 - groovy-groovysh-3.0.9.jar
 - groovy-json-3.0.9.jar
 - groovy-jsr223-3.0.9.jar
 - groovy-sql-3.0.9.jar
 - groovy-templates-3.0.9.jar
 - groovy-xml-3.0.9.jar

Emilian Mitocariu

unread,
Aug 2, 2022, 9:06:24 AMAug 2
to CAS Community, Emilian Mitocariu, Stewart, CAS Community, mohammad almodallal
PS: I was able to use simple groovy scripts (inline in service definitions and scripts with their own files) in the past with the current setup I have
Reply all
Reply to author
Forward
0 new messages