1<?php
2
3/**
4 * Error class of OneLogin PHP Toolkit
5 *
6 * Defines the Error class
7 */
8class OneLogin_Saml2_Error extends Exception
9{
10    // Errors
11    const SETTINGS_FILE_NOT_FOUND = 0;
12    const SETTINGS_INVALID_SYNTAX = 1;
13    const SETTINGS_INVALID = 2;
14    const METADATA_SP_INVALID = 3;
15    const SP_CERTS_NOT_FOUND = 4;
16    // SP_CERTS_NOT_FOUND is deprecated, use CERT_NOT_FOUND instead
17    const CERT_NOT_FOUND = 4;
18    const REDIRECT_INVALID_URL = 5;
19    const PUBLIC_CERT_FILE_NOT_FOUND = 6;
20    const PRIVATE_KEY_FILE_NOT_FOUND = 7;
21    const SAML_RESPONSE_NOT_FOUND = 8;
22    const SAML_LOGOUTMESSAGE_NOT_FOUND = 9;
23    const SAML_LOGOUTREQUEST_INVALID = 10;
24    const SAML_LOGOUTRESPONSE_INVALID  = 11;
25    const SAML_SINGLE_LOGOUT_NOT_SUPPORTED = 12;
26    const PRIVATE_KEY_NOT_FOUND = 13;
27    const UNSUPPORTED_SETTINGS_OBJECT = 14;
28
29    /**
30     * Constructor
31     *
32     * @param string     $msg  Describes the error.
33     * @param int        $code The code error (defined in the error class).
34     * @param array|null $args Arguments used in the message that describes the error.
35     */
36    public function __construct($msg, $code = 0, $args = null)
37    {
38        assert('is_string($msg)');
39        assert('is_int($code)');
40
41        $message = OneLogin_Saml2_Utils::t($msg, $args);
42
43        parent::__construct($message, $code);
44    }
45}
46
47/**
48 * This class implements another custom Exception handler,
49 * related to exceptions that happens during validation process.
50 */
51class OneLogin_Saml2_ValidationError extends Exception
52{
53    # Validation Errors
54    const UNSUPPORTED_SAML_VERSION = 0;
55    const MISSING_ID = 1;
56    const WRONG_NUMBER_OF_ASSERTIONS = 2;
57    const MISSING_STATUS = 3;
58    const MISSING_STATUS_CODE = 4;
59    const STATUS_CODE_IS_NOT_SUCCESS = 5;
60    const WRONG_SIGNED_ELEMENT = 6;
61    const ID_NOT_FOUND_IN_SIGNED_ELEMENT = 7;
62    const DUPLICATED_ID_IN_SIGNED_ELEMENTS = 8;
63    const INVALID_SIGNED_ELEMENT = 9;
64    const DUPLICATED_REFERENCE_IN_SIGNED_ELEMENTS = 10;
65    const UNEXPECTED_SIGNED_ELEMENTS = 11;
66    const WRONG_NUMBER_OF_SIGNATURES_IN_RESPONSE = 12;
67    const WRONG_NUMBER_OF_SIGNATURES_IN_ASSERTION = 13;
68    const INVALID_XML_FORMAT = 14;
69    const WRONG_INRESPONSETO = 15;
70    const NO_ENCRYPTED_ASSERTION = 16;
71    const NO_ENCRYPTED_NAMEID = 17;
72    const MISSING_CONDITIONS = 18;
73    const ASSERTION_TOO_EARLY = 19;
74    const ASSERTION_EXPIRED = 20;
75    const WRONG_NUMBER_OF_AUTHSTATEMENTS = 21;
76    const NO_ATTRIBUTESTATEMENT = 22;
77    const ENCRYPTED_ATTRIBUTES = 23;
78    const WRONG_DESTINATION = 24;
79    const EMPTY_DESTINATION = 25;
80    const WRONG_AUDIENCE = 26;
81    const ISSUER_MULTIPLE_IN_RESPONSE = 27;
82    const ISSUER_NOT_FOUND_IN_ASSERTION = 28;
83    const WRONG_ISSUER = 29;
84    const SESSION_EXPIRED = 30;
85    const WRONG_SUBJECTCONFIRMATION = 31;
86    const NO_SIGNED_MESSAGE = 32;
87    const NO_SIGNED_ASSERTION = 33;
88    const NO_SIGNATURE_FOUND = 34;
89    const KEYINFO_NOT_FOUND_IN_ENCRYPTED_DATA = 35;
90    const CHILDREN_NODE_NOT_FOUND_IN_KEYINFO = 36;
91    const UNSUPPORTED_RETRIEVAL_METHOD = 37;
92    const NO_NAMEID = 38;
93    const EMPTY_NAMEID = 39;
94    const SP_NAME_QUALIFIER_NAME_MISMATCH = 40;
95    const DUPLICATED_ATTRIBUTE_NAME_FOUND = 41;
96    const INVALID_SIGNATURE = 42;
97    const WRONG_NUMBER_OF_SIGNATURES = 43;
98    const RESPONSE_EXPIRED = 44;
99    const UNEXPECTED_REFERENCE = 45;
100    const NOT_SUPPORTED = 46;
101    const KEY_ALGORITHM_ERROR = 47;
102    const MISSING_ENCRYPTED_ELEMENT = 48;
103
104
105    /**
106     * Constructor
107     *
108     * @param string     $msg  Describes the error.
109     * @param int        $code The code error (defined in the error class).
110     * @param array|null $args Arguments used in the message that describes the error.
111     */
112    public function __construct($msg, $code = 0, $args = null)
113    {
114        assert('is_string($msg)');
115        assert('is_int($code)');
116
117        $message = OneLogin_Saml2_Utils::t($msg, $args);
118
119        parent::__construct($message, $code);
120    }
121}
122