public Test_UserRoleBaseSecurity()
 {
     userRoleBaseSecurity       = new UserRoleBaseSecurity();
     HttpContextFactory.Context = new API_Moq_HttpContext().httpContext();
     //userData = new TM_UserData();
     Assert.NotNull(userRoleBaseSecurity);
     Assert.NotNull(HttpContextFactory.Current);
 }
示例#2
0
        public TM_Authentication    mapUserRoles(bool disable_Csrf_Check)           // todo: rename to something like logging request
        {
            //currentUser.setGitUser();        //TODO track this better on user commit
            Disable_Csrf_Check = disable_Csrf_Check;

            // check if there is an AuthToken in the current request, then try WindowsAuthentication (if enabled)
            if (authToken != Guid.Empty)
            {
                sessionID = new TokenAuthentication().login_Using_AuthToken(authToken, sessionID);
                if (sessionID != Guid.Empty)
                {
                    Disable_Csrf_Check = true;
                }
            }
            else if (TMConfig.Current.windowsAuthentication_Enabled())
            {
                if (sessionID == Guid.Empty || sessionID.validSession() == false)
                {
                    sessionID = new WindowsAuthentication().login_Using_WindowsAuthentication(Current_WindowsIdentity);
                }
            }

            //if there is a valid session maps its permissions
            var userGroup = UserGroup.None;

            if (sessionID != Guid.Empty)
            {
                if (check_CSRF_Token())         // only map the roles if the CSRF check passed
                {
                    userGroup = new UserRoleBaseSecurity().MapRolesBasedOnSessionGuid(sessionID);
                }
            }
            if (userGroup == UserGroup.None)
            {
                if (TMConfig.Current.show_ContentToAnonymousUsers())
                {
                    UserGroup.Reader.setThreadPrincipalWithRoles();
                }
                else
                if (TMConfig.Current.show_LibraryToAnonymousUsers())            // when show_LibraryToAnonymousUsers is set, make the default user a Viewer
                {
                    UserGroup.Viewer.setThreadPrincipalWithRoles();
                }
                else
                {
                    UserGroup.None.setThreadPrincipalWithRoles();
                }
            }

            if (HttpContextFactory.Session.notNull())
            {
                HttpContextFactory.Session["principal"] = Thread.CurrentPrincipal;
            }
            return(this);
        }
示例#3
0
        public TM_Authentication    mapUserRoles(bool disable_Csrf_Check)
        {
            Disable_Csrf_Check = disable_Csrf_Check;
            if (sessionID == Guid.Empty || sessionID.validSession() == false)
            {
                /*if (SingleSignOn.singleSignOn_Enabled)
                 * {
                 *  sessionID = new SingleSignOn().authenticateUserBasedOn_SSOToken();
                 * }
                 * else*/
                if (WindowsAuthentication.windowsAuthentication_Enabled)
                {
                    sessionID = new WindowsAuthentication().authenticateUserBaseOn_ActiveDirectory();
                }
            }


            var userGroup = UserGroup.None;

            //"".line().info();
            //">> SessionID: {0} ".info(sessionID);
            //">> URL: {0}".info(HttpContextFactory.Request.Url);
            if (sessionID != Guid.Empty)
            {
                if (check_CSRF_Token())         // only map the roles if the CSRF check passed
                {
                    //"[TM_Authentication] check_CSRF_Token OK".debug();
                    userGroup = new UserRoleBaseSecurity().MapRolesBasedOnSessionGuid(sessionID);
                }
            }
            //"[TM_Authentication][1] userGroup for sessionID: {0} : {1}".debug(sessionID, userGroup);
            if (userGroup == UserGroup.None)
            {
                if (TMConfig.Current.TMSecurity.Show_ContentToAnonymousUsers)
                {
                    UserGroup.Reader.setThreadPrincipalWithRoles();
                }
                else
                {
                    UserGroup.Anonymous.setThreadPrincipalWithRoles();
                }
            }
            //"[TM_Authentication][2] userGroup for sessionID: {0} : {1}".debug(sessionID, userGroup);
            var userRoles = Thread.CurrentPrincipal.roles().toList().join(",");

            //"[TM_Authentication][2] Current Principal roles: {0}".debug(userRoles);
            //"[TM_Authentication][3] Thread id: {0}".error(Thread.CurrentThread.ManagedThreadId);
            if (HttpContextFactory.Session.notNull())
            {
                //"[TM_Authentication][4] SessionId: {0}".info(HttpContextFactory.Session["sessionID"]);
                HttpContextFactory.Session["principal"] = Thread.CurrentPrincipal;
            }
            return(this);
        }
示例#4
0
        public TM_Authentication mapUserRoles(bool disable_Csrf_Check)
        {
            Disable_Csrf_Check = disable_Csrf_Check;
            if (sessionID == Guid.Empty || sessionID.validSession() == false)
                /*if (SingleSignOn.singleSignOn_Enabled)
                {
                    sessionID = new SingleSignOn().authenticateUserBasedOn_SSOToken();
                }
                else*/
                if (WindowsAuthentication.windowsAuthentication_Enabled)
                {
                    sessionID = new WindowsAuthentication().authenticateUserBaseOn_ActiveDirectory();
                }

            var userGroup = UserGroup.None;
            //"".line().info();
            //">> SessionID: {0} ".info(sessionID);
            //">> URL: {0}".info(HttpContextFactory.Request.Url);
            if (sessionID != Guid.Empty)
            {
                if (check_CSRF_Token())		// only map the roles if the CSRF check passed
                {
                    //"[TM_Authentication] check_CSRF_Token OK".debug();
                    userGroup = new UserRoleBaseSecurity().MapRolesBasedOnSessionGuid(sessionID);
                }
            }
            //"[TM_Authentication][1] userGroup for sessionID: {0} : {1}".debug(sessionID, userGroup);
            if (userGroup == UserGroup.None)
            {
                if (TMConfig.Current.TMSecurity.Show_ContentToAnonymousUsers)
                    UserGroup.Reader.setThreadPrincipalWithRoles();
                else
                    UserGroup.Anonymous.setThreadPrincipalWithRoles();
            }
            //"[TM_Authentication][2] userGroup for sessionID: {0} : {1}".debug(sessionID, userGroup);
            var userRoles = Thread.CurrentPrincipal.roles().toList().join(",");
            //"[TM_Authentication][2] Current Principal roles: {0}".debug(userRoles);
            //"[TM_Authentication][3] Thread id: {0}".error(Thread.CurrentThread.ManagedThreadId);
            if (HttpContextFactory.Session.notNull())
            {
                //"[TM_Authentication][4] SessionId: {0}".info(HttpContextFactory.Session["sessionID"]);
                HttpContextFactory.Session["principal"] = Thread.CurrentPrincipal;
            }
            return this;
        }
示例#5
0
        public TM_Authentication mapUserRoles(bool disable_Csrf_Check)
        {
            Disable_Csrf_Check = disable_Csrf_Check;
            if (sessionID == Guid.Empty || sessionID.validSession() == false)
                /*if (SingleSignOn.singleSignOn_Enabled)
                {
                    sessionID = new SingleSignOn().authenticateUserBasedOn_SSOToken();
                }
                else*/
                    if (WindowsAuthentication.windowsAuthentication_Enabled)
                {
                    sessionID = new WindowsAuthentication().authenticateUserBaseOn_ActiveDirectory();
                }

            var userGroup = UserGroup.None;
            if (sessionID != Guid.Empty)
            {
                if (check_CSRF_Token())		// only map the roles if the CSRF check passed
                {
                    userGroup = new UserRoleBaseSecurity().MapRolesBasedOnSessionGuid(sessionID);
                }
            }
            if (userGroup == UserGroup.None)
            {
                if (TMConfig.Current.TMSecurity.Show_ContentToAnonymousUsers)
                    UserGroup.Reader.setThreadPrincipalWithRoles();
                else
                    UserGroup.Anonymous.setThreadPrincipalWithRoles();
            }
            return this;
        }
示例#6
0
        // todo: rename to something like logging request
        public TM_Authentication mapUserRoles(bool disable_Csrf_Check)
        {
            //currentUser.setGitUser();        //TODO track this better on user commit
            Disable_Csrf_Check = disable_Csrf_Check;

            // check if there is an AuthToken in the current request, then try WindowsAuthentication (if enabled)
            if (authToken != Guid.Empty)
            {
                sessionID = new TokenAuthentication().login_Using_AuthToken(authToken, sessionID);
                if (sessionID != Guid.Empty)
                    Disable_Csrf_Check = true;
            }
            else if (TMConfig.Current.windowsAuthentication_Enabled())
                if (sessionID == Guid.Empty || sessionID.validSession() == false)
                {

                    sessionID = new WindowsAuthentication().login_Using_WindowsAuthentication(Current_WindowsIdentity);
                }

            //if there is a valid session maps its permissions
            var userGroup = UserGroup.None;

            if (sessionID != Guid.Empty)
            {
                if (check_CSRF_Token())		// only map the roles if the CSRF check passed
                {
                    userGroup = new UserRoleBaseSecurity().MapRolesBasedOnSessionGuid(sessionID);
                }
            }
            if (userGroup == UserGroup.None)
            {
                if (TMConfig.Current.show_ContentToAnonymousUsers())
                    UserGroup.Reader.setThreadPrincipalWithRoles();
                else
                    if (TMConfig.Current.show_LibraryToAnonymousUsers())        // when show_LibraryToAnonymousUsers is set, make the default user a Viewer
                        UserGroup.Viewer.setThreadPrincipalWithRoles();
                    else
                        UserGroup.None.setThreadPrincipalWithRoles();
            }

            if (HttpContextFactory.Session.notNull())
            {
                HttpContextFactory.Session["principal"] = Thread.CurrentPrincipal;
            }
            return this;
        }