1
1
using System ;
2
2
using System . IO ;
3
3
using System . Net ;
4
+ using System . Runtime . Serialization ;
5
+ using System . Security . Permissions ;
4
6
5
7
namespace Elasticsearch . Net . Connection
6
8
{
9
+ [ Serializable ]
7
10
public abstract class ElasticsearchAuthException : Exception
8
11
{
9
12
protected abstract string ExceptionType { get ; }
10
13
protected abstract int StatusCode { get ; }
11
14
15
+ public ElasticsearchResponse < Stream > Response { get ; private set ; }
16
+
12
17
protected ElasticsearchAuthException ( ElasticsearchResponse < Stream > response )
13
18
{
14
19
this . Response = response ;
15
20
}
16
21
17
- internal ElasticsearchServerException ToElasticsearchServerException ( )
18
- {
19
- if ( this . Response == null )
20
- return null ;
21
- return new ElasticsearchServerException ( this . StatusCode , this . ExceptionType ) ;
22
- }
23
- public ElasticsearchResponse < Stream > Response { get ; private set ; }
22
+ [ SecurityPermission ( SecurityAction . Demand , SerializationFormatter = true ) ]
23
+ protected ElasticsearchAuthException ( SerializationInfo info , StreamingContext context ) : base ( info , context )
24
+ {
25
+ }
26
+
27
+ internal ElasticsearchServerException ToElasticsearchServerException ( ) =>
28
+ this . Response == null ? null : new ElasticsearchServerException ( this . StatusCode , this . ExceptionType ) ;
29
+
30
+
24
31
}
25
32
33
+ [ Serializable ]
26
34
public class ElasticsearchAuthorizationException : ElasticsearchAuthException
27
35
{
28
36
public ElasticsearchAuthorizationException ( ElasticsearchResponse < Stream > response ) : base ( response ) { }
29
37
30
- protected override string ExceptionType { get { return "AuthorizationException" ; } }
38
+ protected override string ExceptionType => "AuthorizationException" ;
39
+
40
+ protected override int StatusCode => 403 ;
41
+
42
+ [ SecurityPermission ( SecurityAction . Demand , SerializationFormatter = true ) ]
43
+ protected ElasticsearchAuthorizationException ( SerializationInfo info , StreamingContext context ) : base ( info , context )
44
+ {
45
+ }
46
+
47
+ [ SecurityPermissionAttribute ( SecurityAction . Demand , SerializationFormatter = true ) ]
48
+ public override void GetObjectData ( SerializationInfo info , StreamingContext context )
49
+ {
50
+ if ( info == null ) throw new ArgumentNullException ( nameof ( info ) ) ;
31
51
32
- protected override int StatusCode { get { return 403 ; } }
52
+ info . AddValue ( "ExceptionType" , this . ExceptionType ) ;
53
+ info . AddValue ( "StatusCode" , this . StatusCode ) ;
54
+ base . GetObjectData ( info , context ) ;
55
+ }
33
56
}
34
57
35
58
59
+ [ Serializable ]
36
60
public class ElasticsearchAuthenticationException : ElasticsearchAuthException
37
61
{
38
- protected override string ExceptionType { get { return "AuthenticationException" ; } }
62
+ protected override string ExceptionType => "AuthenticationException" ;
39
63
40
- protected override int StatusCode { get { return 401 ; } }
64
+ protected override int StatusCode => 401 ;
41
65
42
66
public ElasticsearchAuthenticationException ( ElasticsearchResponse < Stream > response ) : base ( response ) { }
43
67
68
+ [ SecurityPermission ( SecurityAction . Demand , SerializationFormatter = true ) ]
69
+ protected ElasticsearchAuthenticationException ( SerializationInfo info , StreamingContext context ) : base ( info , context )
70
+ {
71
+ }
72
+
73
+ [ SecurityPermissionAttribute ( SecurityAction . Demand , SerializationFormatter = true ) ]
74
+ public override void GetObjectData ( SerializationInfo info , StreamingContext context )
75
+ {
76
+ if ( info == null ) throw new ArgumentNullException ( nameof ( info ) ) ;
77
+
78
+ info . AddValue ( "ExceptionType" , this . ExceptionType ) ;
79
+ info . AddValue ( "StatusCode" , this . StatusCode ) ;
80
+ base . GetObjectData ( info , context ) ;
81
+ }
82
+
44
83
}
45
84
}
0 commit comments