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

公開メンバ関数

void reloadConfiguration ()
 
boolean isNumberRegistered (String number)
 
SendCode sendSMS (String number, String body)
 
boolean updateMobilePhonesAdd (String userId, List< VerifiedMobile > mobiles, VerifiedMobile newPhone)
 
boolean addPhone (String userId, VerifiedMobile newPhone)
 
int getPhonesTotal (String userId)
 
List< VerifiedMobilegetVerifiedPhones (String userId)
 

変数

LdapService ldapService
 
ObjectMapper mapper
 

非公開メンバ関数

void inited ()
 
VerifiedMobile getExtraPhoneInfo (String number, List< VerifiedMobile > list)
 

非公開変数類

Logger logger
 
String fromNumber
 
MessageFactory messageFactory
 

詳解

An app. scoped bean to serve the purpose of sending SMS using the Twilio service

著者
jgomer

関数詳解

◆ addPhone()

boolean org.gluu.credmanager.plugins.authnmethod.service.MobilePhoneService.addPhone ( String  userId,
VerifiedMobile  newPhone 
)
inline
152  {
153  return updateMobilePhonesAdd(userId, getVerifiedPhones(userId), newPhone);
154  }
List< VerifiedMobile > getVerifiedPhones(String userId)
Definition: MobilePhoneService.java:169
boolean updateMobilePhonesAdd(String userId, List< VerifiedMobile > mobiles, VerifiedMobile newPhone)
Definition: MobilePhoneService.java:121

◆ getExtraPhoneInfo()

VerifiedMobile org.gluu.credmanager.plugins.authnmethod.service.MobilePhoneService.getExtraPhoneInfo ( String  number,
List< VerifiedMobile list 
)
inlineprivate

Creates an instance of VerifiedMobile by looking up in the list of VerifiedPhones passed. If the item is not found in the list, it means the user had already that phone added by means of another application, ie. oxTrust. In this case the resulting object will not have properties like nickname, etc. Just the phone number

引数
numberPhone number (LDAP attribute "mobile" inside a user entry)
listList of existing phones enrolled. Ideally, there is an item here corresponding to the uid number passed
戻り値
VerifiedMobile object
196  {
197  //Complements current phone with extra info in the list if any
198  VerifiedMobile phone = new VerifiedMobile(number);
199 
200  Optional<VerifiedMobile> extraInfoPhone = list.stream().filter(ph -> number.equals(ph.getNumber())).findFirst();
201  if (extraInfoPhone.isPresent()) {
202  phone.setAddedOn(extraInfoPhone.get().getAddedOn());
203  phone.setNickName(extraInfoPhone.get().getNickName());
204  }
205  return phone;
206  }

◆ getPhonesTotal()

int org.gluu.credmanager.plugins.authnmethod.service.MobilePhoneService.getPhonesTotal ( String  userId)
inline
156  {
157 
158  int total = 0;
159  try {
160  PersonMobile person = ldapService.get(PersonMobile.class, ldapService.getPersonDn(userId));
161  total = person.getMobileAsList().size();
162  } catch (Exception e) {
163  logger.error(e.getMessage(), e);
164  }
165  return total;
166 
167  }
LdapService ldapService
Definition: BaseService.java:20
Logger logger
Definition: MobilePhoneService.java:41
public< T > T get(Class< T > clazz, String dn)
Definition: LdapService.java:209
String getPersonDn(String id)
Definition: LdapService.java:167

◆ getVerifiedPhones()

List<VerifiedMobile> org.gluu.credmanager.plugins.authnmethod.service.MobilePhoneService.getVerifiedPhones ( String  userId)
inline
169  {
170 
171  List<VerifiedMobile> phones = new ArrayList<>();
172  try {
173  PersonMobile person = ldapService.get(PersonMobile.class, ldapService.getPersonDn(userId));
174  String json = person.getMobileDevices();
175  json = Utils.isEmpty(json) ? "[]" : mapper.readTree(json).get("phones").toString();
176 
177  List<VerifiedMobile> vphones = mapper.readValue(json, new TypeReference<List<VerifiedMobile>>() { });
178  phones = person.getMobileAsList().stream().map(str -> getExtraPhoneInfo(str, vphones)).sorted()
179  .collect(Collectors.toList());
180  logger.trace("getVerifiedPhones. User '{}' has {}", userId, phones.stream().map(VerifiedMobile::getNumber).collect(Collectors.toList()));
181  } catch (Exception e) {
182  logger.error(e.getMessage(), e);
183  }
184  return phones;
185 
186  }
LdapService ldapService
Definition: BaseService.java:20
Logger logger
Definition: MobilePhoneService.java:41
public< T > T get(Class< T > clazz, String dn)
Definition: LdapService.java:209
ObjectMapper mapper
Definition: BaseService.java:22
String getPersonDn(String id)
Definition: LdapService.java:167
VerifiedMobile getExtraPhoneInfo(String number, List< VerifiedMobile > list)
Definition: MobilePhoneService.java:196
String getNumber()
Definition: VerifiedMobile.java:35

◆ inited()

void org.gluu.credmanager.plugins.authnmethod.service.MobilePhoneService.inited ( )
inlineprivate
47  {
49  }
void reloadConfiguration()
Definition: MobilePhoneService.java:51

◆ isNumberRegistered()

boolean org.gluu.credmanager.plugins.authnmethod.service.MobilePhoneService.isNumberRegistered ( String  number)
inline
73  {
74 
75  PersonMobile person = new PersonMobile();
76  person.setMobile(number);
77  List<PersonMobile> matchingPeople = ldapService.find(person, PersonMobile.class, ldapService.getPeopleDn());
78  return Utils.isNotEmpty(matchingPeople);
79 
80  }
LdapService ldapService
Definition: BaseService.java:20
public< T > List< T > find(Class< T > clazz, String parentDn, String filter)
Definition: LdapService.java:222
String getPeopleDn()
Definition: LdapService.java:171

◆ reloadConfiguration()

void org.gluu.credmanager.plugins.authnmethod.service.MobilePhoneService.reloadConfiguration ( )
inline
51  {
52 
53  Map<String, String> props = ldapService.getCustScriptConfigProperties(OTPSmsExtension.ACR);
54 
55  if (props == null) {
56  logger.warn("Config. properties for custom script '{}' could not be read. Features related to {} will not be accessible",
57  OTPSmsExtension.ACR, OTPSmsExtension.ACR.toUpperCase());
58  } else {
59  String sid = props.get("twilio_sid");
60  String token = props.get("twilio_token");
61  fromNumber = props.get("from_number");
62 
63  if (Stream.of(sid, token, fromNumber).anyMatch(Utils::isEmpty)) {
64  logger.warn("Error parsing SMS settings. Please check LDAP entry of SMS custom script");
65  } else {
66  TwilioRestClient client = new TwilioRestClient(sid, token);
67  messageFactory = client.getAccount().getMessageFactory();
68  }
69  }
70 
71  }
LdapService ldapService
Definition: BaseService.java:20
static boolean isEmpty(String string)
Definition: Utils.java:47
Logger logger
Definition: MobilePhoneService.java:41
MessageFactory messageFactory
Definition: MobilePhoneService.java:44
String fromNumber
Definition: MobilePhoneService.java:43
Map< String, String > getCustScriptConfigProperties(String displayName)
Definition: LdapService.java:135

◆ sendSMS()

SendCode org.gluu.credmanager.plugins.authnmethod.service.MobilePhoneService.sendSMS ( String  number,
String  body 
)
inline
82  {
83 
84  SendCode status;
85  if (messageFactory != null) {
86 
87  try {
88  List<NameValuePair> messageParams = new ArrayList<>();
89  messageParams.add(new BasicNameValuePair("From", fromNumber));
90  messageParams.add(new BasicNameValuePair("To", number));
91  messageParams.add(new BasicNameValuePair("Body", body));
92  //TODO: uncomment
93  //Message message = messageFactory.create(messageParams);
94 
95  //String statusMsg = message.getStatus().toLowerCase();
96  String statusMsg = "ok";
97  logger.info("Message delivery status was {}", statusMsg);
98  switch (statusMsg) {
99  case "failed":
100  status = SendCode.DELIVERY_FAILED;
101  break;
102  case "undelivered":
103  status = SendCode.UNDELIVERED;
104  break;
105  default:
106  status = SendCode.SUCCESS;
107  logger.info("Message \"{}\" sent to #{}", body, number);
108  }
109  } catch (Exception e) {
110  status = SendCode.SMS_SERVICE_ERROR;
111  logger.error("No message was sent, error was: {}", e.getMessage());
112  }
113  } else {
114  status = SendCode.APP_SETUP_ERROR;
115  logger.info("No message was sent, messageFactory was not initialized properly");
116  }
117  return status;
118 
119  }
Logger logger
Definition: MobilePhoneService.java:41
MessageFactory messageFactory
Definition: MobilePhoneService.java:44
String fromNumber
Definition: MobilePhoneService.java:43

◆ updateMobilePhonesAdd()

boolean org.gluu.credmanager.plugins.authnmethod.service.MobilePhoneService.updateMobilePhonesAdd ( String  userId,
List< VerifiedMobile mobiles,
VerifiedMobile  newPhone 
)
inline
121  {
122 
123  boolean success = false;
124  try {
125  List<VerifiedMobile> vphones = new ArrayList<>(mobiles);
126  if (newPhone != null) {
127  vphones.add(newPhone);
128  }
129 
130  String[] numbers = vphones.stream().map(VerifiedMobile::getNumber).toArray(String[]::new);
131  String json = numbers.length > 0 ? mapper.writeValueAsString(Collections.singletonMap("phones", vphones)) : null;
132 
133  logger.debug("Updating phones for user '{}'", userId);
134  PersonMobile person = ldapService.get(PersonMobile.class, ldapService.getPersonDn(userId));
135  person.setMobileDevices(json);
136  person.setMobile(numbers);
137 
138  success = ldapService.modify(person, PersonMobile.class);
139 
140  if (success && newPhone != null) {
141  //modify list only if LDAP update took place
142  mobiles.add(newPhone);
143  logger.debug("Added {}", newPhone.getNumber());
144  }
145  } catch (Exception e) {
146  logger.error(e.getMessage(), e);
147  }
148  return success;
149 
150  }
LdapService ldapService
Definition: BaseService.java:20
Logger logger
Definition: MobilePhoneService.java:41
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
String getNumber()
Definition: VerifiedMobile.java:35

メンバ詳解

◆ fromNumber

String org.gluu.credmanager.plugins.authnmethod.service.MobilePhoneService.fromNumber
private

◆ ldapService

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

◆ logger

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

◆ mapper

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

◆ messageFactory

MessageFactory org.gluu.credmanager.plugins.authnmethod.service.MobilePhoneService.messageFactory
private

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