if (Strings.isNullOrEmpty(email)) {
throw new IllegalArgumentException();
}
email = email.trim();
ClientCertificate clientCertificate = getClientCertificate();
if (clientCertificate == null) {
throw new IllegalArgumentException("Client certificate not provided");
}
if (request.challengeResponse == null || Strings.isNullOrEmpty(request.challengeResponse.response)) {
ByteString challenge = loginService.createRegistrationChallenge(clientCertificate);
RegisterResponse response = new RegisterResponse();
response.challenge = BaseEncoding.base64().encode(challenge.toByteArray());
return response;
}
DomainData domain = identityService.getDefaultDomain();
UserData.Builder b = UserData.newBuilder();
// We allow multiple systems to share an email address
// so we use the public key hash as our unique id
{
ByteString publicKeySha1 = clientCertificate.getPublicKeySha1();
String hex = BaseEncoding.base16().encode(publicKeySha1.toByteArray());
b.setName("__pubkey__" + hex);
}
b.setDomainId(domain.getId());
b.setEnabled(true);
b.setEmail(request.email);
String password = null;
UserCreationData userCreationData = new UserCreationData(domain, b, password);
userCreationData.publicKeySha1 = clientCertificate.getPublicKeySha1();
userCreationData.publicKeyChallengeRequest = fromBase64(request.challengeResponse.challenge);
userCreationData.publicKeyChallengeResponse = fromBase64(request.challengeResponse.response);
UserData user = identityService.createUser(userCreationData);