Skip to content

Commit

Permalink
Merge pull request #235 from eclipse-passage/563848
Browse files Browse the repository at this point in the history
[Passage] Licensing dialog should show "does not match" items
eparovyshnaya authored Jun 2, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents 8f66109 + cd2a956 commit 9f59867
Showing 5 changed files with 34 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -227,13 +227,13 @@ public Iterable<FeaturePermission> evaluateConditions(LicensingConfiguration con
} catch (LicensingException e) {
LicensingResult error = e.getResult();
licensingReporter.logResult(error);
licensingReporter.postResult(createEvent(ConditionEvents.CONDITIONS_NOT_VALID,
licensingReporter.sendResult(createEvent(ConditionEvents.CONDITIONS_NOT_VALID,
Collections.singletonList(condition), error));
} catch (Throwable e) {
LicensingResult error = LicensingResults.createError(
BaseMessages.getString("BaseAccessManager_permission_emitter_failure"), source, e); //$NON-NLS-1$
licensingReporter.logResult(error);
licensingReporter.postResult(createEvent(ConditionEvents.CONDITIONS_NOT_VALID,
licensingReporter.sendResult(createEvent(ConditionEvents.CONDITIONS_NOT_VALID,
Collections.singletonList(condition), error));
}
} else {
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@
package org.eclipse.passage.lic.base.access;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -23,6 +24,7 @@
import org.eclipse.passage.lic.api.access.FeaturePermission;
import org.eclipse.passage.lic.api.access.PermissionEmitter;
import org.eclipse.passage.lic.api.conditions.LicensingCondition;
import org.eclipse.passage.lic.base.BaseLicensingResult;
import org.eclipse.passage.lic.base.LicensingResults;
import org.eclipse.passage.lic.base.conditions.LicensingConditions;
import org.eclipse.passage.lic.internal.base.i18n.BaseMessages;
@@ -33,46 +35,41 @@ public abstract class BasePermissionEmitter implements PermissionEmitter {
public Iterable<FeaturePermission> emitPermissions(LicensingConfiguration configuration,
Iterable<LicensingCondition> conditions) throws LicensingException {
List<FeaturePermission> result = new ArrayList<>();
String source = getClass().getName();
if (conditions == null) {
String message = BaseMessages.getString("BasePermissionEmitter_prem_emit_error_invalid_consitions"); //$NON-NLS-1$
Exception e = new IllegalArgumentException();
LicensingResult error = LicensingResults.createError(message, source, e);
LicensingResult error = LicensingResults.createError(message, getClass().getName(), e);
throw new LicensingException(error);
}
for (LicensingCondition condition : conditions) {
String expression = condition.getConditionExpression();
Map<String, String> checks = LicensingConditions.parseExpression(expression);
if (checks.isEmpty()) {
String message = String.format(BaseMessages.getString("BasePermissionEmitter_prem_emit_error_no_expression_checks"), condition); //$NON-NLS-1$
Exception e = new IllegalArgumentException();
LicensingResult error = LicensingResults.createError(message, source, e);
throw new LicensingException(error);
String message = String.format(
BaseMessages.getString("BasePermissionEmitter_prem_emit_error_no_expression_checks"), //$NON-NLS-1$
condition);
throw new LicensingException(failure(condition, 401, message));
}
Set<String> keySet = checks.keySet();

boolean passed = true;
for (String key : keySet) {
String value = checks.get(key);
final boolean passed;
try {
passed = evaluateSegment(key, value);
} catch (Exception e) {
passed = false;
String message = String.format(BaseMessages.getString("BasePermissionEmitter_prem_emit_error_condition_evaluation_error"), condition, //$NON-NLS-1$
key, value);
LicensingResult error = LicensingResults.createError(message, source, e);
throw new LicensingException(error);
} catch (Throwable t) {// any kind of failures should be processed here
String message = String.format(
BaseMessages.getString("BasePermissionEmitter_prem_emit_error_condition_evaluation_error"), //$NON-NLS-1$
condition, key, value);
throw new LicensingException(failure(condition, 401, message));
}
if (!passed) {
String message = String.format(BaseMessages.getString("BasePermissionEmitter_prem_emit_error_condition_rejected"), condition, key, value); //$NON-NLS-1$
Exception e = new IllegalArgumentException();
LicensingResult error = LicensingResults.createError(message, source, e);
throw new LicensingException(error);
String message = String.format(
BaseMessages.getString("BasePermissionEmitter_prem_emit_error_condition_rejected"), //$NON-NLS-1$
condition, key, value);
throw new LicensingException(failure(condition, 403, message));
}
}
if (passed) {
result.add(createPermission(condition, configuration));
}
result.add(createPermission(condition, configuration));
}

return result;
@@ -84,4 +81,13 @@ protected FeaturePermission createPermission(LicensingCondition condition, Licen

protected abstract boolean evaluateSegment(String key, String value);

private LicensingResult failure(LicensingCondition condition, int code, String message) {
List<LicensingResult> details = new ArrayList<>();
Map<String, Object> data = new HashMap<String, Object>();
data.put(LicensingCondition.class.getName(), condition);
LicensingResult error = new BaseLicensingResult(LicensingResult.ERROR, message, code, getClass().getName(),
null, details, data);
return error;
}

}
Original file line number Diff line number Diff line change
@@ -67,6 +67,7 @@ public class JFaceMessages extends NLS {
public static String RestrictionVerdictViewerAdapter_msg_invalid_license;
public static String RestrictionVerdictViewerAdapter_msg_not_started;
public static String RestrictionVerdictViewerAdapter_msg_valid_license;
public static String RestrictionVerdictViewerAdapter_msg_wrong_license;
static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, JFaceMessages.class);
Original file line number Diff line number Diff line change
@@ -62,3 +62,4 @@ RestrictionVerdictViewerAdapter_msg_expired=Expired
RestrictionVerdictViewerAdapter_msg_invalid_license=Invalid license
RestrictionVerdictViewerAdapter_msg_not_started=Not started
RestrictionVerdictViewerAdapter_msg_valid_license=Valid license
RestrictionVerdictViewerAdapter_msg_wrong_license=License does not match
Original file line number Diff line number Diff line change
@@ -77,6 +77,9 @@ private String getVerdictMessage(RestrictionVerdict verdict) {
if (code == 401) {
return JFaceMessages.RestrictionVerdictViewerAdapter_msg_invalid_license;
}
if (code == 403) {
return JFaceMessages.RestrictionVerdictViewerAdapter_msg_wrong_license;
}
if (code == 416) {
return JFaceMessages.RestrictionVerdictViewerAdapter_msg_not_started;
}

0 comments on commit 9f59867

Please sign in to comment.