def getAuthorizationPrincipal(self, username): noOpPassword = CryptUtility.cryptPasswordWithPbkdf2(username) principal = AuthorizationPrincipal(username, noOpPassword) principal.setRole(cdbRole.CDB_USER_ROLE) if self.adminGroupName is not None: principal.setRole(cdbRole.CDB_ADMIN_ROLE) return principal
def runCommand(self): self.parseArgs(usage=""" cdb-add-user --username=USERNAME --first-name=FIRSTNAME --last-name=LASTNAME [--middle-name=MIDDLENAME] [--email=EMAIL] [--description=DESCRIPTION] [--password=PASSWORD|--password-file=PASSWORDFILE] Description: Adds new user into CDB database. This command goes directly to the database and must be run from a CDB administrator account. """) self.checkArgs() api = UserDbApi() username = self.getUsername() firstName = self.getFirstName() lastName = self.getLastName() middleName = self.getMiddleName() email = self.getEmail() description = self.getDescription() password = self.getPassword() cryptedPassword = None if password: cryptedPassword = CryptUtility.cryptPasswordWithPbkdf2(password) userInfo = api.addUser(username, firstName, lastName, middleName, email, description, cryptedPassword) print userInfo.getDisplayString(self.getDisplayKeys(), self.getDisplayFormat())
def authenticatePrincipal(self, principal, password): if principal is not None: principalToken = principal.getToken() if principalToken is not None and len(principalToken): if CryptUtility.verifyPasswordWithPbkdf2( password, principalToken): self.logger.debug('Authentication successful for %s' % principal.getName()) return principal else: self.logger.debug('Authentication failed for %s' % principal.getName()) else: self.logger.debug( 'Token is empty for %s, authentication not performed' % principal.getName()) return None
def cryptPasswordWithPbkdf2(cls, cleartext): return CryptUtility.cryptPasswordWithPbkdf2(cleartext)
def cryptPassword(cls, cleartext): return CryptUtility.cryptPassword(cleartext)
def test_getRandomWord(self): cryptUtility = CryptUtility() random = cryptUtility.getRandomWord(45) self.assertEqual(45, random.__len__(), "Random word generated is not correct length.")
def test_cryptPasswordAndVerify(self): cryptUtility = CryptUtility() password = "******" cryptedPassword = cryptUtility.cryptPassword(password) self.assertTrue(cryptUtility.verifyPassword(password, cryptedPassword), "Failed to decrpt/encrypt password")