Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Building null origins in RelyingParty #347

Open
philsmart opened this issue Feb 2, 2024 · 6 comments
Open

Building null origins in RelyingParty #347

philsmart opened this issue Feb 2, 2024 · 6 comments
Labels
enhancement New feature or request

Comments

@philsmart
Copy link

I think you should be able to build the RelyingParty object using a null Origins Set (it just takes the RP ID if it is). However, the builder will not allow it Caused by: java.lang.NullPointerException: origins is marked non-null but is null. I guess that is because of the nonnull annotation on the origins field.

Version 2.5.0.

@philsmart philsmart changed the title Setting null origins in RelyingParty Building null origins in RelyingParty Feb 2, 2024
@emlun
Copy link
Member

emlun commented Feb 2, 2024

Sorry, I don't understand what you mean by this:

(it just takes the RP ID if it is)

What are you trying to accomplish?

@philsmart
Copy link
Author

If I want to build the RelyingParty object e.g.

final RelyingParty rp = RelyingParty.builder().identity(
                    RelyingPartyIdentity
                    .builder()
                    .id(getRelyingPartyId())
                    .name(getRelyingPartyName())
                    .build()).credentialRepository(getCredentialRepository())
            .allowOriginPort(isAllowOriginPort())
            .allowOriginSubdomain(isAllowOriginSubdomain())
            .origins(getOrigins())
            .build();

If getOrigins is null, the builder fails with an NPE. I want to pass null through the builder, the constructor seems to allow null origins, and if it is null it sets the identity.getId()

    this.origins =
        origins != null
            ? CollectionUtil.immutableSet(origins)
            : Collections.singleton("https://" + identity.getId());

Otherwise, I have to build the Relying Party object conditionally.

@emlun
Copy link
Member

emlun commented Feb 2, 2024

What you're asking for is in fact the default behaviour, i.e., what you get if you do not call the .origins() setter:

public RelyingParty.RelyingPartyBuilder origins(@nonnull @nonnull Set<String> origins)
[...]
The default is the set containing only the string "https://" + RelyingParty.getIdentity().getId().
[...]

Does that solve your problem?

@philsmart
Copy link
Author

Thanks for the quick reply. Yes, I am currently handling it conditionally, e.g. if the origins are not set (configured on my service) I just leave it out, and if it is set I call it. It would be easier not to make that decision when I am building the RelyingParty object, and just send through a null and let the builder handle it.

But I get it is a convenience thing, so feel free to close this issue if it is not something you'd want to change.

@emlun emlun added the enhancement New feature or request label Feb 2, 2024
@emlun
Copy link
Member

emlun commented Feb 2, 2024

Fair enough, I had the same thought while looking into this. We'll consider it for the next release!

@philsmart
Copy link
Author

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

No branches or pull requests

2 participants