+
+ protected User searchForUser(UserAdmin userAdmin, String providedUsername) {
+ try {
+ // TODO check value null or empty
+ Set<User> collectedUsers = new HashSet<>();
+ // try dn
+ User user = null;
+ user = null;
+ // try all indexes
+ for (String attr : indexedUserProperties) {
+ user = userAdmin.getUser(attr, providedUsername);
+ if (user != null)
+ collectedUsers.add(user);
+ }
+ if (collectedUsers.size() == 1) {
+ user = collectedUsers.iterator().next();
+ return user;
+ } else if (collectedUsers.size() > 1) {
+ log.warn(collectedUsers.size() + " users for provided username" + providedUsername);
+ }
+ // try DN as a last resort
+ try {
+ user = (User) userAdmin.getRole(providedUsername);
+ if (user != null)
+ return user;
+ } catch (Exception e) {
+ // silent
+ }
+ return null;
+ } catch (Exception e) {
+ if (log.isTraceEnabled())
+ log.warn("Cannot search for user " + providedUsername, e);
+ return null;
+ }
+
+ }
+
+ protected Group searchForToken(UserAdmin userAdmin, String token) {
+ String dn = cn + "=" + token + "," + NodeConstants.TOKENS_BASEDN;
+ Group tokenGroup = (Group) userAdmin.getRole(dn);
+ return tokenGroup;
+ }
+
+ protected Authorization getAuthorizationFromToken(UserAdmin userAdmin, Group tokenGroup) {
+ if (TokenUtils.isExpired(tokenGroup))
+ return null;
+// String expiryDateStr = (String) tokenGroup.getProperties().get(description.name());
+// if (expiryDateStr != null) {
+// Instant expiryDate = NamingUtils.ldapDateToInstant(expiryDateStr);
+// if (expiryDate.isBefore(Instant.now())) {
+// if (log.isDebugEnabled())
+// log.debug("Token " + tokenGroup.getName() + " has expired.");
+// return null;
+// }
+// }
+ String userDn = TokenUtils.userDn(tokenGroup);
+ User user = (User) userAdmin.getRole(userDn);
+ Authorization auth = userAdmin.getAuthorization(user);
+ return auth;
+ }