gluu
公開メンバ関数 | 関数 | 変数 | 非公開メンバ関数 | 非公開変数類 | 静的非公開変数類 | 全メンバ一覧
org.gluu.credmanager.plugins.authnmethod.service.SGService クラス
org.gluu.credmanager.plugins.authnmethod.service.SGService の継承関係図
Inheritance graph
org.gluu.credmanager.plugins.authnmethod.service.SGService 連携図
Collaboration graph

公開メンバ関数

void reloadConfiguration ()
 
int getDevicesTotal (String userId, boolean active)
 
List< SuperGluuDevicegetDevices (String userId, boolean active)
 
SGConfig getConf ()
 
String generateRequest (String userName, String code, String remoteIp)
 
SuperGluuDevice getLatestSuperGluuDevice (String userId, long time)
 
boolean isDeviceUnique (SuperGluuDevice dev, String userId) throws Exception
 
boolean updateDevice (FidoDevice device)
 
boolean removeDevice (FidoDevice device)
 
int getDevicesTotal (String appId, String userId, boolean active)
 

関数

public< T extends FidoDevice > T getLatestFidoDevice (String userId, long time, String oxApp, Class< T > clazz) throws Exception
 
private< T extends FidoDevice > List< T > getDevices (String userId, boolean active, String oxApplication, Class< T > clazz) throws Exception
 
< T extends FidoDevice > List< T > getSortedDevices (String userId, boolean active, String appId, Class< T > clazz)
 
private< T extends FidoDevice > T getRecentlyCreatedDevice (List< T > devices, long time)
 

変数

MainSettings settings
 

非公開メンバ関数

void inited ()
 

非公開変数類

Logger logger
 
LdapService ldapService
 
SGConfig conf
 
ObjectMapper mapper
 

静的非公開変数類

static final String GEOLOCATION_URL_PATTERN = "http://ip-api.com/json/{0}?fields=regionName,country,city,status,message"
 
static final int GEO_REQ_TIMEOUT = 5000
 

詳解

An app. scoped bean that encapsulates logic needed to enroll supergluu devices

関数詳解

◆ generateRequest()

String org.gluu.credmanager.plugins.authnmethod.service.SGService.generateRequest ( String  userName,
String  code,
String  remoteIp 
)
inline

Builds a string that encodes information in order to display a QR code

引数
userNameUsername string
codeAn enrollment code associated to the code
remoteIpAn IP address to encode in the request (possibly null)
戻り値
A string encoded in JSon format with the information for QR code display
91  {
92 
93  logger.info("Beginning registration request with user={}, ip={}", userName, remoteIp);
94 
95  Map<String, String> reqAsMap = new HashMap<>();
96  reqAsMap.put("username", userName);
97  reqAsMap.put("app", conf.getAppId());
98  reqAsMap.put("issuer", ldapService.getIssuerUrl());
99  reqAsMap.put("created", LocalDateTime.now().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME));
100  reqAsMap.put("enrollment", code);
101  reqAsMap.put("method", "enroll");
102 
103  if (remoteIp != null) { //Add geolocation information only if we have an IP available
104  reqAsMap.put("req_ip", remoteIp);
105 
106  JsonNode geolocation = WebUtils.getGeoLocation(remoteIp, GEOLOCATION_URL_PATTERN, GEO_REQ_TIMEOUT);
107  if (geolocation != null) {
108  String reqLocation = Stream.of("country", "regionName", "city").map(key -> geolocation.get(key).asText())
109  .reduce("", (acc, next) -> acc + ", " + next);
110  reqAsMap.put("req_loc", reqLocation.substring(2)); //Drop space+comma at the beginning
111  }
112  }
113 
114  String request = null;
115  try {
116  request = mapper.writeValueAsString(reqAsMap);
117  logger.debug("Super Gluu request is {}", request);
118  } catch (Exception e) {
119  logger.error(e.getMessage(), e);
120  }
121  return request;
122 
123  }
String getIssuerUrl()
Definition: LdapService.java:81
static final int GEO_REQ_TIMEOUT
Definition: SGService.java:39
static final String GEOLOCATION_URL_PATTERN
Definition: SGService.java:38
LdapService ldapService
Definition: SGService.java:45
String getAppId()
Definition: SGConfig.java:21
SGConfig conf
Definition: SGService.java:47
ObjectMapper mapper
Definition: SGService.java:48

◆ getConf()

SGConfig org.gluu.credmanager.plugins.authnmethod.service.SGService.getConf ( )
inline
80  {
81  return conf;
82  }
SGConfig conf
Definition: SGService.java:47

◆ getDevices() [1/2]

List<SuperGluuDevice> org.gluu.credmanager.plugins.authnmethod.service.SGService.getDevices ( String  userId,
boolean  active 
)
inline
76  {
77  return getSortedDevices(userId, active, conf.getAppId(), SuperGluuDevice.class);
78  }
String getAppId()
Definition: SGConfig.java:21
< T extends FidoDevice > List< T > getSortedDevices(String userId, boolean active, String appId, Class< T > clazz)
Definition: FidoService.java:140
SGConfig conf
Definition: SGService.java:47

◆ getDevices() [2/2]

private<T extends FidoDevice> List<T> org.gluu.credmanager.plugins.authnmethod.service.FidoService.getDevices ( String  userId,
boolean  active,
String  oxApplication,
Class< T >  clazz 
) throws Exception
inlinepackageinherited

Returns a list of FidoDevice instances found under the given branch that matches the oxApplication value given and whose oxStatus attribute equals to "active"

引数
userId
oxApplicationValue to match for oxApplication attribute (see LDAP object class oxDeviceRegistration)
clazzAny subclass of FidoDevice
<T>
戻り値
List of FidoDevices
114  {
115 
116  List<T> devices = new ArrayList<>();
117  List<oxDeviceRegistration> list = getRegistrations(oxApplication, userId, active);
118 
119  for (oxDeviceRegistration deviceRegistration : list) {
120  T device = clazz.getConstructor().newInstance();
121 
122  if (clazz.equals(SuperGluuDevice.class)) {
123  //DeviceData class is annotated with org.codehaus and has no default constructor so using normal mapper gives trouble
124  DeviceData data = codehausMapper.readValue(deviceRegistration.getDeviceData(), DeviceData.class);
125  ((SuperGluuDevice) device).setDeviceData(data);
126  }
127  device.setApplication(deviceRegistration.getOxApplication());
128  device.setNickName(deviceRegistration.getDisplayName());
129  device.setStatus(deviceRegistration.getOxStatus());
130  device.setId(deviceRegistration.getOxId());
131  device.setCreationDate(deviceRegistration.getCreationDate());
132  device.setCounter(deviceRegistration.getOxCounter());
133 
134  devices.add(device);
135  }
136  return devices;
137 
138  }
List< oxDeviceRegistration > getRegistrations(String appId, String userId, boolean active)
Definition: FidoService.java:93
ObjectMapper codehausMapper
Definition: FidoService.java:35

◆ getDevicesTotal() [1/2]

int org.gluu.credmanager.plugins.authnmethod.service.FidoService.getDevicesTotal ( String  appId,
String  userId,
boolean  active 
)
inlineinherited
60  {
61 
62  int total = 0;
63  try {
64  total = getRegistrations(appId, userId, active).size();
65  } catch (Exception e) {
66  logger.error(e.getMessage(), e);
67  }
68  return total;
69 
70  }
List< oxDeviceRegistration > getRegistrations(String appId, String userId, boolean active)
Definition: FidoService.java:93

◆ getDevicesTotal() [2/2]

int org.gluu.credmanager.plugins.authnmethod.service.SGService.getDevicesTotal ( String  userId,
boolean  active 
)
inline
72  {
73  return getDevicesTotal(conf.getAppId(), userId, active);
74  }
String getAppId()
Definition: SGConfig.java:21
int getDevicesTotal(String userId, boolean active)
Definition: SGService.java:72
SGConfig conf
Definition: SGService.java:47

◆ getLatestFidoDevice()

public<T extends FidoDevice> T org.gluu.credmanager.plugins.authnmethod.service.FidoService.getLatestFidoDevice ( String  userId,
long  time,
String  oxApp,
Class< T >  clazz 
) throws Exception
inlinepackageinherited
72  {
73  List<T> list = getDevices(userId, true, oxApp, clazz);
74  logger.debug("getLatestFidoDevice. list is {}", list.stream().map(FidoDevice::getId).collect(Collectors.toList()).toString());
75  return getRecentlyCreatedDevice(list, time);
76  }
private< T extends FidoDevice > List< T > getDevices(String userId, boolean active, String oxApplication, Class< T > clazz)
Definition: FidoService.java:114
private< T extends FidoDevice > T getRecentlyCreatedDevice(List< T > devices, long time)
Definition: FidoService.java:162
String getId()
Definition: FidoDevice.java:18

◆ getLatestSuperGluuDevice()

SuperGluuDevice org.gluu.credmanager.plugins.authnmethod.service.SGService.getLatestSuperGluuDevice ( String  userId,
long  time 
)
inline

Returns the most recently added (with respect to the timestamp passed) Super Gluu device for the user in question

引数
userId
timeTimestamp (milliseconds from the "epoch")
戻り値
A SuperGluuDevice object or null if no device could be found. Device has to have counter=-1 and no displayName yet
131  {
132 
133  SuperGluuDevice sg = null;
134  try {
135  String appId = conf.getAppId();
136  sg = getLatestFidoDevice(userId, time, appId, SuperGluuDevice.class);
137 
138  logger.trace("getLatestSuperGluuDevice. sg id is {}", sg == null ? -1 : sg.getId());
139  if (sg != null && (sg.getNickName() != null || sg.getCounter() >= 0)) {
140  sg = null; //should have no name and counter must be -1
141  }
142  logger.trace("getLatestSuperGluuDevice. sg is null {}", sg == null);
143  } catch (Exception e) {
144  logger.error(e.getMessage(), e);
145  }
146  return sg;
147 
148  }
String getAppId()
Definition: SGConfig.java:21
public< T extends FidoDevice > T getLatestFidoDevice(String userId, long time, String oxApp, Class< T > clazz)
Definition: FidoService.java:72
SGConfig conf
Definition: SGService.java:47

◆ getRecentlyCreatedDevice()

private<T extends FidoDevice> T org.gluu.credmanager.plugins.authnmethod.service.FidoService.getRecentlyCreatedDevice ( List< T >  devices,
long  time 
)
inlinepackageinherited

Chooses one device from a list of devices, such that its creation time is the closest to the timestamp given

引数
devicesA non-null list of fido devices
timeA timestamp as milliseconds elapsed from the "epoch"
<T>
戻り値
The best matching device (only devices added before the time supplied are considered). Null if no suitable device could be found
162  {
163 
164  long[] diffs = devices.stream().mapToLong(key -> time - key.getCreationDate().getTime()).toArray();
165 
166  logger.trace("getRecentlyCreatedDevice. diffs {}", Arrays.asList(diffs));
167  //Search for the smallest time difference
168  int i;
169  Pair<Long, Integer> min = new Pair<>(Long.MAX_VALUE, -1);
170  //it always holds that diffs.length==devices.size()
171  for (i = 0; i < diffs.length; i++) {
172  if (diffs[i] >= 0 && min.getX() > diffs[i]) { //Only search non-negative differences
173  min = new Pair<>(diffs[i], i);
174  }
175  }
176 
177  i = min.getY();
178  return i == -1 ? null : devices.get(i);
179 
180  }

◆ getSortedDevices()

<T extends FidoDevice> List<T> org.gluu.credmanager.plugins.authnmethod.service.FidoService.getSortedDevices ( String  userId,
boolean  active,
String  appId,
Class< T >  clazz 
)
inlinepackageinherited
140  {
141 
142  List<T> devices = new ArrayList<>();
143  try {
144  devices = getDevices(userId, active, appId, clazz).stream().sorted().collect(Collectors.toList());
145  logger.trace("getDevices. User '{}' has {}", userId, devices.stream().map(FidoDevice::getId).collect(Collectors.toList()));
146  } catch (Exception e) {
147  logger.error(e.getMessage(), e);
148  }
149  return devices;
150  }
private< T extends FidoDevice > List< T > getDevices(String userId, boolean active, String oxApplication, Class< T > clazz)
Definition: FidoService.java:114
String getId()
Definition: FidoDevice.java:18

◆ inited()

void org.gluu.credmanager.plugins.authnmethod.service.SGService.inited ( )
inlineprivate
51  {
53  mapper = new ObjectMapper();
54  }
void reloadConfiguration()
Definition: SGService.java:56
ObjectMapper mapper
Definition: SGService.java:48

◆ isDeviceUnique()

boolean org.gluu.credmanager.plugins.authnmethod.service.SGService.isDeviceUnique ( SuperGluuDevice  dev,
String  userId 
) throws Exception
inline

Determines if the device passed is enrolled exactly once or more times

引数
devA SuperGluuDevice instance
userIdA reference to a user
戻り値
Boolean value indicating whether a device with this device's UUID is enrolled once for some user
例外
ExceptionIf the device is not even enrolled
156  {
157 
158  boolean unique = false;
159  String uiid = dev.getDeviceData().getUuid();
160  List<String> uuids = getDevices(userId, true).stream().map(SuperGluuDevice::getDeviceData)
161  .map(DeviceData::getUuid).collect(Collectors.toList());
162 
163  logger.trace("isSGDeviceUnique. All SG user's devices {}", uuids.toString());
164  int size = (int) uuids.stream().filter(uuid -> uuid.equals(uiid)).count();
165  if (size == 0) {
166  throw new Exception(Labels.getLabel("app.error_uniqueness", new String[] { uiid }));
167  } else if (size == 1) {
168  unique = true;
169  }
170  return unique;
171 
172  }
List< SuperGluuDevice > getDevices(String userId, boolean active)
Definition: SGService.java:76
DeviceData getDeviceData()
Definition: SuperGluuDevice.java:20
String getUuid()
Definition: DeviceData.java:63

◆ reloadConfiguration()

void org.gluu.credmanager.plugins.authnmethod.service.SGService.reloadConfiguration ( )
inline
56  {
57  String acr = SuperGluuExtension.ACR;
58 
59  Map<String, String> props = ldapService.getCustScriptConfigProperties(acr);
60  if (props == null) {
61  logger.warn("Config. properties for custom script '{}' could not be read. Features related to {} will not be accessible",
62  acr, acr.toUpperCase());
63  } else {
64  conf = SGConfig.get(props);
65  if (conf != null) {
66  conf.setAppId(ldapService.getCustScriptConfigProperties(ConfigurationHandler.DEFAULT_ACR).get("supergluu_app_id"));
67  }
68  }
69 
70  }
static SGConfig get(Map< String, String > propsMap)
Definition: SGConfig.java:35
LdapService ldapService
Definition: SGService.java:45
void setAppId(String appId)
Definition: SGConfig.java:25
SGConfig conf
Definition: SGService.java:47
Map< String, String > getCustScriptConfigProperties(String displayName)
Definition: LdapService.java:135

◆ removeDevice()

boolean org.gluu.credmanager.plugins.authnmethod.service.FidoService.removeDevice ( FidoDevice  device)
inlineinherited
49  {
50 
51  boolean success = false;
52  oxDeviceRegistration deviceRegistration = getDeviceRegistrationFor(device);
53  if (deviceRegistration != null) {
54  success = ldapService.delete(deviceRegistration, oxDeviceRegistration.class);
55  }
56  return success;
57 
58  }
oxDeviceRegistration getDeviceRegistrationFor(FidoDevice device)
Definition: FidoService.java:78
LdapService ldapService
Definition: BaseService.java:20
public< T > boolean delete(T object, Class< T > clazz)
Definition: LdapService.java:283

◆ updateDevice()

boolean org.gluu.credmanager.plugins.authnmethod.service.FidoService.updateDevice ( FidoDevice  device)
inlineinherited
37  {
38 
39  boolean success = false;
40  oxDeviceRegistration deviceRegistration = getDeviceRegistrationFor(device);
41  if (deviceRegistration != null) {
42  deviceRegistration.setDisplayName(device.getNickName());
43  success = ldapService.modify(deviceRegistration, oxDeviceRegistration.class);
44  }
45  return success;
46 
47  }
oxDeviceRegistration getDeviceRegistrationFor(FidoDevice device)
Definition: FidoService.java:78
LdapService ldapService
Definition: BaseService.java:20
public< T > boolean modify(T object, Class< T > clazz)
Definition: LdapService.java:264

メンバ詳解

◆ conf

SGConfig org.gluu.credmanager.plugins.authnmethod.service.SGService.conf
private

◆ GEO_REQ_TIMEOUT

final int org.gluu.credmanager.plugins.authnmethod.service.SGService.GEO_REQ_TIMEOUT = 5000
staticprivate

◆ GEOLOCATION_URL_PATTERN

final String org.gluu.credmanager.plugins.authnmethod.service.SGService.GEOLOCATION_URL_PATTERN = "http://ip-api.com/json/{0}?fields=regionName,country,city,status,message"
staticprivate

◆ ldapService

LdapService org.gluu.credmanager.plugins.authnmethod.service.SGService.ldapService
private

◆ logger

Logger org.gluu.credmanager.plugins.authnmethod.service.SGService.logger
private

◆ mapper

ObjectMapper org.gluu.credmanager.plugins.authnmethod.service.SGService.mapper
private

◆ settings

MainSettings org.gluu.credmanager.plugins.authnmethod.service.FidoService.settings
packageinherited

このクラス詳解は次のファイルから抽出されました: