private static void setUsersInfo ( Catalog catalog , UsersType users ) throws RuntimeException { if ( users == null ) { return ; } // The database name is not available in deployment.xml (it is defined // in project.xml). However, it must always be named "database", so // I've temporarily hardcoded it here until a more robust solution is // available. Database db = catalog . getClusters ( ) . get ( "cluster" ) . getDatabases ( ) . get ( "database" ) ; SecureRandom sr = new SecureRandom ( ) ; for ( UsersType . User user : users . getUser ( ) ) { Set < String > roles = extractUserRoles ( user ) ; String sha1hex = user . getPassword ( ) ; String sha256hex = user . getPassword ( ) ; if ( user . isPlaintext ( ) ) { sha1hex = extractPassword ( user . getPassword ( ) , ClientAuthScheme . HASH_SHA1 ) ; sha256hex = extractPassword ( user . getPassword ( ) , ClientAuthScheme . HASH_SHA256 ) ; } else if ( user . getPassword ( ) . length ( ) == 104 ) { int sha1len = ClientAuthScheme . getHexencodedDigestLength ( ClientAuthScheme . HASH_SHA1 ) ; sha1hex = sha1hex . substring ( 0 , sha1len ) ; sha256hex = sha256hex . substring ( sha1len ) ; } else { // if one user has invalid password, give a warn. hostLog . warn ( "User \"" + user . getName ( ) + "\" has invalid masked password in deployment file." ) ; // throw exception disable user with invalid masked password throw new RuntimeException ( "User \"" + user . getName ( ) + "\" has invalid masked password in deployment file" ) ; } org . voltdb . catalog . User catUser = db . getUsers ( ) . get ( user . getName ( ) ) ; if ( catUser == null ) { catUser = db . getUsers ( ) . add ( user . getName ( ) ) ; } // generate salt only once for sha1 and sha256 String saltGen = BCrypt . gensalt ( BCrypt . GENSALT_DEFAULT_LOG2_ROUNDS , sr ) ; String hashedPW = BCrypt . hashpw ( sha1hex , saltGen ) ; String hashedPW256 = BCrypt . hashpw ( sha256hex , saltGen ) ; catUser . setShadowpassword ( hashedPW ) ; catUser . setSha256shadowpassword ( hashedPW256 ) ; //use fixed seed for comparison catUser . setPassword ( BCrypt . hashpw ( sha256hex , "$2a$10$pWO/a/OQkFyQWQDpchZdEe" ) ) ; // process the @groups and @roles comma separated list for ( final String role : roles ) { final Group catalogGroup = db . getGroups ( ) . get ( role ) ; // if the role doesn't exist, ignore it. if ( catalogGroup != null ) { GroupRef groupRef = catUser . getGroups ( ) . get ( role ) ; if ( groupRef == null ) { groupRef = catUser . getGroups ( ) . add ( role ) ; } groupRef . setGroup ( catalogGroup ) ; } else { hostLog . warn ( "User \"" + user . getName ( ) + "\" is assigned to non-existent role \"" + role + "\" " + "and may not have the expected database permissions." ) ; } } } }
Set user info in the catalog .