PHP Класс phpCAS

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

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

Метод Описание
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

Приватные методы

Метод Описание
_validateClientExists ( ) : void Checks if a client already exists
_validateProxyExists ( ) : void Checks of a proxy client aready exists

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

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

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.
Результат void

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

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.
Результат void

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

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
Результат void

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

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
Результат 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() публичный статический метод

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)
Результат a newly created CAS_Client object

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

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
Результат void

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

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
Результат boolean Authentication

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

Answer an attribute for the authenticated user.
public static getAttribute ( string $key ) : mixed
$key string attribute name
Результат mixed string for a single value or an array if multiple values exist.

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

Answer attributes about the authenticated user.
public static getAttributes ( ) : array
Результат array

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

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
Результат CAS_ProxiedService

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

This method will only return a non-empty array if we have received and validated a Proxy Ticket.
С версии: 6/25/09
public static getProxies ( ) : array
Результат array

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

or phpCAS::isAuthenticated().
public static getServerLoginURL ( ) : the
Результат the login name of the authenticated user

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

or phpCAS::isAuthenticated().
public static getServerLogoutURL ( ) : the
Результат the login name of the authenticated user

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

Get the URL that is set as the CAS service parameter.
public static getServiceURL ( ) : string
Результат string Service Url

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

This method returns the CAS user's login name.
public static getUser ( ) : string
Результат string the login name of the authenticated user

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

Show is verbose mode is on
public static getVerbose ( ) : boot
Результат boot verbose

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

This method returns the phpCAS version.
public static getVersion ( ) : the
Результат the phpCAS version.

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

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
Результат void

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

Answer true if an attribute exists for the authenticated user.
public static hasAttribute ( string $key ) : boolean
$key string attribute name
Результат boolean

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

Answer true if there are attributes for the authenticated user.
public static hasAttributes ( ) : boolean
Результат boolean

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

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
Результат void

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

This method is called to check if the user is authenticated (previously or by tickets given in the URL).
public static isAuthenticated ( ) : true
Результат true when the user is authenticated.

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

Answer whether or not the client or proxy has been initialized
public static isInitialized ( ) : boolean
Результат boolean

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

Checks whether authenticated based on $_SESSION. Useful to avoid server calls.
С версии: 0.4.22 by Brendan Arnold
public static isSessionAuthenticated ( ) : boolean
Результат boolean true if authenticated, false otherwise.

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

Logs a string in debug mode.
public static log ( string $str ) : void
$str string the string to write
Результат void

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

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
Результат void

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

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
Результат void

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

This method is used to logout from CAS. Halts by redirecting to the CAS server.
Устаревший: 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
Результат void

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

This method is used to logout from CAS. Halts by redirecting to the CAS server.
Устаревший: 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
Результат void

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

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)
Результат a newly created CAS_Client object

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

This method is called to renew the authentication.
public static renewAuthentication ( ) : void
Результат void

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

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
Результат string Proxy Ticket

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

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().
Результат 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() публичный статический метод

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.
Результат 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() публичный статический метод

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.
Результат void

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

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
Результат void

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

For testing purposes, use this method to set the client to a test double
public static setCasClient ( CAS_Client $client ) : void
$client CAS_Client
Результат void

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

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)
Результат void

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

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.
Результат void

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

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
Результат void

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

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
Результат void

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

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
Результат void

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

This method sets the HTML footer used for all outputs.
public static setHTMLFooter ( string $footer ) : void
$footer string the HTML footer.
Результат void

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

This method sets the HTML header used for all outputs.
public static setHTMLHeader ( string $header ) : void
$header string the HTML header.
Результат void

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

This method is used to set the language used by phpCAS.
public static setLang ( string $lang ) : void
$lang string string representing the language.
Результат void

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

Set no SSL validation for the CAS server.
public static setNoCasServerValidation ( ) : void
Результат void

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

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
Результат void

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

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
Результат void

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

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
Результат void

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

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
Результат void

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

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
Результат void

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

Set the login URL of the CAS server.
С версии: 0.4.21 by Wyman Chan
public static setServerLoginURL ( string $url = '' ) : void
$url string the login URL
Результат void

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

Set the logout URL of the CAS server.
С версии: 0.4.21 by Wyman Chan
public static setServerLogoutURL ( string $url = '' ) : void
$url string the logout URL
Результат void

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

Used for all CAS 2.0 validations
public static setServerProxyValidateURL ( string $url = '' ) : void
$url string the proxyValidate URL
Результат void

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

Set the samlValidate URL of the CAS server.
public static setServerSamlValidateURL ( string $url = '' ) : void
$url string the samlValidate URL
Результат void

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

Used only in CAS 1.0 validations
public static setServerServiceValidateURL ( string $url = '' ) : void
$url string the serviceValidate URL
Результат void

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

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
Результат void

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

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
Результат void

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

This method is used to log something in debug mode.
public static trace ( string $str ) : void
$str string string to log
Результат void

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

This method is used to indicate the start of the execution of a function in debug mode.
public static traceBegin ( ) : void
Результат void

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

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
Результат void

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

This method is used to indicate the end of the execution of the program
public static traceExit ( ) : void
Результат void