protected IAuthenticationResult getAccessTokenFromUserCredentials(final String username, final String password) throws Exception {
        val clientId = SpringExpressionLanguageValueResolver.getInstance().resolve(properties.getClientId());
        val scopes = org.springframework.util.StringUtils.commaDelimitedListToSet(properties.getScope());
        if (StringUtils.isNotBlank(properties.getClientSecret())) {
            val clientSecret = SpringExpressionLanguageValueResolver.getInstance().resolve(properties.getClientSecret());
            val clientCredential = ClientCredentialFactory.createFromSecret(clientSecret);
            val context = ConfidentialClientApplication.builder(clientId, clientCredential)
                .authority(properties.getLoginUrl())
                .validateAuthority(true)
                .build();
            val resource = StringUtils.appendIfMissing(properties.getResource(), "/").concat(".default");
            val parameters = ClientCredentialParameters.builder(Set.of(resource))
                .tenant(properties.getTenant())
                .build();
            LOGGER.debug("Acquiring token for [{}] with tenant [{}] for resource [{}]", username, properties.getTenant(), resource);
            val future = context.acquireToken(parameters);
            return future.get();
        }
        val context = PublicClientApplication.builder(clientId)
            .authority(properties.getLoginUrl())
            .validateAuthority(true)
            .build();
        val parameters = UserNamePasswordParameters.builder(scopes, username, password.toCharArray())
            .tenant(SpringExpressionLanguageValueResolver.getInstance().resolve(properties.getTenant()))
            .build();
        LOGGER.debug("Acquiring token for [{}] with tenant [{}] scopes [{}]", username, properties.getTenant(), scopes);
        val future = context.acquireToken(parameters);
        return future.get();
    }
This is {@link AzureActiveDirectoryAuthenticationHandler}.

@author Misagh Moayyed
@since 6.2.0
support/cas-server-support-azuread-authentication/src/main/java/org/apereo/cas/azure/ad/authentication/AzureActiveDirectoryAuthenticationHandler.java