@@ -31,6 +31,36 @@ public enum NSURLCredentialPersistence : UInt {
31
31
@discussion This class is an immutable object representing an authentication credential. The actual type of the credential is determined by the constructor called in the categories declared below.
32
32
*/
33
33
public class NSURLCredential : NSObject , NSSecureCoding , NSCopying {
34
+ internal var _user : String
35
+ internal var _password : String
36
+ internal var _persistence : NSURLCredentialPersistence
37
+
38
+ /*!
39
+ @method initWithUser:password:persistence:
40
+ @abstract Initialize a NSURLCredential with a user and password
41
+ @param user the username
42
+ @param password the password
43
+ @param persistence enum that says to store per session, permanently or not at all
44
+ @result The initialized NSURLCredential
45
+ */
46
+ public init ( user: String , password: String , persistence: NSURLCredentialPersistence ) {
47
+ guard persistence != . Permanent && persistence != . Synchronizable else {
48
+ NSUnimplemented ( )
49
+ }
50
+ _user = user
51
+ _password = password
52
+ _persistence = persistence
53
+ super. init ( )
54
+ }
55
+
56
+ /*!
57
+ @method credentialWithUser:password:persistence:
58
+ @abstract Create a new NSURLCredential with a user and password
59
+ @param user the username
60
+ @param password the password
61
+ @param persistence enum that says to store per session, permanently or not at all
62
+ @result The new autoreleased NSURLCredential
63
+ */
34
64
35
65
public required init ? ( coder aDecoder: NSCoder ) {
36
66
NSUnimplemented ( )
@@ -57,36 +87,14 @@ public class NSURLCredential : NSObject, NSSecureCoding, NSCopying {
57
87
@abstract Determine whether this credential is or should be stored persistently
58
88
@result A value indicating whether this credential is stored permanently, per session or not at all.
59
89
*/
60
- public var persistence : NSURLCredentialPersistence { NSUnimplemented ( ) }
61
- }
62
-
63
- extension NSURLCredential {
64
-
65
- /*!
66
- @method initWithUser:password:persistence:
67
- @abstract Initialize a NSURLCredential with a user and password
68
- @param user the username
69
- @param password the password
70
- @param persistence enum that says to store per session, permanently or not at all
71
- @result The initialized NSURLCredential
72
- */
73
- public convenience init ( user: String , password: String , persistence: NSURLCredentialPersistence ) { NSUnimplemented ( ) }
74
-
75
- /*!
76
- @method credentialWithUser:password:persistence:
77
- @abstract Create a new NSURLCredential with a user and password
78
- @param user the username
79
- @param password the password
80
- @param persistence enum that says to store per session, permanently or not at all
81
- @result The new autoreleased NSURLCredential
82
- */
90
+ public var persistence : NSURLCredentialPersistence { return _persistence }
83
91
84
92
/*!
85
93
@method user
86
94
@abstract Get the username
87
95
@result The user string
88
- */
89
- public var user : String ? { NSUnimplemented ( ) }
96
+ */
97
+ public var user : String ? { return _user }
90
98
91
99
/*!
92
100
@method password
@@ -95,9 +103,9 @@ extension NSURLCredential {
95
103
@discussion This method might actually attempt to retrieve the
96
104
password from an external store, possible resulting in prompting,
97
105
so do not call it unless needed.
98
- */
99
- public var password : String ? { NSUnimplemented ( ) }
100
-
106
+ */
107
+ public var password : String ? { return _password }
108
+
101
109
/*!
102
110
@method hasPassword
103
111
@abstract Find out if this credential has a password, without trying to get it
@@ -106,8 +114,11 @@ extension NSURLCredential {
106
114
external store, the password method may return nil even if this
107
115
method returns YES, since getting the password may fail, or the
108
116
user may refuse access.
109
- */
110
- public var hasPassword : Bool { NSUnimplemented ( ) }
117
+ */
118
+ public var hasPassword : Bool {
119
+ // Currently no support for SecTrust/SecIdentity, always return true
120
+ return true
121
+ }
111
122
}
112
123
113
124
// TODO: We have no implementation for Security.framework primitive types SecIdentity and SecTrust yet
0 commit comments