protected PlainSchema getPlainSchema(final String schemaName) { PlainSchema schema = null; if (StringUtils.isNotBlank(schemaName)) { schema = plainSchemaDAO.find(schemaName); // safely ignore invalid schemas from AttrTO if (schema == null) { LOG.debug("Ignoring invalid schema {}", schemaName); } else if (schema.isReadonly()) { schema = null; LOG.debug("Ignoring readonly schema {}", schemaName); } } return schema; }
result = (classes.isEmpty() ? keyword == null ? plainSchemaDAO.findAll() : plainSchemaDAO.findByKeyword(keyword) : plainSchemaDAO.findByAnyTypeClasses(classes)).stream(). map(schema -> (T) binder.getPlainSchemaTO(schema.getKey())).collect(Collectors.toList());
@PreAuthorize("hasRole('" + StandardEntitlement.SCHEMA_DELETE + "')") public void delete(final SchemaType schemaType, final String schemaKey) { if (!doesSchemaExist(schemaType, schemaKey)) { throw new NotFoundException(schemaType + "/" + schemaKey); } switch (schemaType) { case VIRTUAL: virSchemaDAO.delete(schemaKey); break; case DERIVED: derSchemaDAO.delete(schemaKey); break; case PLAIN: default: plainSchemaDAO.delete(schemaKey); } }
plainSchemaDAO.findByAnyTypeClasses(Collections.singletonList(anyTypeClass)).forEach(schema -> { schema.setAnyTypeClass(null); }); PlainSchema schema = plainSchemaDAO.find(schemaName); if (schema == null || schema.getAnyTypeClass() != null) { LOG.debug("Invalid or already in use" + PlainSchema.class.getSimpleName()
@PreAuthorize("hasRole('" + StandardEntitlement.SCHEMA_UPDATE + "')") public <T extends SchemaTO> void update(final SchemaType schemaType, final T schemaTO) { if (!doesSchemaExist(schemaType, schemaTO.getKey())) { throw new NotFoundException(schemaType + "/" + schemaTO.getKey()); } switch (schemaType) { case VIRTUAL: VirSchema virSchema = virSchemaDAO.find(schemaTO.getKey()); if (virSchema == null) { throw new NotFoundException("Virtual Schema '" + schemaTO.getKey() + "'"); } virSchemaDAO.save(binder.update((VirSchemaTO) schemaTO, virSchema)); break; case DERIVED: DerSchema derSchema = derSchemaDAO.find(schemaTO.getKey()); if (derSchema == null) { throw new NotFoundException("Derived schema '" + schemaTO.getKey() + "'"); } derSchemaDAO.save(binder.update((DerSchemaTO) schemaTO, derSchema)); break; case PLAIN: default: PlainSchema plainSchema = plainSchemaDAO.find(schemaTO.getKey()); if (plainSchema == null) { throw new NotFoundException("Schema '" + schemaTO.getKey() + "'"); } plainSchemaDAO.save(binder.update((PlainSchemaTO) schemaTO, plainSchema)); } }
@Override public void delete(final String key) { AnyTypeClass anyTypeClass = find(key); if (anyTypeClass == null) { return; } for (PlainSchema schema : plainSchemaDAO.findByAnyTypeClasses(Collections.singletonList(anyTypeClass))) { schema.setAnyTypeClass(null); } for (DerSchema schema : derSchemaDAO.findByAnyTypeClasses(Collections.singletonList(anyTypeClass))) { schema.setAnyTypeClass(null); } for (VirSchema schema : virSchemaDAO.findByAnyTypeClasses(Collections.singletonList(anyTypeClass))) { schema.setAnyTypeClass(null); } for (AnyType type : anyTypeDAO.findByTypeClass(anyTypeClass)) { type.getClasses().remove(anyTypeClass); } for (TypeExtension typeExt : groupDAO.findTypeExtensions(anyTypeClass)) { typeExt.getAuxClasses().remove(anyTypeClass); if (typeExt.getAuxClasses().isEmpty()) { typeExt.getGroup().getTypeExtensions().remove(typeExt); typeExt.setGroup(null); } } for (Provision provision : resourceDAO.findProvisionsByAuxClass(anyTypeClass)) { provision.getAuxClasses().remove(anyTypeClass); } entityManager().remove(anyTypeClass); }
@PreAuthorize("hasRole('" + StandardEntitlement.SCHEMA_CREATE + "')") @SuppressWarnings("unchecked") public <T extends SchemaTO> T create(final SchemaType schemaType, final T schemaTO) { if (StringUtils.isBlank(schemaTO.getKey())) { SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.RequiredValuesMissing); sce.getElements().add("Schema key"); throw sce; } if (doesSchemaExist(schemaType, schemaTO.getKey())) { throw new DuplicateException(schemaType + "/" + schemaTO.getKey()); } T created; switch (schemaType) { case VIRTUAL: VirSchema virSchema = virSchemaDAO.save(binder.create((VirSchemaTO) schemaTO)); created = (T) binder.getVirSchemaTO(virSchema.getKey()); break; case DERIVED: DerSchema derSchema = derSchemaDAO.save(binder.create((DerSchemaTO) schemaTO)); created = (T) binder.getDerSchemaTO(derSchema.getKey()); break; case PLAIN: default: PlainSchema plainSchema = plainSchemaDAO.save(binder.create((PlainSchemaTO) schemaTO)); created = (T) binder.getPlainSchemaTO(plainSchema.getKey()); } return created; }
@Override public PlainSchema update(final PlainSchemaTO schemaTO, final PlainSchema schema) { SyncopeClientCompositeException scce = SyncopeClientException.buildComposite(); boolean hasAttrs = false; for (AnyTypeKind anyTypeKind : AnyTypeKind.values()) { AnyUtils anyUtils = anyUtilsFactory.getInstance(anyTypeKind); hasAttrs |= plainSchemaDAO.findAttrs(schema, anyUtils.plainAttrClass()).isEmpty(); } if (hasAttrs) { if (schema.getType() != schemaTO.getType()) { SyncopeClientException e = SyncopeClientException.build(ClientExceptionType.InvalidPlainSchema); e.getElements().add("Cannot change type since " + schema.getKey() + " has attributes"); scce.addException(e); } if (schema.isUniqueConstraint() != schemaTO.isUniqueConstraint()) { SyncopeClientException e = SyncopeClientException.build(ClientExceptionType.InvalidPlainSchema); e.getElements().add("Cannot alter unique contraint since " + schema.getKey() + " has attributes"); scce.addException(e); } } if (scce.hasExceptions()) { throw scce; } return fill(schema, schemaTO); }
PlainSchema merged = plainSchemaDAO.save(schema);
@Override public A findByPlainAttrUniqueValue( final String schemaKey, final PlainAttrValue attrUniqueValue, final boolean ignoreCaseMatch) { PlainSchema schema = plainSchemaDAO.find(schemaKey); if (schema == null) { LOG.error("Invalid schema '{}'", schemaKey); return null; } if (!schema.isUniqueConstraint()) { LOG.error("This schema has not unique constraint: '{}'", schemaKey); return null; } List<A> result = findByPlainAttrValue(schemaKey, attrUniqueValue, ignoreCaseMatch); return result.isEmpty() ? null : result.get(0); }
@PreAuthorize("hasRole('" + StandardEntitlement.CONFIGURATION_DELETE + "')") public void delete(final String schema) { Optional<? extends CPlainAttr> conf = confDAO.find(schema); if (!conf.isPresent()) { PlainSchema plainSchema = plainSchemaDAO.find(schema); if (plainSchema == null) { throw new NotFoundException("Configuration schema " + schema); } } confDAO.delete(schema); }
private SchemaType find(final String key) { Schema schema = plainSchemaDAO.find(key); if (schema == null) { schema = derSchemaDAO.find(key); if (schema == null) { schema = virSchemaDAO.find(key); if (schema == null) { return null; } else { return SchemaType.VIRTUAL; } } else { return SchemaType.DERIVED; } } else { return SchemaType.PLAIN; } }
private boolean doesSchemaExist(final SchemaType schemaType, final String name) { boolean found; switch (schemaType) { case VIRTUAL: found = virSchemaDAO.find(name) != null; break; case DERIVED: found = derSchemaDAO.find(name) != null; break; case PLAIN: found = plainSchemaDAO.find(name) != null; break; default: found = false; } return found; }
if (!used.contains(identifiers.get(i))) { PlainSchema schema = plainSchemaDAO.find(identifiers.get(i)); if (schema == null) { LOG.error("Invalid schema '{}', ignoring", identifiers.get(i));
@PreAuthorize("hasRole('" + StandardEntitlement.CONFIGURATION_GET + "')") @Transactional(readOnly = true) public AttrTO get(final String schema) { AttrTO result; Optional<? extends CPlainAttr> conf = confDAO.find(schema); if (conf.isPresent()) { result = binder.getAttrTO(conf.get()); } else { PlainSchema plainSchema = plainSchemaDAO.find(schema); if (plainSchema == null) { throw new NotFoundException("Configuration schema " + schema); } result = new AttrTO(); result.setSchema(schema); } return result; }
final boolean ignoreCaseMatch) { PlainSchema schema = plainSchemaDAO.find(schemaKey); if (schema == null) { LOG.error("Invalid schema '{}'", schemaKey);
PlainAttrValue value = entityFactory.newEntity(UPlainAttrValue.class); PlainSchema schema = plainSchemaDAO.find(intAttrName.getSchemaName()); if (schema == null) { value.setStringValue(transformed);
PlainAttrValue value = entityFactory.newEntity(UPlainAttrValue.class); PlainSchema schema = plainSchemaDAO.find(intAttrName.getSchemaName()); if (schema == null) { value.setStringValue(transformed);
PlainSchema schema = schemaDAO.find(clause.getField()); if (schema != null) { if (schema.isUniqueConstraint()) {
protected Pair<PlainSchema, PlainAttrValue> check(final AttributeCond cond, final AnyTypeKind kind) { AnyUtils anyUtils = anyUtilsFactory.getInstance(kind); PlainSchema schema = schemaDAO.find(cond.getSchema()); if (schema == null) { LOG.warn("Ignoring invalid schema '{}'", cond.getSchema()); throw new IllegalArgumentException(); } PlainAttrValue attrValue = schema.isUniqueConstraint() ? anyUtils.newPlainAttrUniqueValue() : anyUtils.newPlainAttrValue(); try { if (cond.getType() != AttributeCond.Type.LIKE && cond.getType() != AttributeCond.Type.ILIKE && cond.getType() != AttributeCond.Type.ISNULL && cond.getType() != AttributeCond.Type.ISNOTNULL) { ((JPAPlainSchema) schema).validator().validate(cond.getExpression(), attrValue); } } catch (ValidationException e) { LOG.error("Could not validate expression '" + cond.getExpression() + "'", e); throw new IllegalArgumentException(); } return Pair.of(schema, attrValue); }