RegisterUsers extends MtWilsonClient { public boolean registerUserWithCertificate(RegisterUserWithCertificate obj) { boolean isUserRegistered = false; log.debug("target: {}", getTarget().getUri().toString()); Object result = getTarget().path("rpc/register-user-with-certificate").request().accept(MediaType.APPLICATION_JSON).post(Entity.json(obj), Object.class); if (result.getClass().equals(LinkedHashMap.class)) { LinkedHashMap resultMap = (LinkedHashMap)result; if (resultMap.containsKey("result")) { isUserRegistered = Boolean.parseBoolean(resultMap.get("result").toString().trim()); log.debug("Result of user registration with certificate is {}.", isUserRegistered); } } return isUserRegistered; } RegisterUsers(URL url);  RegisterUsers(Properties properties); boolean registerUserWithCertificate(RegisterUserWithCertificate obj);  }
@Test public void testRegisterUserWithoutCert() { User createUser = new User(); createUser.setUsername("Testing111"); createUser.setComment("Access needed for testing"); RegisterUserWithCertificate rpcUserWithCert = new RegisterUserWithCertificate(); rpcUserWithCert.setUser(createUser); boolean registerUserWithCertificate = client.registerUserWithCertificate(rpcUserWithCert); log.debug("Status of user registration is {}.", registerUserWithCertificate); }
@Test public void testRegisterUserWithCert() throws Exception { String userName = "superadmin99"; User user = new User(); user.setUsername(userName); user.setLocale(Locale.US); user.setComment("Need to manage user accounts."); KeyPair keyPair = RsaUtil.generateRsaKeyPair(RsaUtil.MINIMUM_RSA_KEY_SIZE); X509Certificate certificate = X509Builder.factory().selfSigned(String.format("CN=%s", userName), keyPair).expires(365, TimeUnit.DAYS).build(); UserLoginCertificate userLoginCertificate = new UserLoginCertificate(); userLoginCertificate.setCertificate(certificate.getEncoded()); RegisterUserWithCertificate rpcUserWithCert = new RegisterUserWithCertificate(); rpcUserWithCert.setUser(user); rpcUserWithCert.setUserLoginCertificate(userLoginCertificate); boolean registerUserWithCertificate = client.registerUserWithCertificate(rpcUserWithCert); log.debug("Status of user registration is {}.", registerUserWithCertificate); }