Search in sources :

Example 1 with ConstraintViolation

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;
}
Also used : I18NService(org.openremote.manager.i18n.I18NService) ConstraintViolationReport(org.openremote.model.http.ConstraintViolationReport) ConstraintViolation(org.openremote.model.http.ConstraintViolation) ArrayList(java.util.ArrayList) ResourceBundle(java.util.ResourceBundle)

Example 2 with ConstraintViolation

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;
}
Also used : I18NService(org.openremote.manager.i18n.I18NService) ConstraintViolationReport(org.openremote.model.http.ConstraintViolationReport) ConstraintViolation(org.openremote.model.http.ConstraintViolation) ArrayList(java.util.ArrayList) ResourceBundle(java.util.ResourceBundle)

Example 3 with ConstraintViolation

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;
}
Also used : I18NService(org.openremote.manager.i18n.I18NService) ConstraintViolationReport(org.openremote.model.http.ConstraintViolationReport) ConstraintViolation(org.openremote.model.http.ConstraintViolation) ArrayList(java.util.ArrayList) ClientRequestInfo(org.openremote.container.web.ClientRequestInfo) ResourceBundle(java.util.ResourceBundle)

Example 4 with ConstraintViolation

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()));
}
Also used : Credential(org.openremote.model.security.Credential) ConstraintViolation(org.openremote.model.http.ConstraintViolation)

Example 5 with ConstraintViolation

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;
}
Also used : I18NService(org.openremote.manager.i18n.I18NService) ConstraintViolationReport(org.openremote.model.http.ConstraintViolationReport) ConstraintViolation(org.openremote.model.http.ConstraintViolation) ArrayList(java.util.ArrayList) ClientRequestInfo(org.openremote.container.web.ClientRequestInfo) ResourceBundle(java.util.ResourceBundle)

Aggregations

ConstraintViolation (org.openremote.model.http.ConstraintViolation)5 ArrayList (java.util.ArrayList)4 ResourceBundle (java.util.ResourceBundle)4 I18NService (org.openremote.manager.i18n.I18NService)4 ConstraintViolationReport (org.openremote.model.http.ConstraintViolationReport)4 ClientRequestInfo (org.openremote.container.web.ClientRequestInfo)2 Credential (org.openremote.model.security.Credential)1