@Override
    public String parseRealm(final Map<String, Object> messageContext) throws STSException {
        val url = (String) messageContext.get("org.apache.cxf.request.url");
        val st = new StringTokenizer(url, "/");
        var count = st.countTokens();
        if (count <= 1) {
            return null;
        }
        count--;
        val realm = getRealm(st, count);
        if (StringUtils.isBlank(realm) || !realmMap.containsKey(realm)) {
            LOGGER.warn("Unknown realm: [{}]", realm);
            throw new STSException("Unknown realm: " + realm);
        }

        LOGGER.debug("URI realm parsed: [{}]", realm);
        return realm.trim();
    }
This is {@link UriRealmParser}.

@author Misagh Moayyed
@since 5.1.0
support/cas-server-support-ws-sts-api/src/main/java/org/apereo/cas/support/realm/UriRealmParser.java