def _run(self, args): avatar = Avatar() name = raw_input("New administrator name: ").strip() surname = raw_input("New administrator surname: ").strip() organization = raw_input("New administrator organization: ").strip() email = raw_input("New administrator email: ").strip() login = raw_input("New administrator login: "******"New administrator password: "******"Retype administrator password: "******"Sorry, passwords do not match") avatar.setName(name) avatar.setSurName(surname) avatar.setOrganisation(organization) avatar.setLang("en_GB") avatar.setEmail(email) self.printUserInfo(avatar) if console.yesno("Are you sure to create and grant administrator privileges to this user?"): avatar.activateAccount() loginInfo = LoginInfo(login, password) authMgr = AuthenticatorMgr() userid = authMgr.createIdentity(loginInfo, avatar, "Local") authMgr.add(userid) adminList = info.HelperMaKaCInfo.getMaKaCInfoInstance().getAdminList() AvatarHolder().add(avatar) adminList.grant(avatar) print "New administrator created successfully with id: %s" % avatar.getId()
def setUp(self): super(TestAuthentication, self).setUp() with self._context("database"): # Create few users and groups gh = GroupHolder() ah = AvatarHolder() self._authMgr = AuthenticatorMgr() for i in xrange(1, 3): group = Group() group.setName("fake-group-%d" % i) group.setDescription("fake") group.setEmail("*****@*****.**" % i) group.setId("fake-group-%d" % i) avatar = Avatar() avatar.setName("fake-%d" % i) avatar.setSurName("fake") avatar.setOrganisation("fake") avatar.setLang("en_GB") avatar.setEmail("*****@*****.**" % i) avatar.setId("fake-%d" % i) avatar.activateAccount() group.addMember(avatar) ah.add(avatar) gh.add(group) identity = self._authMgr.createIdentity( LoginInfo("fake-%d" % i, "fake-%d" % i), avatar, "Local") self._authMgr.add(identity)
def create_dummy_user(): """ Creates a dummy user for testing purposes """ avatar = Avatar() avatar.setName("fake") avatar.setSurName("fake") avatar.setOrganisation("fake") avatar.setLang("en_GB") avatar.setEmail("*****@*****.**") # registering user ah = AvatarHolder() ah.add(avatar) # setting up the login info li = LoginInfo("dummyuser", "dummyuser") ih = AuthenticatorMgr() userid = ih.createIdentity(li, avatar, "Local") ih.add(userid) # activate the account avatar.activateAccount() # since the DB is empty, we have to add dummy user as admin minfo = HelperMaKaCInfo.getMaKaCInfoInstance() al = minfo.getAdminList() al.grant(avatar) dc = DefaultConference() HelperMaKaCInfo.getMaKaCInfoInstance().setDefaultConference(dc) return avatar
def setUp(self): super(TestAuthentication, self).setUp() with self._context("database"): # Create few users and groups gh = GroupHolder() ah = AvatarHolder() self._authMgr = AuthenticatorMgr() for i in xrange(1, 3): group = Group() group.setName("fake-group-%d" % i) group.setDescription("fake") group.setEmail("*****@*****.**" % i) group.setId("fake-group-%d" % i) avatar = Avatar() avatar.setName("fake-%d" % i) avatar.setSurName("fake") avatar.setOrganisation("fake") avatar.setLang("en_GB") avatar.setEmail("*****@*****.**" % i) avatar.setId("fake-%d" % i) avatar.activateAccount() group.addMember(avatar) ah.add(avatar) gh.add(group) identity = self._authMgr.createIdentity(LoginInfo("fake-%d" % i, "fake-%d" % i), avatar, "Local") self._authMgr.add(identity)
def create_dummy_user(): """ Creates a dummy user for testing purposes """ avatar = Avatar() avatar.setName("fake") avatar.setSurName("fake") avatar.setOrganisation("fake") avatar.setLang("en_GB") avatar.setEmail("*****@*****.**") # registering user ah = AvatarHolder() ah.add(avatar) # setting up the login info li = LoginInfo("dummyuser", "dummyuser") ih = AuthenticatorMgr() userid = ih.createIdentity(li, avatar, "Local") ih.add(userid) # activate the account avatar.activateAccount() # since the DB is empty, we have to add dummy user as admin minfo = HelperMaKaCInfo.getMaKaCInfoInstance() al = minfo.getAdminList() al.grant(avatar) dc = DefaultConference() HelperMaKaCInfo.getMaKaCInfoInstance().setDefaultConference(dc) return avatar
def _run(self, args): avatar = Avatar() name = raw_input("New administrator name: ").strip() surname = raw_input("New administrator surname: ").strip() organization = raw_input("New administrator organization: ").strip() email = raw_input("New administrator email: ").strip() login = raw_input("New administrator login: "******"New administrator password: "******"Retype administrator password: "******"Sorry, passwords do not match") avatar.setName(name) avatar.setSurName(surname) avatar.setOrganisation(organization) avatar.setLang("en_GB") avatar.setEmail(email) self.printUserInfo(avatar) if console.yesno( "Are you sure to create and grant administrator privileges to this user?" ): avatar.activateAccount() loginInfo = LoginInfo(login, password) authMgr = AuthenticatorMgr() userid = authMgr.createIdentity(loginInfo, avatar, "Local") authMgr.add(userid) adminList = info.HelperMaKaCInfo.getMaKaCInfoInstance( ).getAdminList() AvatarHolder().add(avatar) adminList.grant(avatar) print "New administrator created successfully with id: %s" % avatar.getId( )
def retrieveAvatar(self, rh): """ Login using Shibbolet. """ from MaKaC.user import AvatarHolder, Avatar config = Config.getInstance().getAuthenticatorConfigById(self.id).get("SSOMapping", {}) if config.get('email', 'ADFS_EMAIL') in request.environ: email = request.environ[config.get("email", "ADFS_EMAIL")] login = request.environ[config.get("personId", "ADFS_LOGIN")] personId = request.environ[config.get("personId", "ADFS_PERSONID")] phone = request.environ.get(config.get("phone", "ADFS_PHONENUMBER"), "") fax = request.environ.get(config.get("fax", "ADFS_FAXNUMBER"), "") lastname = request.environ.get(config.get("lastname", "ADFS_LASTNAME"), "") firstname = request.environ.get(config.get("firstname", "ADFS_FIRSTNAME"), "") institute = request.environ.get(config.get("institute", "ADFS_HOMEINSTITUTE"), "") if personId == '-1': personId = None ah = AvatarHolder() av = ah.match({"email": email}, exact=1, onlyActivated=False, searchInAuthenticators=False) if av: av = av[0] # don't allow disabled accounts if av.isDisabled(): return None elif not av.isActivated(): av.activateAccount() av.clearAuthenticatorPersonalData() av.setAuthenticatorPersonalData('phone', phone) av.setAuthenticatorPersonalData('fax', fax) av.setAuthenticatorPersonalData('surName', lastname) av.setAuthenticatorPersonalData('firstName', firstname) av.setAuthenticatorPersonalData('affiliation', institute) if personId != None and personId != av.getPersonId(): av.setPersonId(personId) else: avDict = {"email": email, "name": firstname, "surName": lastname, "organisation": institute, "telephone": phone, "login": login} av = Avatar(avDict) ah.add(av) av.setPersonId(personId) av.activateAccount() self._postLogin(login, av, True) return av return None
def create_user(name, login, authManager): avatar = Avatar() avatar.setName(name) avatar.setSurName(name) avatar.setOrganisation("fake") avatar.setLang("en_GB") avatar.setEmail("*****@*****.**" % name) # setting up the login info li = LoginInfo(login, login) userid = authManager.createIdentity(li, avatar, "Local") authManager.add(userid) # activate the account avatar.activateAccount() return avatar
def create_user(name, login, authManager, set_password=False): avatar = Avatar() avatar.setName(name) avatar.setSurName(name) avatar.setOrganisation("fake") avatar.setLang("en_GB") avatar.setEmail("*****@*****.**" % name) # setting up the login info li = LoginInfo(login, login if set_password else None) userid = authManager.createIdentity(li, avatar, "Local") authManager.add(userid) # activate the account avatar.activateAccount() return avatar
def user_create(grant_admin): """Creates new user""" avatar = Avatar() user_type = 'user' if not grant_admin else 'admin' print() name = prompt("First name") surname = prompt("Last name") organization = prompt("Affiliation") print() login = prompt("Enter username") email = prompt_email().encode('utf-8') if email is None: return password = prompt_pass().encode('utf-8') if password is None: return avatar.setName(name) avatar.setSurName(surname) avatar.setOrganisation(organization) avatar.setLang("en_GB") avatar.setEmail(email) print_user_info(avatar) if prompt_bool(cformat("%{yellow}Create the new {}?").format(user_type), default=True): from MaKaC.authentication import AuthenticatorMgr avatar.activateAccount() login_info = LoginInfo(login, password) auth_mgr = AuthenticatorMgr() try: user_id = auth_mgr.createIdentity(login_info, avatar, "Local") auth_mgr.add(user_id) AvatarHolder().add(avatar) if grant_admin: admin_list = HelperMaKaCInfo.getMaKaCInfoInstance().getAdminList() admin_list.grant(avatar) success("New {} created successfully with ID: {}".format(user_type, avatar.getId())) except UserError as e: error("Error: {}".format(str(e)))
def retrieveAvatar(self, rh): """ Login using Shibbolet. """ from MaKaC.user import AvatarHolder, Avatar config = Config.getInstance().getAuthenticatorConfigById(self.id).get( "SSOMapping", {}) if config.get('email', 'ADFS_EMAIL') in request.environ: email = request.environ[config.get("email", "ADFS_EMAIL")] login = request.environ.get(config.get("login", "ADFS_LOGIN")) personId = request.environ.get( config.get("personId", "ADFS_PERSONID")) phone = request.environ.get( config.get("phone", "ADFS_PHONENUMBER"), "") fax = request.environ.get(config.get("fax", "ADFS_FAXNUMBER"), "") lastname = request.environ.get( config.get("lastname", "ADFS_LASTNAME"), "") firstname = request.environ.get( config.get("firstname", "ADFS_FIRSTNAME"), "") institute = request.environ.get( config.get("institute", "ADFS_HOMEINSTITUTE"), "") if personId == '-1': personId = None ah = AvatarHolder() av = ah.match({"email": email}, exact=1, onlyActivated=False, searchInAuthenticators=False) if av: av = av[0] # don't allow disabled accounts if av.isDisabled(): return None elif not av.isActivated(): av.activateAccount() av.clearAuthenticatorPersonalData() av.setAuthenticatorPersonalData('phone', phone) av.setAuthenticatorPersonalData('fax', fax) av.setAuthenticatorPersonalData('surName', lastname) av.setAuthenticatorPersonalData('firstName', firstname) av.setAuthenticatorPersonalData('affiliation', institute) if personId != None and personId != av.getPersonId(): av.setPersonId(personId) else: avDict = { "email": email, "name": firstname, "surName": lastname, "organisation": institute, "telephone": phone, "login": login } av = Avatar(avDict) ah.add(av) av.setPersonId(personId) av.activateAccount() self._postLogin(login, av, True) return av return None
def start(self, obj): super(RoomBooking_Feature, self).start(obj) with obj._context('database'): # Tell indico to use the current database for roombooking stuff minfo = HelperMaKaCInfo.getMaKaCInfoInstance() cfg = Configuration.Config.getInstance() minfo.setRoomBookingDBConnectionParams(cfg.getDBConnectionParams()) obj._ph.getById('RoomBooking').setActive(True) DALManagerCERN.connect() initializeRoomBookingDB("Universe", force=False) DALManagerCERN.disconnect() # do not use the method for it as it tries to re-create jsvars and fails minfo._roomBookingModuleActive = True DALManagerCERN.connect() # Create dummy avatars in obj._avatarN ah = AvatarHolder() obj._avatars = [] for i in xrange(1, 5): avatar = Avatar() avatar.setName("fake-%d" % i) avatar.setSurName("fake") avatar.setOrganisation("fake") avatar.setLang("en_GB") avatar.setEmail("*****@*****.**" % i) avatar.setId("rb-fake-%d" % i) # setting up the login info li = LoginInfo("fake-%d" % i, "fake-%d" % i) ih = AuthenticatorMgr() userid = ih.createIdentity(li, avatar, "Local") ih.add(userid) # activate the account avatar.activateAccount() ah.add(avatar) obj._avatars.append(avatar) setattr(obj, '_avatar%d' % i, avatar) # Create dummy rooms in obj._roomN - owners are fake1 and fake2 (r1 has f1, r2 has f2, r3 has f1, ...) location = Location.getDefaultLocation() obj._rooms = [] for i in xrange(1, 8): room = location.newRoom() room.locationName = location.friendlyName room.name = 'DummyRoom%d' % i room.site = 'a' room.building = 1 room.floor = 'b' room.roomNr = 'c' room.latitude = '' room.longitude = '' room.isActive = True room.isReservable = True room.resvsNeedConfirmation = False room.responsibleId = 'rb-fake-%d' % (((i - 1) % 2) + 1) room.whereIsKey = 'Nowhere' room.telephone = '123456789' room.capacity = 10 room.division = '' room.surfaceArea = 50 room.comments = '' room.setEquipment([]) room.setAvailableVC([]) room.insert() obj._rooms.append(room) setattr(obj, '_room%d' % i, room)
def _import(self, file): # check Registration period import datetime import pytz utc = pytz.UTC startDate = self._conf.getRegistrationForm().getStartRegistrationDate() endDate = self._conf.getRegistrationForm().getEndRegistrationDate() current = datetime.datetime.now() current = utc.localize(current) if (current < startDate or current > endDate): raise NoReportError("Import registrants not authorized, outside registration period.") reader = csv.DictReader(file) i = 1 errors = [] successfuls = [] unsuccessfuls = [] for row in reader: try: # row['Email'] = row['Email'].lower() self._processImportData(row) matchedUsers = AvatarHolder().match({"email": row['Email']}, exact=1) if matchedUsers: user = matchedUsers[0] elif ('Account Creation' in row) and row['Account Creation'].lower() == 'yes': # account creation avData = self._mapAvatar(row) user = Avatar(avData) user.activateAccount() login_info = LoginInfo(row['Login'], row['Password']) auth_mgr = AuthenticatorMgr() user_id = auth_mgr.createIdentity(login_info, user, "Local") auth_mgr.add(user_id) AvatarHolder().add(user) else: user = None if not (user): reg = Registrant() # new registration self._conf.addRegistrant(reg, user) else: if user.isRegisteredInConf(self._conf): reg = self._conf.getRegistrantsByEmail(user.getEmail()) else: # not registered, new registration reg = Registrant() reg.setAvatar(user) self._conf.addRegistrant(reg, user) user.addRegistrant(reg) regData = self._mapRegistrant(row) regData['import'] = 'import' reg.setValues(regData, user) self._setAffiliation(reg) successfuls.append(reg.getFullName()) except Exception: errors.append(i) unsuccessfuls.append( row["Surname"] + ", " + row["First Name"]) # exception : reg or user might not be defined yet finally: i += 1 self.logimport(successfuls, unsuccessfuls) return errors
def autoLogin(self, rh): """ Login using Shibbolet. """ req = rh._req req.add_common_vars() if req.subprocess_env.has_key("ADFS_EMAIL"): email = req.subprocess_env["ADFS_EMAIL"] login = req.subprocess_env["ADFS_LOGIN"] personId = req.subprocess_env["ADFS_PERSONID"] phone = req.subprocess_env.get("ADFS_PHONENUMBER","") fax = req.subprocess_env.get("ADFS_FAXNUMBER","") lastname = req.subprocess_env.get("ADFS_LASTNAME","") firstname = req.subprocess_env.get("ADFS_FIRSTNAME","") institute = req.subprocess_env.get("ADFS_HOMEINSTITUTE","") if personId == '-1': personId = None from MaKaC.user import AvatarHolder ah = AvatarHolder() av = ah.match({"email":email},exact=1, onlyActivated=False, forceWithoutExtAuth=True) if av: av = av[0] # don't allow disabled accounts if av.isDisabled(): return None # # TODO: is this checking necessary? # if av.getStatus() == 'NotCreated': # #checking if comming from Nice # if av.getId()[:len(self.id)] == self.id: # av.setId("") # ah.add(av) #XXXXX # av.activateAccount() # else: # return None # if not activated elif not av.isActivated(): av.activateAccount() av.clearAuthenticatorPersonalData() av.setAuthenticatorPersonalData('phone', phone) av.setAuthenticatorPersonalData('fax', fax) av.setAuthenticatorPersonalData('surName', lastname) av.setAuthenticatorPersonalData('firstName', firstname) av.setAuthenticatorPersonalData('affiliation', institute) if phone != '' and phone != av.getPhone() and av.isFieldSynced('phone'): av.setTelephone(phone) if fax != '' and fax != av.getFax() and av.isFieldSynced('fax'): av.setFax(fax) if lastname != '' and lastname != av.getFamilyName() and av.isFieldSynced('surName'): av.setSurName(lastname, reindex=True) if firstname != '' and firstname != av.getFirstName() and av.isFieldSynced('firstName'): av.setName(firstname, reindex=True) if institute != '' and institute != av.getAffiliation() and av.isFieldSynced('affiliation'): av.setAffiliation(institute, reindex=True) if personId != None and personId != av.getPersonId(): av.setPersonId(personId) else: avDict = {"email": email, "name": firstname, "surName": lastname, "organisation": institute, "telephone": phone, "login": login} av = Avatar(avDict) ah.add(av) av.setPersonId(personId) av.activateAccount() if login != "" and not self.hasKey(login): ni=NiceIdentity(login, av) self.add(ni) if login != "" and self.hasKey(login) and not av.getIdentityById(login, self.getId()): av.addIdentity(self.getById(login)) return av return None
def _import(self, file): # check Registration period import datetime import pytz utc = pytz.UTC startDate = self._conf.getRegistrationForm().getStartRegistrationDate() endDate = self._conf.getRegistrationForm().getEndRegistrationDate() current = datetime.datetime.now() current = utc.localize(current) if (current < startDate or current > endDate): raise NoReportError( "Import registrants not authorized, outside registration period.") reader = csv.DictReader(file) i = 1 errors = [] successfuls = [] unsuccessfuls = [] for row in reader: try: # row['Email'] = row['Email'].lower() self._processImportData(row) matchedUsers = AvatarHolder().match({"email": row['Email']}, exact=1) if matchedUsers: user = matchedUsers[0] elif ('Account Creation' in row) and row['Account Creation'].lower( ) == 'yes': # account creation avData = self._mapAvatar(row) user = Avatar(avData) user.activateAccount() login_info = LoginInfo(row['Login'], row['Password']) auth_mgr = AuthenticatorMgr() user_id = auth_mgr.createIdentity(login_info, user, "Local") auth_mgr.add(user_id) AvatarHolder().add(user) else: user = None if not (user): reg = Registrant() # new registration self._conf.addRegistrant(reg, user) else: if user.isRegisteredInConf(self._conf): reg = self._conf.getRegistrantsByEmail(user.getEmail()) else: # not registered, new registration reg = Registrant() reg.setAvatar(user) self._conf.addRegistrant(reg, user) user.addRegistrant(reg) regData = self._mapRegistrant(row) regData['import'] = 'import' reg.setValues(regData, user) self._setAffiliation(reg) successfuls.append(reg.getFullName()) except Exception: errors.append(i) unsuccessfuls.append( row["Surname"] + ", " + row["First Name"] ) # exception : reg or user might not be defined yet finally: i += 1 self.logimport(successfuls, unsuccessfuls) return errors
def start(self, obj): super(RoomBooking_Feature, self).start(obj) with obj._context('database'): # Tell indico to use the current database for roombooking stuff minfo = HelperMaKaCInfo.getMaKaCInfoInstance() cfg = Configuration.Config.getInstance() minfo.setRoomBookingDBConnectionParams(cfg.getDBConnectionParams()) obj._ph.getById('RoomBooking').setActive(True) DALManagerCERN.connect() initializeRoomBookingDB("Universe", force=False) DALManagerCERN.disconnect() # do not use the method for it as it tries to re-create jsvars and fails minfo._roomBookingModuleActive = True DALManagerCERN.connect() # Create dummy avatars in obj._avatarN ah = AvatarHolder() obj._avatars = [] for i in xrange(1, 5): avatar = Avatar() avatar.setName("fake-%d" % i) avatar.setSurName("fake") avatar.setOrganisation("fake") avatar.setLang("en_GB") avatar.setEmail("*****@*****.**" % i) avatar.setId("rb-fake-%d" % i) # setting up the login info li = LoginInfo("fake-%d" % i, "fake-%d" % i) ih = AuthenticatorMgr() userid = ih.createIdentity(li, avatar, "Local") ih.add(userid) # activate the account avatar.activateAccount() ah.add(avatar) obj._avatars.append(avatar) setattr(obj, '_avatar%d' % i, avatar) # Create dummy rooms in obj._roomN - owners are fake1 and fake2 (r1 has f1, r2 has f2, r3 has f1, ...) location = Location.getDefaultLocation() obj._rooms = [] for i in xrange(1, 8): room = location.newRoom() room.locationName = location.friendlyName room.name = 'DummyRoom%d' % i room.site = 'a' room.building = 1 room.floor = 'b' room.roomNr = 'c' room.latitude = '' room.longitude = '' room.isActive = True room.isReservable = True room.resvsNeedConfirmation = False room.responsibleId = 'rb-fake-%d' % (((i - 1) % 2) + 1) room.whereIsKey = 'Nowhere' room.telephone = '123456789' room.capacity = 10 room.division = '' room.surfaceArea = 50 room.comments = '' room.setEquipment([]) room.setAvailableVC([]) room.insert() obj._rooms.append(room) setattr(obj, '_room%d' % i, room)