You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by il...@apache.org on 2016/03/09 12:52:50 UTC
[14/17] syncope git commit: Further refactoring as per SYNCOPE-620
http://git-wip-us.apache.org/repos/asf/syncope/blob/28569df5/core/misc/src/main/java/org/apache/syncope/core/misc/utils/EntityUtils.java
----------------------------------------------------------------------
diff --git a/core/misc/src/main/java/org/apache/syncope/core/misc/utils/EntityUtils.java b/core/misc/src/main/java/org/apache/syncope/core/misc/utils/EntityUtils.java
deleted file mode 100644
index e47efc8..0000000
--- a/core/misc/src/main/java/org/apache/syncope/core/misc/utils/EntityUtils.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.syncope.core.misc.utils;
-
-import org.apache.commons.collections4.Transformer;
-import org.apache.syncope.core.persistence.api.entity.Entity;
-
-public final class EntityUtils {
-
- public static <KEY, E extends Entity<KEY>> Transformer<E, KEY> keyTransformer() {
- return new Transformer<E, KEY>() {
-
- @Override
- public KEY transform(final E input) {
- return input.getKey();
- }
- };
- }
-
- /**
- * Private default constructor, for static-only classes.
- */
- private EntityUtils() {
- }
-}
http://git-wip-us.apache.org/repos/asf/syncope/blob/28569df5/core/misc/src/main/java/org/apache/syncope/core/misc/utils/ExceptionUtils2.java
----------------------------------------------------------------------
diff --git a/core/misc/src/main/java/org/apache/syncope/core/misc/utils/ExceptionUtils2.java b/core/misc/src/main/java/org/apache/syncope/core/misc/utils/ExceptionUtils2.java
deleted file mode 100644
index 76ba64f..0000000
--- a/core/misc/src/main/java/org/apache/syncope/core/misc/utils/ExceptionUtils2.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.syncope.core.misc.utils;
-
-import org.apache.commons.lang3.exception.ExceptionUtils;
-
-public final class ExceptionUtils2 {
-
- /**
- * Uses commons lang's ExceptionUtils to provide a representation of the full stack trace of the given throwable.
- *
- * @param t throwable to build stack trace from
- * @return a string representation of full stack trace of the given throwable
- */
- public static String getFullStackTrace(final Throwable t) {
- StringBuilder result = new StringBuilder();
-
- for (Throwable throwable : ExceptionUtils.getThrowableList(t)) {
- result.append(ExceptionUtils.getMessage(throwable)).append('\n').
- append(ExceptionUtils.getStackTrace(throwable)).append("\n\n");
- }
-
- return result.toString();
- }
-
- /**
- * Private default constructor, for static-only classes.
- */
- private ExceptionUtils2() {
- }
-}
http://git-wip-us.apache.org/repos/asf/syncope/blob/28569df5/core/misc/src/main/java/org/apache/syncope/core/misc/utils/FormatUtils.java
----------------------------------------------------------------------
diff --git a/core/misc/src/main/java/org/apache/syncope/core/misc/utils/FormatUtils.java b/core/misc/src/main/java/org/apache/syncope/core/misc/utils/FormatUtils.java
deleted file mode 100644
index 131f310..0000000
--- a/core/misc/src/main/java/org/apache/syncope/core/misc/utils/FormatUtils.java
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.syncope.core.misc.utils;
-
-import java.text.DecimalFormat;
-import java.text.DecimalFormatSymbols;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.Locale;
-import org.apache.commons.lang3.time.DateUtils;
-import org.apache.syncope.common.lib.SyncopeConstants;
-
-/**
- * Utility class for parsing / formatting date and numbers.
- */
-public final class FormatUtils {
-
- private static final ThreadLocal<SimpleDateFormat> DATE_FORMAT = new ThreadLocal<SimpleDateFormat>() {
-
- @Override
- protected SimpleDateFormat initialValue() {
- SimpleDateFormat sdf = new SimpleDateFormat();
- sdf.applyPattern(SyncopeConstants.DEFAULT_DATE_PATTERN);
- return sdf;
- }
- };
-
- private static final ThreadLocal<DecimalFormat> DECIMAL_FORMAT = new ThreadLocal<DecimalFormat>() {
-
- @Override
- protected DecimalFormat initialValue() {
- DecimalFormat df = new DecimalFormat();
- df.setDecimalFormatSymbols(DecimalFormatSymbols.getInstance(Locale.ENGLISH));
- return df;
- }
- };
-
- public static String format(final Date date) {
- return format(date, true);
- }
-
- public static String format(final Date date, final boolean lenient) {
- return format(date, lenient, null);
- }
-
- public static String format(final Date date, final boolean lenient, final String conversionPattern) {
- SimpleDateFormat sdf = DATE_FORMAT.get();
- if (conversionPattern != null) {
- sdf.applyPattern(conversionPattern);
- }
- sdf.setLenient(lenient);
- return sdf.format(date);
- }
-
- public static String format(final long number) {
- return format(number, null);
- }
-
- public static String format(final long number, final String conversionPattern) {
- DecimalFormat df = DECIMAL_FORMAT.get();
- if (conversionPattern != null) {
- df.applyPattern(conversionPattern);
- }
- return df.format(number);
- }
-
- public static String format(final double number) {
- return format(number, null);
- }
-
- public static String format(final double number, final String conversionPattern) {
- DecimalFormat df = DECIMAL_FORMAT.get();
- if (conversionPattern != null) {
- df.applyPattern(conversionPattern);
- }
- return df.format(number);
- }
-
- public static Date parseDate(final String source) throws ParseException {
- return DateUtils.parseDate(source, SyncopeConstants.DATE_PATTERNS);
- }
-
- public static Date parseDate(final String source, final String conversionPattern) throws ParseException {
- SimpleDateFormat sdf = DATE_FORMAT.get();
- sdf.applyPattern(conversionPattern);
- sdf.setLenient(false);
- return sdf.parse(source);
- }
-
- public static Number parseNumber(final String source, final String conversionPattern) throws ParseException {
- DecimalFormat df = DECIMAL_FORMAT.get();
- df.applyPattern(conversionPattern);
- return df.parse(source);
- }
-
- public static void clear() {
- DATE_FORMAT.remove();
- DECIMAL_FORMAT.remove();
- }
-
- private FormatUtils() {
- // private empty constructor
- }
-}
http://git-wip-us.apache.org/repos/asf/syncope/blob/28569df5/core/misc/src/main/java/org/apache/syncope/core/misc/utils/MappingUtils.java
----------------------------------------------------------------------
diff --git a/core/misc/src/main/java/org/apache/syncope/core/misc/utils/MappingUtils.java b/core/misc/src/main/java/org/apache/syncope/core/misc/utils/MappingUtils.java
deleted file mode 100644
index b3102af..0000000
--- a/core/misc/src/main/java/org/apache/syncope/core/misc/utils/MappingUtils.java
+++ /dev/null
@@ -1,841 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.syncope.core.misc.utils;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-import org.apache.commons.collections4.ListUtils;
-import org.apache.commons.jexl3.JexlContext;
-import org.apache.commons.jexl3.MapContext;
-import org.apache.commons.lang3.ClassUtils;
-import org.apache.commons.lang3.SerializationUtils;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.commons.lang3.tuple.ImmutablePair;
-import org.apache.commons.lang3.tuple.Pair;
-import org.apache.syncope.common.lib.to.AnyTO;
-import org.apache.syncope.common.lib.to.AttrTO;
-import org.apache.syncope.common.lib.to.GroupTO;
-import org.apache.syncope.common.lib.to.UserTO;
-import org.apache.syncope.common.lib.types.AttrSchemaType;
-import org.apache.syncope.common.lib.types.IntMappingType;
-import org.apache.syncope.common.lib.types.MappingPurpose;
-import org.apache.syncope.core.misc.policy.InvalidPasswordRuleConf;
-import org.apache.syncope.core.persistence.api.dao.PlainSchemaDAO;
-import org.apache.syncope.core.persistence.api.dao.VirSchemaDAO;
-import org.apache.syncope.core.persistence.api.entity.AnyUtils;
-import org.apache.syncope.core.persistence.api.entity.AnyUtilsFactory;
-import org.apache.syncope.core.persistence.api.entity.EntityFactory;
-import org.apache.syncope.core.persistence.api.entity.resource.MappingItem;
-import org.apache.syncope.core.persistence.api.entity.PlainAttr;
-import org.apache.syncope.core.persistence.api.entity.PlainAttrValue;
-import org.apache.syncope.core.persistence.api.entity.group.GPlainAttrValue;
-import org.apache.syncope.core.persistence.api.entity.group.Group;
-import org.apache.syncope.core.persistence.api.entity.user.UPlainAttrValue;
-import org.apache.syncope.core.persistence.api.entity.user.User;
-import org.apache.syncope.core.provisioning.api.cache.VirAttrCache;
-import org.apache.syncope.core.misc.security.Encryptor;
-import org.apache.syncope.core.misc.jexl.JexlUtils;
-import org.apache.syncope.core.misc.security.PasswordGenerator;
-import org.apache.syncope.core.misc.spring.ApplicationContextProvider;
-import org.apache.syncope.core.persistence.api.attrvalue.validation.ParsingValidationException;
-import org.apache.syncope.core.persistence.api.dao.AnyTypeDAO;
-import org.apache.syncope.core.persistence.api.dao.DerSchemaDAO;
-import org.apache.syncope.core.persistence.api.dao.UserDAO;
-import org.apache.syncope.core.persistence.api.entity.Any;
-import org.apache.syncope.core.persistence.api.entity.DerSchema;
-import org.apache.syncope.core.persistence.api.entity.PlainAttrUniqueValue;
-import org.apache.syncope.core.persistence.api.entity.PlainSchema;
-import org.apache.syncope.core.persistence.api.entity.Schema;
-import org.apache.syncope.core.persistence.api.entity.VirSchema;
-import org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject;
-import org.apache.syncope.core.persistence.api.entity.resource.Mapping;
-import org.apache.syncope.core.persistence.api.entity.resource.Provision;
-import org.apache.syncope.core.provisioning.api.DerAttrHandler;
-import org.apache.syncope.core.provisioning.api.VirAttrHandler;
-import org.apache.syncope.core.provisioning.api.data.MappingItemTransformer;
-import org.identityconnectors.framework.common.FrameworkUtil;
-import org.identityconnectors.framework.common.objects.Attribute;
-import org.identityconnectors.framework.common.objects.AttributeBuilder;
-import org.identityconnectors.framework.common.objects.AttributeUtil;
-import org.identityconnectors.framework.common.objects.Name;
-import org.identityconnectors.framework.common.objects.OperationOptions;
-import org.identityconnectors.framework.common.objects.OperationOptionsBuilder;
-import org.identityconnectors.framework.common.objects.OperationalAttributes;
-import org.identityconnectors.framework.common.objects.Uid;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.support.AbstractBeanDefinition;
-import org.springframework.stereotype.Component;
-import org.springframework.transaction.annotation.Transactional;
-
-@Component
-public class MappingUtils {
-
- private static final Logger LOG = LoggerFactory.getLogger(MappingUtils.class);
-
- private static final Encryptor ENCRYPTOR = Encryptor.getInstance();
-
- @Autowired
- private AnyTypeDAO anyTypeDAO;
-
- @Autowired
- private PlainSchemaDAO plainSchemaDAO;
-
- @Autowired
- private DerSchemaDAO derSchemaDAO;
-
- @Autowired
- private VirSchemaDAO virSchemaDAO;
-
- @Autowired
- private UserDAO userDAO;
-
- @Autowired
- private DerAttrHandler derAttrHandler;
-
- @Autowired
- private VirAttrHandler virAttrHandler;
-
- @Autowired
- private VirAttrCache virAttrCache;
-
- @Autowired
- private PasswordGenerator passwordGenerator;
-
- @Autowired
- private EntityFactory entityFactory;
-
- @Autowired
- private AnyUtilsFactory anyUtilsFactory;
-
- public static MappingItem getConnObjectKeyItem(final Provision provision) {
- Mapping mapping = null;
- if (provision != null) {
- mapping = provision.getMapping();
- }
-
- return mapping == null
- ? null
- : mapping.getConnObjectKeyItem();
- }
-
- private static List<MappingItem> getMappingItems(final Provision provision, final MappingPurpose purpose) {
- List<? extends MappingItem> items = Collections.<MappingItem>emptyList();
- if (provision != null) {
- items = provision.getMapping().getItems();
- }
-
- List<MappingItem> result = new ArrayList<>();
-
- switch (purpose) {
- case SYNCHRONIZATION:
- for (MappingItem item : items) {
- if (MappingPurpose.PROPAGATION != item.getPurpose()
- && MappingPurpose.NONE != item.getPurpose()) {
-
- result.add(item);
- }
- }
- break;
-
- case PROPAGATION:
- for (MappingItem item : items) {
- if (MappingPurpose.SYNCHRONIZATION != item.getPurpose()
- && MappingPurpose.NONE != item.getPurpose()) {
-
- result.add(item);
- }
- }
- break;
-
- case BOTH:
- for (MappingItem item : items) {
- if (MappingPurpose.NONE != item.getPurpose()) {
- result.add(item);
- }
- }
- break;
-
- case NONE:
- for (MappingItem item : items) {
- if (MappingPurpose.NONE == item.getPurpose()) {
- result.add(item);
- }
- }
- break;
-
- default:
- }
-
- return result;
- }
-
- public static List<MappingItem> getBothMappingItems(final Provision provision) {
- return getMappingItems(provision, MappingPurpose.BOTH);
- }
-
- public static List<MappingItem> getPropagationMappingItems(final Provision provision) {
- return getMappingItems(provision, MappingPurpose.PROPAGATION);
- }
-
- public static List<MappingItem> getSyncMappingItems(final Provision provision) {
- return getMappingItems(provision, MappingPurpose.SYNCHRONIZATION);
- }
-
- /**
- * Build __NAME__ for propagation. First look if there ia a defined connObjectLink for the given resource (and in
- * this case evaluate as JEXL); otherwise, take given connObjectKey.
- *
- * @param any given any object
- * @param provision external resource
- * @param connObjectKey connector object key
- * @return the value to be propagated as __NAME__
- */
- public static Name evaluateNAME(final Any<?> any, final Provision provision, final String connObjectKey) {
- if (StringUtils.isBlank(connObjectKey)) {
- // LOG error but avoid to throw exception: leave it to the external resource
- LOG.error("Missing ConnObjectKey for '{}': ", provision.getResource());
- }
-
- // Evaluate connObjectKey expression
- String connObjectLink = provision == null || provision.getMapping() == null
- ? null
- : provision.getMapping().getConnObjectLink();
- String evalConnObjectLink = null;
- if (StringUtils.isNotBlank(connObjectLink)) {
- JexlContext jexlContext = new MapContext();
- JexlUtils.addFieldsToContext(any, jexlContext);
- JexlUtils.addPlainAttrsToContext(any.getPlainAttrs(), jexlContext);
- JexlUtils.addDerAttrsToContext(any, jexlContext);
- evalConnObjectLink = JexlUtils.evaluate(connObjectLink, jexlContext);
- }
-
- // If connObjectLink evaluates to an empty string, just use the provided connObjectKey as Name(),
- // otherwise evaluated connObjectLink expression is taken as Name().
- Name name;
- if (StringUtils.isBlank(evalConnObjectLink)) {
- // add connObjectKey as __NAME__ attribute ...
- LOG.debug("Add connObjectKey [{}] as __NAME__", connObjectKey);
- name = new Name(connObjectKey);
- } else {
- LOG.debug("Add connObjectLink [{}] as __NAME__", evalConnObjectLink);
- name = new Name(evalConnObjectLink);
-
- // connObjectKey not propagated: it will be used to set the value for __UID__ attribute
- LOG.debug("connObjectKey will be used just as __UID__ attribute");
- }
-
- return name;
- }
-
- public static List<MappingItemTransformer> getMappingItemTransformers(final MappingItem mappingItem) {
- List<MappingItemTransformer> result = new ArrayList<>();
-
- for (String className : mappingItem.getMappingItemTransformerClassNames()) {
- try {
- Class<?> transformerClass = ClassUtils.getClass(className);
-
- result.add((MappingItemTransformer) ApplicationContextProvider.
- getBeanFactory().
- createBean(transformerClass, AbstractBeanDefinition.AUTOWIRE_BY_NAME, false));
- } catch (Exception e) {
- LOG.error("Could not instantiate {}, ignoring...", className, e);
- }
- }
-
- return result;
- }
-
- /**
- * Build options for requesting all mapped connector attributes.
- *
- * @param mapItems mapping items
- * @return options for requesting all mapped connector attributes
- * @see OperationOptions
- */
- public static OperationOptions buildOperationOptions(final Iterator<? extends MappingItem> mapItems) {
- OperationOptionsBuilder builder = new OperationOptionsBuilder();
-
- Set<String> attrsToGet = new HashSet<>();
- attrsToGet.add(Name.NAME);
- attrsToGet.add(Uid.NAME);
- attrsToGet.add(OperationalAttributes.ENABLE_NAME);
-
- while (mapItems.hasNext()) {
- MappingItem mapItem = mapItems.next();
- if (mapItem.getPurpose() != MappingPurpose.NONE) {
- attrsToGet.add(mapItem.getExtAttrName());
- }
- }
-
- builder.setAttributesToGet(attrsToGet);
- // -------------------------------------
-
- return builder.build();
- }
-
- /**
- * Prepare attributes for sending to a connector instance.
- *
- * @param any given any object
- * @param password clear-text password
- * @param changePwd whether password should be included for propagation attributes or not
- * @param enable whether any object must be enabled or not
- * @param provision provision information
- * @return connObjectLink + prepared attributes
- */
- @Transactional(readOnly = true)
- public Pair<String, Set<Attribute>> prepareAttrs(
- final Any<?> any,
- final String password,
- final boolean changePwd,
- final Boolean enable,
- final Provision provision) {
-
- LOG.debug("Preparing resource attributes for {} with provision {} for attributes {}",
- any, provision, any.getPlainAttrs());
-
- Set<Attribute> attributes = new HashSet<>();
- String connObjectKey = null;
-
- for (MappingItem mappingItem : getMappingItems(provision, MappingPurpose.PROPAGATION)) {
- LOG.debug("Processing schema {}", mappingItem.getIntAttrName());
-
- try {
- Pair<String, Attribute> preparedAttr = prepareAttr(provision, mappingItem, any, password);
-
- if (preparedAttr != null && preparedAttr.getKey() != null) {
- connObjectKey = preparedAttr.getKey();
- }
-
- if (preparedAttr != null && preparedAttr.getValue() != null) {
- Attribute alreadyAdded = AttributeUtil.find(preparedAttr.getValue().getName(), attributes);
-
- if (alreadyAdded == null) {
- attributes.add(preparedAttr.getValue());
- } else {
- attributes.remove(alreadyAdded);
-
- Set<Object> values = new HashSet<>(alreadyAdded.getValue());
- values.addAll(preparedAttr.getValue().getValue());
-
- attributes.add(AttributeBuilder.build(preparedAttr.getValue().getName(), values));
- }
- }
- } catch (Exception e) {
- LOG.debug("Attribute '{}' processing failed", mappingItem.getIntAttrName(), e);
- }
- }
-
- Attribute connObjectKeyExtAttr =
- AttributeUtil.find(getConnObjectKeyItem(provision).getExtAttrName(), attributes);
- if (connObjectKeyExtAttr != null) {
- attributes.remove(connObjectKeyExtAttr);
- attributes.add(AttributeBuilder.build(getConnObjectKeyItem(provision).getExtAttrName(), connObjectKey));
- }
- attributes.add(evaluateNAME(any, provision, connObjectKey));
-
- if (enable != null) {
- attributes.add(AttributeBuilder.buildEnabled(enable));
- }
- if (!changePwd) {
- Attribute pwdAttr = AttributeUtil.find(OperationalAttributes.PASSWORD_NAME, attributes);
- if (pwdAttr != null) {
- attributes.remove(pwdAttr);
- }
- }
-
- return new ImmutablePair<>(connObjectKey, attributes);
- }
-
- /**
- * Prepare an attribute to be sent to a connector instance.
- *
- * @param provision external resource
- * @param mapItem mapping item for the given attribute
- * @param any any object
- * @param password clear-text password
- * @return connObjectKey + prepared attribute
- */
- private Pair<String, Attribute> prepareAttr(
- final Provision provision, final MappingItem mapItem, final Any<?> any, final String password) {
-
- List<Any<?>> anys = new ArrayList<>();
-
- switch (mapItem.getIntMappingType().getAnyTypeKind()) {
- case USER:
- if (any instanceof User) {
- anys.add(any);
- }
- break;
-
- case GROUP:
- if (any instanceof User) {
- for (Group group : userDAO.findAllGroups((User) any)) {
- anys.add(group);
- }
- } else if (any instanceof Group) {
- anys.add(any);
- }
- break;
-
- case ANY_OBJECT:
- if (any instanceof AnyObject) {
- anys.add(any);
- }
- break;
-
- default:
- }
-
- Schema schema = null;
- boolean readOnlyVirSchema = false;
- AttrSchemaType schemaType;
- Pair<String, Attribute> result;
-
- switch (mapItem.getIntMappingType()) {
- case UserPlainSchema:
- case GroupPlainSchema:
- case AnyObjectPlainSchema:
- schema = plainSchemaDAO.find(mapItem.getIntAttrName());
- schemaType = schema == null ? AttrSchemaType.String : schema.getType();
- break;
-
- case UserVirtualSchema:
- case GroupVirtualSchema:
- case AnyObjectVirtualSchema:
- schema = virSchemaDAO.find(mapItem.getIntAttrName());
- readOnlyVirSchema = (schema != null && schema.isReadonly());
- schemaType = AttrSchemaType.String;
- break;
-
- default:
- schemaType = AttrSchemaType.String;
- }
-
- String extAttrName = mapItem.getExtAttrName();
-
- List<PlainAttrValue> values = getIntValues(provision, mapItem, anys);
-
- LOG.debug("Define mapping for: "
- + "\n* ExtAttrName " + extAttrName
- + "\n* is connObjectKey " + mapItem.isConnObjectKey()
- + "\n* is password " + (mapItem.isPassword() || mapItem.getIntMappingType() == IntMappingType.Password)
- + "\n* mandatory condition " + mapItem.getMandatoryCondition()
- + "\n* Schema " + mapItem.getIntAttrName()
- + "\n* IntMappingType " + mapItem.getIntMappingType().toString()
- + "\n* ClassType " + schemaType.getType().getName()
- + "\n* Values " + values);
-
- if (readOnlyVirSchema) {
- result = null;
- } else {
- List<Object> objValues = new ArrayList<>();
-
- for (PlainAttrValue value : values) {
- if (FrameworkUtil.isSupportedAttributeType(schemaType.getType())) {
- objValues.add(value.getValue());
- } else {
- objValues.add(value.getValueAsString());
- }
- }
-
- if (mapItem.isConnObjectKey()) {
- result = new ImmutablePair<>(objValues.iterator().next().toString(), null);
- } else if (mapItem.isPassword() && any instanceof User) {
- String passwordAttrValue = password;
- if (StringUtils.isBlank(passwordAttrValue)) {
- User user = (User) any;
- if (user.canDecodePassword()) {
- try {
- passwordAttrValue = ENCRYPTOR.decode(user.getPassword(), user.getCipherAlgorithm());
- } catch (Exception e) {
- LOG.error("Could not decode password for {}", user, e);
- }
- } else if (provision.getResource().isRandomPwdIfNotProvided()) {
- try {
- passwordAttrValue = passwordGenerator.generate(user);
- } catch (InvalidPasswordRuleConf e) {
- LOG.error("Could not generate policy-compliant random password for {}", user, e);
- }
- }
- }
-
- if (passwordAttrValue == null) {
- result = null;
- } else {
- result = new ImmutablePair<>(
- null, AttributeBuilder.buildPassword(passwordAttrValue.toCharArray()));
- }
- } else if ((schema != null && schema.isMultivalue())
- || anyUtilsFactory.getInstance(any).getAnyTypeKind()
- != mapItem.getIntMappingType().getAnyTypeKind()) {
-
- result = new ImmutablePair<>(
- null, AttributeBuilder.build(extAttrName, objValues));
- } else {
- result = new ImmutablePair<>(
- null, objValues.isEmpty()
- ? AttributeBuilder.build(extAttrName)
- : AttributeBuilder.build(extAttrName, objValues.iterator().next()));
- }
- }
-
- return result;
- }
-
- private String getGroupOwnerValue(final Provision provision, final Any<?> any) {
- Pair<String, Attribute> preparedAttr = prepareAttr(provision, getConnObjectKeyItem(provision), any, null);
- String connObjectKey = preparedAttr.getKey();
-
- return evaluateNAME(any, provision, connObjectKey).getNameValue();
- }
-
- /**
- * Get attribute values for the given {@link MappingItem} and any objects.
- *
- * @param provision provision information
- * @param mappingItem mapping item
- * @param anys any objects
- * @return attribute values.
- */
- @Transactional(readOnly = true)
- public List<PlainAttrValue> getIntValues(final Provision provision,
- final MappingItem mappingItem, final List<Any<?>> anys) {
-
- LOG.debug("Get attributes for '{}' and mapping type '{}'", anys, mappingItem.getIntMappingType());
-
- boolean transform = true;
-
- List<PlainAttrValue> values = new ArrayList<>();
- switch (mappingItem.getIntMappingType()) {
- case UserPlainSchema:
- case GroupPlainSchema:
- case AnyObjectPlainSchema:
- for (Any<?> any : anys) {
- PlainAttr<?> attr = any.getPlainAttr(mappingItem.getIntAttrName());
- if (attr != null) {
- if (attr.getUniqueValue() != null) {
- PlainAttrUniqueValue value = SerializationUtils.clone(attr.getUniqueValue());
- value.setAttr(null);
- values.add(value);
- } else if (attr.getValues() != null) {
- for (PlainAttrValue value : attr.getValues()) {
- PlainAttrValue shadow = SerializationUtils.clone(value);
- shadow.setAttr(null);
- values.add(shadow);
- }
- }
- }
-
- LOG.debug("Retrieved attribute {}"
- + "\n* IntAttrName {}"
- + "\n* IntMappingType {}"
- + "\n* Attribute values {}",
- attr, mappingItem.getIntAttrName(), mappingItem.getIntMappingType(), values);
- }
-
- break;
-
- case UserDerivedSchema:
- case GroupDerivedSchema:
- case AnyObjectDerivedSchema:
- DerSchema derSchema = derSchemaDAO.find(mappingItem.getIntAttrName());
- if (derSchema != null) {
- for (Any<?> any : anys) {
- String value = derAttrHandler.getValue(any, derSchema);
- if (value != null) {
- AnyUtils anyUtils = anyUtilsFactory.getInstance(any);
- PlainAttrValue attrValue = anyUtils.newPlainAttrValue();
- attrValue.setStringValue(value);
- values.add(attrValue);
-
- LOG.debug("Retrieved values for {}"
- + "\n* IntAttrName {}"
- + "\n* IntMappingType {}"
- + "\n* Attribute values {}",
- derSchema.getKey(), mappingItem.getIntAttrName(), mappingItem.getIntMappingType(),
- values);
- }
- }
- }
- break;
-
- case UserVirtualSchema:
- case GroupVirtualSchema:
- case AnyObjectVirtualSchema:
- // virtual attributes don't get transformed
- transform = false;
-
- VirSchema virSchema = virSchemaDAO.find(mappingItem.getIntAttrName());
- if (virSchema != null) {
- for (Any<?> any : anys) {
- LOG.debug("Expire entry cache {}-{}", any.getKey(), mappingItem.getIntAttrName());
- virAttrCache.expire(any.getType().getKey(), any.getKey(), mappingItem.getIntAttrName());
-
- AnyUtils anyUtils = anyUtilsFactory.getInstance(any);
- for (String value : virAttrHandler.getValues(any, virSchema)) {
- PlainAttrValue attrValue = anyUtils.newPlainAttrValue();
- attrValue.setStringValue(value);
- values.add(attrValue);
- }
-
- LOG.debug("Retrieved values for {}"
- + "\n* IntAttrName {}"
- + "\n* IntMappingType {}"
- + "\n* Attribute values {}",
- virSchema.getKey(), mappingItem.getIntAttrName(), mappingItem.getIntMappingType(),
- values);
- }
- }
- break;
-
- case UserKey:
- case GroupKey:
- case AnyObjectKey:
- for (Any<?> any : anys) {
- AnyUtils anyUtils = anyUtilsFactory.getInstance(any);
- PlainAttrValue attrValue = anyUtils.newPlainAttrValue();
- attrValue.setStringValue(any.getKey().toString());
- values.add(attrValue);
- }
- break;
-
- case Username:
- for (Any<?> any : anys) {
- if (any instanceof User) {
- UPlainAttrValue attrValue = entityFactory.newEntity(UPlainAttrValue.class);
- attrValue.setStringValue(((User) any).getUsername());
- values.add(attrValue);
- }
- }
- break;
-
- case GroupName:
- for (Any<?> any : anys) {
- if (any instanceof Group) {
- GPlainAttrValue attrValue = entityFactory.newEntity(GPlainAttrValue.class);
- attrValue.setStringValue(((Group) any).getName());
- values.add(attrValue);
- }
- }
- break;
-
- case GroupOwnerSchema:
- Mapping uMapping = provision.getAnyType().equals(anyTypeDAO.findUser())
- ? provision.getMapping()
- : null;
- Mapping gMapping = provision.getAnyType().equals(anyTypeDAO.findGroup())
- ? provision.getMapping()
- : null;
-
- for (Any<?> any : anys) {
- if (any instanceof Group) {
- Group group = (Group) any;
- String groupOwnerValue = null;
- if (group.getUserOwner() != null && uMapping != null) {
- groupOwnerValue = getGroupOwnerValue(provision, group.getUserOwner());
- }
- if (group.getGroupOwner() != null && gMapping != null) {
- groupOwnerValue = getGroupOwnerValue(provision, group.getGroupOwner());
- }
-
- if (StringUtils.isNotBlank(groupOwnerValue)) {
- GPlainAttrValue attrValue = entityFactory.newEntity(GPlainAttrValue.class);
- attrValue.setStringValue(groupOwnerValue);
- values.add(attrValue);
- }
- }
- }
- break;
-
- default:
- }
-
- LOG.debug("Values for propagation: {}", values);
-
- List<PlainAttrValue> transformed = values;
- if (transform) {
- for (MappingItemTransformer transformer : getMappingItemTransformers(mappingItem)) {
- transformed = transformer.beforePropagation(transformed);
- }
- LOG.debug("Transformed values for propagation: {}", values);
- } else {
- LOG.debug("No transformation occurred");
- }
-
- return transformed;
- }
-
- /**
- * Get connObjectKey internal value.
- *
- * @param any any object
- * @param provision provision information
- * @return connObjectKey internal value
- */
- @Transactional(readOnly = true)
- public String getConnObjectKeyValue(final Any<?> any, final Provision provision) {
- List<PlainAttrValue> values = getIntValues(provision, provision.getMapping().getConnObjectKeyItem(),
- Collections.<Any<?>>singletonList(any));
- return values == null || values.isEmpty()
- ? null
- : values.get(0).getValueAsString();
- }
-
- /**
- * Set attribute values, according to the given {@link MappingItem}, to any object from attribute received from
- * connector.
- *
- * @param <T> any object
- * @param mappingItem mapping item
- * @param attr attribute received from connector
- * @param anyTO any object
- * @param anyUtils any utils
- */
- @Transactional(readOnly = true)
- public <T extends AnyTO> void setIntValues(
- final MappingItem mappingItem, final Attribute attr, final T anyTO, final AnyUtils anyUtils) {
-
- List<Object> values = null;
- if (attr != null) {
- values = attr.getValue();
- for (MappingItemTransformer transformer : getMappingItemTransformers(mappingItem)) {
- values = transformer.beforeSync(values);
- }
- }
- values = ListUtils.emptyIfNull(values);
-
- switch (mappingItem.getIntMappingType()) {
- case UserKey:
- case GroupKey:
- case AnyObjectKey:
- break;
-
- case Password:
- if (anyTO instanceof UserTO && !values.isEmpty()) {
- ((UserTO) anyTO).setPassword(ConnObjectUtils.getPassword(values.get(0)));
- }
- break;
-
- case Username:
- if (anyTO instanceof UserTO) {
- ((UserTO) anyTO).setUsername(values.isEmpty() || values.get(0) == null
- ? null
- : values.get(0).toString());
- }
- break;
-
- case GroupName:
- if (anyTO instanceof GroupTO) {
- ((GroupTO) anyTO).setName(values.isEmpty() || values.get(0) == null
- ? null
- : values.get(0).toString());
- }
- break;
-
- case GroupOwnerSchema:
- if (anyTO instanceof GroupTO && attr != null) {
- // using a special attribute (with schema "", that will be ignored) for carrying the
- // GroupOwnerSchema value
- AttrTO attrTO = new AttrTO();
- attrTO.setSchema(StringUtils.EMPTY);
- if (values.isEmpty() || values.get(0) == null) {
- attrTO.getValues().add(StringUtils.EMPTY);
- } else {
- attrTO.getValues().add(values.get(0).toString());
- }
-
- ((GroupTO) anyTO).getPlainAttrs().add(attrTO);
- }
- break;
-
- case UserPlainSchema:
- case GroupPlainSchema:
- case AnyObjectPlainSchema:
- AttrTO attrTO = new AttrTO();
- attrTO.setSchema(mappingItem.getIntAttrName());
-
- PlainSchema schema = plainSchemaDAO.find(mappingItem.getIntAttrName());
-
- for (Object value : values) {
- AttrSchemaType schemaType = schema == null ? AttrSchemaType.String : schema.getType();
- if (value != null) {
- PlainAttrValue attrValue = anyUtils.newPlainAttrValue();
- switch (schemaType) {
- case String:
- attrValue.setStringValue(value.toString());
- break;
-
- case Binary:
- attrValue.setBinaryValue((byte[]) value);
- break;
-
- default:
- try {
- attrValue.parseValue(schema, value.toString());
- } catch (ParsingValidationException e) {
- LOG.error("While parsing provided value {}", value, e);
- attrValue.setStringValue(value.toString());
- schemaType = AttrSchemaType.String;
- }
- break;
- }
- attrTO.getValues().add(attrValue.getValueAsString(schemaType));
- }
- }
-
- anyTO.getPlainAttrs().add(attrTO);
- break;
-
- case UserDerivedSchema:
- case GroupDerivedSchema:
- case AnyObjectDerivedSchema:
- attrTO = new AttrTO();
- attrTO.setSchema(mappingItem.getIntAttrName());
- anyTO.getDerAttrs().add(attrTO);
- break;
-
- case UserVirtualSchema:
- case GroupVirtualSchema:
- case AnyObjectVirtualSchema:
- attrTO = new AttrTO();
- attrTO.setSchema(mappingItem.getIntAttrName());
-
- // virtual attributes don't get transformed, iterate over original attr.getValue()
- for (Object value : (attr == null || attr.getValue() == null)
- ? Collections.emptyList() : attr.getValue()) {
-
- if (value != null) {
- attrTO.getValues().add(value.toString());
- }
- }
-
- anyTO.getVirAttrs().add(attrTO);
- break;
-
- default:
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/syncope/blob/28569df5/core/misc/src/main/java/org/apache/syncope/core/misc/utils/RealmUtils.java
----------------------------------------------------------------------
diff --git a/core/misc/src/main/java/org/apache/syncope/core/misc/utils/RealmUtils.java b/core/misc/src/main/java/org/apache/syncope/core/misc/utils/RealmUtils.java
deleted file mode 100644
index f3c0a46..0000000
--- a/core/misc/src/main/java/org/apache/syncope/core/misc/utils/RealmUtils.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.syncope.core.misc.utils;
-
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Set;
-
-public final class RealmUtils {
-
- public static String getGroupOwnerRealm(final String realmPath, final Long groupKey) {
- return realmPath + "@" + groupKey;
- }
-
- public static boolean normalizingAddTo(final Set<String> realms, final String newRealm) {
- boolean dontAdd = false;
- Set<String> toRemove = new HashSet<>();
- for (String realm : realms) {
- if (newRealm.startsWith(realm)) {
- dontAdd = true;
- } else if (realm.startsWith(newRealm)) {
- toRemove.add(realm);
- }
- }
-
- realms.removeAll(toRemove);
- if (!dontAdd) {
- realms.add(newRealm);
- }
- return !dontAdd;
- }
-
- public static Set<String> normalize(final Collection<String> realms) {
- Set<String> normalized = new HashSet<>();
- if (realms != null) {
- for (String realm : realms) {
- normalizingAddTo(normalized, realm);
- }
- }
-
- return normalized;
- }
-
- private RealmUtils() {
- // empty constructor for static utility class
- }
-}
http://git-wip-us.apache.org/repos/asf/syncope/blob/28569df5/core/misc/src/main/java/org/apache/syncope/core/misc/utils/TemplateUtils.java
----------------------------------------------------------------------
diff --git a/core/misc/src/main/java/org/apache/syncope/core/misc/utils/TemplateUtils.java b/core/misc/src/main/java/org/apache/syncope/core/misc/utils/TemplateUtils.java
deleted file mode 100644
index e09e0e2..0000000
--- a/core/misc/src/main/java/org/apache/syncope/core/misc/utils/TemplateUtils.java
+++ /dev/null
@@ -1,224 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.syncope.core.misc.utils;
-
-import java.util.List;
-import java.util.Map;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.commons.lang3.tuple.Pair;
-import org.apache.syncope.common.lib.SyncopeClientException;
-import org.apache.syncope.common.lib.to.AnyObjectTO;
-import org.apache.syncope.common.lib.to.AnyTO;
-import org.apache.syncope.common.lib.to.AttrTO;
-import org.apache.syncope.common.lib.to.GroupTO;
-import org.apache.syncope.common.lib.to.MembershipTO;
-import org.apache.syncope.common.lib.to.RelationshipTO;
-import org.apache.syncope.common.lib.to.UserTO;
-import org.apache.syncope.common.lib.types.ClientExceptionType;
-import org.apache.syncope.core.misc.jexl.JexlUtils;
-import org.apache.syncope.core.persistence.api.dao.GroupDAO;
-import org.apache.syncope.core.persistence.api.dao.UserDAO;
-import org.apache.syncope.core.persistence.api.entity.AnyTemplate;
-import org.apache.syncope.core.persistence.api.entity.group.Group;
-import org.apache.syncope.core.persistence.api.entity.user.User;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Component;
-import org.springframework.transaction.annotation.Transactional;
-
-@Component
-public class TemplateUtils {
-
- @Autowired
- private UserDAO userDAO;
-
- @Autowired
- private GroupDAO groupDAO;
-
- private AttrTO evaluateAttr(final AnyTO anyTO, final AttrTO template) {
- AttrTO result = new AttrTO();
- result.setSchema(template.getSchema());
-
- if (template.getValues() != null && !template.getValues().isEmpty()) {
- for (String value : template.getValues()) {
- String evaluated = JexlUtils.evaluate(value, anyTO);
- if (StringUtils.isNotBlank(evaluated)) {
- result.getValues().add(evaluated);
- }
- }
- }
-
- return result;
- }
-
- private void fill(final AnyTO anyTO, final AnyTO template) {
- if (template.getRealm() != null) {
- anyTO.setRealm(template.getRealm());
- }
-
- Map<String, AttrTO> currentAttrMap = anyTO.getPlainAttrMap();
- for (AttrTO templatePlainAttr : template.getPlainAttrs()) {
- if (!templatePlainAttr.getValues().isEmpty()
- && (!currentAttrMap.containsKey(templatePlainAttr.getSchema())
- || currentAttrMap.get(templatePlainAttr.getSchema()).getValues().isEmpty())) {
-
- anyTO.getPlainAttrs().add(evaluateAttr(anyTO, templatePlainAttr));
- }
- }
-
- currentAttrMap = anyTO.getDerAttrMap();
- for (AttrTO templateDerAttr : template.getDerAttrs()) {
- if (!currentAttrMap.containsKey(templateDerAttr.getSchema())) {
- anyTO.getDerAttrs().add(templateDerAttr);
- }
- }
-
- currentAttrMap = anyTO.getVirAttrMap();
- for (AttrTO templateVirAttr : template.getVirAttrs()) {
- if (!templateVirAttr.getValues().isEmpty()
- && (!currentAttrMap.containsKey(templateVirAttr.getSchema())
- || currentAttrMap.get(templateVirAttr.getSchema()).getValues().isEmpty())) {
-
- anyTO.getVirAttrs().add(evaluateAttr(anyTO, templateVirAttr));
- }
- }
-
- for (String resource : template.getResources()) {
- anyTO.getResources().add(resource);
- }
-
- anyTO.getAuxClasses().addAll(template.getAuxClasses());
- }
-
- private void fillRelationships(final Map<Pair<String, Long>, RelationshipTO> anyRelMap,
- final List<RelationshipTO> anyRels, final List<RelationshipTO> templateRels) {
-
- for (RelationshipTO memb : templateRels) {
- if (!anyRelMap.containsKey(Pair.of(memb.getRightType(), memb.getRightKey()))) {
- anyRels.add(memb);
- }
- }
- }
-
- private void fillMemberships(final Map<Long, MembershipTO> anyMembMap,
- final List<MembershipTO> anyMembs, final List<MembershipTO> templateMembs) {
-
- for (MembershipTO memb : templateMembs) {
- if (!anyMembMap.containsKey(memb.getRightKey())) {
- anyMembs.add(memb);
- }
- }
- }
-
- @Transactional(readOnly = true)
- public <T extends AnyTO> void apply(final T anyTO, final AnyTemplate anyTemplate) {
- if (anyTemplate != null) {
- AnyTO template = anyTemplate.get();
- fill(anyTO, template);
-
- if (template instanceof AnyObjectTO) {
- fillRelationships(((AnyObjectTO) anyTO).getRelationshipMap(),
- ((AnyObjectTO) anyTO).getRelationships(), ((AnyObjectTO) template).getRelationships());
- fillMemberships(((AnyObjectTO) anyTO).getMembershipMap(),
- ((AnyObjectTO) anyTO).getMemberships(), ((AnyObjectTO) template).getMemberships());
- } else if (template instanceof UserTO) {
- if (StringUtils.isNotBlank(((UserTO) template).getUsername())) {
- String evaluated = JexlUtils.evaluate(((UserTO) template).getUsername(), anyTO);
- if (StringUtils.isNotBlank(evaluated)) {
- ((UserTO) anyTO).setUsername(evaluated);
- }
- }
-
- if (StringUtils.isNotBlank(((UserTO) template).getPassword())) {
- String evaluated = JexlUtils.evaluate(((UserTO) template).getPassword(), anyTO);
- if (StringUtils.isNotBlank(evaluated)) {
- ((UserTO) anyTO).setPassword(evaluated);
- }
- }
-
- fillRelationships(((UserTO) anyTO).getRelationshipMap(),
- ((UserTO) anyTO).getRelationships(), ((UserTO) template).getRelationships());
- fillMemberships(((UserTO) anyTO).getMembershipMap(),
- ((UserTO) anyTO).getMemberships(), ((UserTO) template).getMemberships());
- } else if (template instanceof GroupTO) {
- if (StringUtils.isNotBlank(((GroupTO) template).getName())) {
- String evaluated = JexlUtils.evaluate(((GroupTO) template).getName(), anyTO);
- if (StringUtils.isNotBlank(evaluated)) {
- ((GroupTO) anyTO).setName(evaluated);
- }
- }
-
- if (((GroupTO) template).getUserOwner() != null) {
- final User userOwner = userDAO.find(((GroupTO) template).getUserOwner());
- if (userOwner != null) {
- ((GroupTO) anyTO).setUserOwner(userOwner.getKey());
- }
- }
- if (((GroupTO) template).getGroupOwner() != null) {
- final Group groupOwner = groupDAO.find(((GroupTO) template).getGroupOwner());
- if (groupOwner != null) {
- ((GroupTO) anyTO).setGroupOwner(groupOwner.getKey());
- }
- }
- }
- }
- }
-
- public void check(final Map<String, AnyTO> templates, final ClientExceptionType clientExceptionType) {
- SyncopeClientException sce = SyncopeClientException.build(clientExceptionType);
-
- for (Map.Entry<String, AnyTO> entry : templates.entrySet()) {
- for (AttrTO attrTO : entry.getValue().getPlainAttrs()) {
- if (!attrTO.getValues().isEmpty() && !JexlUtils.isExpressionValid(attrTO.getValues().get(0))) {
- sce.getElements().add("Invalid JEXL: " + attrTO.getValues().get(0));
- }
- }
-
- for (AttrTO attrTO : entry.getValue().getVirAttrs()) {
- if (!attrTO.getValues().isEmpty() && !JexlUtils.isExpressionValid(attrTO.getValues().get(0))) {
- sce.getElements().add("Invalid JEXL: " + attrTO.getValues().get(0));
- }
- }
-
- if (entry.getValue() instanceof UserTO) {
- UserTO template = (UserTO) entry.getValue();
- if (StringUtils.isNotBlank(template.getUsername())
- && !JexlUtils.isExpressionValid(template.getUsername())) {
-
- sce.getElements().add("Invalid JEXL: " + template.getUsername());
- }
- if (StringUtils.isNotBlank(template.getPassword())
- && !JexlUtils.isExpressionValid(template.getPassword())) {
-
- sce.getElements().add("Invalid JEXL: " + template.getPassword());
- }
- } else if (entry.getValue() instanceof GroupTO) {
- GroupTO template = (GroupTO) entry.getValue();
- if (StringUtils.isNotBlank(template.getName())
- && !JexlUtils.isExpressionValid(template.getName())) {
-
- sce.getElements().add("Invalid JEXL: " + template.getName());
- }
- }
- }
-
- if (!sce.isEmpty()) {
- throw sce;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/syncope/blob/28569df5/core/misc/src/main/resources/security.properties
----------------------------------------------------------------------
diff --git a/core/misc/src/main/resources/security.properties b/core/misc/src/main/resources/security.properties
deleted file mode 100644
index 73db510..0000000
--- a/core/misc/src/main/resources/security.properties
+++ /dev/null
@@ -1,32 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-adminUser=admin
-adminPassword=5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8
-adminPasswordAlgorithm=SHA1
-
-anonymousUser=${anonymousUser}
-anonymousKey=${anonymousKey}
-
-secretKey=${secretKey}
-# default for LDAP / RFC2307 SSHA
-digester.saltIterations=1
-digester.saltSizeBytes=8
-digester.invertPositionOfPlainSaltInEncryptionResults=true
-digester.invertPositionOfSaltInMessageBeforeDigesting=true
-digester.useLenientSaltSizeCheck=true
-
-passwordGenerator=org.apache.syncope.core.misc.security.DefaultPasswordGenerator
http://git-wip-us.apache.org/repos/asf/syncope/blob/28569df5/core/misc/src/main/resources/securityContext.xml
----------------------------------------------------------------------
diff --git a/core/misc/src/main/resources/securityContext.xml b/core/misc/src/main/resources/securityContext.xml
deleted file mode 100644
index 222d64a..0000000
--- a/core/misc/src/main/resources/securityContext.xml
+++ /dev/null
@@ -1,95 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-Licensed to the Apache Software Foundation (ASF) under one
-or more contributor license agreements. See the NOTICE file
-distributed with this work for additional information
-regarding copyright ownership. The ASF licenses this file
-to you under the Apache License, Version 2.0 (the
-"License"); you may not use this file except in compliance
-with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing,
-software distributed under the License is distributed on an
-"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-KIND, either express or implied. See the License for the
-specific language governing permissions and limitations
-under the License.
--->
-<beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:security="http://www.springframework.org/schema/security"
- xsi:schemaLocation="http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans.xsd
- http://www.springframework.org/schema/security
- http://www.springframework.org/schema/security/spring-security.xsd">
-
- <bean id="adminUser" class="java.lang.String">
- <constructor-arg value="${adminUser}"/>
- </bean>
- <bean id="anonymousUser" class="java.lang.String">
- <constructor-arg value="${anonymousUser}"/>
- </bean>
-
- <bean class="${passwordGenerator}"/>
- <bean class="org.apache.syncope.core.misc.spring.DefaultRolesPrefixPostProcessor"/>
-
- <security:global-method-security pre-post-annotations="enabled"/>
-
- <bean id="filterChainProxy" class="org.springframework.security.web.FilterChainProxy">
- <security:filter-chain-map request-matcher="ant">
- <security:filter-chain pattern="/**" filters="securityContextPersistenceFilter"/>
- </security:filter-chain-map>
- </bean>
-
- <bean id="securityContextRepository" class='org.springframework.security.web.context.NullSecurityContextRepository'/>
-
- <bean id="securityContextPersistenceFilter"
- class="org.springframework.security.web.context.SecurityContextPersistenceFilter">
- <constructor-arg ref="securityContextRepository"/>
- </bean>
-
- <bean id="syncopeAuthenticationDetailsSource"
- class="org.apache.syncope.core.misc.security.SyncopeAuthenticationDetailsSource"/>
-
- <bean id="mustChangePasswordFilter" class="org.apache.syncope.core.misc.security.MustChangePasswordFilter"/>
-
- <bean id="syncopeAuthenticationEntryPoint"
- class="org.apache.syncope.core.misc.security.SyncopeAuthenticationEntryPoint">
- <property name="realmName" value="Apache Syncope authentication"/>
- </bean>
-
- <bean id="syncopeAccessDeniedHandler" class="org.apache.syncope.core.misc.security.SyncopeAccessDeniedHandler"/>
-
- <security:http security-context-repository-ref="securityContextRepository"
- use-expressions="false" disable-url-rewriting="false">
-
- <security:http-basic entry-point-ref="syncopeAuthenticationEntryPoint"
- authentication-details-source-ref="syncopeAuthenticationDetailsSource"/>
- <security:anonymous username="${anonymousUser}"/>
- <security:intercept-url pattern="/**"/>
-
- <security:custom-filter before="FILTER_SECURITY_INTERCEPTOR" ref="mustChangePasswordFilter"/>
-
- <security:access-denied-handler ref="syncopeAccessDeniedHandler"/>
-
- <security:headers disabled="true"/>
- <security:csrf disabled="true"/>
- </security:http>
-
- <bean class="org.apache.syncope.core.misc.security.AuthDataAccessor"/>
-
- <bean id="syncopeUserDetailsService" class="org.apache.syncope.core.misc.security.SyncopeUserDetailsService"/>
-
- <bean id="syncopeAuthenticationProvider" class="org.apache.syncope.core.misc.security.SyncopeAuthenticationProvider">
- <property name="adminPassword" value="${adminPassword}"/>
- <property name="adminPasswordAlgorithm" value="${adminPasswordAlgorithm}"/>
- <property name="anonymousKey" value="${anonymousKey}"/>
- <property name="userDetailsService" ref="syncopeUserDetailsService"/>
- </bean>
-
- <security:authentication-manager>
- <security:authentication-provider ref="syncopeAuthenticationProvider"/>
- </security:authentication-manager>
-</beans>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/syncope/blob/28569df5/core/misc/src/main/resources/utilsContext.xml
----------------------------------------------------------------------
diff --git a/core/misc/src/main/resources/utilsContext.xml b/core/misc/src/main/resources/utilsContext.xml
deleted file mode 100644
index 7b2c9b3..0000000
--- a/core/misc/src/main/resources/utilsContext.xml
+++ /dev/null
@@ -1,32 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-Licensed to the Apache Software Foundation (ASF) under one
-or more contributor license agreements. See the NOTICE file
-distributed with this work for additional information
-regarding copyright ownership. The ASF licenses this file
-to you under the Apache License, Version 2.0 (the
-"License"); you may not use this file except in compliance
-with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing,
-software distributed under the License is distributed on an
-"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-KIND, either express or implied. See the License for the
-specific language governing permissions and limitations
-under the License.
--->
-<beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:context="http://www.springframework.org/schema/context"
- xsi:schemaLocation="http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans.xsd
- http://www.springframework.org/schema/context
- http://www.springframework.org/schema/context/spring-context.xsd">
-
- <bean class="org.apache.syncope.core.misc.AuditManager"/>
-
- <context:component-scan base-package="org.apache.syncope.core.misc.utils"/>
-
-</beans>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/syncope/blob/28569df5/core/misc/src/test/java/org/apache/syncope/core/misc/search/SearchCondConverterTest.java
----------------------------------------------------------------------
diff --git a/core/misc/src/test/java/org/apache/syncope/core/misc/search/SearchCondConverterTest.java b/core/misc/src/test/java/org/apache/syncope/core/misc/search/SearchCondConverterTest.java
deleted file mode 100644
index 189b575..0000000
--- a/core/misc/src/test/java/org/apache/syncope/core/misc/search/SearchCondConverterTest.java
+++ /dev/null
@@ -1,226 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.syncope.core.misc.search;
-
-import static org.junit.Assert.assertEquals;
-
-import org.apache.syncope.common.lib.search.AnyObjectFiqlSearchConditionBuilder;
-import org.apache.syncope.common.lib.search.GroupFiqlSearchConditionBuilder;
-import org.apache.syncope.common.lib.search.SpecialAttr;
-import org.apache.syncope.common.lib.search.UserFiqlSearchConditionBuilder;
-import org.apache.syncope.core.persistence.api.dao.search.AttributeCond;
-import org.apache.syncope.core.persistence.api.dao.search.MembershipCond;
-import org.apache.syncope.core.persistence.api.dao.search.ResourceCond;
-import org.apache.syncope.core.persistence.api.dao.search.RoleCond;
-import org.apache.syncope.core.persistence.api.dao.search.SearchCond;
-import org.apache.syncope.core.persistence.api.dao.search.AnyCond;
-import org.apache.syncope.core.persistence.api.dao.search.AnyTypeCond;
-import org.apache.syncope.core.persistence.api.dao.search.AssignableCond;
-import org.apache.syncope.core.persistence.api.dao.search.RelationshipCond;
-import org.apache.syncope.core.persistence.api.dao.search.RelationshipTypeCond;
-import org.junit.Test;
-
-public class SearchCondConverterTest {
-
- @Test
- public void eq() {
- String fiqlExpression = new UserFiqlSearchConditionBuilder().is("username").equalTo("rossini").query();
- assertEquals("username==rossini", fiqlExpression);
-
- AnyCond attrCond = new AnyCond(AttributeCond.Type.EQ);
- attrCond.setSchema("username");
- attrCond.setExpression("rossini");
- SearchCond simpleCond = SearchCond.getLeafCond(attrCond);
-
- assertEquals(simpleCond, SearchCondConverter.convert(fiqlExpression));
- }
-
- @Test
- public void like() {
- String fiqlExpression = new UserFiqlSearchConditionBuilder().is("username").equalTo("ros*").query();
- assertEquals("username==ros*", fiqlExpression);
-
- AttributeCond attrCond = new AnyCond(AttributeCond.Type.LIKE);
- attrCond.setSchema("username");
- attrCond.setExpression("ros%");
- SearchCond simpleCond = SearchCond.getLeafCond(attrCond);
-
- assertEquals(simpleCond, SearchCondConverter.convert(fiqlExpression));
- }
-
- @Test
- public void isNull() {
- String fiqlExpression = new UserFiqlSearchConditionBuilder().is("loginDate").nullValue().query();
- assertEquals("loginDate==" + SpecialAttr.NULL, fiqlExpression);
-
- AttributeCond attrCond = new AttributeCond(AttributeCond.Type.ISNULL);
- attrCond.setSchema("loginDate");
- SearchCond simpleCond = SearchCond.getLeafCond(attrCond);
-
- assertEquals(simpleCond, SearchCondConverter.convert(fiqlExpression));
- }
-
- @Test
- public void isNotNull() {
- String fiqlExpression = new UserFiqlSearchConditionBuilder().is("loginDate").notNullValue().query();
- assertEquals("loginDate!=" + SpecialAttr.NULL, fiqlExpression);
-
- AttributeCond attrCond = new AttributeCond(AttributeCond.Type.ISNOTNULL);
- attrCond.setSchema("loginDate");
- SearchCond simpleCond = SearchCond.getLeafCond(attrCond);
-
- assertEquals(simpleCond, SearchCondConverter.convert(fiqlExpression));
- }
-
- @Test
- public void relationships() {
- String fiqlExpression = new UserFiqlSearchConditionBuilder().inRelationships(1L).query();
- assertEquals(SpecialAttr.RELATIONSHIPS + "==1", fiqlExpression);
-
- RelationshipCond relationshipCond = new RelationshipCond();
- relationshipCond.setAnyObjectKey(1L);
- SearchCond simpleCond = SearchCond.getLeafCond(relationshipCond);
-
- assertEquals(simpleCond, SearchCondConverter.convert(fiqlExpression));
- }
-
- @Test
- public void relationshipTypes() {
- String fiqlExpression = new UserFiqlSearchConditionBuilder().inRelationshipTypes("type1").query();
- assertEquals(SpecialAttr.RELATIONSHIP_TYPES + "==type1", fiqlExpression);
-
- RelationshipTypeCond relationshipCond = new RelationshipTypeCond();
- relationshipCond.setRelationshipTypeKey("type1");
- SearchCond simpleCond = SearchCond.getLeafCond(relationshipCond);
-
- assertEquals(simpleCond, SearchCondConverter.convert(fiqlExpression));
-
- fiqlExpression = new AnyObjectFiqlSearchConditionBuilder("PRINTER").inRelationshipTypes("neighborhood").query();
- assertEquals(
- SpecialAttr.RELATIONSHIP_TYPES + "==neighborhood;" + SpecialAttr.TYPE + "==PRINTER",
- fiqlExpression);
- }
-
- @Test
- public void groups() {
- String fiqlExpression = new UserFiqlSearchConditionBuilder().inGroups(1L).query();
- assertEquals(SpecialAttr.GROUPS + "==1", fiqlExpression);
-
- MembershipCond groupCond = new MembershipCond();
- groupCond.setGroupKey(1L);
- SearchCond simpleCond = SearchCond.getLeafCond(groupCond);
-
- assertEquals(simpleCond, SearchCondConverter.convert(fiqlExpression));
- }
-
- @Test
- public void roles() {
- String fiqlExpression = new UserFiqlSearchConditionBuilder().inRoles("User reviewer").query();
- assertEquals(SpecialAttr.ROLES + "==User reviewer", fiqlExpression);
-
- RoleCond roleCond = new RoleCond();
- roleCond.setRoleKey("User reviewer");
- SearchCond simpleCond = SearchCond.getLeafCond(roleCond);
-
- assertEquals(simpleCond, SearchCondConverter.convert(fiqlExpression));
- }
-
- @Test
- public void resources() {
- String fiqlExpression = new UserFiqlSearchConditionBuilder().hasResources("resource-ldap").query();
- assertEquals(SpecialAttr.RESOURCES + "==resource-ldap", fiqlExpression);
-
- ResourceCond resCond = new ResourceCond();
- resCond.setResourceName("resource-ldap");
- SearchCond simpleCond = SearchCond.getLeafCond(resCond);
-
- assertEquals(simpleCond, SearchCondConverter.convert(fiqlExpression));
- }
-
- @Test
- public void assignable() {
- String fiqlExpression = new GroupFiqlSearchConditionBuilder().isAssignable().query();
- assertEquals(SpecialAttr.ASSIGNABLE + "==" + SpecialAttr.NULL, fiqlExpression);
-
- AssignableCond assignableCond = new AssignableCond();
- assignableCond.setRealmFullPath("/even/two");
- SearchCond simpleCond = SearchCond.getLeafCond(assignableCond);
-
- assertEquals(simpleCond, SearchCondConverter.convert(fiqlExpression, "/even/two"));
- }
-
- @Test
- public void type() {
- String fiqlExpression = new AnyObjectFiqlSearchConditionBuilder("PRINTER").query();
- assertEquals(SpecialAttr.TYPE + "==PRINTER", fiqlExpression);
-
- AnyTypeCond acond = new AnyTypeCond();
- acond.setAnyTypeName("PRINTER");
- SearchCond simpleCond = SearchCond.getLeafCond(acond);
-
- assertEquals(simpleCond, SearchCondConverter.convert(fiqlExpression));
- }
-
- @Test
- public void and() {
- String fiqlExpression = new UserFiqlSearchConditionBuilder().
- is("fullname").equalTo("*o*").and("fullname").equalTo("*i*").query();
- assertEquals("fullname==*o*;fullname==*i*", fiqlExpression);
-
- AttributeCond fullnameLeafCond1 = new AttributeCond(AttributeCond.Type.LIKE);
- fullnameLeafCond1.setSchema("fullname");
- fullnameLeafCond1.setExpression("%o%");
- AttributeCond fullnameLeafCond2 = new AttributeCond(AttributeCond.Type.LIKE);
- fullnameLeafCond2.setSchema("fullname");
- fullnameLeafCond2.setExpression("%i%");
- SearchCond andCond = SearchCond.getAndCond(
- SearchCond.getLeafCond(fullnameLeafCond1),
- SearchCond.getLeafCond(fullnameLeafCond2));
-
- assertEquals(andCond, SearchCondConverter.convert(fiqlExpression));
- }
-
- @Test
- public void or() {
- String fiqlExpression = new UserFiqlSearchConditionBuilder().
- is("fullname").equalTo("*o*", "*i*", "*ini").query();
- assertEquals("fullname==*o*,fullname==*i*,fullname==*ini", fiqlExpression);
- fiqlExpression = new UserFiqlSearchConditionBuilder().
- is("fullname").equalTo("*o*").or("fullname").equalTo("*i*").or("fullname").equalTo("*ini").query();
- assertEquals("fullname==*o*,fullname==*i*,fullname==*ini", fiqlExpression);
-
- AttributeCond fullnameLeafCond1 = new AttributeCond(AttributeCond.Type.LIKE);
- fullnameLeafCond1.setSchema("fullname");
- fullnameLeafCond1.setExpression("%o%");
- AttributeCond fullnameLeafCond2 = new AttributeCond(AttributeCond.Type.LIKE);
- fullnameLeafCond2.setSchema("fullname");
- fullnameLeafCond2.setExpression("%i%");
- AttributeCond fullnameLeafCond3 = new AttributeCond(AttributeCond.Type.LIKE);
- fullnameLeafCond3.setSchema("fullname");
- fullnameLeafCond3.setExpression("%ini");
- SearchCond orCond = SearchCond.getOrCond(
- SearchCond.getLeafCond(fullnameLeafCond1),
- SearchCond.getOrCond(
- SearchCond.getLeafCond(fullnameLeafCond2),
- SearchCond.getLeafCond(fullnameLeafCond3)));
-
- assertEquals(orCond, SearchCondConverter.convert(fiqlExpression));
- }
-
-}
http://git-wip-us.apache.org/repos/asf/syncope/blob/28569df5/core/misc/src/test/java/org/apache/syncope/core/misc/security/EncryptorTest.java
----------------------------------------------------------------------
diff --git a/core/misc/src/test/java/org/apache/syncope/core/misc/security/EncryptorTest.java b/core/misc/src/test/java/org/apache/syncope/core/misc/security/EncryptorTest.java
deleted file mode 100644
index 98e8061..0000000
--- a/core/misc/src/test/java/org/apache/syncope/core/misc/security/EncryptorTest.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.syncope.core.misc.security;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-import org.apache.syncope.common.lib.types.CipherAlgorithm;
-import org.junit.Test;
-
-/**
- * Test class to test all encryption algorithms.
- */
-public class EncryptorTest {
-
- private final String password = "password";
-
- private final Encryptor encryptor = Encryptor.getInstance();
-
- /**
- * Verify all algorithms.
- */
- @Test
- public void testEncoder() throws Exception {
- for (CipherAlgorithm cipherAlgorithm : CipherAlgorithm.values()) {
- final String encPassword = encryptor.encode(password, cipherAlgorithm);
-
- assertNotNull(encPassword);
- assertTrue(encryptor.verify(password, cipherAlgorithm, encPassword));
- assertFalse(encryptor.verify("pass", cipherAlgorithm, encPassword));
-
- // check that same password encoded with BCRYPT or Salted versions results in different digest
- if (cipherAlgorithm.equals(CipherAlgorithm.BCRYPT) || cipherAlgorithm.getAlgorithm().startsWith("S-")) {
- final String encSamePassword = encryptor.encode(password, cipherAlgorithm);
- assertNotNull(encSamePassword);
- assertFalse(encSamePassword.equals(encPassword));
- assertTrue(encryptor.verify(password, cipherAlgorithm, encSamePassword));
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/syncope/blob/28569df5/core/misc/src/test/java/org/apache/syncope/core/misc/security/PasswordGeneratorTest.java
----------------------------------------------------------------------
diff --git a/core/misc/src/test/java/org/apache/syncope/core/misc/security/PasswordGeneratorTest.java b/core/misc/src/test/java/org/apache/syncope/core/misc/security/PasswordGeneratorTest.java
deleted file mode 100644
index 536fa60..0000000
--- a/core/misc/src/test/java/org/apache/syncope/core/misc/security/PasswordGeneratorTest.java
+++ /dev/null
@@ -1,144 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.syncope.core.misc.security;
-
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.fail;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import org.apache.syncope.common.lib.policy.DefaultPasswordRuleConf;
-import org.apache.syncope.common.lib.policy.PasswordRuleConf;
-import org.apache.syncope.core.misc.policy.InvalidPasswordRuleConf;
-import org.apache.syncope.core.misc.policy.PolicyPattern;
-import org.junit.Test;
-
-public class PasswordGeneratorTest {
-
- private final DefaultPasswordGenerator passwordGenerator = new DefaultPasswordGenerator();
-
- private DefaultPasswordRuleConf createBaseDefaultPasswordRuleConf() {
- DefaultPasswordRuleConf baseDefaultPasswordRuleConf = new DefaultPasswordRuleConf();
- baseDefaultPasswordRuleConf.setAlphanumericRequired(false);
- baseDefaultPasswordRuleConf.setDigitRequired(false);
- baseDefaultPasswordRuleConf.setLowercaseRequired(false);
- baseDefaultPasswordRuleConf.setMaxLength(1000);
- baseDefaultPasswordRuleConf.setMinLength(8);
- baseDefaultPasswordRuleConf.setMustEndWithAlpha(false);
- baseDefaultPasswordRuleConf.setMustEndWithDigit(false);
- baseDefaultPasswordRuleConf.setMustEndWithNonAlpha(false);
- baseDefaultPasswordRuleConf.setMustStartWithAlpha(false);
- baseDefaultPasswordRuleConf.setMustStartWithDigit(false);
- baseDefaultPasswordRuleConf.setMustStartWithNonAlpha(false);
- baseDefaultPasswordRuleConf.setMustntEndWithAlpha(false);
- baseDefaultPasswordRuleConf.setMustntEndWithDigit(false);
- baseDefaultPasswordRuleConf.setMustntEndWithNonAlpha(false);
- baseDefaultPasswordRuleConf.setMustntStartWithAlpha(false);
- baseDefaultPasswordRuleConf.setMustntStartWithDigit(false);
- baseDefaultPasswordRuleConf.setMustntStartWithNonAlpha(false);
- baseDefaultPasswordRuleConf.setNonAlphanumericRequired(false);
- baseDefaultPasswordRuleConf.setUppercaseRequired(false);
- return baseDefaultPasswordRuleConf;
- }
-
- @Test
- public void startEndWithDigit() throws InvalidPasswordRuleConf {
- DefaultPasswordRuleConf pwdRuleConf = createBaseDefaultPasswordRuleConf();
- pwdRuleConf.setMustStartWithDigit(true);
-
- DefaultPasswordRuleConf pwdRuleConf2 = createBaseDefaultPasswordRuleConf();
- pwdRuleConf2.setMustEndWithDigit(true);
-
- List<PasswordRuleConf> ruleConfs = new ArrayList<>();
- ruleConfs.add(pwdRuleConf);
- ruleConfs.add(pwdRuleConf2);
- String generatedPassword = passwordGenerator.generate(ruleConfs);
- assertTrue(Character.isDigit(generatedPassword.charAt(0)));
- assertTrue(Character.isDigit(generatedPassword.charAt(generatedPassword.length() - 1)));
- }
-
- @Test
- public void startWithDigitAndWithAlpha() throws InvalidPasswordRuleConf {
- DefaultPasswordRuleConf pwdRuleConf = createBaseDefaultPasswordRuleConf();
- pwdRuleConf.setMustStartWithDigit(true);
-
- DefaultPasswordRuleConf pwdRuleConf2 = createBaseDefaultPasswordRuleConf();
- pwdRuleConf2.setMustEndWithAlpha(true);
-
- List<PasswordRuleConf> pwdRuleConfs = new ArrayList<>();
- pwdRuleConfs.add(pwdRuleConf);
- pwdRuleConfs.add(pwdRuleConf2);
- String generatedPassword = passwordGenerator.generate(pwdRuleConfs);
- assertTrue(Character.isDigit(generatedPassword.charAt(0)));
- assertTrue(Character.isLetter(generatedPassword.charAt(generatedPassword.length() - 1)));
- }
-
- @Test
- public void passwordWithNonAlpha() throws InvalidPasswordRuleConf {
- DefaultPasswordRuleConf pwdRuleConf = createBaseDefaultPasswordRuleConf();
- pwdRuleConf.setNonAlphanumericRequired(true);
-
- DefaultPasswordRuleConf pwdRuleConf2 = createBaseDefaultPasswordRuleConf();
- pwdRuleConf2.setMustEndWithAlpha(true);
-
- List<PasswordRuleConf> pwdRuleConfs = new ArrayList<>();
- pwdRuleConfs.add(pwdRuleConf);
- pwdRuleConfs.add(pwdRuleConf2);
- String generatedPassword = passwordGenerator.generate(pwdRuleConfs);
- assertTrue(PolicyPattern.NON_ALPHANUMERIC.matcher(generatedPassword).matches());
- assertTrue(Character.isLetter(generatedPassword.charAt(generatedPassword.length() - 1)));
- }
-
- @Test(expected = InvalidPasswordRuleConf.class)
- public void incopatiblePolicies() throws InvalidPasswordRuleConf {
- DefaultPasswordRuleConf pwdRuleConf = createBaseDefaultPasswordRuleConf();
- pwdRuleConf.setMinLength(12);
-
- DefaultPasswordRuleConf pwdRuleConf2 = createBaseDefaultPasswordRuleConf();
- pwdRuleConf.setMaxLength(10);
-
- List<PasswordRuleConf> pwdRuleConfs = new ArrayList<>();
- pwdRuleConfs.add(pwdRuleConf);
- pwdRuleConfs.add(pwdRuleConf2);
- passwordGenerator.generate(pwdRuleConfs);
- }
-
- @Test
- public void issueSYNCOPE678() {
- String password = null;
- try {
- password = passwordGenerator.generate(Collections.<PasswordRuleConf>emptyList());
- } catch (InvalidPasswordRuleConf e) {
- fail(e.getMessage());
- }
- assertNotNull(password);
-
- DefaultPasswordRuleConf ppSpec = createBaseDefaultPasswordRuleConf();
- ppSpec.setMinLength(0);
- password = null;
- try {
- password = passwordGenerator.generate(Collections.<PasswordRuleConf>singletonList(ppSpec));
- } catch (InvalidPasswordRuleConf e) {
- fail(e.getMessage());
- }
- assertNotNull(password);
- }
-}
http://git-wip-us.apache.org/repos/asf/syncope/blob/28569df5/core/persistence-api/pom.xml
----------------------------------------------------------------------
diff --git a/core/persistence-api/pom.xml b/core/persistence-api/pom.xml
index 10745e7..b06a192 100644
--- a/core/persistence-api/pom.xml
+++ b/core/persistence-api/pom.xml
@@ -61,6 +61,19 @@ under the License.
<artifactId>syncope-common-lib</artifactId>
<version>${project.version}</version>
</dependency>
+
+ <!-- TEST -->
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
+ <version>${slf4j.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>