lib/accessing.js
function AccessContext(context, app) {
    if (!(this instanceof AccessContext)) {
        return new AccessContext(context, app);
    }
    context = context || {};
    this.app = app;

    this.principals = context.principals || [];
    var model = context.model;
    model = ('string' === typeof model) ? app.model(model) : model;
    this.model = model;
    this.modelName = model && model.modelName;

    this.modelId = context.id || context.modelId;
    this.property = context.property || AccessContext.ALL;

    this.method = context.method;
    this.sharedMethod = context.sharedMethod;
    this.sharedClass = this.sharedMethod && this.sharedMethod.sharedClass;
    if(this.sharedMethod) {
        this.methodNames = this.sharedMethod.aliases.concat([this.sharedMethod.name]);
    } else {
        this.methodNames = [];
    }

    if(this.sharedMethod) {
        this.accessType = sec.getAccessTypeForMethod(this.sharedMethod);
    }

    this.accessType = context.accessType || AccessContext.ALL;
    this.accessToken = context.accessToken || app.model('AccessToken').ANONYMOUS;

    var principalType = context.principalType || Principal.USER;
    var principalId = context.principalId || undefined;
    var principalName = context.principalName || undefined;
    if (principalId) {
        this.addPrincipal(principalType, principalId, principalName);
    }

    var token = this.accessToken || {};

    if (token.userId) {
        this.addPrincipal(Principal.USER, token.userId);
    }
    if (token.appId) {
        this.addPrincipal(Principal.APPLICATION, token.appId);
    }

    this.remoteContext = context.remoteContext;
}
function AccessContext(context, app) {
    if (!(this instanceof AccessContext)) {
        return new AccessContext(context, app);
    }
    context = context || {};
    this.app = app;

    this.principals = context.principals || [];
    var model = context.model;
    model = ('string' === typeof model) ? app.model(model) : model;
    this.model = model;
    this.modelName = model && model.modelName;

    this.modelId = context.id || context.modelId;
    this.property = context.property || AccessContext.ALL;

    this.method = context.method;
    this.sharedMethod = context.sharedMethod;
    this.sharedClass = this.sharedMethod && this.sharedMethod.sharedClass;
    if(this.sharedMethod) {
        this.methodNames = this.sharedMethod.aliases.concat([this.sharedMethod.name]);
    } else {
        this.methodNames = [];
    }

    if(this.sharedMethod) {
        this.accessType = sec.getAccessTypeForMethod(this.sharedMethod);
    }

    this.accessType = context.accessType || AccessContext.ALL;
    this.accessToken = context.accessToken || app.model('AccessToken').ANONYMOUS;

    var principalType = context.principalType || Principal.USER;
    var principalId = context.principalId || undefined;
    var principalName = context.principalName || undefined;
    if (principalId) {
        this.addPrincipal(principalType, principalId, principalName);
    }

    var token = this.accessToken || {};

    if (token.userId) {
        this.addPrincipal(Principal.USER, token.userId);
    }
    if (token.appId) {
        this.addPrincipal(Principal.APPLICATION, token.appId);
    }

    this.remoteContext = context.remoteContext;
}
function AccessContext ( context , app ) { if ( ! ( this instanceof AccessContext ) ) { return new AccessContext ( context , app ) ; } context = context || { } ; this . app = app ; this . principals = context . principals || [ ] ; var model = context . model ; model = ( 'string' === typeof model ) ? app . model ( model ) : model ; this . model = model ; this . modelName = model && model . modelName ; this . modelId = context . id || context . modelId ; this . property = context . property || AccessContext . ALL ; this . method = context . method ; this . sharedMethod = context . sharedMethod ; this . sharedClass = this . sharedMethod && this . sharedMethod . sharedClass ; if ( this . sharedMethod ) { this . methodNames = this . sharedMethod . aliases . concat ( [ this . sharedMethod . name ] ) ; } else { this . methodNames = [ ] ; } if ( this . sharedMethod ) { this . accessType = sec . getAccessTypeForMethod ( this . sharedMethod ) ; } this . accessType = context . accessType || AccessContext . ALL ; this . accessToken = context . accessToken || app . model ( 'AccessToken' ) . ANONYMOUS ; var principalType = context . principalType || Principal . USER ; var principalId = context . principalId || undefined ; var principalName = context . principalName || undefined ; if ( principalId ) { this . addPrincipal ( principalType , principalId , principalName ) ; } var token = this . accessToken || { } ; if ( token . userId ) { this . addPrincipal ( Principal . USER , token . userId ) ; } if ( token . appId ) { this . addPrincipal ( Principal . APPLICATION , token . appId ) ; } this . remoteContext = context . remoteContext ; }
Access context represents the context for a request to access protected
resources

@class
@param {Object} context The context object
@param {Principal[]} context.principals An array of principals
@param {Function} context.model The model class
@param {String} context.modelName The model name
@param {String} context.modelId The model id
@param {String} context.property The model property/method/relation name
@param {String} context.method The model method to be invoked
@param {String} context.accessType The access type
@param {Object} context.accessToken The access token
@param {Application} app The sira app instance

@returns {AccessContext}
@constructor
Access context represents the context for a request to access protected resources