String getUserName(AuthenticationResult result) { UserInfo userInfo = result.getUserInfo(); if (userInfo.getGivenName() != null && userInfo.getFamilyName() != null) { return userInfo.getGivenName() + " " + userInfo.getFamilyName(); } if (result.getIdToken() != null) { String base64EncodedJWTPayload = result.getIdToken().split("\\.")[JWT_PAYLOAD_PART_INDEX]; JSONObject token = new JSONObject(new String(Base64.getDecoder().decode(base64EncodedJWTPayload))); if (token.has(NAME_CLAIM)) { return token.getString(NAME_CLAIM); } } LOGGER.warn(String.format("User's name not found from authentication token for user %s", userInfo.getUniqueId())); return userInfo.getDisplayableId(); }
private UserInfo prepareUserInfo(AuthenticationResult authenticationResult) { com.microsoft.aad.adal4j.UserInfo ui = authenticationResult.getUserInfo(); log.info("Extracted user info display id {}, {} {}", ui.getDisplayableId(), ui.getGivenName(), ui.getFamilyName()); if (ui.getDisplayableId() != null && !ui.getDisplayableId().isEmpty()) { UserInfo userInfo = new UserInfo(ui.getDisplayableId(), getRandomToken()); userInfo.setFirstName(ui.getGivenName()); userInfo.setLastName(ui.getFamilyName()); userInfo.getKeys().put("refresh_token", authenticationResult.getRefreshToken()); userInfo.getKeys().put("created_date_of_refresh_token", Long.toString(System.currentTimeMillis())); return userInfo; } throw new DlabException("Cannot verify user identity"); }
private boolean authenticateByAzureAD(String username, String password) { AuthenticationContext context = null; AuthenticationResult result = null; ExecutorService service = null; try { String clientId = JiveGlobals.getProperty("org.jitsi.videobridge.ofmeet.azure.clientid", CLIENT_ID); if (clientId != null & !"".equals(clientId)) { service = Executors.newFixedThreadPool(1); context = new AuthenticationContext(AUTHORITY, false, service); Future<AuthenticationResult> future = context.acquireToken("https://graph.windows.net", clientId, username, password, null); result = future.get(); } } catch (Exception e) { Log.error("of_authenticate_365", e); } finally { service.shutdown(); } if (result != null) { accessToken = result.getAccessToken(); refreshToken = result.getRefreshToken(); idToken = result.getIdToken(); givenName = result.getUserInfo().getGivenName(); familyName = result.getUserInfo().getFamilyName(); } return result != null; }
static UserInfo createFromAdAlUserInfo(final com.microsoft.aad.adal4j.UserInfo adalUserInfo) { if (adalUserInfo == null) { return null; } final UserInfo userInfo = new UserInfo(); userInfo.uniqueId = adalUserInfo.getUniqueId(); userInfo.displayableId = adalUserInfo.getDisplayableId(); userInfo.givenName = adalUserInfo.getGivenName(); userInfo.familyName = adalUserInfo.getFamilyName(); userInfo.identityProvider = adalUserInfo.getIdentityProvider(); userInfo.passwordExpiresOn = adalUserInfo.getPasswordExpiresOn(); userInfo.passwordChangeUrl = adalUserInfo.getPasswordChangeUrl(); return userInfo; }