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

公開メンバ関数

void reloadConfiguration ()
 
int getDevicesTotal (String userId, boolean active)
 
List< SecurityKeygetDevices (String userId, boolean active)
 
String generateJsonRegisterMessage (String userName, String enrollmentCode) throws Exception
 
void finishRegistration (String userName, String response)
 
String getRegistrationResult (String jsonString) throws Exception
 
SecurityKey getLatestSecurityKey (String userId, long time)
 
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)
 

変数

LdapService ldapService
 
ObjectMapper mapper
 

非公開メンバ関数

void inited ()
 

非公開変数類

Logger logger
 
MainSettings settings
 
U2FConfig conf
 
RegistrationRequestService registrationRequestService
 

詳解

An app. scoped bean that encapsulates logic related to management of registration requests for u2f devices

著者
jgomer

関数詳解

◆ finishRegistration()

void org.gluu.credmanager.plugins.authnmethod.service.U2fService.finishRegistration ( String  userName,
String  response 
)
inline

Executes the finish registration step of the U2F service

引数
userNameAs required per org.xdi.oxauth.client.fido.u2f.RegistrationRequestService::finishRegistration
responseThis is the Json response obtained in the web browser after calling the u2f.register function in Javascript
107  {
108  //first parameter is not used in current implementation, see: org.xdi.oxauth.ws.rs.fido.u2f.U2fRegistrationWS#finishRegistration
109  RegisterStatus status = registrationRequestService.finishRegistration(userName, response);
110  logger.info("Response of finish registration: {}", status.getStatus());
111  }
RegistrationRequestService registrationRequestService
Definition: U2fService.java:45
RegisterStatus finishRegistration(@FormParam("username") String userName, @FormParam("tokenResponse") String registerResponseString)

◆ generateJsonRegisterMessage()

String org.gluu.credmanager.plugins.authnmethod.service.U2fService.generateJsonRegisterMessage ( String  userName,
String  enrollmentCode 
) throws Exception
inline

Triggers a registration request to a U2F endpoint and outputs the request message returned by the service in form of JSON

引数
userNameAs required per org.xdi.oxauth.client.fido.u2f.RegistrationRequestService::startRegistration
enrollmentCodeA previously generated random code stored under user's LDAP entry
戻り値
Json string representation
例外
ExceptionNetwork problem, De/Serialization error, ...
89  {
90 
91  RegisterRequestMessage message = registrationRequestService.startRegistration(userName, conf.getAppId(), null, enrollmentCode);
92 
93  //This is needed as serialization of RegisterRequestMessage instances behave very weirdly making Chrome suck more than usual
94  Map<String, Object> request = mapper.convertValue(message, new TypeReference<Map<String, Object>>() { });
95  request.put("authenticateRequests", Collections.emptyList());
96 
97  logger.info("Beginning registration start with uid={}, app_id={}", userName, conf.getAppId());
98  return mapper.writeValueAsString(request);
99 
100  }
RegistrationRequestService registrationRequestService
Definition: U2fService.java:45
RegisterRequestMessage startRegistration(@QueryParam("username") String userName, @QueryParam("application") String appId, @QueryParam("session_id") String sessionId)
ObjectMapper mapper
Definition: BaseService.java:22
String getAppId()
Definition: U2FConfig.java:17
U2FConfig conf
Definition: U2fService.java:44

◆ getDevices() [1/2]

List<SecurityKey> org.gluu.credmanager.plugins.authnmethod.service.U2fService.getDevices ( String  userId,
boolean  active 
)
inline
78  {
79  return getSortedDevices(userId, active, conf.getAppId(), SecurityKey.class);
80  }
< T extends FidoDevice > List< T > getSortedDevices(String userId, boolean active, String appId, Class< T > clazz)
Definition: FidoService.java:140
String getAppId()
Definition: U2FConfig.java:17
U2FConfig conf
Definition: U2fService.java:44

◆ 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.U2fService.getDevicesTotal ( String  userId,
boolean  active 
)
inline
74  {
75  return getDevicesTotal(conf.getAppId(), userId, active);
76  }
int getDevicesTotal(String userId, boolean active)
Definition: U2fService.java:74
String getAppId()
Definition: U2FConfig.java:17
U2FConfig conf
Definition: U2fService.java:44

◆ 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

◆ getLatestSecurityKey()

SecurityKey org.gluu.credmanager.plugins.authnmethod.service.U2fService.getLatestSecurityKey ( String  userId,
long  time 
)
inline
135  {
136 
137  SecurityKey sk = null;
138  try {
139  sk = getLatestFidoDevice(userId, time, conf.getAppId(), SecurityKey.class);
140  if (sk != null && sk.getNickName() != null) {
141  sk = null; //should have no name
142  }
143  } catch (Exception e) {
144  logger.error(e.getMessage(), e);
145  }
146  return sk;
147 
148  }
String getAppId()
Definition: U2FConfig.java:17
public< T extends FidoDevice > T getLatestFidoDevice(String userId, long time, String oxApp, Class< T > clazz)
Definition: FidoService.java:72
U2FConfig conf
Definition: U2fService.java:44

◆ 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  }

◆ getRegistrationResult()

String org.gluu.credmanager.plugins.authnmethod.service.U2fService.getRegistrationResult ( String  jsonString) throws Exception
inline
113  {
114 
115  String value = null;
116  JsonNode tree = mapper.readTree(jsonString);
117 
118  logger.info("Finished registration start with response: {}", jsonString);
119  JsonNode tmp = tree.get("errorCode");
120 
121  if (tmp != null) {
122  try {
123  value = U2fClientCodes.get(tmp.asInt()).toString();
124  logger.error("Registration failed with error: {}", value);
125  value = value.toLowerCase();
126  } catch (Exception e) {
127  logger.error(e.getMessage(), e);
128  value = Labels.getLabel("general.error.general");
129  }
130  }
131  return value;
132 
133  }
ObjectMapper mapper
Definition: BaseService.java:22

◆ 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.U2fService.inited ( )
inlineprivate
48  {
50  }
void reloadConfiguration()
Definition: U2fService.java:52

◆ reloadConfiguration()

void org.gluu.credmanager.plugins.authnmethod.service.U2fService.reloadConfiguration ( )
inline
52  {
53 
54  conf = new U2FConfig();
55  String metadataUri = Optional.ofNullable(settings.getU2fSettings()).map(U2fSettings::getRelativeMetadataUri)
56  .orElse(".well-known/fido-u2f-configuration");
57  conf.setEndpointUrl(String.format("%s/%s", ldapService.getIssuerUrl(), metadataUri));
58 
59  try {
60  Map<String, String> props = ldapService.getCustScriptConfigProperties(ConfigurationHandler.DEFAULT_ACR);
61  conf.setAppId(props.get("u2f_app_id"));
62 
63  logger.info("U2f settings found were: {}", mapper.writeValueAsString(conf));
64 
65  U2fConfigurationService u2fCfgServ = FidoU2fClientFactory.instance().createMetaDataConfigurationService(conf.getEndpointUrl());
66  U2fConfiguration metadataConf = u2fCfgServ.getMetadataConfiguration();
67  registrationRequestService = FidoU2fClientFactory.instance().createRegistrationRequestService(metadataConf);
68  } catch (Exception e) {
69  logger.error(e.getMessage(), e);
70  }
71 
72  }
String getIssuerUrl()
Definition: LdapService.java:81
LdapService ldapService
Definition: BaseService.java:20
MainSettings settings
Definition: U2fService.java:42
U2fSettings getU2fSettings()
Definition: MainSettings.java:120
RegistrationRequestService registrationRequestService
Definition: U2fService.java:45
String getEndpointUrl()
Definition: U2FConfig.java:25
ObjectMapper mapper
Definition: BaseService.java:22
void setAppId(String appId)
Definition: U2FConfig.java:21
void setEndpointUrl(String endpointUrl)
Definition: U2FConfig.java:29
String getRelativeMetadataUri()
Definition: U2fSettings.java:21
U2FConfig conf
Definition: U2fService.java:44
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

U2FConfig org.gluu.credmanager.plugins.authnmethod.service.U2fService.conf
private

◆ ldapService

LdapService org.gluu.credmanager.plugins.authnmethod.service.BaseService.ldapService
packageinherited

◆ logger

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

◆ mapper

ObjectMapper org.gluu.credmanager.plugins.authnmethod.service.BaseService.mapper
packageinherited

◆ registrationRequestService

RegistrationRequestService org.gluu.credmanager.plugins.authnmethod.service.U2fService.registrationRequestService
private

◆ settings

MainSettings org.gluu.credmanager.plugins.authnmethod.service.U2fService.settings
private

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