Search in sources :

Example 6 with StringUtils.substringBefore

use of org.apache.commons.lang3.StringUtils.substringBefore in project syncope by apache.

the class SCIMDataBinder method toSCIMUser.

public SCIMUser toSCIMUser(final UserTO userTO, final String location, final List<String> attributes, final List<String> excludedAttributes) {
    SCIMConf conf = confManager.get();
    List<String> schemas = new ArrayList<>();
    schemas.add(Resource.User.schema());
    if (conf.getEnterpriseUserConf() != null) {
        schemas.add(Resource.EnterpriseUser.schema());
    }
    SCIMUser user = new SCIMUser(userTO.getKey(), schemas, new Meta(Resource.User, userTO.getCreationDate(), userTO.getLastChangeDate() == null ? userTO.getCreationDate() : userTO.getLastChangeDate(), userTO.getETagValue(), location), output(attributes, excludedAttributes, "userName", userTO.getUsername()), !userTO.isSuspended());
    Map<String, AttrTO> attrs = new HashMap<>();
    attrs.putAll(EntityTOUtils.buildAttrMap(userTO.getPlainAttrs()));
    attrs.putAll(EntityTOUtils.buildAttrMap(userTO.getDerAttrs()));
    attrs.putAll(EntityTOUtils.buildAttrMap(userTO.getVirAttrs()));
    if (conf.getUserConf() != null) {
        if (output(attributes, excludedAttributes, "name") && conf.getUserConf().getName() != null) {
            SCIMUserName name = new SCIMUserName();
            if (conf.getUserConf().getName().getFamilyName() != null && attrs.containsKey(conf.getUserConf().getName().getFamilyName())) {
                name.setFamilyName(attrs.get(conf.getUserConf().getName().getFamilyName()).getValues().get(0));
            }
            if (conf.getUserConf().getName().getFormatted() != null && attrs.containsKey(conf.getUserConf().getName().getFormatted())) {
                name.setFormatted(attrs.get(conf.getUserConf().getName().getFormatted()).getValues().get(0));
            }
            if (conf.getUserConf().getName().getGivenName() != null && attrs.containsKey(conf.getUserConf().getName().getGivenName())) {
                name.setGivenName(attrs.get(conf.getUserConf().getName().getGivenName()).getValues().get(0));
            }
            if (conf.getUserConf().getName().getHonorificPrefix() != null && attrs.containsKey(conf.getUserConf().getName().getHonorificPrefix())) {
                name.setHonorificPrefix(attrs.get(conf.getUserConf().getName().getHonorificPrefix()).getValues().get(0));
            }
            if (conf.getUserConf().getName().getHonorificSuffix() != null && attrs.containsKey(conf.getUserConf().getName().getHonorificSuffix())) {
                name.setHonorificSuffix(attrs.get(conf.getUserConf().getName().getHonorificSuffix()).getValues().get(0));
            }
            if (conf.getUserConf().getName().getMiddleName() != null && attrs.containsKey(conf.getUserConf().getName().getMiddleName())) {
                name.setMiddleName(attrs.get(conf.getUserConf().getName().getMiddleName()).getValues().get(0));
            }
            if (!name.isEmpty()) {
                user.setName(name);
            }
        }
        if (output(attributes, excludedAttributes, "displayName") && conf.getUserConf().getDisplayName() != null && attrs.containsKey(conf.getUserConf().getDisplayName())) {
            user.setDisplayName(attrs.get(conf.getUserConf().getDisplayName()).getValues().get(0));
        }
        if (output(attributes, excludedAttributes, "nickName") && conf.getUserConf().getNickName() != null && attrs.containsKey(conf.getUserConf().getNickName())) {
            user.setNickName(attrs.get(conf.getUserConf().getNickName()).getValues().get(0));
        }
        if (output(attributes, excludedAttributes, "profileUrl") && conf.getUserConf().getProfileUrl() != null && attrs.containsKey(conf.getUserConf().getProfileUrl())) {
            user.setProfileUrl(attrs.get(conf.getUserConf().getProfileUrl()).getValues().get(0));
        }
        if (output(attributes, excludedAttributes, "title") && conf.getUserConf().getTitle() != null && attrs.containsKey(conf.getUserConf().getTitle())) {
            user.setTitle(attrs.get(conf.getUserConf().getTitle()).getValues().get(0));
        }
        if (output(attributes, excludedAttributes, "userType") && conf.getUserConf().getUserType() != null && attrs.containsKey(conf.getUserConf().getUserType())) {
            user.setUserType(attrs.get(conf.getUserConf().getUserType()).getValues().get(0));
        }
        if (output(attributes, excludedAttributes, "preferredLanguage") && conf.getUserConf().getPreferredLanguage() != null && attrs.containsKey(conf.getUserConf().getPreferredLanguage())) {
            user.setPreferredLanguage(attrs.get(conf.getUserConf().getPreferredLanguage()).getValues().get(0));
        }
        if (output(attributes, excludedAttributes, "locale") && conf.getUserConf().getLocale() != null && attrs.containsKey(conf.getUserConf().getLocale())) {
            user.setLocale(attrs.get(conf.getUserConf().getLocale()).getValues().get(0));
        }
        if (output(attributes, excludedAttributes, "timezone") && conf.getUserConf().getTimezone() != null && attrs.containsKey(conf.getUserConf().getTimezone())) {
            user.setTimezone(attrs.get(conf.getUserConf().getTimezone()).getValues().get(0));
        }
        if (output(attributes, excludedAttributes, "emails")) {
            fill(attrs, conf.getUserConf().getEmails(), user.getEmails());
        }
        if (output(attributes, excludedAttributes, "phoneNumbers")) {
            fill(attrs, conf.getUserConf().getPhoneNumbers(), user.getPhoneNumbers());
        }
        if (output(attributes, excludedAttributes, "ims")) {
            fill(attrs, conf.getUserConf().getIms(), user.getIms());
        }
        if (output(attributes, excludedAttributes, "photos")) {
            fill(attrs, conf.getUserConf().getPhotos(), user.getPhotos());
        }
        if (output(attributes, excludedAttributes, "addresses")) {
            conf.getUserConf().getAddresses().forEach(addressConf -> {
                SCIMUserAddress address = new SCIMUserAddress();
                if (addressConf.getFormatted() != null && attrs.containsKey(addressConf.getFormatted())) {
                    address.setFormatted(attrs.get(addressConf.getFormatted()).getValues().get(0));
                }
                if (addressConf.getStreetAddress() != null && attrs.containsKey(addressConf.getStreetAddress())) {
                    address.setStreetAddress(attrs.get(addressConf.getStreetAddress()).getValues().get(0));
                }
                if (addressConf.getLocality() != null && attrs.containsKey(addressConf.getLocality())) {
                    address.setLocality(attrs.get(addressConf.getLocality()).getValues().get(0));
                }
                if (addressConf.getRegion() != null && attrs.containsKey(addressConf.getRegion())) {
                    address.setRegion(attrs.get(addressConf.getRegion()).getValues().get(0));
                }
                if (addressConf.getCountry() != null && attrs.containsKey(addressConf.getCountry())) {
                    address.setCountry(attrs.get(addressConf.getCountry()).getValues().get(0));
                }
                if (addressConf.getType() != null) {
                    address.setType(addressConf.getType().name());
                }
                if (addressConf.isPrimary()) {
                    address.setPrimary(true);
                }
                if (!address.isEmpty()) {
                    user.getAddresses().add(address);
                }
            });
        }
        if (output(attributes, excludedAttributes, "x509Certificates")) {
            conf.getUserConf().getX509Certificates().stream().filter(certificate -> attrs.containsKey(certificate)).forEachOrdered(certificate -> {
                user.getX509Certificates().add(new Value(attrs.get(certificate).getValues().get(0)));
            });
        }
        if (conf.getEnterpriseUserConf() != null) {
            SCIMEnterpriseInfo enterpriseInfo = new SCIMEnterpriseInfo();
            if (output(attributes, excludedAttributes, "employeeNumber") && conf.getEnterpriseUserConf().getEmployeeNumber() != null && attrs.containsKey(conf.getEnterpriseUserConf().getEmployeeNumber())) {
                enterpriseInfo.setEmployeeNumber(attrs.get(conf.getEnterpriseUserConf().getEmployeeNumber()).getValues().get(0));
            }
            if (output(attributes, excludedAttributes, "costCenter") && conf.getEnterpriseUserConf().getCostCenter() != null && attrs.containsKey(conf.getEnterpriseUserConf().getCostCenter())) {
                enterpriseInfo.setCostCenter(attrs.get(conf.getEnterpriseUserConf().getCostCenter()).getValues().get(0));
            }
            if (output(attributes, excludedAttributes, "organization") && conf.getEnterpriseUserConf().getOrganization() != null && attrs.containsKey(conf.getEnterpriseUserConf().getOrganization())) {
                enterpriseInfo.setOrganization(attrs.get(conf.getEnterpriseUserConf().getOrganization()).getValues().get(0));
            }
            if (output(attributes, excludedAttributes, "division") && conf.getEnterpriseUserConf().getDivision() != null && attrs.containsKey(conf.getEnterpriseUserConf().getDivision())) {
                enterpriseInfo.setDivision(attrs.get(conf.getEnterpriseUserConf().getDivision()).getValues().get(0));
            }
            if (output(attributes, excludedAttributes, "department") && conf.getEnterpriseUserConf().getDepartment() != null && attrs.containsKey(conf.getEnterpriseUserConf().getDepartment())) {
                enterpriseInfo.setDepartment(attrs.get(conf.getEnterpriseUserConf().getDepartment()).getValues().get(0));
            }
            if (output(attributes, excludedAttributes, "manager") && conf.getEnterpriseUserConf().getManager() != null) {
                SCIMUserManager manager = new SCIMUserManager();
                if (conf.getEnterpriseUserConf().getManager().getKey() != null && attrs.containsKey(conf.getEnterpriseUserConf().getManager().getKey())) {
                    try {
                        UserTO userManager = userLogic.read(attrs.get(conf.getEnterpriseUserConf().getManager().getKey()).getValues().get(0));
                        manager.setValue(userManager.getKey());
                        manager.setRef(StringUtils.substringBefore(location, "/Users") + "/Users/" + userManager.getKey());
                        if (conf.getEnterpriseUserConf().getManager().getDisplayName() != null) {
                            AttrTO displayName = userManager.getPlainAttr(conf.getEnterpriseUserConf().getManager().getDisplayName()).orElse(null);
                            if (displayName == null) {
                                displayName = userManager.getDerAttr(conf.getEnterpriseUserConf().getManager().getDisplayName()).orElse(null);
                            }
                            if (displayName == null) {
                                displayName = userManager.getVirAttr(conf.getEnterpriseUserConf().getManager().getDisplayName()).orElse(null);
                            }
                            if (displayName != null) {
                                manager.setDisplayName(displayName.getValues().get(0));
                            }
                        }
                    } catch (Exception e) {
                        LOG.error("Could not read user {}", conf.getEnterpriseUserConf().getManager().getKey(), e);
                    }
                }
                if (!manager.isEmpty()) {
                    enterpriseInfo.setManager(manager);
                }
            }
            if (!enterpriseInfo.isEmpty()) {
                user.setEnterpriseInfo(enterpriseInfo);
            }
        }
        if (output(attributes, excludedAttributes, "groups")) {
            userTO.getMemberships().forEach(membership -> {
                user.getGroups().add(new Group(membership.getGroupKey(), StringUtils.substringBefore(location, "/Users") + "/Groups/" + membership.getGroupKey(), membership.getGroupName(), Function.direct));
            });
            userTO.getDynMemberships().forEach(membership -> {
                user.getGroups().add(new Group(membership.getGroupKey(), StringUtils.substringBefore(location, "/Users") + "/Groups/" + membership.getGroupKey(), membership.getGroupName(), Function.indirect));
            });
        }
        if (output(attributes, excludedAttributes, "entitlements")) {
            authDataAccessor.getAuthorities(userTO.getUsername()).forEach(authority -> {
                user.getEntitlements().add(new Value(authority.getAuthority() + " on Realm(s) " + authority.getRealms()));
            });
        }
        if (output(attributes, excludedAttributes, "roles")) {
            userTO.getRoles().forEach(role -> {
                user.getRoles().add(new Value(role));
            });
        }
    }
    return user;
}
Also used : Arrays(java.util.Arrays) BadRequestException(org.apache.syncope.ext.scimv2.api.BadRequestException) Group(org.apache.syncope.ext.scimv2.api.data.Group) AttrTO(org.apache.syncope.common.lib.to.AttrTO) EntityTOUtils(org.apache.syncope.common.lib.EntityTOUtils) SCIMUserAddressConf(org.apache.syncope.common.lib.scim.SCIMUserAddressConf) ErrorType(org.apache.syncope.ext.scimv2.api.type.ErrorType) LoggerFactory(org.slf4j.LoggerFactory) OrderByClause(org.apache.syncope.core.persistence.api.dao.search.OrderByClause) SCIMUserAddress(org.apache.syncope.ext.scimv2.api.data.SCIMUserAddress) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) Map(java.util.Map) SCIMUserManager(org.apache.syncope.ext.scimv2.api.data.SCIMUserManager) MembershipTO(org.apache.syncope.common.lib.to.MembershipTO) SCIMComplexValue(org.apache.syncope.ext.scimv2.api.data.SCIMComplexValue) SyncopeConstants(org.apache.syncope.common.lib.SyncopeConstants) SCIMGroup(org.apache.syncope.ext.scimv2.api.data.SCIMGroup) Logger(org.slf4j.Logger) SearchCond(org.apache.syncope.core.persistence.api.dao.search.SearchCond) Value(org.apache.syncope.ext.scimv2.api.data.Value) SCIMUserName(org.apache.syncope.ext.scimv2.api.data.SCIMUserName) SCIMEnterpriseInfo(org.apache.syncope.ext.scimv2.api.data.SCIMEnterpriseInfo) Set(java.util.Set) GroupTO(org.apache.syncope.common.lib.to.GroupTO) AuthDataAccessor(org.apache.syncope.core.spring.security.AuthDataAccessor) Function(org.apache.syncope.ext.scimv2.api.type.Function) SCIMUser(org.apache.syncope.ext.scimv2.api.data.SCIMUser) List(java.util.List) Meta(org.apache.syncope.ext.scimv2.api.data.Meta) Component(org.springframework.stereotype.Component) Resource(org.apache.syncope.ext.scimv2.api.type.Resource) SCIMComplexConf(org.apache.syncope.common.lib.scim.SCIMComplexConf) SCIMConf(org.apache.syncope.common.lib.scim.SCIMConf) AnyDAO(org.apache.syncope.core.persistence.api.dao.AnyDAO) SCIMConfManager(org.apache.syncope.core.logic.scim.SCIMConfManager) Member(org.apache.syncope.ext.scimv2.api.data.Member) Optional(java.util.Optional) UserTO(org.apache.syncope.common.lib.to.UserTO) MembershipCond(org.apache.syncope.core.persistence.api.dao.search.MembershipCond) Collections(java.util.Collections) Meta(org.apache.syncope.ext.scimv2.api.data.Meta) SCIMUserManager(org.apache.syncope.ext.scimv2.api.data.SCIMUserManager) Group(org.apache.syncope.ext.scimv2.api.data.Group) SCIMGroup(org.apache.syncope.ext.scimv2.api.data.SCIMGroup) SCIMUser(org.apache.syncope.ext.scimv2.api.data.SCIMUser) HashMap(java.util.HashMap) SCIMUserName(org.apache.syncope.ext.scimv2.api.data.SCIMUserName) ArrayList(java.util.ArrayList) AttrTO(org.apache.syncope.common.lib.to.AttrTO) SCIMUserAddress(org.apache.syncope.ext.scimv2.api.data.SCIMUserAddress) SCIMConf(org.apache.syncope.common.lib.scim.SCIMConf) SCIMEnterpriseInfo(org.apache.syncope.ext.scimv2.api.data.SCIMEnterpriseInfo) BadRequestException(org.apache.syncope.ext.scimv2.api.BadRequestException) UserTO(org.apache.syncope.common.lib.to.UserTO) SCIMComplexValue(org.apache.syncope.ext.scimv2.api.data.SCIMComplexValue) Value(org.apache.syncope.ext.scimv2.api.data.Value)

Example 7 with StringUtils.substringBefore

use of org.apache.commons.lang3.StringUtils.substringBefore in project syncope by apache.

the class DomainProcessEngineFactoryBean method getObject.

@Override
public DomainProcessEngine getObject() throws Exception {
    if (engine == null) {
        Map<String, ProcessEngine> engines = new HashMap<>();
        ctx.getBeansOfType(DataSource.class).entrySet().stream().filter(entry -> (!entry.getKey().startsWith("local"))).forEachOrdered(entry -> {
            String domain = StringUtils.substringBefore(entry.getKey(), DataSource.class.getSimpleName());
            DataSource dataSource = entry.getValue();
            PlatformTransactionManager transactionManager = ctx.getBean(domain + "TransactionManager", PlatformTransactionManager.class);
            Object entityManagerFactory = ctx.getBean(domain + "EntityManagerFactory");
            SpringProcessEngineConfiguration conf = ctx.getBean(SpringProcessEngineConfiguration.class);
            conf.setDataSource(dataSource);
            conf.setTransactionManager(transactionManager);
            conf.setTransactionsExternallyManaged(true);
            conf.setJpaEntityManagerFactory(entityManagerFactory);
            if (conf.getBeans() == null) {
                conf.setBeans(new SpringBeanFactoryProxyMap(ctx));
            }
            if (conf.getExpressionManager() == null) {
                conf.setExpressionManager(new SpringExpressionManager(ctx, conf.getBeans()));
            }
            if (EngineServiceUtil.getIdmEngineConfiguration(conf) == null) {
                conf.addEngineConfiguration(EngineConfigurationConstants.KEY_IDM_ENGINE_CONFIG, ctx.getBean(SpringIdmEngineConfiguration.class));
            }
            engines.put(domain, conf.buildProcessEngine());
        });
        engine = new DomainProcessEngine(engines);
    }
    return engine;
}
Also used : EngineServiceUtil(org.flowable.engine.impl.util.EngineServiceUtil) EngineConfigurationConstants(org.flowable.engine.common.impl.interceptor.EngineConfigurationConstants) HashMap(java.util.HashMap) BeansException(org.springframework.beans.BeansException) StringUtils(org.apache.commons.lang3.StringUtils) ProcessEngine(org.flowable.engine.ProcessEngine) ApplicationContext(org.springframework.context.ApplicationContext) SpringIdmEngineConfiguration(org.flowable.idm.spring.SpringIdmEngineConfiguration) PlatformTransactionManager(org.springframework.transaction.PlatformTransactionManager) SpringBeanFactoryProxyMap(org.flowable.engine.common.impl.cfg.SpringBeanFactoryProxyMap) FactoryBean(org.springframework.beans.factory.FactoryBean) SpringExpressionManager(org.flowable.spring.SpringExpressionManager) Map(java.util.Map) DisposableBean(org.springframework.beans.factory.DisposableBean) DataSource(javax.sql.DataSource) SpringProcessEngineConfiguration(org.flowable.spring.SpringProcessEngineConfiguration) ApplicationContextAware(org.springframework.context.ApplicationContextAware) HashMap(java.util.HashMap) PlatformTransactionManager(org.springframework.transaction.PlatformTransactionManager) DataSource(javax.sql.DataSource) SpringIdmEngineConfiguration(org.flowable.idm.spring.SpringIdmEngineConfiguration) SpringBeanFactoryProxyMap(org.flowable.engine.common.impl.cfg.SpringBeanFactoryProxyMap) SpringProcessEngineConfiguration(org.flowable.spring.SpringProcessEngineConfiguration) SpringExpressionManager(org.flowable.spring.SpringExpressionManager) ProcessEngine(org.flowable.engine.ProcessEngine)

Aggregations

Map (java.util.Map)7 StringUtils (org.apache.commons.lang3.StringUtils)7 Set (java.util.Set)5 ArrayList (java.util.ArrayList)4 Collections (java.util.Collections)4 List (java.util.List)4 Collectors (java.util.stream.Collectors)4 MetadataAccess (com.thinkbiganalytics.metadata.api.MetadataAccess)3 Arrays (java.util.Arrays)3 HashSet (java.util.HashSet)3 Inject (javax.inject.Inject)3 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3 FeedMetadata (com.thinkbiganalytics.feedmgr.rest.model.FeedMetadata)2 AccessController (com.thinkbiganalytics.security.AccessController)2 HashMap (java.util.HashMap)2 Stream (java.util.stream.Stream)2 EnumDeclaration (com.github.javaparser.ast.body.EnumDeclaration)1 FieldDeclaration (com.github.javaparser.ast.body.FieldDeclaration)1 BooleanLiteralExpr (com.github.javaparser.ast.expr.BooleanLiteralExpr)1