PingAuthorize

SpEL processing examples

PingAuthorize enhances SpEL expressions with a rich library of custom functions designed to simplify complex tasks and streamline your processor configurations. The following sections introduce some of these functions with examples, focusing on common use cases for working with collections, dates and times, and Uniform Resource Identifiers (URIs).

Collection functions

To help you create and manipulate collections and maps dynamically, PingAuthorize provides a set of functions for common collection transformations in SpEL expressions.

CreateList

Creates a new collection containing the specified items.

Syntax

#CreateList(item1, item2, …​, itemN)

Arguments
  • item1, item2, …​, itemN (Type: Any): One or more items of any data type to include in the new collection. These items appear in the new collection in the order they’re provided.

Examples
Creating a collection of strings
  • SpEL: #CreateList("view_profile", "edit_settings", "delete_account")

  • Result: ["view_profile", "edit_settings", "delete_account"]

Creating a collection of numbers
  • SpEL: #CreateList(1, 2, 3, 4, 5)

  • Result: [1, 2, 3, 4, 5]

Creating a collection with mixed data types
  • SpEL: #CreateList("config_A", 100, true)

  • Result: ["config_A", 100, true]

ConcatLists

Combines two existing collections into a single new collection.

Syntax

#ConcatLists(list1, list2)

Arguments
  • list1 (Type: Collection): The first collection

  • list2 (Type: Collection): The second collection

    The items in list2 are appended to the end of list1.

Examples
Combining two collections of permissions
  • SpEL: #ConcatLists(["read_basic"], ["read_extended", "write_comments"])

  • Result: ["read_basic", "read_extended", "write_comments"]

Combining dynamically created collections
  • SpEL: #ConcatLists(#CreateList(1, 2, 3), #CreateList(4, 5, 6))

  • Result: [1, 2, 3, 4, 5, 6]

CreateMap

Creates a new map from two separate collections: one containing the keys and the other containing the corresponding values. Each key is paired with the value at the same index.

Syntax

#CreateMap(keysList, valuesList)

Arguments
  • keysList (Type: Collection): A collection of items used as keys in the map

  • valuesList (Type: Collection): A collection of items used as values in the map

    The item at valuesList[i] becomes the value for the key at keysList[i].

    If keysList and valuesList have different lengths, the resulting map will only contain key-value pairs up to the length of the shorter collection. Each key in the map must be unique.
Examples
Creating a map of user attributes
  • SpEL: #CreateMap(#CreateList("username", "email", "status"), #CreateList("jdoe", "jdoe@example.com", "active"))

  • Result: {"username": "jdoe", "email": "jdoe@example.com", "status": "active"}

Creating a map with numeric keys and values
  • SpEL: #CreateMap(#CreateList(1, 2, 3), #CreateList(10, 20, 30))

  • Result: {1: 10, 2: 20, 3: 30}

MergeMaps

Merges two existing maps into a single new map.

Syntax

#MergeMaps(map1, map2)

Arguments
  • map1 (Type: Map): The first map

  • map2 (Type: Map): The second map

    If both map1 and map2 contain the same key, the value from map2 overrides the value from map1 in the resulting map.
Example: Merging maps with distinct keys
  • SpEL: MergeMaps({#CreateMap(#CreateList(1, 2), #CreateList(10, 20))}, {#CreateMap(#CreateList(3, 4), #CreateList(30, 40))})

  • Result: {1: 10, 2: 20, 3: 30, 4: 40}

Date and time functions

PingAuthorize provides a set of functions for common date and time manipulations in SpEL expressions. These functions leverage Java’s java.time API and help you parse, convert, and calculate durations involving dates and times. Learn more in the java.time API specification in the Java documentation.

DateTime

Parses a date-time string using a specified custom format. This function can parse strings into LocalDateTime (date-time without time zone) or ZonedDateTime (date-time with time zone), depending on the input string and format.

Syntax

#DateTime(dateString, formatPattern)

Arguments
  • dateString (Type: String): The date-time string to be parsed

  • formatPattern (Type: String): A pattern string that defines the format of the dateString. The pattern should conform to Java’s DateTimeFormatter patterns ("uuuu-MM-dd HH:mm:ss", "MM/dd/uuuu’T’HH:mm:ssXXX").

Example: Parsing a date-time with a custom format
  • SpeL: #DateTime("11:09:08 07-22-2018", "HH:mm:ss MM-dd-uuuu")

  • Result: A LocalDateTime object representing July 22, 2018, 11:09:08

ISO8601DateTime

Parses a date-time string that conforms to the ISO 8601 standard. This function can parse strings into LocalDateTime or ZonedDateTime.

Syntax

#ISO8601DateTime(dateString)

Arguments
  • dateString (Type: String): The date-time string in ISO 8601 format ("2019-01-01T10:01:01", "2019-01-01T10:01:01Z", "2019-01-01T10:01:01+02:00")

Example: Parsing an ISO 8601 local date-time string
  • SpEL: #ISO8601DateTime("2024-05-30T15:45:00")

  • Result: A LocalDateTime object representing May 30, 2024, 15:45:00

Date

Parses a date string using a specified custom format into LocalDate (a date without time-of-day and time zone).

Syntax

#Date(dateString, formatPattern)

Arguments
  • dateString (Type: String): The date string to be parsed

  • formatPattern (Type: String): A pattern string that defines the format of the dateString ("uuuu-MM-dd", "MM/dd/uuuu")

Example: Parsing a date with "year-month-day" format
  • SpEL: #Date("2024-12-25", "uuuu-MM-dd")

  • Result: A LocalDate object representing December 25, 2024

ISO8601Date

Parses a date string that conforms to the ISO 8601 standard (YYYY-MM-DD) into LocalDate.

Syntax

#ISO8601Date(dateString)

Arguments
  • dateString (Type: String): The date string in ISO 8601 format ("2019-01-01")

Example: Parsing an ISO 8601 date string
  • SpEL: #ISO8601Date("2019-01-01")

  • Result: A LocalDate object representing January 1, 2019

LocalDateTimeFromUnix

Converts a Unix timestamp (seconds since the 1970-01-01T00:00:00Z epoch) to LocalDateTime, representing the date and time in the system’s default time zone.

Syntax

#LocalDateTimeFromUnix(unixTimestamp)

Arguments

unixTimestamp (Type: Long): The Unix timestamp value in seconds

Example: Converting a Unix timestamp
  • SpEL: #LocalDateTimeFromUnix(1572348852L)

  • Result: A LocalDateTime object. For the specified timestamp, this corresponds to 2019-10-29T11:34:12.

UnixFromLocalDateTime

Converts LocalDateTime to a Unix timestamp (seconds since the 1970-01-01T00:00:00Z epoch). The conversion assumes the LocalDateTime is in Coordinated Universal Time (UTC).

Syntax

#UnixFromLocalDateTime(localDateTime)

Arguments

localDateTime (Type: LocalDateTime): The LocalDateTime to be converted

Example: Converting a specific LocalDateTime to Unix time
  • SpEL: #UnixFromLocalDateTime(#ISO8601DateTime('2019-10-29T11:34:12'))

  • Result: 1572348852L

GetPeriodBetween

Calculates the time period (in years, months, and days) between two LocalDate objects.

Syntax

#GetPeriodBetween(startDate, endDate)

Arguments
  • startDate (Type: LocalDate): The start date of the period (inclusive)

  • endDate (Type: LocalDate): The end date of the period (exclusive)

Returns

A Period object representing the duration between startDate and endDate. You can access the result’s components using properties like .years, .months, and .days.

Example: Calculating the period between two dates
  • SpEL: #GetPeriodBetween(#ISO8601Date("2018-02-15"), #ISO8601Date("2019-04-25"))

  • Result:

    • periodObject.years = 1

    • periodObject.months = 2

    • periodObject.days = 10

URI functions

PingAuthorize provides a set of functions for parsing and constructing URIs in SpEL expressions. These functions leverage Java’s java.net.URI capabilities to simplify the manipulation of URI components.

URIParse

Parses a URI string into its components and returns a map that associates each component name with its corresponding value.

Syntax

#URIParse(uriString)

Arguments
  • uriString (Type: String): The complete URI string to be parsed

Examples
Parsing a complex URI
  • SpEL: #URIParse('https://jane.doe:s3cr3t@api.example.com:8443/v1/resources?type=widget&id=42#details')

  • Result:

    {
      "scheme": "https",
      "userInfo": "jane.doe:s3cr3t",
      "host": "api.example.com",
      "port": 8443,
      "path": "/v1/resources",
      "query": {
        "type": "widget",
        "id": "42"
      },
      "fragment": "details"
    }
Parsing a URI with a valueless query parameter
  • SpEL: #URIParse('http://example.com/search?q=ping&enabled')

  • Result:

    {
      "scheme": "http",
      "host": "example.com",
      "path": "/search",
      "query": {
        "q": "ping",
        "enabled": ""
      }
    }
URIBuild

Constructs a URI string from a map containing the URI’s individual components.

Syntax

#URIBuild(componentsMap)

Arguments
  • componentsMap (Type: Map<String: Any>): A map that associates URI component names with the corresponding values used to construct the URI

    The following table describes the allowable URI component names:

    Component Data type Description Required

    scheme

    String

    The URI scheme.

    Required

    host

    String

    The host name or IP address.

    Required

    userInfo

    String

    Information about the user.

    Optional

    port

    Integer

    The port number. If this value is null or not provided, the port isn’t included in the URI string.

    Optional

    path

    String

    The path component. For a root path, use /. If this value is empty or null, the URI will have no path component after the authority.

    Optional

    query

    Map<String, Any>

    A map of query parameter names and their corresponding values.

    Optional

    fragment

    String

    The fragment identifier.

    Optional

Example: Building a simple URI
  • SpEL: #URIBuild(#{'scheme': 'http', 'host': 'localhost', 'path': '/status'})

  • Result: "http://localhost/status"