web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Code access permission

(0) ShareShare
ReportReport
Posted on by 28

Dear All,

I never work in Code access permission.
What is the purpose of use Code Access Permission?
Could you please give me practical experience how it's work practically in Dynamics AX 2012 R3.

Please give me more shed on this.

Thanks!
Arpan Sen


*This post is locked for comments

I have the same question (0)
  • @rp@n Profile Picture
    28 on at
    RE: Code access permission

    Thanks martin.

  • Martin Dráb Profile Picture
    236,124 Most Valuable Professional on at
    RE: Code access permission

    As I mentioned, and you surely read in the documentation, you don't have to ever use CodeAccessPermission::revertAssert(), so let's ignore that.

    By assert(), you grant permissions to run a specific protected API, such as code for opening a file. And yes, this topic is called "Code Access Security" (as you can see in documentation) and classes such as FileIoPermission represent permissions (as names suggest).

  • @rp@n Profile Picture
    28 on at
    RE: Code access permission

    Hi Martin,

    As you suggested i go through the piece of code. It's mentioned assert() and CodeAccessPermission::revertAssert().

    Suppose in application in any where if i got pieces of code with assert() and CodeAccessPermission::revertAssert() that means it's indicate "Code access permission?

    Thanks!

    Arpan Sen

  • @rp@n Profile Picture
    28 on at
    RE: Code access permission

    Sure, Thanks Martin

  • Verified answer
    Martin Dráb Profile Picture
    236,124 Most Valuable Professional on at
    RE: Code access permission

    No setup except of the code. Please look at the example in documentation, it's very short.

  • @rp@n Profile Picture
    28 on at
    RE: Code access permission

    Thanks Martin,

    So, for that i need to do any setup for CAP? Or it will check permission through assert().

    Thanks!

    Arpan Sen

  • Martin Dráb Profile Picture
    236,124 Most Valuable Professional on at
    RE: Code access permission

    It checks if code in the call stack explicitly granted permissions to access that particular resource, such as the given file. If somebody (such as an attacker) tries to run such code without permissions, it with fail.

    You use assert() method to grant permissions; yo can revert it by CodeAccessPermission::revertAssert(), but it's also removed when the method ends. It's explained in the documentation linked above; use it as a reference.

  • @rp@n Profile Picture
    28 on at
    RE: Code access permission

    Thanks a lot Vilmos.

    Means it will check that i have full permission or not to write file in a class.

    Is there any particular syntax which indicate Code access permission started before starting my logic and after ending my logic.

    I think it's like one scope.

    Please give me more shed on this.

    Thanks!

    Arpan Sen

  • Martin Dráb Profile Picture
    236,124 Most Valuable Professional on at
    RE: Code access permission

    Compiler has nothing to do with it, because the feature analyzes call stacks at runtime. What Vilmos meant by that (I think) was that you can run BP checks automatically after compilation. I don't remember what BP checks applies to CAS.

  • Suggested answer
    Vilmos Kintera Profile Picture
    46,149 on at
    RE: Code access permission

    For example if you try to write to a file in a class that runs server-side, you will get an error if you do not do assert fileiopermission with #io_write intent. You just have to create a class, set the property to run on Server, and add code that is using logic like with CommaIO or AsciiIO to write information to a file (you could google for examples). Then try to compile and run it from a job with assertion commented out. You could also upload that model file with the code on LCS and see what does the code analysis highlight.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Community Member Profile Picture

Community Member 4

#2
Guy Terry Profile Picture

Guy Terry 2 Moderator

#2
Martin Dráb Profile Picture

Martin Dráb 2 Most Valuable Professional

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans