66 * PHP version 5.5.9
77 *
88 * @category Authentication
9- * @copyright 2017 Staffbase, GmbH.
9+ * @copyright 2017-2019 Staffbase, GmbH.
1010 * @author Vitaliy Ivanov
1111 * @license http://www.apache.org/licenses/LICENSE-2.0
1212 * @link https://github.com/staffbase/plugins-sdk-php
1313 */
1414
1515namespace Staffbase \plugins \sdk ;
1616
17- use Exception ;
1817use Lcobucci \JWT \Parser ;
1918use Lcobucci \JWT \Builder ;
2019use Lcobucci \JWT \ValidationData ;
2120use Lcobucci \JWT \Claim \Validatable ;
2221use Lcobucci \JWT \Signer \Keychain ;
2322use Lcobucci \JWT \Signer \Rsa \Sha256 ;
23+ use Staffbase \plugins \sdk \Exceptions \SSOException ;
24+ use Staffbase \plugins \sdk \Exceptions \SSOAuthenticationException ;
2425
2526/**
2627 * A container which is able to decrypt and store the data transmitted
@@ -40,18 +41,18 @@ class SSOToken extends SSOData
4041 * @param string $tokenData The token text.
4142 * @param int $leeway count of seconds added to current timestamp
4243 *
43- * @throws Exception on invalid parameters.
44+ * @throws SSOException on invalid parameters.
4445 */
4546 public function __construct ($ appSecret , $ tokenData , $ leeway = 0 ) {
4647
4748 if (!trim ($ appSecret ))
48- throw new Exception ('Parameter appSecret for SSOToken is empty. ' );
49+ throw new SSOException ('Parameter appSecret for SSOToken is empty. ' );
4950
5051 if (!trim ($ tokenData ))
51- throw new Exception ('Parameter tokenData for SSOToken is empty. ' );
52+ throw new SSOException ('Parameter tokenData for SSOToken is empty. ' );
5253
5354 if (!is_numeric ($ leeway ))
54- throw new Exception ('Parameter leeway has to be numeric. ' );
55+ throw new SSOException ('Parameter leeway has to be numeric. ' );
5556
5657 // convert secret to PEM if its a plain base64 string and does not yield an url
5758 if (strpos (trim ($ appSecret ),'----- ' ) !== 0 && strpos (trim ($ appSecret ), 'file:// ' ) !==0 )
@@ -69,7 +70,7 @@ public function __construct($appSecret, $tokenData, $leeway = 0) {
6970 *
7071 * @return Lcobucci\JWT\Token;
7172 *
72- * @throws Exception if the parsing/verification/validation of the token fails.
73+ * @throws SSOAuthenticationException if the parsing/verification/validation of the token fails.
7374 */
7475 protected function parseToken ($ appSecret , $ tokenData , $ leeway ) {
7576
@@ -81,7 +82,7 @@ protected function parseToken($appSecret, $tokenData, $leeway) {
8182 $ keychain = new Keychain ();
8283
8384 if (!$ this ->token ->verify ($ signer , $ keychain ->getPublicKey ($ appSecret )))
84- throw new Exception ('Token verification failed. ' );
85+ throw new SSOAuthenticationException ('Token verification failed. ' );
8586
8687 // validate claims
8788 $ data = new ValidationData (time () +$ leeway ); // iat, nbf and exp are validated by default
@@ -92,7 +93,7 @@ protected function parseToken($appSecret, $tokenData, $leeway) {
9293
9394 // its a security risk to work with tokens lacking instance id
9495 if (!trim ($ this ->getInstanceId ()))
95- throw new Exception ('Token lacks instance id. ' );
96+ throw new SSOAuthenticationException ('Token lacks instance id. ' );
9697 }
9798
9899 /**
@@ -128,7 +129,7 @@ public static function base64ToPEMPublicKey($data) {
128129 *
129130 * @param Lcobucci\JWT\ValidationData $data to validate against
130131 *
131- * @throws Exception always.
132+ * @throws SSOAuthenticationException always.
132133 */
133134 protected function throwVerboseException (ValidationData $ data ) {
134135
@@ -144,13 +145,13 @@ protected function throwVerboseException(ValidationData $data) {
144145 $ operator = array_pop ($ segments );
145146 $ operand = $ data ->get ($ claimName );
146147
147- throw new Exception ("Token Validation failed on claim ' $ claimName' $ claimValue $ operator $ operand. " );
148+ throw new SSOAuthenticationException ("Token Validation failed on claim ' $ claimName' $ claimValue $ operator $ operand. " );
148149 }
149150 }
150151 }
151152
152153 // unknown reason, probably an addition to used library
153- throw new Exception ('Token Validation failed. ' );
154+ throw new SSOAuthenticationException ('Token Validation failed. ' );
154155 }
155156
156157 /**
0 commit comments