forked from ravendb/ravendb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:ayende/ravendb into 2.1
Conflicts: Raven.Abstractions/Data/IJsonDocumentMetadata.cs Raven.Abstractions/Data/PutResult.cs Raven.Abstractions/Data/StringDistanceTypes.cs Raven.Abstractions/Exceptions/ConcurrencyException.cs Raven.Abstractions/Smuggler/SmugglerOptions.cs Raven.Client.Lightweight/Changes/RemoteDatabaseChanges.cs Raven.Client.Lightweight/Connection/HttpJsonRequestFactory.cs Raven.Client.Lightweight/Connection/ServerClient.cs Raven.Client.Lightweight/Document/AbstractDocumentQuery.cs Raven.Client.Lightweight/Document/InMemoryDocumentSessionOperations.cs Raven.Client.Lightweight/Document/RemoteBulkInsertOperation.cs Raven.Client.Lightweight/IAsyncDocumentSession.cs Raven.Client.Lightweight/Indexes/ExpressionStringBuilder.cs Raven.Client.Lightweight/Linq/LinqPathProvider.cs Raven.Client.Lightweight/PublicExtensions/LinqExtensions.cs Raven.Client.VisualBasic.Tests/Raven.Client.VisualBasic.Tests.vbproj Raven.Client.VisualBasic.Tests/packages.config Raven.Database/Data/AttachmentInformation.cs Raven.Database/Data/IndexQueryResult.cs Raven.Database/DocumentDatabase.cs Raven.Database/Extensions/AdminFinder.cs Raven.Database/Extensions/HttpContextExtensions.cs Raven.Database/Extensions/HttpExtensions.cs Raven.Database/Indexing/CurrentIndexingScope.cs Raven.Database/Indexing/IndexingExecuter.cs Raven.Database/Indexing/ReducingExecuter.cs Raven.Database/Plugins/Builtins/Tenants/ModifiedTenantDatabase.cs Raven.Database/Server/Responders/Docs.cs Raven.Database/Server/Responders/Facets.cs Raven.Database/Server/Security/OAuth/OAuthRequestAuthorizer.cs Raven.Database/Server/Security/Windows/WindowsRequestAuthorizer.cs Raven.Database/Storage/Esent/Backup/RestoreOperation.cs Raven.Database/Storage/Esent/StorageActions/Indexing.cs Raven.Database/Storage/Esent/StorageActions/Lists.cs Raven.Database/Storage/Esent/StorageActions/MappedResults.cs Raven.Database/Storage/Esent/TransactionalStorage.cs Raven.Database/Storage/IListsStorageActions.cs Raven.Database/Storage/Managed/ListsStorageActions.cs Raven.Database/Storage/Managed/MappedResultsStorageAction.cs Raven.Database/Storage/Managed/TransactionStorageActions.cs Raven.Server/App.config Raven.Studio/Controls/DateTimePicker.xaml Raven.Studio/Models/EditableDocumentModel.cs Raven.Studio/Models/ServerModel.cs Raven.Studio/Views/Edit.xaml Raven.Tests/App.config Raven.Tests/Bundles/Replication/Issues/RavenDB677.cs Raven.Tests/MailingList/IisQueryLengthIssues.cs Raven.Tests/Querying/UsingDynamicQueryWithRemoteServer.cs Raven.Tests/Storage/Lists.cs Raven.Tryouts/Program.cs
- Loading branch information
Showing
498 changed files
with
21,281 additions
and
6,503 deletions.
There are no files selected for viewing
104 changes: 104 additions & 0 deletions
104
Bundles/Raven.Bundles.Tests/Authorization/Bugs/Matthew.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
extern alias client; | ||
using Raven.Client.Exceptions; | ||
using client::Raven.Bundles.Authorization.Model; | ||
using System.Collections.Generic; | ||
using Raven.Client; | ||
using Xunit; | ||
|
||
namespace Raven.Bundles.Tests.Authorization.Bugs | ||
{ | ||
public class Matthew : AuthorizationTest | ||
{ | ||
[Fact] | ||
public void AuthorizationDemo_Works() | ||
{ | ||
// Arrange | ||
using (IDocumentSession session = store.OpenSession()) | ||
{ | ||
session.Store( | ||
new AuthorizationRole | ||
{ | ||
Id = "Authorization/Roles/Nurses", | ||
Permissions = | ||
{ | ||
new OperationPermission | ||
{ | ||
Allow = true, | ||
Operation = "Appointment/Schedule", | ||
Tags = new List<string> {"Patient"} | ||
} | ||
} | ||
}); | ||
|
||
// Allow doctors to authorize hospitalizations | ||
session.Store( | ||
new AuthorizationRole | ||
{ | ||
Id = "Authorization/Roles/Doctors", | ||
Permissions = | ||
{ | ||
new OperationPermission | ||
{ | ||
Allow = true, | ||
Operation = "Hospitalization/Authorize", | ||
Tags = new List<string> {"Patient"} | ||
} | ||
} | ||
}); | ||
// Associate Patient with clinic | ||
var maryMallon = new Patient {Id = "Patients/MaryMallon"}; | ||
session.Store(maryMallon); | ||
client::Raven.Client.Authorization.AuthorizationClientExtensions.SetAuthorizationFor(session, maryMallon, | ||
new DocumentAuthorization | ||
{ | ||
Tags = | ||
{ | ||
"Clinics/Kirya", | ||
"Patient" | ||
} | ||
}); | ||
|
||
// Associate Doctor with clinic | ||
session.Store( | ||
new AuthorizationUser | ||
{ | ||
Id = "Authorization/Users/DrHowser", | ||
Name = "Doogie Howser", | ||
Roles = {"Authorization/Roles/Doctors"}, | ||
Permissions = | ||
{ | ||
new OperationPermission | ||
{ | ||
Allow = true, | ||
Operation = "Patient/View", | ||
Tags = new List<string> {"Clinics/Kirya"} | ||
}, | ||
} | ||
}); | ||
session.SaveChanges(); | ||
} | ||
|
||
|
||
// Assert | ||
using (IDocumentSession session = store.OpenSession()) | ||
{ | ||
client::Raven.Client.Authorization.AuthorizationClientExtensions.SecureFor(session, | ||
"Authorization/Users/NotDrHowser", | ||
"Hospitalization/Authorize"); | ||
var readVetoException = Assert.Throws<ReadVetoException>(() => session.Load<Patient>("Patients/MaryMallon")); | ||
Assert.Contains( | ||
"Could not find user: Authorization/Users/NotDrHowser for secured document: Patients/MaryMallon", | ||
readVetoException.Message); | ||
} | ||
} | ||
} | ||
|
||
public class Patient | ||
{ | ||
public string Id { get; set; } | ||
|
||
public void AuthorizeHospitalization() | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
Bundles/Raven.Bundles.Tests/Replication/ReplicationDestinationDisabled.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,54 @@ | ||
using System; | ||
using System.Collections.Concurrent; | ||
using System.IO; | ||
using System.Net; | ||
using Raven.Abstractions.Data; | ||
using Raven.Abstractions.OAuth; | ||
|
||
namespace Raven.Abstractions.Connection | ||
{ | ||
public class HttpRavenRequestFactory | ||
{ | ||
public int? RequestTimeoutInMs { get; set; } | ||
|
||
private bool RefreshOauthToken(RavenConnectionStringOptions options, WebResponse response) | ||
readonly ConcurrentDictionary<string, SecuredAuthenticator> authenticators = new ConcurrentDictionary<string, SecuredAuthenticator>(); | ||
|
||
public void ConfigureRequest(RavenConnectionStringOptions options, WebRequest request) | ||
{ | ||
var oauthSource = response.Headers["OAuth-Source"]; | ||
if (string.IsNullOrEmpty(oauthSource)) | ||
return false; | ||
if (RequestTimeoutInMs.HasValue) | ||
request.Timeout = RequestTimeoutInMs.Value; | ||
|
||
|
||
var authRequest = PrepareOAuthRequest(options, oauthSource); | ||
using (var authResponse = authRequest.GetResponse()) | ||
using (var stream = authResponse.GetResponseStreamWithHttpDecompression()) | ||
using (var reader = new StreamReader(stream)) | ||
if (options.ApiKey == null) | ||
{ | ||
options.CurrentOAuthToken = "Bearer " + reader.ReadToEnd(); | ||
request.Credentials = options.Credentials ?? CredentialCache.DefaultNetworkCredentials; | ||
return; | ||
} | ||
return true; | ||
} | ||
|
||
private HttpWebRequest PrepareOAuthRequest(RavenConnectionStringOptions options, string oauthSource) | ||
{ | ||
var authRequest = (HttpWebRequest) WebRequest.Create(oauthSource); | ||
authRequest.Credentials = options.Credentials; | ||
authRequest.Headers["Accept-Encoding"] = "deflate,gzip"; | ||
authRequest.Accept = "application/json;charset=UTF-8"; | ||
|
||
authRequest.Headers["grant_type"] = "client_credentials"; | ||
var value = authenticators.GetOrAdd(options.ApiKey, s => new SecuredAuthenticator(s)); | ||
|
||
if (string.IsNullOrEmpty(options.ApiKey) == false) | ||
authRequest.Headers["Api-Key"] = options.ApiKey; | ||
|
||
return authRequest; | ||
value.ConfigureRequest(this, new WebRequestEventArgs | ||
{ | ||
Request = request | ||
}); | ||
} | ||
|
||
public void ConfigureRequest(RavenConnectionStringOptions options, WebRequest request) | ||
public HttpRavenRequest Create(string url, string method, RavenConnectionStringOptions connectionStringOptions) | ||
{ | ||
request.Credentials = options.Credentials ?? CredentialCache.DefaultNetworkCredentials; | ||
|
||
if (RequestTimeoutInMs.HasValue) | ||
request.Timeout = RequestTimeoutInMs.Value; | ||
|
||
if (string.IsNullOrEmpty(options.CurrentOAuthToken) == false) | ||
request.Headers["Authorization"] = options.CurrentOAuthToken; | ||
return new HttpRavenRequest(url, method, ConfigureRequest, HandleUnauthorizedResponse, connectionStringOptions); | ||
} | ||
|
||
public HttpRavenRequest Create(string url, string method, RavenConnectionStringOptions connectionStringOptions) | ||
private bool HandleUnauthorizedResponse(RavenConnectionStringOptions options, WebResponse webResponse) | ||
{ | ||
return new HttpRavenRequest(url, method, ConfigureRequest, RefreshOauthToken, connectionStringOptions); | ||
if (options.ApiKey == null) | ||
return false; | ||
|
||
var value = authenticators.GetOrAdd(options.ApiKey, s => new SecuredAuthenticator(s)); | ||
|
||
var oauthSource = options.Url + "/OAuth/API-Key"; | ||
|
||
var result = value.DoOAuthRequest(oauthSource); | ||
return result != null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.