Skip to content

Commit

Permalink
Merge branch 'Hikariii-feature-master/codestyle'
Browse files Browse the repository at this point in the history
  • Loading branch information
pitbulk committed May 9, 2016
2 parents 9a1cec3 + 6762531 commit 874950f
Show file tree
Hide file tree
Showing 14 changed files with 209 additions and 139 deletions.
4 changes: 2 additions & 2 deletions endpoints/acs.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@
echo '<h1>'._('User attributes:').'</h1>';
echo '<table><thead><th>'._('Name').'</th><th>'._('Values').'</th></thead><tbody>';
foreach ($attributes as $attributeName => $attributeValues) {
echo '<tr><td>' . htmlentities($attributeName) . '</td><td><ul>';
echo '<tr><td>'.htmlentities($attributeName).'</td><td><ul>';
foreach ($attributeValues as $attributeValue) {
echo '<li>' . htmlentities($attributeValue) . '</li>';
echo '<li>'.htmlentities($attributeValue).'</li>';
}
echo '</ul></td></tr>';
}
Expand Down
14 changes: 12 additions & 2 deletions lib/Saml/AuthRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class OneLogin_Saml_AuthRequest
* Constructs the OneLogin_Saml2_Auth, initializing
* the SP SAML instance.
*
* @param OneLogin_Saml2_Settings $settings Settings
* @param array|object $settings SAML Toolkit Settings
*/
public function __construct($settings)
{
Expand All @@ -23,7 +23,11 @@ public function __construct($settings)
* Obtains the SSO URL containing the AuthRequest
* message deflated.
*
* @param OneLogin_Saml2_Settings $settings Settings
* @param string|null $returnTo
*
* @return string
*
* @throws OneLogin_Saml2_Error
*/
public function getRedirectUrl($returnTo = null)
{
Expand All @@ -39,11 +43,17 @@ public function getRedirectUrl($returnTo = null)
return $url;
}

/**
* @return string
*/
protected function _generateUniqueID()
{
return OneLogin_Saml2_Utils::generateUniqueID();
}

/**
* @return string
*/
protected function _getTimestamp()
{
$defaultTimezone = date_default_timezone_get();
Expand Down
13 changes: 12 additions & 1 deletion lib/Saml/Metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,28 @@ class OneLogin_Saml_Metadata

protected $_settings;

public function __construct($settings=null)
/**
* @param array|object|null $settings Setting data
*/
public function __construct($settings = null)
{
$auth = new OneLogin_Saml2_Auth($settings);
$this->_settings = $auth->getSettings();
}

/**
* @return string
*
* @throws OneLogin_Saml2_Error
*/
public function getXml()
{
return $this->_settings->getSPMetadata();
}

/**
* @return string
*/
protected function _getMetadataValidTimestamp()
{
$timeZone = date_default_timezone_get();
Expand Down
16 changes: 10 additions & 6 deletions lib/Saml/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ class OneLogin_Saml_Response extends OneLogin_Saml2_Response
* Internally initializes an SP SAML instance
* and an OneLogin_Saml2_Response.
*
* @param OneLogin_Saml_Settings $oldSettings Settings
* @param string $$assertion SAML Response
* @param array|object $oldSettings Settings
* @param string $assertion SAML Response
*/
public function __construct($oldSettings, $assertion)
{
Expand All @@ -18,16 +18,20 @@ public function __construct($oldSettings, $assertion)
}

/**
* Retrieves an Array with the logged user data.
*/
* Retrieves an Array with the logged user data.
*
* @return array
*/
public function get_saml_attributes()
{
return $this->getAttributes();
}

/**
* Retrieves the nameId
*/
* Retrieves the nameId
*
* @return string
*/
public function get_nameid()
{
return $this->getNameId();
Expand Down
2 changes: 1 addition & 1 deletion lib/Saml/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class OneLogin_Saml_Settings
public $requestedNameIdFormat = self::NAMEID_EMAIL_ADDRESS;

/**
* Return an Array with the values (compatibility with the new version)
* @return array<string,array> Values (compatibility with the new version)
*/
public function getValues()
{
Expand Down
8 changes: 4 additions & 4 deletions lib/Saml/XmlSec.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public function validateTimestamps()

/**
* @return bool
*
* @throws Exception
*/
public function isValid()
Expand Down Expand Up @@ -95,9 +96,8 @@ public function isValid()
}

try {
$retVal = $objXMLSecDSig->validateReference();
}
catch (Exception $e) {
$objXMLSecDSig->validateReference();
} catch (Exception $e) {
throw new Exception('Reference Validation Failed');
}

Expand All @@ -107,4 +107,4 @@ public function isValid()

return ($objXMLSecDSig->verify($objKey) === 1);
}
}
}
68 changes: 40 additions & 28 deletions lib/Saml2/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class OneLogin_Saml2_Auth
/**
* If user is authenticated.
*
* @var boolean
* @var bool
*/
private $_authenticated = false;

Expand Down Expand Up @@ -76,7 +76,7 @@ class OneLogin_Saml2_Auth
/**
* Initializes the SP SAML instance.
*
* @param array|OneLogin_Saml_Settings $oldSettings Setting data. (OneLogin_Saml_Settings is the settings object of the old implementation)
* @param array|object|null $oldSettings Setting data (You can provide a OneLogin_Saml_Settings, the settings object of the Saml folder implementation)
*/
public function __construct($oldSettings = null)
{
Expand All @@ -86,7 +86,7 @@ public function __construct($oldSettings = null)
/**
* Returns the settings info
*
* @return OneLogin_Saml2_Settings The settings data.
* @return OneLogin_Saml2_Settings The settings data.
*/
public function getSettings()
{
Expand All @@ -96,7 +96,7 @@ public function getSettings()
/**
* Set the strict mode active/disable
*
* @param boolean $value Strict parameter
* @param bool $value Strict parameter
*
* @return array The settings data.
*/
Expand All @@ -109,7 +109,9 @@ public function setStrict($value)
/**
* Process the SAML Response sent by the IdP.
*
* @param string $requestId The ID of the AuthNRequest sent by this SP to the IdP
* @param string|null $requestId The ID of the AuthNRequest sent by this SP to the IdP
*
* @throws OneLogin_Saml2_Error
*/
public function processResponse($requestId = null)
{
Expand Down Expand Up @@ -140,13 +142,15 @@ public function processResponse($requestId = null)
/**
* Process the SAML Logout Response / Logout Request sent by the IdP.
*
* @param boolean $keepLocalSession When false will destroy the local session, otherwise will keep it
* @param string $requestId The ID of the LogoutRequest sent by this SP to the IdP
* @param bool $retrieveParametersFromServer
* @param callable $cbDeleteSession
* @param boolean $stay True if we want to stay (returns the url string) False to redirect
* @param bool $keepLocalSession When false will destroy the local session, otherwise will keep it
* @param string|null $requestId The ID of the LogoutRequest sent by this SP to the IdP
* @param bool $retrieveParametersFromServer
* @param callable $cbDeleteSession
* @param bool $stay True if we want to stay (returns the url string) False to redirect
*
* @return string|void
* @throws \OneLogin_Saml2_Error
*
* @throws OneLogin_Saml2_Error
*/
public function processSLO($keepLocalSession = false, $requestId = null, $retrieveParametersFromServer = false, $cbDeleteSession = null, $stay=false)
{
Expand Down Expand Up @@ -214,7 +218,7 @@ public function processSLO($keepLocalSession = false, $requestId = null, $retrie
*
* @param string $url The target URL to redirect the user.
* @param array $parameters Extra parameters to be passed as part of the url
* @param boolean $stay True if we want to stay (returns the url string) False to redirect
* @param bool $stay True if we want to stay (returns the url string) False to redirect
*/
public function redirectTo($url = '', $parameters = array(), $stay = false)
{
Expand All @@ -231,7 +235,7 @@ public function redirectTo($url = '', $parameters = array(), $stay = false)
/**
* Checks if the user is authenticated or not.
*
* @return boolean True if the user is authenticated
* @return bool True if the user is authenticated
*/
public function isAuthenticated()
{
Expand Down Expand Up @@ -261,7 +265,7 @@ public function getNameId()
/**
* Returns the SessionIndex
*
* @return string The SessionIndex of the assertion
* @return string|null The SessionIndex of the assertion
*/
public function getSessionIndex()
{
Expand Down Expand Up @@ -303,7 +307,7 @@ public function getLastErrorReason()
*
* @param string $name The requested attribute of the user.
*
* @return NULL || array Requested SAML attribute ($name).
* @return array|null Requested SAML attribute ($name).
*/
public function getAttribute($name)
{
Expand All @@ -319,12 +323,12 @@ public function getAttribute($name)
/**
* Initiates the SSO process.
*
* @param string $returnTo The target URL the user should be returned to after login.
* @param array $parameters Extra parameters to be added to the GET
* @param bool $forceAuthn When true the AuthNReuqest will set the ForceAuthn='true'
* @param bool $isPassive When true the AuthNReuqest will set the Ispassive='true'
* @param boolean $stay True if we want to stay (returns the url string) False to redirect
* @param bool $nameIdPolicy When true the AuthNReuqest will set a nameIdPolicy element
* @param string|null $returnTo The target URL the user should be returned to after login.
* @param array $parameters Extra parameters to be added to the GET
* @param bool $forceAuthn When true the AuthNReuqest will set the ForceAuthn='true'
* @param bool $isPassive When true the AuthNReuqest will set the Ispassive='true'
* @param bool $stay True if we want to stay (returns the url string) False to redirect
* @param bool $nameIdPolicy When true the AuthNReuqest will set a nameIdPolicy element
*
* @return If $stay is True, it return a string with the SLO URL + LogoutRequest + parameters
*/
Expand Down Expand Up @@ -357,13 +361,15 @@ public function login($returnTo = null, $parameters = array(), $forceAuthn = fal
/**
* Initiates the SLO process.
*
* @param string $returnTo The target URL the user should be returned to after logout.
* @param array $parameters Extra parameters to be added to the GET
* @param string $nameId The NameID that will be set in the LogoutRequest.
* @param string $sessionIndex The SessionIndex (taken from the SAML Response in the SSO process).
* @param boolean $stay True if we want to stay (returns the url string) False to redirect
* @param string|null $returnTo The target URL the user should be returned to after logout.
* @param array $parameters Extra parameters to be added to the GET
* @param string|null $nameId The NameID that will be set in the LogoutRequest.
* @param string|null $sessionIndex The SessionIndex (taken from the SAML Response in the SSO process).
* @param bool $stay True if we want to stay (returns the url string) False to redirect
*
* @return If $stay is True, it return a string with the SLO URL + LogoutRequest + parameters
*
* @throws OneLogin_Saml2_Error
*/
public function logout($returnTo = null, $parameters = array(), $nameId = null, $sessionIndex = null, $stay=false)
{
Expand Down Expand Up @@ -448,6 +454,9 @@ public function getLastRequestID()
* @param string $signAlgorithm Signature algorithm method
*
* @return string A base64 encoded signature
*
* @throws Exception
* @throws OneLogin_Saml2_Error
*/
public function buildRequestSignature($samlRequest, $relayState, $signAlgorithm = XMLSecurityKey::RSA_SHA1)
{
Expand All @@ -473,11 +482,14 @@ public function buildRequestSignature($samlRequest, $relayState, $signAlgorithm
/**
* Generates the Signature for a SAML Response
*
* @param string $samlResponse The SAML Response
* @param string $relayState The RelayState
* @param string $samlResponse The SAML Response
* @param string $relayState The RelayState
* @param string $signAlgorithm Signature algorithm method
*
* @return string A base64 encoded signature
*
* @throws Exception
* @throws OneLogin_Saml2_Error
*/
public function buildResponseSignature($samlResponse, $relayState, $signAlgorithm = XMLSecurityKey::RSA_SHA1)
{
Expand Down
6 changes: 3 additions & 3 deletions lib/Saml2/Error.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ class OneLogin_Saml2_Error extends Exception
/**
* Constructor
*
* @param string $msg Describes the error.
* @param integer $code The code error (defined in the error class).
* @param array $args Arguments used in the message that describes the error.
* @param string $msg Describes the error.
* @param int $code The code error (defined in the error class).
* @param array|null $args Arguments used in the message that describes the error.
*/
public function __construct($msg, $code = 0, $args = null)
{
Expand Down
15 changes: 8 additions & 7 deletions lib/Saml2/LogoutRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,9 @@ class OneLogin_Saml2_LogoutRequest
* Constructs the Logout Request object.
*
* @param OneLogin_Saml2_Settings $settings Settings
* @param string $response A UUEncoded Logout Request.
* @param string $nameId The NameID that will be set in the LogoutRequest.
* @param string $session The SessionIndex (taken from the SAML Response in the SSO process).
*
* @param string|null $request A UUEncoded Logout Request.
* @param string|null $nameId The NameID that will be set in the LogoutRequest.
* @param string|null $sessionIndex The SessionIndex (taken from the SAML Response in the SSO process).
*/
public function __construct(OneLogin_Saml2_Settings $settings, $request = null, $nameId = null, $sessionIndex = null)
{
Expand Down Expand Up @@ -143,9 +142,11 @@ public static function getID($request)
* Gets the NameID Data of the the Logout Request.
*
* @param string|DOMDocument $request Logout Request Message
* @param string $key The SP key
* @param string|null $key The SP key
*
* @return array Name ID Data (Value, Format, NameQualifier, SPNameQualifier)
*
* @throws Exception
*/
public static function getNameIdData($request, $key = null)
{
Expand Down Expand Up @@ -197,7 +198,7 @@ public static function getNameIdData($request, $key = null)
* Gets the NameID of the Logout Request.
*
* @param string|DOMDocument $request Logout Request Message
* @param string $key The SP key
* @param string|null $key The SP key
*
* @return string Name ID Value
*/
Expand Down Expand Up @@ -261,7 +262,7 @@ public static function getSessionIndexes($request)
/**
* Checks if the Logout Request recieved is valid.
*
* @return boolean If the Logout Request is or not valid
* @return bool If the Logout Request is or not valid
*/
public function isValid($retrieveParametersFromServer=false)
{
Expand Down
6 changes: 4 additions & 2 deletions lib/Saml2/LogoutResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,12 @@ public function getStatus()
/**
* Determines if the SAML LogoutResponse is valid
*
* @param string $requestId The ID of the LogoutRequest sent by this SP to the IdP
* @param string|null $requestId The ID of the LogoutRequest sent by this SP to the IdP
* @param bool $retrieveParametersFromServer
*
* @throws Exception
* @return bool Returns if the SAML LogoutResponse is or not valid
*
* @throws Exception
*/
public function isValid($requestId = null, $retrieveParametersFromServer=false)
{
Expand Down
Loading

0 comments on commit 874950f

Please sign in to comment.