bug5774: Extended the paywall documentation by adding examples. Did some rework after reviewing code for the example documentation.

This commit is contained in:
Udo Wessels committed 2024-05-17 11:54:03 +02:00
1 parent 1845e0158e
commit fac34ecb74
15 files changed
+99 -69

No files matched your search

@@ -49,20 +49,20 @@ public abstract class LeaderboardSettings extends AbstractGenericSerializableSet
maneuverDetails.add(DetailType.JIBE);
maneuverDetails.add(DetailType.PENALTY_CIRCLE);
maneuverDetailsToShow = new SecuredEnumSetSetting<>("maneuverDetailsToShow", this, maneuverDetails, DetailType::valueOfString,
context.getPaywallResolver(), context.getSecuredDTO());
context);
List<DetailType> legDetails = new ArrayList<>();
legDetails.add(DetailType.LEG_RANK_GAIN);
legDetailsToShow = new SecuredEnumSetSetting<>("legDetailsToShow", this, legDetails, DetailType::valueOfString,
context.getPaywallResolver(), context.getSecuredDTO());
context);
List<DetailType> raceDetails = new ArrayList<>();
raceDetails.add(DetailType.RACE_DISPLAY_LEGS);
raceDetails.add(DetailType.RACE_DISPLAY_BOATS);
raceDetailsToShow = new SecuredEnumSetSetting<>("raceDetailsToShow", this, raceDetails, DetailType::valueOfString,
context.getPaywallResolver(), context.getSecuredDTO());
context);
List<DetailType> overallDetails = new ArrayList<>();
overallDetails.add(DetailType.REGATTA_RANK);
overallDetailsToShow = new SecuredEnumSetSetting<>("overallDetailsToShow", this, overallDetails, DetailType::valueOfString,
context.getPaywallResolver(), context.getSecuredDTO());
context);
delayBetweenAutoAdvancesInMilliseconds = new LongSetting("delayBetweenAutoAdvancesInMilliseconds", this, LeaderboardEntryPoint.DEFAULT_REFRESH_INTERVAL_MILLIS);
showAddedScores = new BooleanSetting("showAddedScores", this, false);
showCompetitorShortNameColumn = new BooleanSetting("showCompetitorShortNameColumn", this, true);
@@ -9,13 +9,13 @@ import com.sap.sse.security.ui.client.premium.settings.AbstractSecuredValueSetti
public class SecuredDistanceSetting extends AbstractSecuredValueSetting<Distance> {
public SecuredDistanceSetting(String name, AbstractGenericSerializableSettingsWithContext<SecurityChildSettingsContext> settings,
Action action) {
this(name, settings, null, action);
Action action, SecurityChildSettingsContext securityContext) {
this(name, settings, null, action, securityContext);
}
public SecuredDistanceSetting(String name, AbstractGenericSerializableSettingsWithContext<SecurityChildSettingsContext> settings, Distance defaultValue,
Action action) {
super(name, settings, defaultValue, DistanceConverter.INSTANCE, action);
Action action, SecurityChildSettingsContext securityContext) {
super(name, settings, defaultValue, DistanceConverter.INSTANCE, action, securityContext);
}
}
@@ -9,13 +9,13 @@ import com.sap.sse.security.ui.client.premium.settings.AbstractSecuredValueSetti
public class SecuredDurationSetting extends AbstractSecuredValueSetting<Duration> {
public SecuredDurationSetting(String name, AbstractGenericSerializableSettingsWithContext<SecurityChildSettingsContext> settings,
Action action) {
this(name, settings, null, action);
Action action, SecurityChildSettingsContext securityContext) {
this(name, settings, null, action, securityContext);
}
public SecuredDurationSetting(String name, AbstractGenericSerializableSettingsWithContext<SecurityChildSettingsContext> settings, Duration defaultValue,
Action action) {
super(name, settings, defaultValue, DurationConverter.INSTANCE, action);
Action action, SecurityChildSettingsContext securityContext) {
super(name, settings, defaultValue, DurationConverter.INSTANCE, action, securityContext);
}
}
@@ -118,9 +118,9 @@ public class RaceMapSettings extends AbstractGenericSerializableSettingsWithCont
helpLinesSettings = new RaceMapHelpLinesSettings(HELP_LINES_SETTINGS, this);
windUpSetting = new BooleanSetting(PARAM_MAP_ORIENTATION_WIND_UP, this, false);
buoyZoneRadiusSetting = new DistanceSetting(PARAM_BUOY_ZONE_RADIUS_IN_METERS, this, DEFAULT_BUOY_ZONE_RADIUS);
showWindStreamletOverlaySetting = new SecuredBooleanSetting(PARAM_VIEW_SHOW_STREAMLETS, this, false, TrackedRaceActions.VIEWSTREAMLETS);
showWindStreamletColorsSetting = new SecuredBooleanSetting(PARAM_VIEW_SHOW_STREAMLET_COLORS, this, false, TrackedRaceActions.VIEWSTREAMLETS);
showSimulationOverlaySetting = new SecuredBooleanSetting(PARAM_VIEW_SHOW_SIMULATION, this, false, TrackedRaceActions.SIMULATOR);
showWindStreamletOverlaySetting = new SecuredBooleanSetting(PARAM_VIEW_SHOW_STREAMLETS, this, false, TrackedRaceActions.VIEWSTREAMLETS, context);
showWindStreamletColorsSetting = new SecuredBooleanSetting(PARAM_VIEW_SHOW_STREAMLET_COLORS, this, false, TrackedRaceActions.VIEWSTREAMLETS, context);
showSimulationOverlaySetting = new SecuredBooleanSetting(PARAM_VIEW_SHOW_SIMULATION, this, false, TrackedRaceActions.SIMULATOR, context);
showWindLadderSetting = new BooleanSetting(PARAM_SHOW_WIND_LADDER, this, false);
zoomSettings = new RaceMapZoomSettings(ZOOM_SETTINGS, this);
transparentHoverlinesSetting = new BooleanSetting(TRANSPARENT_HOVERLINES, this, false);
@@ -16,11 +16,11 @@ public abstract class AbstractSecuredValueSetting<T> extends AbstractValueSettin
private final SecuredDTO securedDTO;
protected AbstractSecuredValueSetting(String name, AbstractGenericSerializableSettingsWithContext<SecurityChildSettingsContext> settings, T defaultValue,
ValueConverter<T> valueConverter, Action action) {
ValueConverter<T> valueConverter, Action action, SecurityChildSettingsContext securityContext) {
super(name, settings, defaultValue, valueConverter);
this.paywallResolver = settings.getContext().getPaywallResolver();
this.paywallResolver = securityContext.getPaywallResolver();
this.action = action;
this.securedDTO = settings.getContext().getSecuredDTO();
this.securedDTO = securityContext.getSecuredDTO();
}
public boolean hasPermission() {
@@ -8,12 +8,12 @@ import com.sap.sse.security.ui.client.SecurityChildSettingsContext;
public class SecuredBooleanSetting extends AbstractSecuredValueSetting<Boolean> {
public SecuredBooleanSetting(String name, AbstractGenericSerializableSettingsWithContext<SecurityChildSettingsContext> settings,
Action action) {
this(name, settings, null, action);
Action action, SecurityChildSettingsContext securityContext) {
this(name, settings, null, action, securityContext);
}
public SecuredBooleanSetting(String name, AbstractGenericSerializableSettingsWithContext<SecurityChildSettingsContext> settings, Boolean defaultValue,
Action action) {
super(name, settings, defaultValue, BooleanConverter.INSTANCE, action);
Action action, SecurityChildSettingsContext securityContext) {
super(name, settings, defaultValue, BooleanConverter.INSTANCE, action, securityContext);
}
}
@@ -10,12 +10,12 @@ import com.sap.sse.security.ui.client.SecurityChildSettingsContext;
public class SecuredDecimalSetting extends AbstractSecuredValueSetting<BigDecimal> {
public SecuredDecimalSetting(String name, AbstractGenericSerializableSettingsWithContext<SecurityChildSettingsContext> settings,
Action action) {
this(name, settings, null, action);
Action action, SecurityChildSettingsContext securityContext) {
this(name, settings, null, action, securityContext);
}
public SecuredDecimalSetting(String name, AbstractGenericSerializableSettingsWithContext<SecurityChildSettingsContext> settings, BigDecimal defaultValue,
Action action) {
super(name, settings, defaultValue, DecimalConverter.INSTANCE, action);
Action action, SecurityChildSettingsContext securityContext) {
super(name, settings, defaultValue, DecimalConverter.INSTANCE, action, securityContext);
}
}
@@ -8,12 +8,12 @@ import com.sap.sse.security.ui.client.SecurityChildSettingsContext;
public class SecuredDoubleSetting extends AbstractSecuredValueSetting<Double> {
public SecuredDoubleSetting(String name, AbstractGenericSerializableSettingsWithContext<SecurityChildSettingsContext> settings,
Action action) {
this(name, settings, null, action);
Action action, SecurityChildSettingsContext securityContext) {
this(name, settings, null, action, securityContext);
}
public SecuredDoubleSetting(String name, AbstractGenericSerializableSettingsWithContext<SecurityChildSettingsContext> settings, Double defaultValue,
Action action) {
super(name, settings, defaultValue, DoubleConverter.INSTANCE, action);
Action action, SecurityChildSettingsContext securityContext) {
super(name, settings, defaultValue, DoubleConverter.INSTANCE, action, securityContext);
}
}
@@ -2,7 +2,6 @@ package com.sap.sse.security.ui.client.premium.settings;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import java.util.stream.StreamSupport;
@@ -22,22 +21,12 @@ public class SecuredEnumSetSetting<T extends Enum<T> & SecuredEnum> extends Abst
private final PaywallResolver paywallResolver;
private final SecuredDTO securedDto;
private final Set<SecuredBooleanSetting> securedValues = new HashSet<>();
private final AbstractGenericSerializableSettingsWithContext<SecurityChildSettingsContext> securedSettings;
public SecuredEnumSetSetting(String name, AbstractGenericSerializableSettingsWithContext<SecurityChildSettingsContext> settings,
Iterable<T> defaultValues, StringToEnumConverter<T> stringToEnumConverter,
PaywallResolver paywallResolver, SecuredDTO securedDto) {
Iterable<T> defaultValues, StringToEnumConverter<T> stringToEnumConverter, SecurityChildSettingsContext securityContext) {
super(name, settings, defaultValues, new EnumConverter<>(stringToEnumConverter));
this.securedSettings = settings;
this.paywallResolver = paywallResolver;
this.securedDto = securedDto;
}
public final void setValuesSecured(Iterable<T> values) {
for (T value: values) {
securedValues.add(new SecuredBooleanSetting(value.name(), securedSettings, value.getPremiumAction()));
}
this.paywallResolver = securityContext.getPaywallResolver();
this.securedDto = securityContext.getSecuredDTO();
}
/**
@@ -70,8 +59,4 @@ public class SecuredEnumSetSetting<T extends Enum<T> & SecuredEnum> extends Abst
}
return permittedCollection;
}
public Collection<SecuredBooleanSetting> getSecuredValues() {
return securedValues;
}
}
@@ -9,12 +9,12 @@ import com.sap.sse.security.ui.client.SecurityChildSettingsContext;
public class SecuredEnumSetting<T extends Enum<T>> extends AbstractSecuredValueSetting<T> {
public SecuredEnumSetting(String name, AbstractGenericSerializableSettingsWithContext<SecurityChildSettingsContext> settings,
StringToEnumConverter<T> stringToEnumConverter, Action action) {
this(name, settings, null, stringToEnumConverter, action);
StringToEnumConverter<T> stringToEnumConverter, Action action, SecurityChildSettingsContext securityContext) {
this(name, settings, null, stringToEnumConverter, action, securityContext);
}
public SecuredEnumSetting(String name, AbstractGenericSerializableSettingsWithContext<SecurityChildSettingsContext> settings, T defaultValue,
StringToEnumConverter<T> stringToEnumConverter, Action action) {
super(name, settings, defaultValue, new EnumConverter<>(stringToEnumConverter), action);
StringToEnumConverter<T> stringToEnumConverter, Action action, SecurityChildSettingsContext securityContext) {
super(name, settings, defaultValue, new EnumConverter<>(stringToEnumConverter), action, securityContext);
}
}
@@ -8,12 +8,12 @@ import com.sap.sse.security.ui.client.SecurityChildSettingsContext;
public class SecuredIntegerSetting extends AbstractSecuredValueSetting<Integer> {
public SecuredIntegerSetting(String name, AbstractGenericSerializableSettingsWithContext<SecurityChildSettingsContext> settings,
Action action) {
this(name, settings, null, action);
Action action, SecurityChildSettingsContext securityContext) {
this(name, settings, null, action, securityContext);
}
public SecuredIntegerSetting(String name, AbstractGenericSerializableSettingsWithContext<SecurityChildSettingsContext> settings, Integer defaultValue,
Action action) {
super(name, settings, defaultValue, IntegerConverter.INSTANCE, action);
Action action, SecurityChildSettingsContext securityContext) {
super(name, settings, defaultValue, IntegerConverter.INSTANCE, action, securityContext);
}
}
@@ -8,12 +8,12 @@ import com.sap.sse.security.ui.client.SecurityChildSettingsContext;
public class SecuredLongSetting extends AbstractSecuredValueSetting<Long> {
public SecuredLongSetting(String name, AbstractGenericSerializableSettingsWithContext<SecurityChildSettingsContext> settings,
Action action) {
this(name, settings, null, action);
Action action, SecurityChildSettingsContext securityContext) {
this(name, settings, null, action, securityContext);
}
public SecuredLongSetting(String name, AbstractGenericSerializableSettingsWithContext<SecurityChildSettingsContext> settings, Long defaultValue,
Action action) {
super(name, settings, defaultValue, LongConverter.INSTANCE, action);
Action action, SecurityChildSettingsContext securityContext) {
super(name, settings, defaultValue, LongConverter.INSTANCE, action, securityContext);
}
}
@@ -8,13 +8,13 @@ import com.sap.sse.security.ui.client.SecurityChildSettingsContext;
public class SecuredStringSetting extends AbstractSecuredValueSetting<String> {
public SecuredStringSetting(final String name, final AbstractGenericSerializableSettingsWithContext<SecurityChildSettingsContext> settings,
Action action) {
this(name, settings, null, action);
Action action, SecurityChildSettingsContext securityContext) {
this(name, settings, null, action, securityContext);
}
public SecuredStringSetting(final String name, final AbstractGenericSerializableSettingsWithContext<SecurityChildSettingsContext> settings,
final String defaultValue, Action action) {
super(name, settings, defaultValue, StringConverter.INSTANCE, action);
final String defaultValue, Action action, SecurityChildSettingsContext securityContext) {
super(name, settings, defaultValue, StringConverter.INSTANCE, action, securityContext);
}
public boolean isNotBlank() {
@@ -10,12 +10,12 @@ import com.sap.sse.security.ui.client.SecurityChildSettingsContext;
public class SecuredUUIDSetting extends AbstractSecuredValueSetting<UUID> {
public SecuredUUIDSetting(String name, AbstractGenericSerializableSettingsWithContext<SecurityChildSettingsContext> settings,
Action action) {
this(name, settings, null, action);
Action action, SecurityChildSettingsContext securityContext) {
this(name, settings, null, action, securityContext);
}
public SecuredUUIDSetting(String name, AbstractGenericSerializableSettingsWithContext<SecurityChildSettingsContext> settings, UUID defaultValue,
Action action) {
super(name, settings, defaultValue, UUIDConverter.INSTANCE, action);
Action action, SecurityChildSettingsContext securityContext) {
super(name, settings, defaultValue, UUIDConverter.INSTANCE, action, securityContext);
}
}
+46 -1
View File
@@ -12,7 +12,7 @@ The paywall mainly interacts with the SubscriptionService through the PaywallRes
The PaywallResolver is used as the main utility tool to interact with all services that are related to the paywall. It has been introduced mainly to slim down the number of parameters handed down through constructors in the application.
As an example, it is injected into all Settings of type AbstractSecuredValueCollectionSettings and AbstractSecuredValueSettings to forward the actual permission evaluation.
it does provide the following features:
It does provide the following features:
On SubscriptionService side:
- Gives access to functions directly related to subscriptions.
- Gives a list of all SubscriptionPlans that would unlock a specified feature.
@@ -50,6 +50,30 @@ Following behaviour need to be known:
* if no secureDTO is available -> value will be return without permission check
* if all three requirements are available, but permission check will fail -> default value will be returned
Here is an example of setting up a **secured** Setting (RaceMapSettings.java)
```
public class RaceMapSettings extends AbstractGenericSerializableSettingsWithContext<SecurityChildSettingsContext> {
[...]
@Override
protected void addChildSettings(SecurityChildSettingsContext context) {
[...]
showWindStreamletOverlaySetting = new SecuredBooleanSetting(
PARAM_VIEW_SHOW_STREAMLETS, this, false, TrackedRaceActions.VIEWSTREAMLETS, context);
showWindStreamletColorsSetting = new SecuredBooleanSetting(
PARAM_VIEW_SHOW_STREAMLET_COLORS, this, false, TrackedRaceActions.VIEWSTREAMLETS, context);
showSimulationOverlaySetting = new SecuredBooleanSetting(
PARAM_VIEW_SHOW_SIMULATION, this, false, TrackedRaceActions.SIMULATOR, context);
[...]
}
[...]
}
```
The class is extending the `AbstractGenericSerializableSettingsWithContext<SecurityChildSettingsContext>` instead of `AbstractGenericSerializableSettings` to have the needed PaywallResolver and SecuredDTO in place (a security context will be set before addChildSettings is permormed, so the context is always available in an AbstractGenericSerializableSettingsWithContext).
This change maybe needs some adaptions to the constructors to set the security context objects accordingly, but this will be automatically visible by checking the compiler errors.
### SecuredEnumSetSetting
The secured ENUM set setting is somehow special, because it's based on a list of enums instead of single values like the normal SecuredSettings. It is mainly used for Leaderboard settings.
@@ -58,6 +82,27 @@ This leads to a special situation. If the user do not have premium rights to cha
Because this won't make sence in the most cases, it is highly recommended to **don't add premium features to default settings**. A good example for an exception could be advertising, where it is wanted that the user cannot *disable* it, if he is not a premium user.
Here is an example of setting up a **secured** EnumSetSetting with default values (LeaderboardSettings.java):
```
public abstract class LeaderboardSettings extends AbstractGenericSerializableSettingsWithContext<SecurityChildSettingsContext> {
[...]
@Override
protected void addChildSettings(SecurityChildSettingsContext context) {
[...]
List<DetailType> overallDetails = new ArrayList<>();
overallDetails.add(DetailType.REGATTA_RANK);
overallDetailsToShow = new SecuredEnumSetSetting<>(
"overallDetailsToShow", this, overallDetails, DetailType::valueOfString, context);
[...]
}
[...]
}
```
#### Premium default values (as idea for future)
See bug ->
## Premium UI Elements
Anything extending com.sap.sse.security.ui.client.premium.uielements.PremiumUiElement<T> can be used to establish additional paywall features.