Determining a Flex application’s current security sandbox type

by Peter deHaan on September 20, 2007

in Security

The following example shows how you can determine the current security sandbox type for a Flex application by checking the static, read-only Security.sandboxType property. You can also check for specific sandbox types by comparing the sandboxType property to the static constants in the Security class (LOCAL_TRUSTED, LOCAL_WITH_FILE, LOCAL_WITH_NETWORK, and REMOTE).

Full code after the jump.

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2007/09/20/determing-a-flex-applications-current-security-sandbox-type/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white"
        creationComplete="init();">

    <mx:Script>
        <![CDATA[
            private function init():void {
                switch (Security.sandboxType) {
                    case Security.LOCAL_TRUSTED:
                        sandboxLabel.text += " (Local trusted)";
                        break;
                    case Security.LOCAL_WITH_FILE:
                        sandboxLabel.text += " (Local with file)";
                        break;
                    case Security.LOCAL_WITH_NETWORK:
                        sandboxLabel.text += " (Local with network)";
                        break;
                    case Security.REMOTE:
                        sandboxLabel.text += " (Remote)";
                        break;
                }
            }
        ]]>
    </mx:Script>

    <mx:Form>
        <mx:FormItem label="Security.sandboxType:" fontSize="16">
            <mx:Label id="sandboxLabel" text="{Security.sandboxType}" />
        </mx:FormItem>
    </mx:Form>

</mx:Application>

View source is enabled in the following example.

{ 3 comments… read them below or add one }

1 John C. Bland II September 21, 2007 at 12:10 am

Peter, what would be a use-case for this? The only thing I can think of is automatically switching between a live url or a test url (for local dev’ that is).

BTW, where’s the RSS or subscribe feature for comments? :-D (not that I can really talk but figured I’d ask)

Reply

2 peterd September 21, 2007 at 6:59 am

Their isn’t a valid use case for this example specifically. But I’m working on the security feature and the loading rules are different for each of the 4 sandbox types.
Typically when you build an application you’d know where it is being deployed though.

RSS for comments? There are two. Look in the footer for the site-wide comments, where it says “powered by WordPress and Redoable 1.2″. The link is http://blog.flexexamples.com/comments/feed/.
If you want RSS for a specific entry, look below the lone Google ad around the entry comments. There should be an orange RSS icon which says “Feed for this Entry”, or, it looks like you can just append “/feed/” to the end of the URL. So for this specific entry it’d be:
http://blog.flexexamples.com/2007/09/20/determing-a-flex-applications-current-security-sandbox-type/feed/

Peter

Reply

3 John Pencola May 12, 2009 at 2:44 pm

One such use-case that I just ran into involved checking the sandbox type to know whether to pass a SecurityDomain to a LoaderContext. This worked nicely to allow me to fork the LoaderContext logic when running the SWF from the filesystem as opposed to a server.

Reply

Leave a Comment

Sorry, this blog is terrible at eating HTML comments.
If you're pasting any HTML/XML/MXML code, you need to convert your < characters to &lt; and your > characters to &gt; .

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Anti-Spam Protection by WP-SpamFree

Previous post:

Next post: