public AcquisitionFlow acquire(final String providerId, final URI baseUrl, final URI returnUrl) { final CredentialProvider credentialProvider = providerFor(providerId); final CredentialFlowState flowState = credentialProvider.prepare(providerId, baseUrl, returnUrl); return new AcquisitionFlow.Builder().type(flowState.type()).redirectUrl(flowState.getRedirectUrl()).state(flowState).build(); }
@Override public Connection applyTo(final Connection connection, final CredentialFlowState givenFlowState) { final OAuth1CredentialFlowState flowState = flowState(givenFlowState); return applicator.applyTo(connection, flowState.getAccessToken()); }
@Override public Connection applyTo(final Connection connection, final CredentialFlowState givenFlowState) { final OAuth2CredentialFlowState flowState = flowState(givenFlowState); return applicator.applyTo(connection, flowState.getAccessGrant()); }
@Override public AcquisitionMethod acquisitionMethod() { return new AcquisitionMethod.Builder().label(labelFor(id)).icon(iconFor(id)).type(Type.OAUTH2) .description(descriptionFor(id)).build(); }
@Override public AcquisitionMethod acquisitionMethod() { return new AcquisitionMethod.Builder().label(labelFor(id)).icon(iconFor(id)).type(Type.OAUTH1) .description(descriptionFor(id)).build(); }
public static AcquisitionResponse.Builder from(final AcquisitionFlow flow) { return new AcquisitionResponse.Builder().type(flow.getType()).redirectUrl(flow.getRedirectUrl()); }
/* default */ CredentialProvider providerFrom(final CredentialFlowState flowState) { final String connectorId = flowState.getConnectorId(); return providerFor(connectorId); }
/** * Fill a builder with attribute values from the provided {@code AcquisitionRequest} instance. * Regular attribute values will be replaced with those from the given instance. * Absent optional values will not replace present values. * @param instance The instance from which to copy values * @return {@code this} builder for use in a chained invocation */ public final AcquisitionRequest.Builder from(AcquisitionRequest instance) { Objects.requireNonNull(instance, "instance"); returnUrl(instance.getReturnUrl()); return (AcquisitionRequest.Builder) this; }
/** * Copy the current immutable object by setting a value for the {@link AcquisitionFlow#getType() type} attribute. * A value equality check is used to prevent copying of the same value by returning {@code this}. * @param value A new value for type (can be {@code null}) * @return A modified copy of the {@code this} object */ public final ImmutableAcquisitionFlow withType(Type value) { if (this.type == value) return this; return validate(new ImmutableAcquisitionFlow(this, this.redirectUrl, value, this.state)); }
public AcquisitionMethod acquisitionMethodFor(final String providerId) { try { return providerFor(providerId).acquisitionMethod(); } catch (final IllegalArgumentException ignored) { return AcquisitionMethod.NONE; } }
public CredentialFlowState finishAcquisition(final CredentialFlowState flowState, final URI baseUrl) { final CredentialProvider credentialProvider = providerFrom(flowState); return credentialProvider.finish(flowState, baseUrl); }
public CredentialModule() { addDeserializer(OAuthToken.class, new OAuthTokenDeserializer()); } }
/** * Copy the current immutable object by setting a value for the {@link AcquisitionResponse.State#persist() persist} attribute. * A value equality check is used to prevent copying of the same value by returning {@code this}. * @param value A new value for persist (can be {@code null}) * @return A modified copy of the {@code this} object */ public final ImmutableState withPersist(AcquisitionResponse.State.Persist value) { if (this.persist == value) return this; return validate(new ImmutableState(value, this.spec)); }
/** * Construct a new immutable {@code AcquisitionResponse} instance. * @param redirectUrl The value for the {@code redirectUrl} attribute * @param type The value for the {@code type} attribute * @param state The value for the {@code state} attribute * @return An immutable AcquisitionResponse instance */ public static AcquisitionResponse of(String redirectUrl, Type type, AcquisitionResponse.State state) { return validate(new ImmutableAcquisitionResponse(redirectUrl, type, state)); }
/** * Builds a new {@link ImmutableAcquisitionRequest ImmutableAcquisitionRequest}. * @return An immutable instance of AcquisitionRequest * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableAcquisitionRequest build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return new ImmutableAcquisitionRequest(returnUrl); }
/** * Builds a new {@link AcquisitionMethod AcquisitionMethod}. * @return An immutable instance of AcquisitionMethod * @throws java.lang.IllegalStateException if any required attributes are missing */ public AcquisitionMethod build() { return ImmutableAcquisitionMethod.validate(new ImmutableAcquisitionMethod(description, icon, label, type)); } }
/** * Builds a new {@link OAuth2CredentialFlowState OAuth2CredentialFlowState}. * @return An immutable instance of OAuth2CredentialFlowState * @throws java.lang.IllegalStateException if any required attributes are missing */ public OAuth2CredentialFlowState build() { return ImmutableOAuth2CredentialFlowState.validate(new ImmutableOAuth2CredentialFlowState(this)); } }
/** * Builds a new {@link AcquisitionFlow AcquisitionFlow}. * @return An immutable instance of AcquisitionFlow * @throws java.lang.IllegalStateException if any required attributes are missing */ public AcquisitionFlow build() { return ImmutableAcquisitionFlow.validate(new ImmutableAcquisitionFlow(null, redirectUrl, type, state)); } }
/** * Builds a new {@link AcquisitionResponse.State State}. * @return An immutable instance of State * @throws java.lang.IllegalStateException if any required attributes are missing */ public AcquisitionResponse.State build() { return ImmutableState.validate(new ImmutableState(persist, spec)); } }
/** * Construct a new immutable {@code AcquisitionFlow} instance. * @param redirectUrl The value for the {@code redirectUrl} attribute * @param type The value for the {@code type} attribute * @param state The value for the {@code state} attribute * @return An immutable AcquisitionFlow instance */ public static AcquisitionFlow of(String redirectUrl, Type type, Optional<CredentialFlowState> state) { return validate(new ImmutableAcquisitionFlow(redirectUrl, type, state)); }