use of org.openremote.model.http.ConstraintViolation in project openremote by openremote.
the class TenantResourceImpl method isIllegalMasterRealmDeletion.
protected ConstraintViolationReport isIllegalMasterRealmDeletion(String realm) {
if (!realm.equals(MASTER_REALM))
return null;
ResourceBundle validationMessages = getContainer().getService(I18NService.class).getValidationMessages();
List<ConstraintViolation> violations = new ArrayList<>();
ConstraintViolation violation = new ConstraintViolation();
violation.setConstraintType(ConstraintViolation.Type.PARAMETER);
violation.setMessage(validationMessages.getString("Tenant.masterDeleted"));
violations.add(violation);
ConstraintViolationReport report = new ConstraintViolationReport();
report.setParameterViolations(violations.toArray(new ConstraintViolation[violations.size()]));
return report;
}
use of org.openremote.model.http.ConstraintViolation in project openremote by openremote.
the class TenantResourceImpl method isIllegalMasterRealmMutation.
protected ConstraintViolationReport isIllegalMasterRealmMutation(String realm, Tenant tenant) {
if (!realm.equals(MASTER_REALM))
return null;
ResourceBundle validationMessages = getContainer().getService(I18NService.class).getValidationMessages();
List<ConstraintViolation> violations = new ArrayList<>();
if (tenant.getEnabled() == null || !tenant.getEnabled()) {
ConstraintViolation violation = new ConstraintViolation();
violation.setConstraintType(ConstraintViolation.Type.PARAMETER);
violation.setPath("Tenant.enabled");
violation.setMessage(validationMessages.getString("Tenant.masterDisabled"));
violations.add(violation);
}
if (tenant.getRealm() == null || !tenant.getRealm().equals(MASTER_REALM)) {
ConstraintViolation violation = new ConstraintViolation();
violation.setConstraintType(ConstraintViolation.Type.PARAMETER);
violation.setPath("Tenant.realm");
violation.setMessage(validationMessages.getString("Tenant.masterRealmChanged"));
violations.add(violation);
}
if (violations.size() > 0) {
ConstraintViolationReport report = new ConstraintViolationReport();
report.setParameterViolations(violations.toArray(new ConstraintViolation[violations.size()]));
return report;
}
return null;
}
use of org.openremote.model.http.ConstraintViolation in project openremote by openremote.
the class UserResourceImpl method isIllegalMasterAdminUserDeletion.
protected ConstraintViolationReport isIllegalMasterAdminUserDeletion(RequestParams requestParams, String realm, String userId) {
if (!realm.equals(MASTER_REALM))
return null;
if (!identityService.getIdentityProvider().isMasterRealmAdmin(new ClientRequestInfo(getClientRemoteAddress(), requestParams.getBearerAuth()), userId))
return null;
ResourceBundle validationMessages = getContainer().getService(I18NService.class).getValidationMessages();
List<ConstraintViolation> violations = new ArrayList<>();
ConstraintViolation violation = new ConstraintViolation();
violation.setConstraintType(ConstraintViolation.Type.PARAMETER);
violation.setMessage(validationMessages.getString("User.masterAdminDeleted"));
violations.add(violation);
ConstraintViolationReport report = new ConstraintViolationReport();
report.setParameterViolations(violations.toArray(new ConstraintViolation[violations.size()]));
return report;
}
use of org.openremote.model.http.ConstraintViolation in project openremote by openremote.
the class AdminUserEditActivity method handlePasswordReset.
protected void handlePasswordReset() {
String password = adminContent.getPassword();
String passwordControl = adminContent.getPasswordControl();
adminContent.clearPassword();
adminContent.clearPasswordControl();
if (password == null)
return;
if (!password.equals(passwordControl)) {
ConstraintViolation violation = new ConstraintViolation();
violation.setConstraintType(ConstraintViolation.Type.FIELD);
violation.setPath("password");
violation.setMessage(environment.getMessages().passwordsMustMatch());
validationErrorHandler.accept(new ConstraintViolation[] { violation });
return;
}
Credential credential = new Credential(password, false);
environment.getApp().getRequests().sendWith(credentialMapper, requestParams -> userResource.resetPassword(requestParams, realm, userId, credential), 204, () -> adminContent.addFormMessageSuccess(environment.getMessages().passwordUpdated()));
}
use of org.openremote.model.http.ConstraintViolation in project openremote by openremote.
the class UserResourceImpl method isIllegalMasterAdminUserMutation.
protected ConstraintViolationReport isIllegalMasterAdminUserMutation(RequestParams requestParams, String realm, User user) {
if (!realm.equals(MASTER_REALM))
return null;
if (!identityService.getIdentityProvider().isMasterRealmAdmin(new ClientRequestInfo(getClientRemoteAddress(), requestParams.getBearerAuth()), user.getId()))
return null;
ResourceBundle validationMessages = getContainer().getService(I18NService.class).getValidationMessages();
List<ConstraintViolation> violations = new ArrayList<>();
if (user.getEnabled() == null || !user.getEnabled()) {
ConstraintViolation violation = new ConstraintViolation();
violation.setConstraintType(ConstraintViolation.Type.PARAMETER);
violation.setPath("User.enabled");
violation.setMessage(validationMessages.getString("User.masterAdminDisabled"));
violations.add(violation);
}
if (violations.size() > 0) {
ConstraintViolationReport report = new ConstraintViolationReport();
report.setParameterViolations(violations.toArray(new ConstraintViolation[violations.size()]));
return report;
}
return null;
}
Aggregations