PHP Class phpCAS

Afficher le fichier Open project: jasig/phpcas Class Usage Examples

Méthodes publiques

Méthode Description
addRebroadcastHeader ( String $header ) : void This method is used to add header parameters when rebroadcasting pgtIou/pgtId or logoutRequest.
addRebroadcastNode ( string $rebroadcastNodeUrl ) : void Add a pgtIou/pgtId and logoutRequest rebroadcast node.
allowProxyChain ( CAS_ProxyChain_Interface $proxy_chain ) : void If you want your service to be proxied you have to enable it (default disabled) and define an accepable list of proxies that are allowed to proxy your service.
checkAuthentication ( ) : true This method is called to check if the user is already authenticated locally or has a global cas session. A already existing cas session is determined by a cas gateway call.(cas login call without any interactive prompt)
client ( string $server_version, string $server_hostname, string $server_port, string $server_uri, boolean $changeSessionID = true ) : a phpCAS client initializer.
error ( string $msg ) : void This method is used by interface methods to print an error and where the function was originally called from.
forceAuthentication ( ) : boolean This method is called to force authentication if the user was not already authenticated. If the user is not authenticated, halt by redirecting to the CAS server.
getAttribute ( string $key ) : mixed Answer an attribute for the authenticated user.
getAttributes ( ) : array Answer attributes about the authenticated user.
getProxiedService ( string $type ) : CAS_ProxiedService Answer a proxy-authenticated service handler.
getProxies ( ) : array Answer an array of proxies that are sitting in front of this application.
getServerLoginURL ( ) : the This method returns the URL to be used to login.
getServerLogoutURL ( ) : the This method returns the URL to be used to login.
getServiceURL ( ) : string Get the URL that is set as the CAS service parameter.
getUser ( ) : string This method returns the CAS user's login name.
getVerbose ( ) : boot Show is verbose mode is on
getVersion ( ) : the This method returns the phpCAS version.
handleLogoutRequests ( boolean $check_client = true, array $allowed_clients = false ) : void Handle logout requests.
hasAttribute ( string $key ) : boolean Answer true if an attribute exists for the authenticated user.
hasAttributes ( ) : boolean Answer true if there are attributes for the authenticated user.
initializeProxiedService ( CAS_ProxiedService $proxiedService ) : void Initialize a proxied-service handler with the proxy-ticket it should use.
isAuthenticated ( ) : true This method is called to check if the user is authenticated (previously or by tickets given in the URL).
isInitialized ( ) : boolean Answer whether or not the client or proxy has been initialized
isSessionAuthenticated ( ) : boolean Checks whether authenticated based on $_SESSION. Useful to avoid server calls.
log ( string $str ) : void Logs a string in debug mode.
logout ( string $params = "" ) : void This method is used to logout from CAS.
logoutWithRedirectService ( string $service ) : void This method is used to logout from CAS. Halts by redirecting to the CAS server.
logoutWithRedirectServiceAndUrl ( string $service, string $url ) : void This method is used to logout from CAS. Halts by redirecting to the CAS server.
logoutWithUrl ( string $url ) : void This method is used to logout from CAS. Halts by redirecting to the CAS server.
proxy ( string $server_version, string $server_hostname, string $server_port, string $server_uri, boolean $changeSessionID = true ) : a phpCAS proxy initializer.
renewAuthentication ( ) : void This method is called to renew the authentication.
retrievePT ( string $target_service, &$err_code, &$err_msg ) : string Retrieve a Proxy Ticket from the CAS server.
serviceMail ( string $url, string $service, string $flags, &$err_code, &$err_msg, &$pt ) : object This method is used to access an IMAP/POP3/NNTP service.
serviceWeb ( string $url, &$err_code, &$output ) : boolean This method is used to access an HTTP[S] service.
setCacheTimesForAuthRecheck ( integer $n ) : void Set the times authentication will be cached before really accessing the CAS server in gateway mode: - -1: check only once, and then never again (until you pree login) - 0: always check - n: check every "n" time
setCasAttributeParserCallback ( string $function, array $additionalArgs = [] ) : void Set a callback function to be run when receiving CAS attributes
setCasClient ( CAS_Client $client ) : void For testing purposes, use this method to set the client to a test double
setCasServerCACert ( string $cert, boolean $validate_cn = true ) : void Set the certificate of the CAS server CA and if the CN should be properly verified.
setDebug ( string $filename = '' ) : void Set/unset debug mode
setExtraCurlOption ( string $key, string $value ) : void Change CURL options.
setFixedCallbackURL ( string $url = '' ) : void Set the fixed URL that will be used by the CAS server to transmit the PGT. When this method is not called, a phpCAS script uses its own URL for the callback.
setFixedServiceURL ( string $url ) : void Set the fixed URL that will be set as the CAS service parameter. When this method is not called, a phpCAS script uses its own URL.
setHTMLFooter ( string $footer ) : void This method sets the HTML footer used for all outputs.
setHTMLHeader ( string $header ) : void This method sets the HTML header used for all outputs.
setLang ( string $lang ) : void This method is used to set the language used by phpCAS.
setNoCasServerValidation ( ) : void Set no SSL validation for the CAS server.
setNoClearTicketsFromUrl ( ) : void Disable the removal of a CAS-Ticket from the URL when authenticating DISABLING POSES A SECURITY RISK: We normally remove the ticket by an additional redirect as a security precaution to prevent a ticket in the HTTP_REFERRER or be carried over in the URL parameter
setPGTStorage ( CAS_PGTStorage $storage ) : void This method can be used to set a custom PGT storage object.
setPGTStorageDb ( string $dsn_or_pdo, string $username = '', string $password = '', string $table = '', string $driver_options = null ) : void This method is used to tell phpCAS to store the response of the CAS server to PGT requests in a database.
setPGTStorageFile ( string $path = '' ) : void This method is used to tell phpCAS to store the response of the CAS server to PGT requests onto the filesystem.
setPostAuthenticateCallback ( string $function, array $additionalArgs = [] ) : void Set a callback function to be run when a user authenticates.
setServerLoginURL ( string $url = '' ) : void Set the login URL of the CAS server.
setServerLogoutURL ( string $url = '' ) : void Set the logout URL of the CAS server.
setServerProxyValidateURL ( string $url = '' ) : void Set the proxyValidate URL of the CAS server.
setServerSamlValidateURL ( string $url = '' ) : void Set the samlValidate URL of the CAS server.
setServerServiceValidateURL ( string $url = '' ) : void Set the serviceValidate URL of the CAS server.
setSingleSignoutCallback ( string $function, array $additionalArgs = [] ) : void Set a callback function to be run when a single-signout request is received. The callback function will be passed a $logoutTicket as its first parameter, followed by any $additionalArgs you pass. The $logoutTicket parameter is an opaque string that can be used to map a session-id to the logout request in order to support single-signout in applications that manage their own sessions (rather than letting phpCAS start and destroy the session).
setVerbose ( boolean $verbose ) : void Enable verbose errors messages in the website output This is a security relevant since internal status info may leak an may help an attacker. Default is therefore false
trace ( string $str ) : void This method is used to log something in debug mode.
traceBegin ( ) : void This method is used to indicate the start of the execution of a function in debug mode.
traceEnd ( string $res = '' ) : void This method is used to indicate the end of the execution of a function in debug mode.
traceExit ( ) : void This method is used to indicate the end of the execution of the program

Private Methods

Méthode Description
_validateClientExists ( ) : void Checks if a client already exists
_validateProxyExists ( ) : void Checks of a proxy client aready exists

Method Details

addRebroadcastHeader() public static méthode

This method is used to add header parameters when rebroadcasting pgtIou/pgtId or logoutRequest.
public static addRebroadcastHeader ( String $header ) : void
$header String Header to send when rebroadcasting.
Résultat void

addRebroadcastNode() public static méthode

Add a pgtIou/pgtId and logoutRequest rebroadcast node.
public static addRebroadcastNode ( string $rebroadcastNodeUrl ) : void
$rebroadcastNodeUrl string The rebroadcast node URL. Can be hostname or IP.
Résultat void

allowProxyChain() public static méthode

Add each allowed proxy definition object. For the normal CAS_ProxyChain class, the constructor takes an array of proxies to match. The list is in reverse just as seen from the service. Proxies have to be defined in reverse from the service to the user. If a user hits service A and gets proxied via B to service C the list of acceptable on C would be array(B,A). The definition of an individual proxy can be either a string or a regexp (preg_match is used) that will be matched against the proxy list supplied by the cas server when validating the proxy tickets. The strings are compared starting from the beginning and must fully match with the proxies in the list. Example: phpCAS::allowProxyChain(new CAS_ProxyChain(array( 'https://app.example.com/' ))); phpCAS::allowProxyChain(new CAS_ProxyChain(array( '/^https:\/\/app[0-9]\.example\.com\/rest\//', 'http://client.example.com/' ))); For quick testing or in certain production screnarios you might want to allow allow any other valid service to proxy your service. To do so, add the "Any" chain: phpcas::allowProxyChain(new CAS_ProxyChain_Any); THIS SETTING IS HOWEVER NOT RECOMMENDED FOR PRODUCTION AND HAS SECURITY IMPLICATIONS: YOU ARE ALLOWING ANY SERVICE TO ACT ON BEHALF OF A USER ON THIS SERVICE.
public static allowProxyChain ( CAS_ProxyChain_Interface $proxy_chain ) : void
$proxy_chain CAS_ProxyChain_Interface A proxy-chain that will be matched against the proxies requesting access
Résultat void

checkAuthentication() public static méthode

This method is called to check if the user is already authenticated locally or has a global cas session. A already existing cas session is determined by a cas gateway call.(cas login call without any interactive prompt)
public static checkAuthentication ( ) : true
Résultat true when the user is authenticated, false when a previous gateway login failed or the function will not return if the user is redirected to the cas server for a gateway login attempt

client() public static méthode

phpCAS client initializer.
public static client ( string $server_version, string $server_hostname, string $server_port, string $server_uri, boolean $changeSessionID = true ) : a
$server_version string the version of the CAS server
$server_hostname string the hostname of the CAS server
$server_port string the port the CAS server is running on
$server_uri string the URI the CAS server is responding on
$changeSessionID boolean Allow phpCAS to change the session_id (Single Sign Out/handleLogoutRequests is based on that change)
Résultat a newly created CAS_Client object

error() public static méthode

This method is used by interface methods to print an error and where the function was originally called from.
public static error ( string $msg ) : void
$msg string the message to print
Résultat void

forceAuthentication() public static méthode

This method is called to force authentication if the user was not already authenticated. If the user is not authenticated, halt by redirecting to the CAS server.
public static forceAuthentication ( ) : boolean
Résultat boolean Authentication

getAttribute() public static méthode

Answer an attribute for the authenticated user.
public static getAttribute ( string $key ) : mixed
$key string attribute name
Résultat mixed string for a single value or an array if multiple values exist.

getAttributes() public static méthode

Answer attributes about the authenticated user.
public static getAttributes ( ) : array
Résultat array

getProxiedService() public static méthode

Answer a proxy-authenticated service handler.
public static getProxiedService ( string $type ) : CAS_ProxiedService
$type string The service type. One of PHPCAS_PROXIED_SERVICE_HTTP_GET; PHPCAS_PROXIED_SERVICE_HTTP_POST; PHPCAS_PROXIED_SERVICE_IMAP
Résultat CAS_ProxiedService

getProxies() public static méthode

This method will only return a non-empty array if we have received and validated a Proxy Ticket.
Since: 6/25/09
public static getProxies ( ) : array
Résultat array

getServerLoginURL() public static méthode

or phpCAS::isAuthenticated().
public static getServerLoginURL ( ) : the
Résultat the login name of the authenticated user

getServerLogoutURL() public static méthode

or phpCAS::isAuthenticated().
public static getServerLogoutURL ( ) : the
Résultat the login name of the authenticated user

getServiceURL() public static méthode

Get the URL that is set as the CAS service parameter.
public static getServiceURL ( ) : string
Résultat string Service Url

getUser() public static méthode

This method returns the CAS user's login name.
public static getUser ( ) : string
Résultat string the login name of the authenticated user

getVerbose() public static méthode

Show is verbose mode is on
public static getVerbose ( ) : boot
Résultat boot verbose

getVersion() public static méthode

This method returns the phpCAS version.
public static getVersion ( ) : the
Résultat the phpCAS version.

handleLogoutRequests() public static méthode

Handle logout requests.
public static handleLogoutRequests ( boolean $check_client = true, array $allowed_clients = false ) : void
$check_client boolean additional safety check
$allowed_clients array array of allowed clients
Résultat void

hasAttribute() public static méthode

Answer true if an attribute exists for the authenticated user.
public static hasAttribute ( string $key ) : boolean
$key string attribute name
Résultat boolean

hasAttributes() public static méthode

Answer true if there are attributes for the authenticated user.
public static hasAttributes ( ) : boolean
Résultat boolean

initializeProxiedService() public static méthode

Initialize a proxied-service handler with the proxy-ticket it should use.
public static initializeProxiedService ( CAS_ProxiedService $proxiedService ) : void
$proxiedService CAS_ProxiedService Proxied Service Handler
Résultat void

isAuthenticated() public static méthode

This method is called to check if the user is authenticated (previously or by tickets given in the URL).
public static isAuthenticated ( ) : true
Résultat true when the user is authenticated.

isInitialized() public static méthode

Answer whether or not the client or proxy has been initialized
public static isInitialized ( ) : boolean
Résultat boolean

isSessionAuthenticated() public static méthode

Checks whether authenticated based on $_SESSION. Useful to avoid server calls.
Since: 0.4.22 by Brendan Arnold
public static isSessionAuthenticated ( ) : boolean
Résultat boolean true if authenticated, false otherwise.

log() public static méthode

Logs a string in debug mode.
public static log ( string $str ) : void
$str string the string to write
Résultat void

logout() public static méthode

This method is used to logout from CAS.
public static logout ( string $params = "" ) : void
$params string an array that contains the optional url and service parameters that will be passed to the CAS server
Résultat void

logoutWithRedirectService() public static méthode

This method is used to logout from CAS. Halts by redirecting to the CAS server.
public static logoutWithRedirectService ( string $service ) : void
$service string a URL that will be transmitted to the CAS server
Résultat void

logoutWithRedirectServiceAndUrl() public static méthode

This method is used to logout from CAS. Halts by redirecting to the CAS server.
Deprecation: The url parameter has been removed from the CAS server as of version 3.3.5.1
public static logoutWithRedirectServiceAndUrl ( string $service, string $url ) : void
$service string a URL that will be transmitted to the CAS server
$url string a URL that will be transmitted to the CAS server
Résultat void

logoutWithUrl() public static méthode

This method is used to logout from CAS. Halts by redirecting to the CAS server.
Deprecation: The url parameter has been removed from the CAS server as of version 3.3.5.1
public static logoutWithUrl ( string $url ) : void
$url string a URL that will be transmitted to the CAS server
Résultat void

proxy() public static méthode

phpCAS proxy initializer.
public static proxy ( string $server_version, string $server_hostname, string $server_port, string $server_uri, boolean $changeSessionID = true ) : a
$server_version string the version of the CAS server
$server_hostname string the hostname of the CAS server
$server_port string the port the CAS server is running on
$server_uri string the URI the CAS server is responding on
$changeSessionID boolean Allow phpCAS to change the session_id (Single Sign Out/handleLogoutRequests is based on that change)
Résultat a newly created CAS_Client object

renewAuthentication() public static méthode

This method is called to renew the authentication.
public static renewAuthentication ( ) : void
Résultat void

retrievePT() public static méthode

Retrieve a Proxy Ticket from the CAS server.
public static retrievePT ( string $target_service, &$err_code, &$err_msg ) : string
$target_service string Url string of service to proxy
Résultat string Proxy Ticket

serviceMail() public static méthode

This method is used to access an IMAP/POP3/NNTP service.
public static serviceMail ( string $url, string $service, string $flags, &$err_code, &$err_msg, &$pt ) : object
$url string a string giving the URL of the service, including the mailing box for IMAP URLs, as accepted by imap_open().
$service string a string giving for CAS retrieve Proxy ticket
$flags string options given to imap_open().
Résultat object IMAP stream on success, false otherwise (in this later case, $err_code gives the reason why it failed and $err_msg contains an error message).

serviceWeb() public static méthode

This method is used to access an HTTP[S] service.
public static serviceWeb ( string $url, &$err_code, &$output ) : boolean
$url string the service to access.
Résultat boolean true on success, false otherwise (in this later case, $err_code gives the reason why it failed and $output contains an error message).

setCacheTimesForAuthRecheck() public static méthode

Set the times authentication will be cached before really accessing the CAS server in gateway mode: - -1: check only once, and then never again (until you pree login) - 0: always check - n: check every "n" time
public static setCacheTimesForAuthRecheck ( integer $n ) : void
$n integer an integer.
Résultat void

setCasAttributeParserCallback() public static méthode

The callback function will be passed an $success_elements payload of the response (\DOMElement) as its first parameter.
public static setCasAttributeParserCallback ( string $function, array $additionalArgs = [] ) : void
$function string Callback function
$additionalArgs array optional array of arguments
Résultat void

setCasClient() public static méthode

For testing purposes, use this method to set the client to a test double
public static setCasClient ( CAS_Client $client ) : void
$client CAS_Client
Résultat void

setCasServerCACert() public static méthode

Set the certificate of the CAS server CA and if the CN should be properly verified.
public static setCasServerCACert ( string $cert, boolean $validate_cn = true ) : void
$cert string CA certificate file name
$validate_cn boolean Validate CN in certificate (default true)
Résultat void

setDebug() public static méthode

Set/unset debug mode
public static setDebug ( string $filename = '' ) : void
$filename string the name of the file used for logging, or false to stop debugging.
Résultat void

setExtraCurlOption() public static méthode

CURL is used to connect through HTTPS to CAS server
public static setExtraCurlOption ( string $key, string $value ) : void
$key string the option key
$value string the value to set
Résultat void

setFixedCallbackURL() public static méthode

Set the fixed URL that will be used by the CAS server to transmit the PGT. When this method is not called, a phpCAS script uses its own URL for the callback.
public static setFixedCallbackURL ( string $url = '' ) : void
$url string the URL
Résultat void

setFixedServiceURL() public static méthode

Set the fixed URL that will be set as the CAS service parameter. When this method is not called, a phpCAS script uses its own URL.
public static setFixedServiceURL ( string $url ) : void
$url string the URL
Résultat void

setHTMLFooter() public static méthode

This method sets the HTML footer used for all outputs.
public static setHTMLFooter ( string $footer ) : void
$footer string the HTML footer.
Résultat void

setHTMLHeader() public static méthode

This method sets the HTML header used for all outputs.
public static setHTMLHeader ( string $header ) : void
$header string the HTML header.
Résultat void

setLang() public static méthode

This method is used to set the language used by phpCAS.
public static setLang ( string $lang ) : void
$lang string string representing the language.
Résultat void

setNoCasServerValidation() public static méthode

Set no SSL validation for the CAS server.
public static setNoCasServerValidation ( ) : void
Résultat void

setNoClearTicketsFromUrl() public static méthode

Disable the removal of a CAS-Ticket from the URL when authenticating DISABLING POSES A SECURITY RISK: We normally remove the ticket by an additional redirect as a security precaution to prevent a ticket in the HTTP_REFERRER or be carried over in the URL parameter
public static setNoClearTicketsFromUrl ( ) : void
Résultat void

setPGTStorage() public static méthode

This method can be used to set a custom PGT storage object.
public static setPGTStorage ( CAS_PGTStorage $storage ) : void
$storage CAS_PGTStorage a PGT storage object that inherits from the CAS_PGTStorage class
Résultat void

setPGTStorageDb() public static méthode

This method is used to tell phpCAS to store the response of the CAS server to PGT requests in a database.
public static setPGTStorageDb ( string $dsn_or_pdo, string $username = '', string $password = '', string $table = '', string $driver_options = null ) : void
$dsn_or_pdo string a dsn string to use for creating a PDO object or a PDO object
$username string the username to use when connecting to the database
$password string the password to use when connecting to the database
$table string the table to use for storing and retrieving PGT's
$driver_options string any driver options to use when connecting to the database
Résultat void

setPGTStorageFile() public static méthode

This method is used to tell phpCAS to store the response of the CAS server to PGT requests onto the filesystem.
public static setPGTStorageFile ( string $path = '' ) : void
$path string the path where the PGT's should be stored
Résultat void

setPostAuthenticateCallback() public static méthode

The callback function will be passed a $logoutTicket as its first parameter, followed by any $additionalArgs you pass. The $logoutTicket parameter is an opaque string that can be used to map the session-id to logout request in order to support single-signout in applications that manage their own sessions (rather than letting phpCAS start the session). phpCAS::forceAuthentication() will always exit and forward client unless they are already authenticated. To perform an action at the moment the user logs in (such as registering an account, performing logging, etc), register a callback function here.
public static setPostAuthenticateCallback ( string $function, array $additionalArgs = [] ) : void
$function string Callback function
$additionalArgs array optional array of arguments
Résultat void

setServerLoginURL() public static méthode

Set the login URL of the CAS server.
Since: 0.4.21 by Wyman Chan
public static setServerLoginURL ( string $url = '' ) : void
$url string the login URL
Résultat void

setServerLogoutURL() public static méthode

Set the logout URL of the CAS server.
Since: 0.4.21 by Wyman Chan
public static setServerLogoutURL ( string $url = '' ) : void
$url string the logout URL
Résultat void

setServerProxyValidateURL() public static méthode

Used for all CAS 2.0 validations
public static setServerProxyValidateURL ( string $url = '' ) : void
$url string the proxyValidate URL
Résultat void

setServerSamlValidateURL() public static méthode

Set the samlValidate URL of the CAS server.
public static setServerSamlValidateURL ( string $url = '' ) : void
$url string the samlValidate URL
Résultat void

setServerServiceValidateURL() public static méthode

Used only in CAS 1.0 validations
public static setServerServiceValidateURL ( string $url = '' ) : void
$url string the serviceValidate URL
Résultat void

setSingleSignoutCallback() public static méthode

Set a callback function to be run when a single-signout request is received. The callback function will be passed a $logoutTicket as its first parameter, followed by any $additionalArgs you pass. The $logoutTicket parameter is an opaque string that can be used to map a session-id to the logout request in order to support single-signout in applications that manage their own sessions (rather than letting phpCAS start and destroy the session).
public static setSingleSignoutCallback ( string $function, array $additionalArgs = [] ) : void
$function string Callback function
$additionalArgs array optional array of arguments
Résultat void

setVerbose() public static méthode

Enable verbose errors messages in the website output This is a security relevant since internal status info may leak an may help an attacker. Default is therefore false
public static setVerbose ( boolean $verbose ) : void
$verbose boolean enable verbose output
Résultat void

trace() public static méthode

This method is used to log something in debug mode.
public static trace ( string $str ) : void
$str string string to log
Résultat void

traceBegin() public static méthode

This method is used to indicate the start of the execution of a function in debug mode.
public static traceBegin ( ) : void
Résultat void

traceEnd() public static méthode

This method is used to indicate the end of the execution of a function in debug mode.
public static traceEnd ( string $res = '' ) : void
$res string the result of the function
Résultat void

traceExit() public static méthode

This method is used to indicate the end of the execution of the program
public static traceExit ( ) : void
Résultat void