docs: public Enrollment enroll(String user, String secret, EnrollmentRequest req) throws EnrollmentException, InvalidArgumentException {
  
          logger.debug(format("url:%s enroll user: %s", url, user));
  
          if (Utils.isNullOrEmpty(user)) {
              throw new InvalidArgumentException("enrollment user is not set");
          }
          if (Utils.isNullOrEmpty(secret)) {
              throw new InvalidArgumentException("enrollment secret is not set");
          }
  
          if (cryptoSuite == null) {
              throw new InvalidArgumentException("Crypto primitives not set.");
          }
  
          setUpSSL();
  
          try {
              String pem = req.getCsr();
              KeyPair keypair = req.getKeyPair();
              if (null != pem && keypair == null) {
                  throw new InvalidArgumentException("If certificate signing request is supplied the key pair needs to be supplied too.");
              }
              if (keypair == null) {
                  logger.debug("[HFCAClient.enroll] Generating keys...");
  
                  // generate ECDSA keys: signing and encryption keys
                  keypair = cryptoSuite.keyGen();
  
                  logger.debug("[HFCAClient.enroll] Generating keys...done!");
              }
  
              if (pem == null) {
                  String csr = cryptoSuite.generateCertificationRequest(user, keypair);
                  req.setCSR(csr);
              }
  
              if (caName != null && !caName.isEmpty()) {
                  req.setCAName(caName);
              }
              String body = req.toJson();
  
              String responseBody = httpPost(url + HFCA_ENROLL, body,
                      new UsernamePasswordCredentials(user, secret));
  
              logger.debug("response:" + responseBody);
  
              JsonReader reader = Json.createReader(new StringReader(responseBody));
              JsonObject jsonst = (JsonObject) reader.read();
  
              boolean success = jsonst.getBoolean("success");
              logger.debug(format("[HFCAClient] enroll success:[%s]", success));
  
              if (!success) {
                  throw new EnrollmentException(format("FabricCA failed enrollment for user %s response success is false.", user));
              }
  
              JsonObject result = jsonst.getJsonObject("result");
              if (result == null) {
                  throw new EnrollmentException(format("FabricCA failed enrollment for user %s - response did not contain a result", user));
              }
  
              Base64.Decoder b64dec = Base64.getDecoder();
  
              String signedPem = new String(b64dec.decode(result.getString("Cert").getBytes(UTF_8)));
              logger.debug(format("[HFCAClient] enroll returned pem:[%s]", signedPem));
  
              JsonArray messages = jsonst.getJsonArray("messages");
              if (messages != null && !messages.isEmpty()) {
                  JsonObject jo = messages.getJsonObject(0);
                  String message = format("Enroll request response message [code %d]: %s", jo.getInt("code"), jo.getString("message"));
                  logger.info(message);
              }
              logger.debug("Enrollment done.");
  
              return new X509Enrollment(keypair, signedPem);
  
          } catch (EnrollmentException ee) {
              logger.error(format("url:%s, user:%s  error:%s", url, user, ee.getMessage()), ee);
              throw ee;
  
          } catch (Exception e) {
              EnrollmentException ee = new EnrollmentException(format("Url:%s, Failed to enroll user %s ", url, user), e);
              logger.error(e.getMessage(), e);
              throw ee;
          }
  
      }