PHP Класс OneLogin_Saml2_Utils

Defines several often used methods
Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
addSign ( string | DomDocument $xml, string $key, string $cert, string $signAlgorithm = XMLSecurityKey::RSA_SHA1 ) : string Adds signature key and senders certificate to an element (Message or Assertion).
calculateX509Fingerprint ( string $x509cert, $alg = 'sha1' ) : null | string Calculates the fingerprint of a x509cert.
castKey ( XMLSecurityKey $key, string $algorithm, string $type = 'public' ) : XMLSecurityKey Converts a XMLSecurityKey to the correct algorithm.
decryptElement ( DOMElement $encryptedData, XMLSecurityKey $inputKey ) : DOMElement Decrypts an encrypted element.
deleteLocalSession ( ) Deletes the local session.
extractOriginalQueryParam ( string $name ) : string Extract a query param - as it was sent - from $_SERVER[QUERY_STRING]
formatCert ( string $cert, boolean $heads = true ) : string Returns a x509 cert (adding header & footer if required).
formatFingerPrint ( string $fingerprint ) : string Formates a fingerprint.
formatPrivateKey ( string $key, boolean $heads = true ) : string Returns a private key (adding header & footer if required).
generateNameId ( string $value, string $spnq, string $format, string | null $cert = null ) : string Generates a nameID.
generateUniqueID ( ) : string Generates an unique string (used for example as ID for assertions).
getBaseURLPath ( ) return string The baseurlpath to be used when constructing URLs
getExpireTime ( string $cacheDuration = null, string $validUntil = null ) : integer Compares 2 dates and returns the earliest.
getProxyVars ( ) return bool
getSelfHost ( ) : string Returns the current host.
getSelfPort ( ) : null | string
getSelfProtocol ( ) : string
getSelfRoutedURLNoQuery ( ) : string Returns the routed URL of the current host + current view.
getSelfURL ( ) : string Returns the URL of the current host + current view + query.
getSelfURLNoQuery ( ) : string Returns the URL of the current host + current view.
getSelfURLhost ( ) : string Returns the protocol + the current host + the port (if different than common ports).
getStatus ( DOMDocument $dom ) : array Gets Status from a Response.
get_string_between ( string $str, string $start, string $end ) : string Extracts a substring between 2 marks
isHTTPS ( ) : boolean Checks if https or http.
isSessionStarted ( ) : boolean Checks if the session is started or not.
loadXML ( DOMDocument $dom, string $xml ) : DOMDocument This function load an XML string in a save way.
parseDuration ( string $duration, integer | null $timestamp = null ) : integer | null Interprets a ISO8601 duration value relative to a given timestamp.
parseSAML2Time ( string $time ) : integer Converts a SAML2 timestamp on the form yyyy-mm-ddThh:mm:ss(\.s+)?Z to a UNIX timestamp. The sub-second part is ignored.
parseTime2SAML ( string $time ) : string Converts a UNIX timestamp to SAML2 timestamp on the form yyyy-mm-ddThh:mm:ss(\.s+)?Z.
query ( DOMDocument $dom, string $query, DomElement $context = null ) : DOMNodeList Extracts nodes from the DOMDocument.
redirect ( string $url, array $parameters = [], boolean $stay = false ) : string | null Executes a redirection to the provided url (or return the target url).
setBaseURL ( $baseurl )
setBaseURLPath ( $baseurlpath )
setProxyVars ( $proxyVars )
setSelfHost ( $host )
setSelfPort ( $port )
setSelfProtocol ( $protocol )
t ( string $msg, array | null $args = [] ) : string Translates any string. Accepts args
validateSign ( string | DomNode $xml, string | null $cert = null, string | null $fingerprint = null, string | null $fingerprintalg = 'sha1', string | null $xpath = null ) : boolean Validates a signature (Message or Assertion).
validateXML ( string | DOMDocument $xml, string $schema, boolean $debug = false ) : string | DOMDocument This function attempts to validate an XML string against the specified schema.

Защищенные методы

Метод Описание
buildWithBaseURLPath ( $info ) : string Returns the part of the URL with the BaseURLPath.
getRawHost ( ) : string

Описание методов

addSign() публичный статический Метод

Adds signature key and senders certificate to an element (Message or Assertion).
public static addSign ( string | DomDocument $xml, string $key, string $cert, string $signAlgorithm = XMLSecurityKey::RSA_SHA1 ) : string
$xml string | DomDocument The element we should sign
$key string The private key
$cert string The public
$signAlgorithm string Signature algorithm method
Результат string

buildWithBaseURLPath() защищенный статический Метод

Returns the part of the URL with the BaseURLPath.
protected static buildWithBaseURLPath ( $info ) : string
Результат string

calculateX509Fingerprint() публичный статический Метод

Calculates the fingerprint of a x509cert.
public static calculateX509Fingerprint ( string $x509cert, $alg = 'sha1' ) : null | string
$x509cert string x509 cert
Результат null | string Formatted fingerprint

castKey() публичный статический Метод

Converts a XMLSecurityKey to the correct algorithm.
public static castKey ( XMLSecurityKey $key, string $algorithm, string $type = 'public' ) : XMLSecurityKey
$key XMLSecurityKey The key.
$algorithm string The desired algorithm.
$type string Public or private key, defaults to public.
Результат XMLSecurityKey The new key.

decryptElement() публичный статический Метод

Decrypts an encrypted element.
public static decryptElement ( DOMElement $encryptedData, XMLSecurityKey $inputKey ) : DOMElement
$encryptedData DOMElement The encrypted data.
$inputKey XMLSecurityKey The decryption key.
Результат DOMElement The decrypted element.

deleteLocalSession() публичный статический Метод

Deletes the local session.
public static deleteLocalSession ( )

extractOriginalQueryParam() публичный статический Метод

Extract a query param - as it was sent - from $_SERVER[QUERY_STRING]
public static extractOriginalQueryParam ( string $name ) : string
$name string The param to-be extracted
Результат string

formatCert() публичный статический Метод

Returns a x509 cert (adding header & footer if required).
public static formatCert ( string $cert, boolean $heads = true ) : string
$cert string A x509 unformated cert
$heads boolean True if we want to include head and footer
Результат string $x509 Formatted cert

formatFingerPrint() публичный статический Метод

Formates a fingerprint.
public static formatFingerPrint ( string $fingerprint ) : string
$fingerprint string fingerprint
Результат string Formatted fingerprint

formatPrivateKey() публичный статический Метод

Returns a private key (adding header & footer if required).
public static formatPrivateKey ( string $key, boolean $heads = true ) : string
$key string A private key
$heads boolean True if we want to include head and footer
Результат string $rsaKey Formatted private key

generateNameId() публичный статический Метод

Generates a nameID.
public static generateNameId ( string $value, string $spnq, string $format, string | null $cert = null ) : string
$value string fingerprint
$spnq string SP Name Qualifier
$format string SP Format
$cert string | null IdP Public cert to encrypt the nameID
Результат string $nameIDElement DOMElement | XMLSec nameID

generateUniqueID() публичный статический Метод

Generates an unique string (used for example as ID for assertions).
public static generateUniqueID ( ) : string
Результат string A unique string

getBaseURLPath() публичный статический Метод

return string The baseurlpath to be used when constructing URLs
public static getBaseURLPath ( )

getExpireTime() публичный статический Метод

Compares 2 dates and returns the earliest.
public static getExpireTime ( string $cacheDuration = null, string $validUntil = null ) : integer
$cacheDuration string The duration, as a string.
$validUntil string The valid until date, as a string or as a timestamp
Результат integer $expireTime The expiration time.

getProxyVars() публичный статический Метод

return bool
public static getProxyVars ( )

getRawHost() защищенный статический Метод

protected static getRawHost ( ) : string
Результат string The raw host name

getSelfHost() публичный статический Метод

Returns the current host.
public static getSelfHost ( ) : string
Результат string $currentHost The current host

getSelfPort() публичный статический Метод

public static getSelfPort ( ) : null | string
Результат null | string The port number used for the request

getSelfProtocol() публичный статический Метод

public static getSelfProtocol ( ) : string
Результат string http|https

getSelfRoutedURLNoQuery() публичный статический Метод

Returns the routed URL of the current host + current view.
public static getSelfRoutedURLNoQuery ( ) : string
Результат string

getSelfURL() публичный статический Метод

Returns the URL of the current host + current view + query.
public static getSelfURL ( ) : string
Результат string

getSelfURLNoQuery() публичный статический Метод

Returns the URL of the current host + current view.
public static getSelfURLNoQuery ( ) : string
Результат string

getSelfURLhost() публичный статический Метод

Returns the protocol + the current host + the port (if different than common ports).
public static getSelfURLhost ( ) : string
Результат string $url

getStatus() публичный статический Метод

Gets Status from a Response.
public static getStatus ( DOMDocument $dom ) : array
$dom DOMDocument The Response as XML
Результат array $status The Status, an array with the code and a message.

get_string_between() публичный статический Метод

Extracts a substring between 2 marks
public static get_string_between ( string $str, string $start, string $end ) : string
$str string The target string
$start string The initial mark
$end string The end mark
Результат string A substring or an empty string if is not able to find the marks or if there is no string between the marks

isHTTPS() публичный статический Метод

Checks if https or http.
public static isHTTPS ( ) : boolean
Результат boolean $isHttps False if https is not active

isSessionStarted() публичный статический Метод

Checks if the session is started or not.
public static isSessionStarted ( ) : boolean
Результат boolean true if the sessíon is started

loadXML() публичный статический Метод

Prevent XEE/XXE Attacks
public static loadXML ( DOMDocument $dom, string $xml ) : DOMDocument
$dom DOMDocument The document where load the xml.
$xml string The XML string to be loaded.
Результат DOMDocument $dom The result of load the XML at the DomDocument

parseDuration() публичный статический Метод

Interprets a ISO8601 duration value relative to a given timestamp.
public static parseDuration ( string $duration, integer | null $timestamp = null ) : integer | null
$duration string The duration, as a string.
$timestamp integer | null The unix timestamp we should apply the duration to. Optional, default to the current time.
Результат integer | null The new timestamp, after the duration is applied.

parseSAML2Time() публичный статический Метод

Converts a SAML2 timestamp on the form yyyy-mm-ddThh:mm:ss(\.s+)?Z to a UNIX timestamp. The sub-second part is ignored.
public static parseSAML2Time ( string $time ) : integer
$time string The time we should convert (SAML Timestamp).
Результат integer $timestamp Converted to a unix timestamp.

parseTime2SAML() публичный статический Метод

Converts a UNIX timestamp to SAML2 timestamp on the form yyyy-mm-ddThh:mm:ss(\.s+)?Z.
public static parseTime2SAML ( string $time ) : string
$time string The time we should convert (DateTime).
Результат string $timestamp SAML2 timestamp.

query() публичный статический Метод

Extracts nodes from the DOMDocument.
public static query ( DOMDocument $dom, string $query, DomElement $context = null ) : DOMNodeList
$dom DOMDocument The DOMDocument
$query string Xpath Expresion
$context DomElement Context Node (DomElement)
Результат DOMNodeList The queried nodes

redirect() публичный статический Метод

Executes a redirection to the provided url (or return the target url).
public static redirect ( string $url, array $parameters = [], boolean $stay = false ) : string | null
$url string The target url
$parameters array Extra parameters to be passed as part of the url
$stay boolean True if we want to stay (returns the url string) False to redirect
Результат string | null $url

setBaseURL() публичный статический Метод

public static setBaseURL ( $baseurl )
$baseurl string The base url to be used when constructing URLs

setBaseURLPath() публичный статический Метод

public static setBaseURLPath ( $baseurlpath )
$baseurlpath string The baseurl path to use when constructing URLs

setProxyVars() публичный статический Метод

public static setProxyVars ( $proxyVars )
$proxyVars bool Whether to use `X-Forwarded-*` headers to determine port/domain/protocol

setSelfHost() публичный статический Метод

public static setSelfHost ( $host )
$host string The host to use when constructing URLs

setSelfPort() публичный статический Метод

public static setSelfPort ( $port )
$port int The port number to use when constructing URLs

setSelfProtocol() публичный статический Метод

public static setSelfProtocol ( $protocol )
$protocol string The protocol to identify as using, usually http or https

t() публичный статический Метод

Translates any string. Accepts args
public static t ( string $msg, array | null $args = [] ) : string
$msg string Message to be translated
$args array | null Arguments
Результат string $translatedMsg Translated text

validateSign() публичный статический Метод

Validates a signature (Message or Assertion).
public static validateSign ( string | DomNode $xml, string | null $cert = null, string | null $fingerprint = null, string | null $fingerprintalg = 'sha1', string | null $xpath = null ) : boolean
$xml string | DomNode The element we should validate
$cert string | null The pubic cert
$fingerprint string | null The fingerprint of the public cert
$fingerprintalg string | null The algorithm used to get the fingerprint
$xpath string | null The xpath of the signed element
Результат boolean

validateXML() публичный статический Метод

It will parse the string into a DOM document and validate this document against the schema.
public static validateXML ( string | DOMDocument $xml, string $schema, boolean $debug = false ) : string | DOMDocument
$xml string | DOMDocument The XML string or document which should be validated.
$schema string The schema filename which should be used.
$debug boolean To disable/enable the debug mode
Результат string | DOMDocument $dom string that explains the problem or the DOMDocument