One issue caused Custom Authorization

Nov 13, 2012 at 10:38 PM

Hi there,

I'm using Custom Authorization provided by NOF 5 in our project. It has caused one issue described below. I'm not sure what went wrong. Basically, I defined a default authorizer in our project. To make things simple, I comment out all the logic in IsEditable() and IsVisible() method, and just return 'True' for both methods.

Before I plug in the default authorizer, I run the application, I am able to see everything on the menus because 'true' values are returned in my default authorizer. Then in our application, I try to find a customer by entering 'firstname' and 'lastname', click ok, it gives me a list of customers. Click any of customers returned in the list, it displays properties for the slected customer. All work fine at this point.

Then I plug in my default authorizer by adding code like below to runweb.cs file

  protected override NakedObjects.Reflector.Security.IAuthoriserInstaller Authoriser        {            get            {                return new CustomAuthoriserInstaller(new SdmDefaultAuthoriser());                      }       

         } 

Run the application again, I'm able to see everything on the menus as well. However, when I try to find a customer by entering 'firstname' and 'lastname', then click ok. It doesn't give me a list of customers this time. Instead, it gives the error like below. If you look into the stack trace below, the error was thrown by this line.

 NakedObjects.Security.CustomAuthorisationManager.GetTypeAuthoriserFor(INakedObject target) +65

 

Look into the code for GetTypeAuthoriserFor() method in CustomAuthorisationManager class, I guess it's the parameter passed in to this method, which is INakedObject target is null. But I don't understand why that would be null.

Could you shed some light on this please?

 

Object reference not set to an instance of an object.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error: 

 

Line 10:         <%: Html.Object(Model)%>

Line 11:         <%: Html.UserMessages() %>

Line 12:         <%: Html.Collection(Model)%>

Line 13:    

Line 14: </asp:Content>


Source File: c:\BOM_PAGS\Trunk\Code\DELIVERY\business4\Sdm.App\Sdm.App\Views\Shared\StandaloneTable.aspx    Line: 12 

Stack Trace: 

 

[NullReferenceException: Object reference not set to an instance of an object.]

   NakedObjects.Security.CustomAuthorisationManager.GetTypeAuthoriserFor(INakedObject target) +65

   NakedObjects.Security.CustomAuthorisationManager.IsVisible(ISession session, INakedObject target, IIdentifier identifier) +82

   NakedObjects.Reflector.Security.SecurityHideForSessionFacet.HiddenReason(ISession session, INakedObject target) +88

   NakedObjects.Architecture.Facets.Hide.HideForSessionFacetAbstract.Hides(InteractionContext ic) +104

   NakedObjects.Architecture.Interactions.InteractionUtils.IsVisible(IFacetHolder facetHolder, InteractionContext ic) +247

   NakedObjects.Architecture.Reflect.NakedObjectMemberAbstract.IsVisible(ISession session, INakedObject target) +130

   NakedObjects.Web.Mvc.Html.CommonHtmlHelper.<CollectionAssociations>b__af(INakedObjectAssociation a) +81

   System.Linq.<>c__DisplayClassf`1.<CombinePredicates>b__e(TSource x) +21

   System.Linq.WhereSelectArrayIterator`2.MoveNext() +4211784

   System.Linq.Enumerable.Any(IEnumerable`1 source) +83

   NakedObjects.Web.Mvc.Html.CommonHtmlHelper.AddHeader(HtmlHelper html, INakedObject collectionNakedObject, TagBuilder table, Boolean isStandalone, Boolean isSelection, Boolean defaultChecked, Func`2 filter, Func`2 order) +701

   NakedObjects.Web.Mvc.Html.CommonHtmlHelper.CollectionTable(HtmlHelper html, INakedObject collectionNakedObject, Func`2 linkFunc, Func`2 filter, Func`2 order, Boolean isStandalone, Boolean withSelection, Boolean defaultChecked) +276

   NakedObjects.Web.Mvc.Html.CommonHtmlHelper.GetStandalone(HtmlHelper html, INakedObject collectionNakedObject, Func`2 filter, Func`2 order, TagBuilder tag) +404

   NakedObjects.Web.Mvc.Html.CommonHtmlHelper.GetStandaloneList(HtmlHelper html, INakedObject collectionNakedObject, Func`2 order) +228

   NakedObjects.Web.Mvc.Html.CollectionExtensions.CollectionListInternal(HtmlHelper html, IEnumerable collection) +90

   NakedObjects.Web.Mvc.Html.CollectionExtensions.Collection(HtmlHelper html, IEnumerable collection, String defaultTo) +114

   ASP.views_shared_standalonetable_aspx.__RenderContent2(HtmlTextWriter __w, Control parameterContainer) in c:\BOM_PAGS\Trunk\Code\DELIVERY\business4\Sdm.App\Sdm.App\Views\Shared\StandaloneTable.aspx:12

   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +109

   System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +8

   System.Web.UI.Control.Render(HtmlTextWriter writer) +10

   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27

   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +100

   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25

   ASP.views_shared_site_withservices_master.__Render__control1(HtmlTextWriter __w, Control parameterContainer) in c:\BOM_PAGS\Trunk\Code\DELIVERY\business4\Sdm.App\Sdm.App\Views\Shared\Site.WithServices.Master:26

   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +109

   System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +8

   System.Web.UI.Control.Render(HtmlTextWriter writer) +10

   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27

   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +100

   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25

   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +208

   System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +8

   System.Web.Mvc.ViewPage.Render(HtmlTextWriter writer) +56

   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27

   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +100

   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25

   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3060

 

Coordinator
Nov 14, 2012 at 7:19 AM
Edited Nov 14, 2012 at 7:34 AM

This is a known issue, Xiao  -  see http://nakedobjects.codeplex.com/workitem/103

We will be fixing this for the next release (no release date, yet).  Meantime, so as not to hold you up, I recommend you proceed as follows:

- Copy the source for the CustomAuthoriserInstaller and CustomAuthorisationManager  & rename to say, SdmAuthoriserInstaller and SdmAuthorisationManager, such that the new installer references the new manager.  Then just add in a simple check for the passed-in naked object being null and effect an appropriate default behaviour.  Then register the new SdmAuthoriserInstaller in the Authoriser property in the RunWebClass.

Nov 14, 2012 at 9:23 AM

Thanks very much, Richard. I will follow your suggestion 

Nov 14, 2012 at 5:44 PM

It worked after I implemented the check for the null value for target object passed in. 

It seems to me when it retrieves single object, NOF works fine. However when it retrieves a list of objects and display the hyperlinks to them on the page, this causes the issue. It tries to pass in null value to the method. It appears to me NOF tries to call Authoriser for each of object in the list but with null value for target object passed into GetTypeAuthoriserFor() method. 

I think It would be better if NOF doesn't need to call Authoriser  when it just displays a list of hyperlinks to the objects.