Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/oxTrust/issues/#815'
Browse files Browse the repository at this point in the history
  • Loading branch information
shekhar16 committed Jun 16, 2018
2 parents e904e61 + 3a93e32 commit d6d9944
Show file tree
Hide file tree
Showing 7 changed files with 252 additions and 13 deletions.
50 changes: 50 additions & 0 deletions model/src/main/java/org/gluu/oxtrust/model/Device.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package org.gluu.oxtrust.model;

public class Device {
private String addedOn;

private String id;

private String nickName;


public String getAddedOn() {
return addedOn;
}

public void setAddedOn(String addedOn) {
this.addedOn = addedOn;
}

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public String getNickName() {
return nickName;
}

public void setNickName(String nickName) {
this.nickName = nickName;
updateHash();
}

public void updateHash() {

if (nickName == null) {
id = "";
} else {
String str = nickName.replaceFirst("hotp:", "").replaceFirst("totp:", "");
int idx = str.indexOf(";");
if (idx > 0) {
str = str.substring(0, idx);
}
id = str;
}
}

}
24 changes: 23 additions & 1 deletion model/src/main/java/org/gluu/oxtrust/model/GluuCustomPerson.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,30 @@ public class GluuCustomPerson extends User

@LdapAttribute(name = "oxExternalUid")
private List<String> oxExternalUid;

@LdapAttribute(name = "oxOTPDevices")
private String oxOTPDevices;

@LdapAttribute(name = "oxMobileDevices")
private String oxMobileDevices;

public String getOxMobileDevices() {
return oxMobileDevices;
}

public void setOxMobileDevices(String oxMobileDevices) {
this.oxMobileDevices = oxMobileDevices;
}

public String getOxOTPDevices() {
return oxOTPDevices;
}

public void setOxOTPDevices(String oxOTPDevices) {
this.oxOTPDevices = oxOTPDevices;
}

@LdapAttribute(name = "oxCreationTimestamp")
@LdapAttribute(name = "oxCreationTimestamp")
private Date creationDate;

@LdapAttribute
Expand Down
17 changes: 17 additions & 0 deletions model/src/main/java/org/gluu/oxtrust/model/MobileDevice.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.gluu.oxtrust.model;

import java.util.ArrayList;

public class MobileDevice {

private ArrayList<Phone> phones;

public ArrayList<Phone> getPhones() {
return phones;
}

public void setPhones(ArrayList<Phone> phones) {
this.phones = phones;
}

}
17 changes: 17 additions & 0 deletions model/src/main/java/org/gluu/oxtrust/model/OTPDevice.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.gluu.oxtrust.model;

import java.util.ArrayList;

public class OTPDevice {

private ArrayList<Device> devices;

public ArrayList<Device> getDevices() {
return this.devices;
}

public void setDevices(ArrayList<Device> devices) {
this.devices = devices;
}

}
35 changes: 35 additions & 0 deletions model/src/main/java/org/gluu/oxtrust/model/Phone.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.gluu.oxtrust.model;

public class Phone {
private String addedOn;

private String number;

private String nickName;

public String getAddedOn() {
return addedOn;
}

public void setAddedOn(String addedOn) {
this.addedOn = addedOn;
}

public String getNumber() {
return number;
}

public void setNumber(String number) {
this.number = number;
}

public String getNickName() {
return nickName;
}

public void setNickName(String nickName) {
this.nickName = nickName;
}


}
116 changes: 105 additions & 11 deletions server/src/main/java/org/gluu/oxtrust/action/UpdatePersonAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,16 @@

import java.io.IOException;
import java.io.Serializable;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;

import javax.enterprise.context.ConversationScoped;
import javax.faces.application.FacesMessage;
Expand All @@ -32,9 +38,13 @@
import org.gluu.oxtrust.ldap.service.IPersonService;
import org.gluu.oxtrust.ldap.service.MemberService;
import org.gluu.oxtrust.ldap.service.OrganizationService;
import org.gluu.oxtrust.model.Device;
import org.gluu.oxtrust.model.GluuCustomAttribute;
import org.gluu.oxtrust.model.GluuCustomPerson;
import org.gluu.oxtrust.model.GluuGroup;
import org.gluu.oxtrust.model.MobileDevice;
import org.gluu.oxtrust.model.OTPDevice;
import org.gluu.oxtrust.model.Phone;
import org.gluu.oxtrust.model.fido.GluuCustomFidoDevice;
import org.gluu.oxtrust.model.fido.GluuDeviceDataBean;
import org.gluu.oxtrust.service.external.ExternalUpdateUserService;
Expand Down Expand Up @@ -222,7 +232,9 @@ public String update() {
try {
this.gluuStatus = this.person.getStatus();
List <String> oxexternal = this.person.getOxExternalUid();
String oxOTPDevices = this.person.getOxOTPDevices();
externalAuthCustomAttributes = new ArrayList<String>();
String oxMobileDevices = this.person.getOxMobileDevices();
if(oxexternal != null && oxexternal.size()>0){
for(String oxexternalStr : oxexternal){
String [] args = oxexternalStr.split(":");
Expand Down Expand Up @@ -255,18 +267,55 @@ public String update() {
gluuDeviceDataBean.setModality(modality);
deviceDataMap.add(gluuDeviceDataBean);
}
}
}

if(oxexternal != null && oxexternal.size()>0){
for(String oxexternalStr : oxexternal){
String [] args = oxexternalStr.split(":");
GluuDeviceDataBean gluuDeviceDataBean= new GluuDeviceDataBean();
if (oxOTPDevices != null && !oxOTPDevices.trim().equals("")) {
ObjectMapper mapper = new ObjectMapper();
OTPDevice oTPDevice = mapper.readValue(oxOTPDevices, OTPDevice.class);
ArrayList<Device> devices = oTPDevice.getDevices();

if (devices != null && devices.size() > 0) {
for (Device device : devices) {
GluuDeviceDataBean gluuDeviceDataBean = new GluuDeviceDataBean();
gluuDeviceDataBean.setNickName(device.getNickName());
gluuDeviceDataBean.setModality("OTP Device");
gluuDeviceDataBean.setId(device.getId());
Timestamp stamp = new Timestamp(Long.valueOf(device.getAddedOn()).longValue());
gluuDeviceDataBean.setCreationDate(stamp.toGMTString());
deviceDataMap.add(gluuDeviceDataBean);
}
}
}

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) {
GluuDeviceDataBean gluuDeviceDataBean = new GluuDeviceDataBean();
gluuDeviceDataBean.setNickName(phone.getNickName());
gluuDeviceDataBean.setModality("Mobile Device");
gluuDeviceDataBean.setId(phone.getNumber());

Timestamp stamp = new Timestamp(Long.valueOf(phone.getAddedOn()).longValue());
gluuDeviceDataBean.setCreationDate(stamp.toGMTString());
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[1]);
gluuDeviceDataBean.setId(oxexternalStr);
gluuDeviceDataBean.setModality("Passport");
gluuDeviceDataBean.setId("-");
gluuDeviceDataBean.setCreationDate("-");
deviceDataMap.add(gluuDeviceDataBean);
}

}
}
} catch (Exception e) {
// TODO Auto-generated catch block
Expand Down Expand Up @@ -536,17 +585,18 @@ public void validateConfirmPassword(FacesContext context, UIComponent comp, Obje
public void removeDevice(GluuDeviceDataBean deleteDeviceData){
try {
List<GluuCustomFidoDevice> gluuCustomFidoDevices = fidoDeviceService.searchFidoDevices( this.person.getInum(),null);

if(gluuCustomFidoDevices != null){
for( GluuCustomFidoDevice gluuCustomFidoDevice : gluuCustomFidoDevices){
if(gluuCustomFidoDevice.getId().equals(deleteDeviceData.getId())){
fidoDeviceService.removeGluuCustomFidoDevice(gluuCustomFidoDevice);
this.deviceDataMap.remove(deleteDeviceData);
return;
}
}
}


List <String> list = new ArrayList<String>(this.person.getOxExternalUid());
if(list != null){
for( String external : list){
if(deleteDeviceData.getId().trim().equals(external.trim())){
list.remove(external);
Expand All @@ -555,6 +605,50 @@ public void removeDevice(GluuDeviceDataBean deleteDeviceData){
return;
}
}
}

String oxOTPDevices = this.person.getOxOTPDevices();
if (oxOTPDevices != null && !oxOTPDevices.trim().equals("")) {
ObjectMapper mapper = new ObjectMapper();
OTPDevice oTPDevice = mapper.readValue(oxOTPDevices, OTPDevice.class);
ArrayList<Device> devices = oTPDevice.getDevices();

if (devices != null && devices.size() > 0) {
for (Device device : devices) {
if(deleteDeviceData.getId().equals(device.getId())){
deviceDataMap.remove(deleteDeviceData);
devices.remove(device);
Map<String, ArrayList<Device>> map= new HashMap<String, ArrayList<Device>>();
map.put("devices", devices);
String jsonInString = mapper.writeValueAsString(map);
this.person.setOxOTPDevices(jsonInString);
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) {
// TODO Auto-generated catch block
log.error("Failed to remove device ", e);
Expand Down
6 changes: 5 additions & 1 deletion server/src/main/webapp/WEB-INF/incl/person/personForm.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -438,11 +438,15 @@
<h:panelGroup id="U2fPanelid">
<a4j:commandLink id="u2fConfig" action="#{updatePersonAction.fetchFidoRecord(_value.id)}"
value="#{_value.id}"
rendered="#{not _value.id.contains(':')}"
rendered="#{(not _value.id.contains(':')) and (_value.modality ne 'OTP Device') and ( _value.modality ne 'Mobile Device')}"
render=":U2fPanel"
oncomplete="#{rich:component('U2fPanel')}.show();"
execute="@this" />
</h:panelGroup>

<h:panelGroup id="NoU2fPanelid" rendered="#{(_value.modality eq 'OTP Device') or ( _value.modality eq 'Mobile Device')}">
#{_value.id}
</h:panelGroup>
</h:column>

<h:column>
Expand Down

0 comments on commit d6d9944

Please sign in to comment.