/** * Returns a new SubjectId based on the provided string. * * @param subjectIssuerWithId the Subject issuer + Subject ID (separated with a "{@value * SubjectId#ISSUER_DELIMITER}"). * @return a new SubjectId. * @throws NullPointerException if {@code subjectIssuerWithId} is {@code null}. * @throws IllegalArgumentException if {@code subjectIssuerWithId} is empty. */ public static SubjectId of(final CharSequence subjectIssuerWithId) { argumentNotEmpty(subjectIssuerWithId, "subjectIssuerWithId"); if (Placeholders.containsAnyPlaceholder(subjectIssuerWithId)) { // in case of placeholders, just use the whole input as subject, use an empty issuer return of(EMPTY_ISSUER, subjectIssuerWithId); } final String subjectIdAsString = subjectIssuerWithId.toString(); if (!subjectIdAsString.contains(ISSUER_DELIMITER)) { throw SubjectIdInvalidException.newBuilder(subjectIssuerWithId).build(); } final int ignoredDelimiterIndex = subjectIdAsString.indexOf(IGNORED_DELIMITER); final int lastDelimiter = ignoredDelimiterIndex >= 0 ? subjectIdAsString.indexOf(ISSUER_DELIMITER, ignoredDelimiterIndex + IGNORED_DELIMITER.length()) : subjectIdAsString.indexOf(ISSUER_DELIMITER); final SubjectIssuer issuer = PoliciesModelFactory.newSubjectIssuer(subjectIdAsString.substring(0, lastDelimiter)); final String subject = subjectIdAsString.replaceFirst(Pattern.quote(issuer.toString() + ISSUER_DELIMITER), ""); return of(issuer, subject); }