use of org.xdi.oxauth.model.fido.u2f.protocol.DeviceData in project oxAuth by GluuFederation.
the class RegistrationService method finishRegistration.
public DeviceRegistrationResult finishRegistration(RegisterRequestMessage requestMessage, RegisterResponse response, String userInum, Set<String> facets) throws BadInputException {
RegisterRequest request = requestMessage.getRegisterRequest();
String appId = request.getAppId();
ClientData clientData = response.getClientData();
clientDataValidationService.checkContent(clientData, RawRegistrationService.SUPPORTED_REGISTER_TYPES, request.getChallenge(), facets);
RawRegisterResponse rawRegisterResponse = rawRegistrationService.parseRawRegisterResponse(response.getRegistrationData());
rawRegistrationService.checkSignature(appId, clientData, rawRegisterResponse);
Date now = new GregorianCalendar(TimeZone.getTimeZone("UTC")).getTime();
DeviceRegistration deviceRegistration = rawRegistrationService.createDevice(rawRegisterResponse);
deviceRegistration.setStatus(DeviceRegistrationStatus.ACTIVE);
deviceRegistration.setApplication(appId);
deviceRegistration.setCreationDate(now);
int keyHandleHashCode = deviceRegistrationService.getKeyHandleHashCode(rawRegisterResponse.getKeyHandle());
deviceRegistration.setKeyHandleHashCode(keyHandleHashCode);
final String deviceRegistrationId = String.valueOf(System.currentTimeMillis());
deviceRegistration.setId(deviceRegistrationId);
String responseDeviceData = response.getDeviceData();
if (StringHelper.isNotEmpty(responseDeviceData)) {
try {
String responseDeviceDataDecoded = new String(Base64Util.base64urldecode(responseDeviceData));
DeviceData deviceData = ServerUtil.jsonMapperWithWrapRoot().readValue(responseDeviceDataDecoded, DeviceData.class);
deviceRegistration.setDeviceData(deviceData);
} catch (Exception ex) {
throw new BadInputException(String.format("Device data is invalid: %s", responseDeviceData), ex);
}
}
boolean approved = StringHelper.equals(RawRegistrationService.REGISTER_FINISH_TYPE, response.getClientData().getTyp());
if (!approved) {
log.debug("Registratio request with keyHandle '{}' was canceled", rawRegisterResponse.getKeyHandle());
return new DeviceRegistrationResult(deviceRegistration, DeviceRegistrationResult.Status.CANCELED);
}
boolean twoStep = StringHelper.isNotEmpty(userInum);
if (twoStep) {
deviceRegistration.setDn(deviceRegistrationService.getDnForU2fDevice(userInum, deviceRegistrationId));
// Check if there is device registration with keyHandle in LDAP already
List<DeviceRegistration> foundDeviceRegistrations = deviceRegistrationService.findDeviceRegistrationsByKeyHandle(appId, deviceRegistration.getKeyHandle(), "oxId");
if (foundDeviceRegistrations.size() != 0) {
throw new BadInputException(String.format("KeyHandle %s was compromised", deviceRegistration.getKeyHandle()));
}
deviceRegistrationService.addUserDeviceRegistration(userInum, deviceRegistration);
} else {
deviceRegistration.setDn(deviceRegistrationService.getDnForOneStepU2fDevice(deviceRegistrationId));
deviceRegistrationService.addOneStepDeviceRegistration(deviceRegistration);
}
return new DeviceRegistrationResult(deviceRegistration, DeviceRegistrationResult.Status.APPROVED);
}
use of org.xdi.oxauth.model.fido.u2f.protocol.DeviceData in project oxTrust by GluuFederation.
the class UpdatePersonAction method getDeviceata.
private DeviceData getDeviceata(String data) {
ObjectMapper mapper = new ObjectMapper();
// JSON from file to Object
DeviceData obj = null;
try {
obj = mapper.readValue(data, DeviceData.class);
} catch (JsonParseException e) {
// TODO Auto-generated catch block
log.error("Failed to convert device string to object JsonParseException", e);
} catch (JsonMappingException e) {
// TODO Auto-generated catch block
log.error("Failed to convert device string to object JsonMappingException", e);
} catch (IOException e) {
// TODO Auto-generated catch block
log.error("Failed to convert device string to object IOException", e);
}
return obj;
}
use of org.xdi.oxauth.model.fido.u2f.protocol.DeviceData in project oxTrust by GluuFederation.
the class UpdatePersonAction method update.
/**
* Initializes attributes for updating person
*
* @return String describing success of the operation
* @throws Exception
*/
public String update() {
if (this.person != null) {
return OxTrustConstants.RESULT_SUCCESS;
}
this.update = true;
try {
this.person = personService.getPersonByInum(inum);
} catch (BaseMappingException ex) {
log.error("Failed to find person {}", inum, ex);
facesMessages.add(FacesMessage.SEVERITY_ERROR, "Failed to find person");
conversationService.endConversation();
return OxTrustConstants.RESULT_FAILURE;
}
initAttributes(false);
try {
this.gluuStatus = this.person.getStatus();
List<String> oxexternal = this.person.getOxExternalUid();
externalAuthCustomAttributes = new ArrayList<String>();
if (oxexternal != null && oxexternal.size() > 0) {
for (String oxexternalStr : oxexternal) {
String[] args = oxexternalStr.split(":");
externalAuthCustomAttributes.add(args[0]);
}
}
List<GluuCustomFidoDevice> gluuCustomFidoDevices = fidoDeviceService.searchFidoDevices(this.person.getInum(), null);
deviceDataMap = new ArrayList<GluuDeviceDataBean>();
if (gluuCustomFidoDevices != null) {
for (GluuCustomFidoDevice gluuCustomFidoDevice : gluuCustomFidoDevices) {
GluuDeviceDataBean gluuDeviceDataBean = new GluuDeviceDataBean();
gluuDeviceDataBean.setCreationDate(ldapEntryManager.decodeGeneralizedTime(gluuCustomFidoDevice.getCreationDate()).toGMTString());
gluuDeviceDataBean.setId(gluuCustomFidoDevice.getId());
String devicedata = gluuCustomFidoDevice.getDeviceData();
String modality = "";
String nickName = "";
if (devicedata != null) {
DeviceData deviceData = getDeviceata(devicedata);
// nickName = deviceData.getName();
nickName = gluuCustomFidoDevice.getNickname();
modality = "Super-Gluu Device";
} else {
// nickName = "U2F";
nickName = gluuCustomFidoDevice.getNickname();
modality = "U2F device";
}
gluuDeviceDataBean.setNickName(nickName);
gluuDeviceDataBean.setModality(modality);
deviceDataMap.add(gluuDeviceDataBean);
}
}
if (oxexternal != null && oxexternal.size() > 0) {
for (String oxexternalStr : oxexternal) {
String[] args = oxexternalStr.split(":");
GluuDeviceDataBean gluuDeviceDataBean = new GluuDeviceDataBean();
gluuDeviceDataBean.setNickName(args[0]);
gluuDeviceDataBean.setModality(args[0]);
gluuDeviceDataBean.setId(oxexternalStr);
deviceDataMap.add(gluuDeviceDataBean);
}
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
userPasswordAction.setPerson(this.person);
return OxTrustConstants.RESULT_SUCCESS;
}
Aggregations