Skip to content
Permalink
Browse files

Merge pull request #1489 from /issues/1485

NPE when removing devices in user's profile #1485
  • Loading branch information...
syntrydy committed Jan 29, 2019
2 parents fbf2ae3 + 53f2f14 commit 5c3c4eb477f338eaea8d2722f337b1edb3b863af
@@ -11,10 +11,8 @@
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;

import javax.enterprise.context.ConversationScoped;
@@ -258,10 +256,8 @@ public String update() {
this.gluuStatus = this.person.getStatus();
this.oxExternalUids = this.person.getOxExternalUid();
fillExternalAuthCustomAttributes();
addFidoDevices();
addOtpDevices();
addMobileDevices();
addExternalUids();
addFidoDevices();
} catch (Exception e) {
log.error(e.getMessage(), e);
return OxTrustConstants.RESULT_FAILURE;
@@ -272,7 +268,9 @@ public String update() {
private void addExternalUids() {
ArrayList<Device> devices = new ArrayList<Device>();
OTPDevice oxOTPDevices = this.person.getOxOTPDevices();
devices.addAll(oxOTPDevices.getDevices());
if (oxOTPDevices !=null && oxOTPDevices.getDevices() != null) {
devices.addAll(oxOTPDevices.getDevices());
}
if (oxExternalUids != null && oxExternalUids.size() > 0) {
for (String oxExternalUid : oxExternalUids) {
String[] args = oxExternalUid.split(COLON);
@@ -293,6 +291,8 @@ private void addExternalUids() {
if (device.getId().equalsIgnoreCase("" + key.hashCode())) {
canAdd = false;
break;
} else if (!canBeConvertToInteger(device.getId())) {
canAdd = false;
}
}
if (canAdd) {
@@ -317,6 +317,15 @@ private void addExternalUids() {
}
}

private boolean canBeConvertToInteger(String id) {
try {
Double.valueOf(id);
return true;
} catch (Exception e) {
return false;
}
}

@SuppressWarnings("deprecation")
private void addMobileDevices() throws IOException, JsonParseException, JsonMappingException {
String oxMobileDevices = this.person.getOxMobileDevices();
@@ -347,12 +356,14 @@ private void addOtpDevices() {
}
if (devices != null && devices.size() > 0) {
List<String> oxExternalUids = this.person.getOxExternalUid();
boolean canProceed = false;
canProceed = oxExternalUids != null && oxExternalUids.size() > 0;
for (Device device : devices) {
GluuDeviceDataBean gluuDeviceDataBean = new GluuDeviceDataBean();
gluuDeviceDataBean.setNickName(device.getNickName());
gluuDeviceDataBean.setModality(OTP_DEVICE);
String hash = device.getId();
if (oxExternalUids != null && oxExternalUids.size() > 0) {
if (canProceed && canBeConvertToInteger(device.getId())) {
for (String oxExternalUid : oxExternalUids) {
String firstPart = oxExternalUid.split(COLON)[0];
if (firstPart.equalsIgnoreCase(TOTP) || firstPart.equalsIgnoreCase(HOTP)) {
@@ -770,9 +781,10 @@ public void removeDevice(GluuDeviceDataBean deleteDeviceData) {
try {
List<GluuCustomFidoDevice> gluuCustomFidoDevices = fidoDeviceService
.searchFidoDevices(this.person.getInum(), null);
String idOfDeviceToRemove = deleteDeviceData.getId();
if (gluuCustomFidoDevices != null) {
for (GluuCustomFidoDevice gluuCustomFidoDevice : gluuCustomFidoDevices) {
if (gluuCustomFidoDevice.getId().equals(deleteDeviceData.getId())) {
if (gluuCustomFidoDevice.getId().equals(idOfDeviceToRemove)) {
fidoDeviceService.removeGluuCustomFidoDevice(gluuCustomFidoDevice);
this.deviceDataMap.remove(deleteDeviceData);
return;
@@ -783,7 +795,7 @@ public void removeDevice(GluuDeviceDataBean deleteDeviceData) {
List<String> list = new ArrayList<String>(this.person.getOxExternalUid());
if (list != null) {
for (String external : list) {
if (deleteDeviceData.getId().equals(external.split(COLON)[1])) {
if (idOfDeviceToRemove.equals(external.split(COLON)[0])) {
list.remove(external);
this.person.setOxExternalUid(list);
this.deviceDataMap.remove(deleteDeviceData);
@@ -792,44 +804,6 @@ public void removeDevice(GluuDeviceDataBean deleteDeviceData) {
}
}

OTPDevice oxOTPDevices = this.person.getOxOTPDevices();
ArrayList<Device> devices = new ArrayList<Device>();
if (oxOTPDevices != null) {
devices = oxOTPDevices.getDevices();
}
if (devices != null && devices.size() > 0) {
for (Device device : devices) {
if (deleteDeviceData.getId().equals(device.getId())) {
deviceDataMap.remove(deleteDeviceData);
devices.remove(device);
oxOTPDevices.setDevices(devices);
this.person.setOxOTPDevices(oxOTPDevices);
return;
}
}
}

String oxMobileDevices = this.person.getOxMobileDevices();
if (oxMobileDevices != null && !oxMobileDevices.trim().equals("")) {
ObjectMapper mapper = new ObjectMapper();
MobileDevice mobileDevice = mapper.readValue(oxMobileDevices, MobileDevice.class);
ArrayList<Phone> phones = mobileDevice.getPhones();

if (phones != null && phones.size() > 0) {
for (Phone phone : phones) {
if (phone.getNumber().equals(deleteDeviceData.getId())) {
deviceDataMap.remove(deleteDeviceData);
phones.remove(phone);
Map<String, ArrayList<Phone>> map = new HashMap<String, ArrayList<Phone>>();
map.put("phones", phones);
String jsonInString = mapper.writeValueAsString(map);
this.person.setOxMobileDevices(jsonInString);
return;
}
}
}
}

} catch (Exception e) {
log.error("Failed to remove device ", e);
}
@@ -9,61 +9,6 @@
xmlns:richext="http://xmlns.jcp.org/jsf/composite/richext"
xmlns:c="http://xmlns.jcp.org/jsp/jstl/core">
<h:outputStylesheet>
.rf-pick-btn {
width: 100%;
white-space: nowrap;
background-image: url(../org.richfaces.images/autocompleteButtonGradient.png);
background-repeat: repeat-x;
background-position: top left;
background-color: #337AB7;
border-left-width: 1px;
border-left-style: solid;
border-left-color: #337AB7;
display: inline-block;
vertical-align: top;
cursor: pointer;
text-align: left;
}

.rf-pick-sel {
width: 100%;
background-color: #337AB7;
border-width: 1px;
border-style: dotted;
border-color: #000000;
}

button[disabled], input[type="reset"][disabled], input[type="submit"][disabled], input[type="button"][disabled] {
color: #337AB7;
border-color: #cccccc;
background-color: #cccccc;
background-image: url(org.richfaces.images/buttonDisabledBackgroundImage.png);
background-position: top left;
}

button:hover, input[type="reset"]:hover, input[type="submit"]:hover, input[type="button"]:hover {
background-position: bottom left !important;;
background-repeat: repeat-x !important;
background-image:none ;
}


button, input[type="reset"], input[type="submit"], input[type="button"] {
border-width: 1px;
border-color: #C0C0C0;
font-size: 11px;
font-family: Arial, Verdana, sans-serif;
color: #FFFFFF;
background-repeat: repeat-x;
background-position: top left;
background-color: #337AB7;
background-image:none ;
}

.rf-pp-cntr {
width: 95% !important;
}

</h:outputStylesheet>
<script src="#{oxTrustConfigurationService.jsLocation}/jsoneditor.min.js" type="text/javascript"/>
<script>
@@ -72,7 +17,7 @@
JSONEditor.defaults.iconlib = 'bootstrap3';
</script>

<rich:popupPanel id="U2fPanel" onmaskclick="#{rich:component('U2fPanel')}.hide()" keepVisualState="true" zindex="1000" minHeight="1000" top="60" >
<rich:popupPanel id="U2fPanel" onmaskclick="#{rich:component('U2fPanel')}.hide()" keepVisualState="true" zindex="1000" top="60" width="500" height="600" >
<f:facet name="header">
<h:outputText value="Device Detail" />
</f:facet>
@@ -82,7 +27,7 @@
</f:facet>

<h:form>
<h:panelGrid columns="1" id="U2fMenu" width="700" style="margin: 0 auto; ">
<h:panelGrid columns="1" id="U2fMenu" style="margin: 0 auto; width: 100%;">

<h:panelGroup id="U2fConfigMenu">
<h:panelGroup style="overflow:auto; height: 300px; width: 100%;" layout="block">
@@ -93,21 +38,8 @@

<h:outputText value="Device Key Handle :" style="margin-top: 10px;display: block;" />
<h:inputText value="#{updatePersonAction.fidoDevice.deviceKeyHandle}" disabled="true" id="devicekey" autocomplete="off" styleClass="form-control" style="margin-top: 10px;">

</h:inputText>

<ui:decorate id="DeviceRegiConfig" prependId="false"
template="/WEB-INF/incl/layout/jsoneditor.xhtml">
<ui:param name="id" value="DeviceRegiConf"/>
<ui:param name="parentId" value="DeviceRegiConfig"/>
<ui:param name="json" value="#{updatePersonAction.fidoDevice.deviceRegistrationConf}"/>
<ui:param name="jsonSchema"
value="#{request.contextPath}/schema/u2f.properties.json"/>
<ui:param name="saveBtnId" value="saveOxTrustConfigBtn"/>
<ui:param name="saveBtnLabelHide"
value="hide"/>
</ui:decorate>


<h:panelGroup id="U2fDeviceConfigMenu" rendered="#{updatePersonAction.deviceDetail != null}">

<h:outputText value="UUID :" style="margin-top: 10px;display: block;" />

0 comments on commit 5c3c4eb

Please sign in to comment.
You can’t perform that action at this time.