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

公開メンバ関数

OTPConfig getConf ()
 
void reloadConfiguration ()
 
int getDevicesTotal (String userId)
 
List< OTPDevicegetDevices (String userId)
 
boolean updateDevicesAdd (String userId, List< OTPDevice > devices, OTPDevice newDevice)
 
boolean addDevice (String userId, OTPDevice newDevice)
 
IOTPAlgorithm getAlgorithmService (OTPKey.OTPType type)
 

変数

LdapService ldapService
 
ObjectMapper mapper
 

非公開メンバ関数

void inited ()
 
OTPDevice getExtraOTPInfo (String uid, List< OTPDevice > list)
 

非公開変数類

Logger logger
 
TOTPAlgorithmService tAS
 
HOTPAlgorithmService hAS
 
OTPConfig conf
 

詳解

著者
jgomer

関数詳解

◆ addDevice()

boolean org.gluu.credmanager.plugins.authnmethod.service.OTPService.addDevice ( String  userId,
OTPDevice  newDevice 
)
inline
134  {
135  return updateDevicesAdd(userId, getDevices(userId), newDevice);
136  }
boolean updateDevicesAdd(String userId, List< OTPDevice > devices, OTPDevice newDevice)
Definition: OTPService.java:105
List< OTPDevice > getDevices(String userId)
Definition: OTPService.java:86

◆ getAlgorithmService()

IOTPAlgorithm org.gluu.credmanager.plugins.authnmethod.service.OTPService.getAlgorithmService ( OTPKey.OTPType  type)
inline
161  {
162 
163  switch (type) {
164  case HOTP:
165  hAS.init((HOTPConfig) Utils.cloneObject(conf.getHotp()), conf.getIssuer());
166  return hAS;
167  case TOTP:
168  tAS.init((TOTPConfig) Utils.cloneObject(conf.getTotp()), conf.getIssuer());
169  return tAS;
170  default:
171  return null;
172  }
173  }
TOTPConfig getTotp()
Definition: OTPConfig.java:41
void init(HOTPConfig conf, String issuer)
Definition: HOTPAlgorithmService.java:42
OTPConfig conf
Definition: OTPService.java:49
void init(TOTPConfig conf, String issuer)
Definition: TOTPAlgorithmService.java:43
String getIssuer()
Definition: OTPConfig.java:33
HOTPConfig getHotp()
Definition: OTPConfig.java:37
TOTPAlgorithmService tAS
Definition: OTPService.java:44
HOTPAlgorithmService hAS
Definition: OTPService.java:47

◆ getConf()

OTPConfig org.gluu.credmanager.plugins.authnmethod.service.OTPService.getConf ( )
inline
56  {
57  return conf;
58  }
OTPConfig conf
Definition: OTPService.java:49

◆ getDevices()

List<OTPDevice> org.gluu.credmanager.plugins.authnmethod.service.OTPService.getDevices ( String  userId)
inline
86  {
87 
88  List<OTPDevice> devices = new ArrayList<>();
89  try {
90  PersonOTP person = ldapService.get(PersonOTP.class, ldapService.getPersonDn(userId));
91  String json = person.getOTPDevices();
92  json = Utils.isEmpty(json) ? "[]" : mapper.readTree(json).get("devices").toString();
93 
94  List<OTPDevice> devs = mapper.readValue(json, new TypeReference<List<OTPDevice>>() { });
95  devices = person.getExternalUids().stream().filter(uid -> uid.startsWith("totp:") || uid.startsWith("hotp:"))
96  .map(uid -> getExtraOTPInfo(uid, devs)).sorted().collect(Collectors.toList());
97  logger.trace("getDevices. User '{}' has {}", userId, devices.stream().map(OTPDevice::getId).collect(Collectors.toList()));
98  } catch (Exception e) {
99  logger.error(e.getMessage(), e);
100  }
101  return devices;
102 
103  }
LdapService ldapService
Definition: BaseService.java:20
public< T > T get(Class< T > clazz, String dn)
Definition: LdapService.java:209
ObjectMapper mapper
Definition: BaseService.java:22
int getId()
Definition: OTPDevice.java:50
String getPersonDn(String id)
Definition: LdapService.java:167
OTPDevice getExtraOTPInfo(String uid, List< OTPDevice > list)
Definition: OTPService.java:146

◆ getDevicesTotal()

int org.gluu.credmanager.plugins.authnmethod.service.OTPService.getDevicesTotal ( String  userId)
inline
73  {
74 
75  int total = 0;
76  try {
77  PersonOTP person = ldapService.get(PersonOTP.class, ldapService.getPersonDn(userId));
78  total = (int) person.getExternalUids().stream().filter(uid -> uid.startsWith("totp:") || uid.startsWith("hotp:")).count();
79  } catch (Exception e) {
80  logger.error(e.getMessage(), e);
81  }
82  return total;
83 
84  }
LdapService ldapService
Definition: BaseService.java:20
public< T > T get(Class< T > clazz, String dn)
Definition: LdapService.java:209
String getPersonDn(String id)
Definition: LdapService.java:167

◆ getExtraOTPInfo()

OTPDevice org.gluu.credmanager.plugins.authnmethod.service.OTPService.getExtraOTPInfo ( String  uid,
List< OTPDevice list 
)
inlineprivate

Creates an instance of OTPDevice by looking up in the list of OTPDevices passed. If the item is not found in the in the list, it means the device was previously enrolled by using a different application. In this case the resulting object will not have properties like nickname, etc. Just a basic ID

引数
uidIdentifier of an OTP device (LDAP attribute "oxExternalUid" inside a user entry)
listList of existing OTP devices enrolled. Ideally, there is an item here corresponding to the uid passed
戻り値
OTPDevice object
146  {
147  //Complements current otp device with extra info in the list if any
148 
149  OTPDevice device = new OTPDevice(uid);
150  int hash = device.getId();
151 
152  Optional<OTPDevice> extraInfoOTP = list.stream().filter(dev -> dev.getId() == hash).findFirst();
153  if (extraInfoOTP.isPresent()) {
154  device.setAddedOn(extraInfoOTP.get().getAddedOn());
155  device.setNickName(extraInfoOTP.get().getNickName());
156  }
157  return device;
158 
159  }

◆ inited()

void org.gluu.credmanager.plugins.authnmethod.service.OTPService.inited ( )
inlineprivate
52  {
54  }
void reloadConfiguration()
Definition: OTPService.java:60

◆ reloadConfiguration()

void org.gluu.credmanager.plugins.authnmethod.service.OTPService.reloadConfiguration ( )
inline
60  {
61 
62  String acr = OTPExtension.ACR;
63  Map<String, String> props = ldapService.getCustScriptConfigProperties(acr);
64  if (props == null) {
65  logger.warn("Config. properties for custom script '{}' could not be read. Features related to {} will not be accessible",
66  acr, acr.toUpperCase());
67  } else {
68  conf = OTPConfig.get(props);
69  }
70 
71  }
static OTPConfig get(Map< String, String > propsMap)
Definition: OTPConfig.java:63
LdapService ldapService
Definition: BaseService.java:20
OTPConfig conf
Definition: OTPService.java:49
Map< String, String > getCustScriptConfigProperties(String displayName)
Definition: LdapService.java:135

◆ updateDevicesAdd()

boolean org.gluu.credmanager.plugins.authnmethod.service.OTPService.updateDevicesAdd ( String  userId,
List< OTPDevice devices,
OTPDevice  newDevice 
)
inline
105  {
106 
107  boolean success = false;
108  try {
109  List<OTPDevice> vdevices = new ArrayList<>(devices);
110  if (newDevice != null) {
111  vdevices.add(newDevice);
112  }
113  String[] uids = vdevices.stream().map(OTPDevice::getUid).toArray(String[]::new);
114  String json = uids.length == 0 ? null : mapper.writeValueAsString(Collections.singletonMap("devices", vdevices));
115 
116  logger.debug("Updating otp devices for user '{}'", userId);
117  PersonOTP person = ldapService.get(PersonOTP.class, ldapService.getPersonDn(userId));
118  person.setOTPDevices(json);
119  person.setExternalUid(uids);
120 
121  success = ldapService.modify(person, PersonOTP.class);
122 
123  if (success && newDevice != null) {
124  devices.add(newDevice);
125  logger.debug("Added {}", newDevice.getNickName());
126  }
127  } catch (Exception e) {
128  logger.error(e.getMessage(), e);
129  }
130  return success;
131 
132  }
LdapService ldapService
Definition: BaseService.java:20
String getUid()
Definition: OTPDevice.java:54
public< T > T get(Class< T > clazz, String dn)
Definition: LdapService.java:209
ObjectMapper mapper
Definition: BaseService.java:22
public< T > boolean modify(T object, Class< T > clazz)
Definition: LdapService.java:264
String getPersonDn(String id)
Definition: LdapService.java:167

メンバ詳解

◆ conf

OTPConfig org.gluu.credmanager.plugins.authnmethod.service.OTPService.conf
private

◆ hAS

HOTPAlgorithmService org.gluu.credmanager.plugins.authnmethod.service.OTPService.hAS
private

◆ ldapService

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

◆ logger

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

◆ mapper

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

◆ tAS

TOTPAlgorithmService org.gluu.credmanager.plugins.authnmethod.service.OTPService.tAS
private

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