def setup_inventory(self): banner("Read Dicts") self.sample_user = ConfigDict(filename=config_file("/me.yaml")) self.portalname = self.sample_user.get("portalname") print("PORTALNAME", self.portalname) print("SAMPLE USER", self.sample_user) banner("create user from template, duplicates cm init generate me") t = cm_template(config_file("/etc/cloudmesh.yaml")) pprint(set(t.variables())) self.config = t.replace(kind="dict", values=self.sample_user) print(type(self.config)) print(self.config) # # BUG? # self.idp = cm_userLDAP() self.idp.connect("fg-ldap", "ldap") self.idp.refresh() ldap_info = self.idp.get(self.portalname) print(ldap_info) print(type(self.config)) self.config['cloudmesh']['projects'] = ldap_info['projects'] self.config['cloudmesh']['keys'] = ldap_info['keys'] try: self.config['cloudmesh']['projects'][ 'deafult'] = ldap_info['projects']['active'][0] except: print("ERROR: you have no projects")
def setup_inventory(self): banner("Read Dicts") self.sample_user = ConfigDict(filename=config_file("/me.yaml")) self.portalname = self.sample_user.get("portalname") print("PORTALNAME", self.portalname) print("SAMPLE USER", self.sample_user) banner("create user from template, duplicates cm init generate me") t = cm_template(config_file("/etc/cloudmesh.yaml")) pprint(set(t.variables())) self.config = t.replace(kind="dict", values=self.sample_user) print(type(self.config)) print(self.config) # # BUG? # self.idp = cm_userLDAP() self.idp.connect("fg-ldap", "ldap") self.idp.refresh() ldap_info = self.idp.get(self.portalname) print(ldap_info) print(type(self.config)) self.config['cloudmesh']['projects'] = ldap_info['projects'] self.config['cloudmesh']['keys'] = ldap_info['keys'] try: self.config['cloudmesh']['projects']['deafult'] = ldap_info[ 'projects']['active'][0] except: print("ERROR: you have no projects")
def authenticate(self, userId, password): if not self.with_ldap: return True try: idp = cm_userLDAP () idp.connect("fg-ldap", "ldap") return idp.authenticate(userId, password) except Exception, e: log.error("{0}".format(e)) return False
def mongo(): register() filename = "~/.futuregrid/cloudmesh.yaml" banner("reding data from {0}".format(filename)) config = cm_config(filename=filename) profile = config.profile() element = { "firstname" : profile["firstname"], "lastname" : profile["lastname"], "uidNumber" : profile["uid"], "phone" : profile["phone"], "gidNumber" : profile["gid"], "address" : profile["address"][0], "cm_user_id" : config.get("cloudmesh.hpc.username"), "email" : profile["email"], "activeclouds" : config.get("cloudmesh.active") } projects = {} active = config.get("cloudmesh.projects.active") if active != ['None']: projects["active"] = active completed = config.get("cloudmesh.projects.completed") if completed != ['None']: projects["completed"] = completed if projects != {}: element["projects"] = projects # get keys and clean the key titles (replace '.' with '_' due to mongo restriction) keys = config.get("cloudmesh.keys.keylist") for keytitle in keys.keys(): if "." in keytitle: keycontent = keys[keytitle] newkeytitle = keytitle.replace(".", "_") del keys[keytitle] keys[newkeytitle] = keycontent element['keys'] = keys pprint (element) # hpc username as key username = element["cm_user_id"] # populate the local userinfo into the same mongo as though it were from LDAP. userstore = cm_userLDAP() userstore.updates(username, element) user_obj = cm_user() user_obj.init_defaults(username)
def authenticate(self, userId, password): if not self.with_ldap: # return True passhash = self.get_credential(userId, 'cm_password_local', 'cm_password_local')['password'] return sha256_crypt.verify(password, passhash) try: idp = cm_userLDAP() idp.connect("fg-ldap", "ldap") return idp.authenticate(userId, password) except Exception, e: log.error("{0}".format(e)) return False
def authenticate(self, userId, password): if not self.with_ldap: # return True passhash = self.get_credential(userId, 'cm_password_local', 'cm_password_local')['password'] return sha256_crypt.verify(password, passhash) try: idp = cm_userLDAP() idp.connect("fg-ldap", "ldap") return idp.authenticate(userId, password) except Exception, e: log.error("{0}".format(e)) return False
def ldap(username=None): ''' fetches a user list from ldap and displays it ''' idp = cm_userLDAP() idp.connect("fg-ldap", "ldap") if username: idp.refresh_one(username) else: idp.refresh() _users = idp.list() print _users print("Fetching {0} Users from LDAP".format(len(_users)))
def ldap(username=None): """ fetches a user list from ldap and displays it """ idp = cm_userLDAP() idp.connect("fg-ldap", "ldap") if username: idp.refresh_one(username) else: idp.refresh() _users = idp.list() print _users print ("Fetching {0} Users from LDAP".format(len(_users)))
class LoginForm(Form): username = TextField('Username') password = PasswordField('Password') idp = cm_userLDAP() idp.connect("fg-ldap", "ldap") user = None def validate(self): print "validate" self.user = self.idp.find_one({'cm_user_id': self.username.data}) print "UUU", self.user # user = User.query.filter_by( # username=self.username.data).first() if self.user is None: print "user is None" self.error = 'Unknown user' return False else: print "user not None" if self.user['cm_user_id'] != self.username.data: print "username invalid" self.error = 'Invalid username' return False else: print "user found" # if not self.user['password'] == self.password.data: test = self.idp.authenticate(self.username.data, self.password.data) if not test: print "password invalid" self.error = 'Invalid password' return False else: print "password found" return True
def login(): # A hypothetical login form that uses Flask-WTF form = LoginForm() if form.validate_on_submit(): form.error = None try: idp = cm_userLDAP () idp.connect("fg-ldap", "ldap") user = idp.find_one({'cm_user_id': form.username.data}) except Exception, e: error = "LDAP server not reachable" error += str(e) return render_template('error.html', error=error, type="Can not reach LDAP", msg="") if user is None: form.error = 'Login Invalid' elif user['cm_user_id'] != form.username.data: form.error = 'Login Invalid' elif idp.authenticate(form.username.data, form.password.data): print "LOGIN USER" g.user = load_user(form.username.data) ret = login_user(g.user) identity_changed.send(current_app._get_current_object(), identity=Identity(g.user.id)) return redirect(request.args.get('next') or '/') else: form.error = 'Login Invalid'
def login(): # A hypothetical login form that uses Flask-WTF form = LoginForm() if request.method == 'POST' and form.validate_on_submit(): form.error = None try: idp = cm_userLDAP() idp.connect("fg-ldap", "ldap") user = idp.find_one({'cm_user_id': form.username.data}) except Exception, e: error = "LDAP server not reachable" error += str(e) return render_template('error.html', error=error, type="Can not reach LDAP", msg="") if user is None: form.error = 'Login Invalid' elif user['cm_user_id'] != form.username.data: form.error = 'Login Invalid' elif idp.authenticate(form.username.data, form.password.data): print "LOGIN USER" g.user = load_user(form.username.data) ret = login_user(g.user) identity_changed.send(current_app._get_current_object(), identity=Identity(g.user.id)) return redirect(request.args.get('next') or '/') else: form.error = 'Login Invalid'
def initialize_user(self): self.set_credentials() element = { "firstname": self.profile["firstname"], "lastname": self.profile["lastname"], "uidNumber": self.profile["uid"], "phone": self.profile["phone"], "gidNumber": self.profile["gid"], "address": self.profile["address"][0], "cm_user_id": self.config.get("cloudmesh.hpc.username"), "email": self.profile["email"], "activeclouds": self.config.get("cloudmesh.active") } projects = {} active = self.config.get("cloudmesh.projects.active") if active != ['None']: projects["active"] = active completed = self.config.get("cloudmesh.projects.completed") if completed != ['None']: projects["completed"] = completed if projects != {}: element["projects"] = projects # get keys and clean the key titles (replace '.' with '_' due # to mongo restriction) keys = self.config.get("cloudmesh.keys.keylist") for keytitle in keys.keys(): keycontent = keys[keytitle] if keytype(keycontent) == "file": keycontent = get_key_from_file(keycontent) if keycontent: keycontent = keycontent.strip() keys[keytitle] = keycontent else: print( "The specified key file does not exist and thus ingored!" ) print("You can run ssh-keygen to generate one key pair") del keys[keytitle] break if "." in keytitle: newkeytitle = keytitle.replace(".", "_") del keys[keytitle] keys[newkeytitle] = keycontent element['keys'] = keys pprint(element) # hpc username as key username = element["cm_user_id"] # populate the local userinfo into the same mongo as though it # were from LDAP. userstore = cm_userLDAP() userstore.updates(username, element) self.user_obj = cm_user() self.user_obj.init_defaults(username) # # info disabled due to NameError: global name 'info' is not # defined info(username) # ------------------------------------------------------------------------------ # added by Mark X. on Aug.25 2014 add clouds information to # mongo when initialize user iformation in mongo self.mongo.db_clouds.remove({ 'cm_kind': 'cloud', 'cm_user_id': username }) cloudsdict = self.config.get("cloudmesh", "clouds") for key in cloudsdict: Database.import_cloud_to_mongo(cloudsdict[key], key, username) print("cloud '{0}' added.".format(key))
# ROUTE: PAGES # ============================================================ @app.route('/<path:path>/') def page(path): page = pages.get_or_404(path) return render_template('page.html', page=page) # ============================================================ # PRINCIPAL LOGIN # ============================================================ if cloudmesh.with_login: idp = cm_userLDAP() idp.connect("fg-ldap", "ldap") @app.before_request def before_request(): g.user = current_user @identity_loaded.connect_via(app) def on_identity_loaded(sender, identity): if 'user_id' in session: current_user = load_user(session['user_id']) # Set the identity user object identity.user = current_user
def initialize_user(self): self.set_credentials() element = { "firstname": self.profile["firstname"], "lastname": self.profile["lastname"], "uidNumber": self.profile["uid"], "phone": self.profile["phone"], "gidNumber": self.profile["gid"], "address": self.profile["address"][0], "cm_user_id": self.config.get("cloudmesh.hpc.username"), "email": self.profile["email"], "activeclouds": self.config.get("cloudmesh.active") } projects = {} active = self.config.get("cloudmesh.projects.active") if active != ['None']: projects["active"] = active completed = self.config.get("cloudmesh.projects.completed") if completed != ['None']: projects["completed"] = completed if projects != {}: element["projects"] = projects # get keys and clean the key titles (replace '.' with '_' due # to mongo restriction) keys = self.config.get("cloudmesh.keys.keylist") for keytitle in keys.keys(): keycontent = keys[keytitle] if keytype(keycontent) == "file": keycontent = get_key_from_file(keycontent) if keycontent: keycontent = keycontent.strip() keys[keytitle] = keycontent else: print("The specified key file does not exist and thus ingored!") print("You can run ssh-keygen to generate one key pair") del keys[keytitle] break if "." in keytitle: newkeytitle = keytitle.replace(".", "_") del keys[keytitle] keys[newkeytitle] = keycontent element['keys'] = keys pprint(element) # hpc username as key username = element["cm_user_id"] # populate the local userinfo into the same mongo as though it # were from LDAP. userstore = cm_userLDAP() userstore.updates(username, element) self.user_obj = cm_user() self.user_obj.init_defaults(username) # # info disabled due to NameError: global name 'info' is not # defined info(username) # ------------------------------------------------------------------------------ # added by Mark X. on Aug.25 2014 add clouds information to # mongo when initialize user iformation in mongo self.mongo.db_clouds.remove({ 'cm_kind': 'cloud', 'cm_user_id': username }) cloudsdict = self.config.get("cloudmesh", "clouds") for key in cloudsdict: Database.import_cloud_to_mongo(cloudsdict[key], key, username) print("cloud '{0}' added.".format(key))
# ROUTE: PAGES # ============================================================ @app.route('/<path:path>/') def page(path): page = pages.get_or_404(path) return render_template('page.html', page=page) # ============================================================ # PRINCIPAL LOGIN # ============================================================ if cloudmesh.with_login: idp = cm_userLDAP () idp.connect("fg-ldap", "ldap") @app.before_request def before_request(): g.user = current_user @identity_loaded.connect_via(app) def on_identity_loaded(sender, identity): if 'user_id' in session: current_user = load_user(session['user_id']) # Set the identity user object identity.user = current_user
def setup(self): self.idp = cm_userLDAP() self.idp.connect("fg-ldap", "ldap") self.idp.refresh()