예제 #1
0
 public PersonGroupAssociationSyncManager(SWDBHibernateDAO dao, IConfigurationFacade facade, HlagLocationManager locationManager, PersonGroupSyncManager personGroupSyncManager, HapagPersonGroupHelper hapagHelper, EntityRepository repository)
     : base(dao, facade, repository)
 {
     _locationManager        = locationManager;
     _personGroupSyncManager = personGroupSyncManager;
     _hapagHelper            = hapagHelper;
 }
예제 #2
0
        public IGenericResponseResult Submit(string password)
        {
            var user       = SecurityFacade.CurrentUser();
            var authorized = false;
            var adminUser  = new SWDBHibernateDAO().FindSingleByQuery <User>(sW4.Security.Entities.User.UserByUserName, "swadmin");

            if (adminUser.Password != null)
            {
                var authenticatedAdminUser = SecurityFacade.GetInstance().Login(adminUser, password, string.Empty);
                if (authenticatedAdminUser != null)
                {
                    if (!user.IsInRole(Role.SysAdmin))
                    {
                        var adminRole = _dao.FindSingleByQuery <Role>(Role.RoleByName, Role.SysAdmin);
                        user.Roles.Add(adminRole);
                    }
                    if (!user.IsInRole(Role.ClientAdmin))
                    {
                        var clientRole = _dao.FindSingleByQuery <Role>(Role.RoleByName, Role.ClientAdmin);
                        user.Roles.Add(clientRole);
                    }
                    authorized = true;
                }
            }
            return(new GenericResponseResult <bool>(authorized));
        }
예제 #3
0
        public static ICollection <UserProfile> FetchAllProfiles(Boolean eager)
        {
            var before = Stopwatch.StartNew();

            if (ProfileCache.Count != 0)
            {
                return(ProfileCache.Values);
            }

            using (var session = SWDBHibernateDAO.CurrentSession()) {
                using (var transaction = session.BeginTransaction()) {
                    var query      = DAO.BuildQuery("from UserProfile", (object[])null, session);
                    var dbProfiles = query.List();
                    var profiles   = new Dictionary <string, UserProfile>();
                    foreach (var profile in dbProfiles)
                    {
                        var userProfile = (UserProfile)profile;
                        if (eager)
                        {
                            NHibernateUtil.Initialize(userProfile.Roles);
                            NHibernateUtil.Initialize(userProfile.DataConstraints);
                        }
                        profiles.Add(userProfile.Name, userProfile);
                        ProfileCache.Add(userProfile.Id, userProfile);
                    }
                    Log.Info(LoggingUtil.BaseDurationMessage("Profiles Loaded in {0}", before));
                    return(profiles.Values);
                }
            }
        }
예제 #4
0
 public HlagLocationManager(SWDBHibernateDAO dao, MaximoHibernateDAO maxDAO, EntityRepository repository, IContextLookuper contextLookuper)
 {
     _dao             = dao;
     _repository      = repository;
     _personEntity    = MetadataProvider.Entity("person");
     _contextLookuper = contextLookuper;
     _maxDAO          = maxDAO;
 }
예제 #5
0
 private SWDBHibernateDAO GetDAO()
 {
     if (_dao == null)
     {
         _dao = SimpleInjectorGenericFactory.Instance.GetObject <SWDBHibernateDAO>(typeof(SWDBHibernateDAO));
     }
     return(_dao);
 }
예제 #6
0
 public ConfigurationController(CategoryTreeCache cache, ConfigurationService configService, I18NResolver resolver, SWDBHibernateDAO dao, ConditionService conditionService)
 {
     _cache            = cache;
     _configService    = configService;
     _resolver         = resolver;
     _dao              = dao;
     _conditionService = conditionService;
 }
예제 #7
0
        public static void LoadActiveRoles()
        {
            var before      = Stopwatch.StartNew();
            var activeRoles = new SWDBHibernateDAO().FindByQuery <Role>("from Role where Active = true");

            _activeRoles = new HashSet <Role>(activeRoles);
            Log.Info(LoggingUtil.BaseDurationMessage("Active Roles Loaded in {0}", before));
        }
예제 #8
0
 //TODO: remove customUserRoles and customUSerCOnstraints which were exclusions from this profile ==> They don´t make sense anymore (tough,they are useless anyway)
 public static void DeleteProfile(UserProfile profile)
 {
     using (ISession session = SWDBHibernateDAO.CurrentSession()) {
         using (ITransaction transaction = session.BeginTransaction()) {
             DAO.Delete(profile);
             if (ProfileCache.ContainsKey(profile.Id))
             {
                 ProfileCache.Remove(profile.Id);
             }
         }
     }
 }
예제 #9
0
        public InMemoryUser Login(string userName, string password, string userTimezoneOffset)
        {
            var shaPassword = AuthUtils.GetSha1HashData(password);
            var md5Password = AuthUtils.GetHashData(password, SHA256.Create());
            var dbUser      = new SWDBHibernateDAO().FindSingleByQuery <User>(LoginQuery, userName);

            if (dbUser == null || !MatchPassword(dbUser, password))
            {
                return(null);
            }

            return(UserFound(dbUser, userTimezoneOffset));
        }
예제 #10
0
 public static void DeleteRole(Role role)
 {
     using (ISession session = SWDBHibernateDAO.CurrentSession()) {
         using (ITransaction transaction = session.BeginTransaction()) {
             DAO.ExecuteSql("delete from sw_userprofile_role");
             DAO.ExecuteSql("delete from sw_user_customrole");
             DAO.Delete(role);
             Role oldRole = _activeRoles.FirstOrDefault(r => r.Id == role.Id);
             if (oldRole != null)
             {
                 _activeRoles.Remove(oldRole);
             }
         }
     }
 }
예제 #11
0
        public GenericResponseResult <UserProfileListDto> Get(Boolean refreshRoles = true)
        {
            //maybe if the number of profiles gets too big, we should lazy-fetch them, in a way to retrieve less data to the list screen
            var          profiles = SecurityFacade.FetchAllProfiles(true);
            IList <Role> roles    = new List <Role>();

            if (refreshRoles)
            {
                roles = new SWDBHibernateDAO().FindByQuery <Role>("from Role order by name");
            }
            var dto = new UserProfileListDto {
                Profiles = profiles, Roles = roles
            };

            return(new GenericResponseResult <UserProfileListDto>(dto));
        }
예제 #12
0
        public GenericResponseResult <UserListDto> List(bool refreshData = true)
        {
            var users = new SWDBHibernateDAO().FindByQuery <User>("select new User(id,UserName,FirstName,LastName,IsActive) from User order by UserName");
            ICollection <UserProfile> profiles = new List <UserProfile>();
            IList <Role> roles = new List <Role>();

            if (refreshData)
            {
                roles    = new SWDBHibernateDAO().FindByQuery <Role>("from Role order by name");
                profiles = SecurityFacade.FetchAllProfiles(true);
            }

            return(new GenericResponseResult <UserListDto>(new UserListDto {
                Users = users, Roles = roles, Profiles = profiles
            }));
        }
예제 #13
0
        public static InMemoryUser CurrentUser(Boolean fetchFromDB = true, bool throwAnonymousException = true)
        {
            if (ApplicationConfiguration.IsUnitTest)
            {
                return(InMemoryUser.TestInstance("test"));
            }

            var currLogin = LogicalThreadContext.GetData <string>("user") ?? CurrentPrincipalLogin;

            if (currLogin == "")
            {
                if (!throwAnonymousException)
                {
                    return(new InMemoryUser {
                        Login = "******"
                    });
                }
                throw new UnauthorizedAccessException();
            }

            if (!fetchFromDB || currLogin == null || _users.ContainsKey(currLogin))
            {
                return(_users[currLogin]);
            }
            //cookie authenticated already
            //TODO: remove this in prod?
            var dbUser = new SWDBHibernateDAO().FindSingleByQuery <User>(User.UserByUserName, currLogin);

            if (dbUser == null)
            {
                throw new InvalidOperationException("user should exist at DB");
            }

            var formsIdentity = CurrentPrincipal.Identity as System.Web.Security.FormsIdentity;
            var timezone      = String.Empty;

            if (formsIdentity != null && formsIdentity.Ticket != null && !String.IsNullOrWhiteSpace(formsIdentity.Ticket.UserData))
            {
                var userData = PropertyUtil.ConvertToDictionary(formsIdentity.Ticket.UserData);
                timezone = userData["userTimezoneOffset"];
            }
            UserFound(dbUser, timezone);
            return(_users[currLogin]);
        }
예제 #14
0
        private InMemoryUser GetUser(string userName, string password, string userTimezoneOffset)
        {
            var userAux = new SWDBHibernateDAO().FindSingleByQuery <User>(sW4.Security.Entities.User.UserByUserName, userName);
            var allowNonUsersToLogin = "******".Equals(MetadataProvider.GlobalProperty("ldap.allownonmaximousers"));

            if (userAux == null)
            {
                if (!allowNonUsersToLogin)
                {
                    //user not found and we will not create a new one --> fail
                    return(null);
                }

                //if this flag is true, we will create the user on the fly
                var ldapResult = _ldapManager.LdapAuth(userName, password);
                if (ldapResult.Success)
                {
                    userAux = UserManager.CreateMissingDBUser(userName);
                    if (userAux == null)
                    {
                        //user might not exist on maximo either, in that case we should block its access
                        return(null);
                    }
                    return(SecurityFacade.GetInstance().LdapLogin(userAux, userTimezoneOffset));
                }
                return(null);
            }

            //this will trigger default ldap auth ==> The user already exists in our database
            if (userAux.Password == null)
            {
                var ldapResult = _ldapManager.LdapAuth(userName, password);
                if (ldapResult.Success)
                {
                    return(SecurityFacade.GetInstance().LdapLogin(userAux, userTimezoneOffset));
                }
                return(null);
            }

            var user = SecurityFacade.GetInstance().Login(userAux, password, userTimezoneOffset);

            return(user);
        }
예제 #15
0
        public static Role SaveUpdateRole(Role role)
        {
            bool updatingRole = role.Id != null;

            role = new SWDBHibernateDAO().Save(role);
            if (updatingRole)
            {
                Role oldRole = _activeRoles.FirstOrDefault(r => r.Id == role.Id);
                if (oldRole != null)
                {
                    _activeRoles.Remove(oldRole);
                }
            }
            if (role.Active)
            {
                _activeRoles.Add(role);
            }

            return(role);
        }
예제 #16
0
        public List <PersonGroup> UpdateCacheOnSync(IEnumerable <PersonGroup> personGroupsToIntegrate)
        {
            var toInsert = new List <PersonGroup>();
            var toUpdate = new List <PersonGroup>();

            foreach (var group in personGroupsToIntegrate)
            {
                if (!AllGroupsCached.ContainsKey(group.Name))
                {
                    AllGroupsCached.Add(group.Name, group);
                    toInsert.Add(group);
                }
                else if (AllGroupsCached[group.Name].Rowstamp != group.Rowstamp)
                {
                    group.Id = AllGroupsCached[group.Name].Id;
                    AllGroupsCached[group.Name] = group;
                    toUpdate.Add(group);
                }
            }

            _dao.BulkSave(toInsert);



            using (var session = SWDBHibernateDAO.CurrentSession()) {
                using (var transaction = session.BeginTransaction()) {
                    foreach (var personGrop in toUpdate)
                    {
                        var dbGroup = _dao.FindByPK <PersonGroup>(typeof(PersonGroup), personGrop.Id);
                        dbGroup.Description = personGrop.Description;
                        dbGroup.Rowstamp    = personGrop.Rowstamp;
                        _dao.Save(dbGroup);
                    }
                    transaction.Commit();
                }
            }

            toInsert.AddRange(toUpdate);
            return(toInsert);
        }
예제 #17
0
 public UserSyncManager(SWDBHibernateDAO dao, IConfigurationFacade facade, EntityRepository repository)
     : base(dao, facade, repository)
 {
 }
예제 #18
0
 protected BaseISMDecorator()
 {
     DAO = SimpleInjectorGenericFactory.Instance.GetObject <SWDBHibernateDAO>(typeof(SWDBHibernateDAO));
 }
예제 #19
0
 public HapagProfileInitializer(SWDBHibernateDAO dao)
 {
     _dao = dao;
 }
예제 #20
0
 public MakeSWAdminController(SWDBHibernateDAO dao)
 {
     _dao = dao;
 }
예제 #21
0
 public IsmChangeCrudConnector()
 {
     _dao = SimpleInjectorGenericFactory.Instance.GetObject <SWDBHibernateDAO>(typeof(SWDBHibernateDAO));
 }
예제 #22
0
 public R0042ExtractorJob(EntityRepository entityRepository, IConfigurationFacade configFacade, SWDBHibernateDAO dao)
 {
     _entityRepository = entityRepository;
     ConfigFacade      = configFacade;
     DAO = dao;
 }
예제 #23
0
 public HapagInitializer(SWDBHibernateDAO dao, HapagRoleInitializer hapagRoleInitializer, HapagProfileInitializer hapagProfileInitializer)
 {
     _dao = dao;
     _hapagRoleInitializer    = hapagRoleInitializer;
     _hapagProfileInitializer = hapagProfileInitializer;
 }
예제 #24
0
 public DbUserInitializer(SWDBHibernateDAO dao)
 {
     _dao = dao;
 }
예제 #25
0
        public GenericResponseResult <IList <Role> > Get()
        {
            var roles = new SWDBHibernateDAO().FindByQuery <Role>("from Role order by name");

            return(new GenericResponseResult <IList <Role> >(roles));
        }
예제 #26
0
 public ConditionService(SWDBHibernateDAO dao)
 {
     _dao = dao;
 }
예제 #27
0
 public ComInitializer(SWDBHibernateDAO dao, ComProfileInitializer comProfileInitializer)
 {
     _dao = dao;
     _comProfileInitializer = comProfileInitializer;
 }
예제 #28
0
 public HapagPersonGroupHelper(SWDBHibernateDAO dao)
 {
     this._dao = dao;
 }
예제 #29
0
 public ComConfigurationRegistry(IConfigurationFacade facade, IWhereClauseFacade wcFacade, SWDBHibernateDAO dao)
 {
     _wcFacade = wcFacade;
     _facade   = facade;
 }
예제 #30
0
 public CategoryTreeCache(SWDBHibernateDAO dao)
 {
     _dao = dao;
 }