All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.microsoft.aad.msal4j.UserIdentifier Maven / Gradle / Ivy

Go to download

Microsoft Authentication Library for Java gives you the ability to obtain tokens from Azure AD v2 (work and school accounts, MSA) and Azure AD B2C, gaining access to Microsoft Cloud API and any other API secured by Microsoft identities

There is a newer version: 1.17.1
Show newest version
// Generated by delombok at Wed Jan 25 19:50:33 UTC 2023
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
package com.microsoft.aad.msal4j;

/**
 * Used for populating the X-AnchorMailbox header, which is used in the cached credential service

 * (CCS) routing
 */
public class UserIdentifier {
    // Format is "userObjectId@userTenantId"
    private static final String OID_HEADER_FORMAT = "%s@%s";
    private String upn;
    private String oid;

    private UserIdentifier() {
    }

    public static UserIdentifier fromUpn(String upn) {
        UserIdentifier userIdentifier = new UserIdentifier();
        userIdentifier.upn = upn;
        return userIdentifier;
    }

    public static UserIdentifier fromHomeAccountId(String homeAccountId) {
        UserIdentifier userIdentifier = new UserIdentifier();
        // HomeAccountId is userObjectId.userTenantId
        String[] homeAccountIdParts = homeAccountId.split("\\.");
        if (homeAccountIdParts.length < 2 || StringHelper.isBlank(homeAccountIdParts[0]) || StringHelper.isBlank(homeAccountIdParts[1])) {
            userIdentifier.oid = null;
            return userIdentifier;
        }
        userIdentifier.oid = String.format(OID_HEADER_FORMAT, homeAccountIdParts[0], homeAccountIdParts[1]);
        return userIdentifier;
    }

    @java.lang.SuppressWarnings("all")
    String upn() {
        return this.upn;
    }

    @java.lang.SuppressWarnings("all")
    String oid() {
        return this.oid;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy