added CMISStandardUntrustedSSLAuthenticationProvider to support untrusted SSL connections in test environments as suggested by Mike Hatfield @Alfresco
git-svn-id: https://svn.apache.org/repos/asf/chemistry/objectivecmis/trunk@1501205 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/ObjectiveCMIS/Common/CMISAuthenticationProvider.h b/ObjectiveCMIS/Common/CMISAuthenticationProvider.h
index a8ce9be..b1e6bec 100644
--- a/ObjectiveCMIS/Common/CMISAuthenticationProvider.h
+++ b/ObjectiveCMIS/Common/CMISAuthenticationProvider.h
@@ -19,7 +19,7 @@
#import <Foundation/Foundation.h>
-@protocol CMISAuthenticationProvider
+@protocol CMISAuthenticationProvider <NSObject>
/**
* Returns a set of HTTP headers (key-value pairs) that should be added to a
diff --git a/ObjectiveCMIS/Common/CMISStandardUntrustedSSLAuthenticationProvider.h b/ObjectiveCMIS/Common/CMISStandardUntrustedSSLAuthenticationProvider.h
new file mode 100644
index 0000000..4c91e24
--- /dev/null
+++ b/ObjectiveCMIS/Common/CMISStandardUntrustedSSLAuthenticationProvider.h
@@ -0,0 +1,24 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+
+#import "CMISStandardAuthenticationProvider.h"
+
+@interface CMISStandardUntrustedSSLAuthenticationProvider : CMISStandardAuthenticationProvider
+
+@end
diff --git a/ObjectiveCMIS/Common/CMISStandardUntrustedSSLAuthenticationProvider.m b/ObjectiveCMIS/Common/CMISStandardUntrustedSSLAuthenticationProvider.m
new file mode 100644
index 0000000..2fbad88
--- /dev/null
+++ b/ObjectiveCMIS/Common/CMISStandardUntrustedSSLAuthenticationProvider.m
@@ -0,0 +1,50 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+
+#import "CMISStandardUntrustedSSLAuthenticationProvider.h"
+
+@implementation CMISStandardUntrustedSSLAuthenticationProvider
+
+- (BOOL)canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace
+{
+ if ([protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) {
+ return YES;
+ } else {
+ return [super canAuthenticateAgainstProtectionSpace:protectionSpace];
+ }
+}
+
+/**
+ * NOTE: Once the TLS Session has been cached for an untrusted connection, that session will be reused
+ * by iOS (since 6.0) and willSendRequestForAuthenticationChallenge: will not be called again until the session is cleared.
+ * The session is cleared by an app restart or after around 10 minutes.
+ * See Apple Technical Q&A QA1727 http://developer.apple.com/library/ios/#qa/qa1727 for full details.
+ */
+- (void)didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
+{
+ if ((challenge.previousFailureCount == 0) &&
+ ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]))
+ {
+ [challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];
+ } else {
+ [super didReceiveAuthenticationChallenge:challenge];
+ }
+}
+
+@end
diff --git a/ObjectiveCMIS/Utils/CMISLog.h b/ObjectiveCMIS/Utils/CMISLog.h
index 1f98fb8..a0caf55 100644
--- a/ObjectiveCMIS/Utils/CMISLog.h
+++ b/ObjectiveCMIS/Utils/CMISLog.h
@@ -13,13 +13,10 @@
*/
/**
- * Default logging macros and log level
+ * Default logging level
*
- * The default logging writes to NSLog.
* The default logging level is Info for release builds and Debug for debug builds.
- * The recommended way to override the default is to #import this header file in your app's .pch file
- * and then redefine the CMIS_LOG_LEVEL macro to suit, e.g.
- * #undef CMIS_LOG_LEVEL
+ * This can easily be overriden in your app's .pch file, e.g.
* #define CMIS_LOG_LEVEL CMISLogLevelTrace
*/
#if !defined(CMISLogError)