A Supreme Court ruling has upheld a law letting police take DNA samples when they arrest people for serious crimes.