diff options
| author | Luke Pulverenti <luke.pulverenti@gmail.com> | 2014-11-14 21:31:03 -0500 |
|---|---|---|
| committer | Luke Pulverenti <luke.pulverenti@gmail.com> | 2014-11-14 21:31:03 -0500 |
| commit | a4b75934e5a4737ba7721c33ad9a009060a8a246 (patch) | |
| tree | a738ce7e7a6b707107b438220457d73585d0e4dd /MediaBrowser.Controller | |
| parent | 15a56fa069d85382fa2e053a9a60e763308c2d66 (diff) | |
revise endpoint attributes
Diffstat (limited to 'MediaBrowser.Controller')
11 files changed, 134 insertions, 24 deletions
diff --git a/MediaBrowser.Controller/Entities/UserViewBuilder.cs b/MediaBrowser.Controller/Entities/UserViewBuilder.cs index a76a284693..71e26b23cc 100644 --- a/MediaBrowser.Controller/Entities/UserViewBuilder.cs +++ b/MediaBrowser.Controller/Entities/UserViewBuilder.cs @@ -1618,7 +1618,7 @@ namespace MediaBrowser.Controller.Entities var parent = user.RootFolder; - list.Add(await GetUserView(SpecialFolder.LiveTvNowPlaying, user, "0", parent).ConfigureAwait(false)); + //list.Add(await GetUserView(SpecialFolder.LiveTvNowPlaying, user, "0", parent).ConfigureAwait(false)); list.Add(await GetUserView(SpecialFolder.LiveTvChannels, user, string.Empty, parent).ConfigureAwait(false)); list.Add(await GetUserView(SpecialFolder.LiveTvRecordingGroups, user, string.Empty, parent).ConfigureAwait(false)); diff --git a/MediaBrowser.Controller/MediaBrowser.Controller.csproj b/MediaBrowser.Controller/MediaBrowser.Controller.csproj index 69edabfb92..72a8f60163 100644 --- a/MediaBrowser.Controller/MediaBrowser.Controller.csproj +++ b/MediaBrowser.Controller/MediaBrowser.Controller.csproj @@ -220,8 +220,11 @@ <Compile Include="Net\IHttpResultFactory.cs" /> <Compile Include="Net\IHttpServer.cs" /> <Compile Include="Net\IRestfulService.cs" /> + <Compile Include="Net\IServiceRequest.cs" /> <Compile Include="Net\ISessionContext.cs" /> <Compile Include="Net\LoggedAttribute.cs" /> + <Compile Include="Net\SecurityException.cs" /> + <Compile Include="Net\ServiceStackServiceRequest.cs" /> <Compile Include="Net\StaticResultOptions.cs" /> <Compile Include="News\INewsService.cs" /> <Compile Include="Notifications\INotificationManager.cs" /> diff --git a/MediaBrowser.Controller/Net/AuthenticatedAttribute.cs b/MediaBrowser.Controller/Net/AuthenticatedAttribute.cs index 17c91c9773..b1bab79c5c 100644 --- a/MediaBrowser.Controller/Net/AuthenticatedAttribute.cs +++ b/MediaBrowser.Controller/Net/AuthenticatedAttribute.cs @@ -5,7 +5,7 @@ using System.Linq; namespace MediaBrowser.Controller.Net { - public class AuthenticatedAttribute : Attribute, IHasRequestFilter, IAuthenticated + public class AuthenticatedAttribute : Attribute, IHasRequestFilter, IAuthenticationAttributes { public IAuthService AuthService { get; set; } @@ -22,6 +22,12 @@ namespace MediaBrowser.Controller.Net public bool EscapeParentalControl { get; set; } /// <summary> + /// Gets or sets a value indicating whether [allow before startup wizard]. + /// </summary> + /// <value><c>true</c> if [allow before startup wizard]; otherwise, <c>false</c>.</value> + public bool AllowBeforeStartupWizard { get; set; } + + /// <summary> /// The request filter is executed before the service. /// </summary> /// <param name="request">The http request wrapper</param> @@ -29,7 +35,9 @@ namespace MediaBrowser.Controller.Net /// <param name="requestDto">The request DTO</param> public void RequestFilter(IRequest request, IResponse response, object requestDto) { - AuthService.Authenticate(request, response, requestDto, this); + var serviceRequest = new ServiceStackServiceRequest(request); + + AuthService.Authenticate(serviceRequest, this); } /// <summary> @@ -60,9 +68,10 @@ namespace MediaBrowser.Controller.Net } } - public interface IAuthenticated + public interface IAuthenticationAttributes { bool EscapeParentalControl { get; } + bool AllowBeforeStartupWizard { get; } IEnumerable<string> GetRoles(); } diff --git a/MediaBrowser.Controller/Net/IAuthService.cs b/MediaBrowser.Controller/Net/IAuthService.cs index 9d335566ff..dc298c8d90 100644 --- a/MediaBrowser.Controller/Net/IAuthService.cs +++ b/MediaBrowser.Controller/Net/IAuthService.cs @@ -1,12 +1,9 @@ -using ServiceStack.Web; - + namespace MediaBrowser.Controller.Net { public interface IAuthService { - void Authenticate(IRequest request, - IResponse response, - object requestDto, - IAuthenticated authAttribtues); + void Authenticate(IServiceRequest request, + IAuthenticationAttributes authAttribtues); } } diff --git a/MediaBrowser.Controller/Net/IAuthorizationContext.cs b/MediaBrowser.Controller/Net/IAuthorizationContext.cs index 9cf5623700..bdaed60469 100644 --- a/MediaBrowser.Controller/Net/IAuthorizationContext.cs +++ b/MediaBrowser.Controller/Net/IAuthorizationContext.cs @@ -1,5 +1,4 @@ -using ServiceStack.Web; - + namespace MediaBrowser.Controller.Net { public interface IAuthorizationContext @@ -9,6 +8,13 @@ namespace MediaBrowser.Controller.Net /// </summary> /// <param name="requestContext">The request context.</param> /// <returns>AuthorizationInfo.</returns> - AuthorizationInfo GetAuthorizationInfo(IRequest requestContext); + AuthorizationInfo GetAuthorizationInfo(object requestContext); + + /// <summary> + /// Gets the authorization information. + /// </summary> + /// <param name="requestContext">The request context.</param> + /// <returns>AuthorizationInfo.</returns> + AuthorizationInfo GetAuthorizationInfo(IServiceRequest requestContext); } } diff --git a/MediaBrowser.Controller/Net/IServiceRequest.cs b/MediaBrowser.Controller/Net/IServiceRequest.cs new file mode 100644 index 0000000000..e48247362b --- /dev/null +++ b/MediaBrowser.Controller/Net/IServiceRequest.cs @@ -0,0 +1,15 @@ +using System.Collections.Generic; +using System.Collections.Specialized; + +namespace MediaBrowser.Controller.Net +{ + public interface IServiceRequest + { + object OriginalRequest { get; } + string RemoteIp { get; } + NameValueCollection Headers { get; } + NameValueCollection QueryString { get; } + IDictionary<string,object> Items { get; } + void AddResponseHeader(string name, string value); + } +} diff --git a/MediaBrowser.Controller/Net/ISessionContext.cs b/MediaBrowser.Controller/Net/ISessionContext.cs index 31ccd53731..be8d28acc6 100644 --- a/MediaBrowser.Controller/Net/ISessionContext.cs +++ b/MediaBrowser.Controller/Net/ISessionContext.cs @@ -1,13 +1,14 @@ using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Session; -using ServiceStack.Web; namespace MediaBrowser.Controller.Net { public interface ISessionContext { - SessionInfo GetSession(IRequest requestContext); - - User GetUser(IRequest requestContext); + SessionInfo GetSession(object requestContext); + User GetUser(object requestContext); + + SessionInfo GetSession(IServiceRequest requestContext); + User GetUser(IServiceRequest requestContext); } } diff --git a/MediaBrowser.Controller/Net/LoggedAttribute.cs b/MediaBrowser.Controller/Net/LoggedAttribute.cs index ea07b1c7f5..d56a015a86 100644 --- a/MediaBrowser.Controller/Net/LoggedAttribute.cs +++ b/MediaBrowser.Controller/Net/LoggedAttribute.cs @@ -22,8 +22,10 @@ namespace MediaBrowser.Controller.Net /// <param name="requestDto">The request DTO</param> public void RequestFilter(IRequest request, IResponse response, object requestDto) { + var serviceRequest = new ServiceStackServiceRequest(request); + //This code is executed before the service - var auth = AuthorizationContext.GetAuthorizationInfo(request); + var auth = AuthorizationContext.GetAuthorizationInfo(serviceRequest); if (auth != null) { diff --git a/MediaBrowser.Controller/Net/SecurityException.cs b/MediaBrowser.Controller/Net/SecurityException.cs new file mode 100644 index 0000000000..b251ab9a92 --- /dev/null +++ b/MediaBrowser.Controller/Net/SecurityException.cs @@ -0,0 +1,21 @@ +using System; + +namespace MediaBrowser.Controller.Net +{ + public class SecurityException : Exception + { + public SecurityException(string message) + : base(message) + { + + } + + public SecurityExceptionType SecurityExceptionType { get; set; } + } + + public enum SecurityExceptionType + { + Unauthenticated = 0, + ParentalControl = 1 + } +} diff --git a/MediaBrowser.Controller/Net/ServiceStackServiceRequest.cs b/MediaBrowser.Controller/Net/ServiceStackServiceRequest.cs new file mode 100644 index 0000000000..a33e9c1c6e --- /dev/null +++ b/MediaBrowser.Controller/Net/ServiceStackServiceRequest.cs @@ -0,0 +1,62 @@ +using ServiceStack.Web; +using System; +using System.Collections.Generic; +using System.Collections.Specialized; + +namespace MediaBrowser.Controller.Net +{ + public class ServiceStackServiceRequest : IServiceRequest + { + private readonly IRequest _request; + + public ServiceStackServiceRequest(IRequest request) + { + _request = request; + } + + public object OriginalRequest + { + get { return _request; } + } + + public string RemoteIp + { + get { return _request.RemoteIp; } + } + + private NameValueCollection _headers; + public NameValueCollection Headers + { + get { return _headers ?? (_headers = Get(_request.Headers)); } + } + + private NameValueCollection _query; + public NameValueCollection QueryString + { + get { return _query ?? (_query = Get(_request.QueryString)); } + } + + private NameValueCollection Get(INameValueCollection coll) + { + var nv = new NameValueCollection(StringComparer.OrdinalIgnoreCase); + + foreach (var key in coll.AllKeys) + { + nv[key] = coll[key]; + } + + return nv; + //return coll.ToNameValueCollection(); + } + + public IDictionary<string, object> Items + { + get { return _request.Items; } + } + + public void AddResponseHeader(string name, string value) + { + _request.Response.AddHeader(name, value); + } + } +} diff --git a/MediaBrowser.Controller/Session/ISessionManager.cs b/MediaBrowser.Controller/Session/ISessionManager.cs index 8bc5168875..f0272b3350 100644 --- a/MediaBrowser.Controller/Session/ISessionManager.cs +++ b/MediaBrowser.Controller/Session/ISessionManager.cs @@ -256,12 +256,6 @@ namespace MediaBrowser.Controller.Session SessionInfo GetSession(string deviceId, string client, string version); /// <summary> - /// Validates the security token. - /// </summary> - /// <param name="accessToken">The access token.</param> - void ValidateSecurityToken(string accessToken); - - /// <summary> /// Logouts the specified access token. /// </summary> /// <param name="accessToken">The access token.</param> |
