Search in sources :

Example 11 with AdminUser

use of org.broadleafcommerce.openadmin.server.security.domain.AdminUser in project BroadleafCommerce by BroadleafCommerce.

the class BroadleafAdminRequestProcessor method process.

@Override
public void process(WebRequest request) throws SiteNotFoundException {
    BroadleafRequestContext brc = BroadleafRequestContext.getBroadleafRequestContext();
    if (brc == null) {
        brc = new BroadleafRequestContext();
        BroadleafRequestContext.setBroadleafRequestContext(brc);
    }
    brc.getAdditionalProperties().putAll(entityExtensionManagers);
    if (brc.getSite() == null) {
        Site site = siteResolver.resolveSite(request);
        brc.setSite(site);
    }
    brc.setWebRequest(request);
    brc.setIgnoreSite(brc.getSite() == null);
    brc.setAdmin(true);
    if (adminStrictValidateProductionChanges) {
        brc.setValidateProductionChangesState(ValidateProductionChangesState.ADMIN);
    } else {
        brc.setValidateProductionChangesState(ValidateProductionChangesState.UNDEFINED);
    }
    Locale locale = localeResolver.resolveLocale(request);
    brc.setLocale(locale);
    brc.setMessageSource(messageSource);
    TimeZone timeZone = broadleafTimeZoneResolver.resolveTimeZone(request);
    brc.setTimeZone(timeZone);
    // Note: The currencyResolver will set the currency on the BroadleafRequestContext but
    // later modules (specifically PriceListRequestProcessor in BLC enterprise) may override based
    // on the desired currency.
    BroadleafRequestedCurrencyDto dto = currencyResolver.resolveCurrency(request);
    if (dto != null) {
        brc.setBroadleafCurrency(dto.getCurrencyToUse());
        brc.setRequestedBroadleafCurrency(dto.getRequestedCurrency());
    }
    AdminUser adminUser = adminRemoteSecurityService.getPersistentAdminUser();
    if (adminUser != null) {
        brc.setAdminUserId(adminUser.getId());
    }
    prepareSandBox(request, brc);
    prepareProfile(request, brc);
    prepareCatalog(request, brc);
    brc.getAdditionalProperties().put(staleStateProtectionService.getStateVersionTokenParameter(), staleStateProtectionService.getStateVersionToken());
}
Also used : Site(org.broadleafcommerce.common.site.domain.Site) Locale(org.broadleafcommerce.common.locale.domain.Locale) TimeZone(java.util.TimeZone) BroadleafRequestContext(org.broadleafcommerce.common.web.BroadleafRequestContext) AdminUser(org.broadleafcommerce.openadmin.server.security.domain.AdminUser) BroadleafRequestedCurrencyDto(org.broadleafcommerce.common.currency.domain.BroadleafRequestedCurrencyDto)

Example 12 with AdminUser

use of org.broadleafcommerce.openadmin.server.security.domain.AdminUser in project BroadleafCommerce by BroadleafCommerce.

the class BroadleafAdminRequestProcessor method prepareProfile.

protected void prepareProfile(WebRequest request, BroadleafRequestContext brc) {
    AdminUser adminUser = adminRemoteSecurityService.getPersistentAdminUser();
    if (adminUser == null) {
        // clear any profile
        if (BLCRequestUtils.isOKtoUseSession(request)) {
            request.removeAttribute(PROFILE_REQ_PARAM, WebRequest.SCOPE_GLOBAL_SESSION);
        }
    } else {
        Site profile = null;
        if (StringUtils.isNotBlank(request.getParameter(PROFILE_REQ_PARAM))) {
            Long profileId = Long.parseLong(request.getParameter(PROFILE_REQ_PARAM));
            profile = siteService.retrievePersistentSiteById(profileId);
            if (profile == null) {
                throw new IllegalArgumentException(String.format("Unable to find the requested profile: %s", profileId));
            }
            String token = request.getParameter(staleStateProtectionService.getStateVersionTokenParameter());
            staleStateProtectionService.compareToken(token);
            staleStateProtectionService.invalidateState(true);
        }
        if (profile == null) {
            Long previouslySetProfileId = null;
            if (BLCRequestUtils.isOKtoUseSession(request)) {
                previouslySetProfileId = (Long) request.getAttribute(PROFILE_REQ_PARAM, WebRequest.SCOPE_GLOBAL_SESSION);
            }
            if (previouslySetProfileId != null) {
                profile = siteService.retrievePersistentSiteById(previouslySetProfileId);
            }
        }
        if (profile == null) {
            List<Site> profiles = new ArrayList<Site>();
            if (brc.getNonPersistentSite() != null) {
                Site currentSite = siteService.retrievePersistentSiteById(brc.getNonPersistentSite().getId());
                if (extensionManager != null) {
                    ExtensionResultHolder<Set<Site>> profilesResult = new ExtensionResultHolder<Set<Site>>();
                    extensionManager.retrieveProfiles(currentSite, profilesResult);
                    if (!CollectionUtils.isEmpty(profilesResult.getResult())) {
                        profiles.addAll(profilesResult.getResult());
                    }
                }
            }
            if (profiles.size() > 0) {
                profile = profiles.get(0);
            }
        }
        if (profile != null) {
            if (BLCRequestUtils.isOKtoUseSession(request)) {
                request.setAttribute(PROFILE_REQ_PARAM, profile.getId(), WebRequest.SCOPE_GLOBAL_SESSION);
            }
            brc.setCurrentProfile(profile);
        }
    }
}
Also used : Site(org.broadleafcommerce.common.site.domain.Site) Set(java.util.Set) ArrayList(java.util.ArrayList) AdminUser(org.broadleafcommerce.openadmin.server.security.domain.AdminUser) ExtensionResultHolder(org.broadleafcommerce.common.extension.ExtensionResultHolder)

Example 13 with AdminUser

use of org.broadleafcommerce.openadmin.server.security.domain.AdminUser in project BroadleafCommerce by BroadleafCommerce.

the class BroadleafAdminRequestProcessor method prepareCatalog.

protected void prepareCatalog(WebRequest request, BroadleafRequestContext brc) {
    AdminUser adminUser = adminRemoteSecurityService.getPersistentAdminUser();
    if (adminUser == null) {
        // clear any catalog
        if (BLCRequestUtils.isOKtoUseSession(request)) {
            request.removeAttribute(CATALOG_REQ_PARAM, WebRequest.SCOPE_GLOBAL_SESSION);
        }
    } else {
        Catalog catalog = null;
        if (StringUtils.isNotBlank(request.getParameter(CATALOG_REQ_PARAM))) {
            Long catalogId = Long.parseLong(request.getParameter(CATALOG_REQ_PARAM));
            catalog = siteService.findCatalogById(catalogId);
            if (catalog == null) {
                throw new IllegalArgumentException(String.format("Unable to find the requested catalog: %s", catalogId));
            }
            String token = request.getParameter(staleStateProtectionService.getStateVersionTokenParameter());
            staleStateProtectionService.compareToken(token);
            staleStateProtectionService.invalidateState(true);
        }
        if (catalog == null) {
            Long previouslySetCatalogId = null;
            if (BLCRequestUtils.isOKtoUseSession(request)) {
                previouslySetCatalogId = (Long) request.getAttribute(CATALOG_REQ_PARAM, WebRequest.SCOPE_GLOBAL_SESSION);
            }
            if (previouslySetCatalogId != null) {
                catalog = siteService.findCatalogById(previouslySetCatalogId);
            }
        }
        if (catalog == null) {
            List<Catalog> catalogs = new ArrayList<Catalog>();
            if (brc.getNonPersistentSite() != null) {
                Site currentSite = siteService.retrievePersistentSiteById(brc.getNonPersistentSite().getId());
                if (extensionManager != null) {
                    ExtensionResultHolder<Set<Catalog>> catalogResult = new ExtensionResultHolder<Set<Catalog>>();
                    extensionManager.retrieveCatalogs(currentSite, catalogResult);
                    if (!CollectionUtils.isEmpty(catalogResult.getResult())) {
                        catalogs.addAll(catalogResult.getResult());
                    }
                }
            }
            if (catalogs.size() > 0) {
                catalog = catalogs.get(0);
            }
        }
        if (catalog != null) {
            if (BLCRequestUtils.isOKtoUseSession(request)) {
                request.setAttribute(CATALOG_REQ_PARAM, catalog.getId(), WebRequest.SCOPE_GLOBAL_SESSION);
            }
            brc.setCurrentCatalog(catalog);
        }
        if (extensionManager != null) {
            if (brc.getNonPersistentSite() != null) {
                Site currentSite = siteService.retrievePersistentSiteById(brc.getNonPersistentSite().getId());
                ExtensionResultHolder<Catalog> catalogResult = new ExtensionResultHolder<Catalog>();
                extensionManager.overrideCurrentCatalog(request, currentSite, catalogResult);
                if (catalogResult.getResult() != null) {
                    brc.setCurrentCatalog(catalogResult.getResult());
                }
                ExtensionResultHolder<Site> profileResult = new ExtensionResultHolder<Site>();
                extensionManager.overrideCurrentProfile(request, currentSite, profileResult);
                if (profileResult.getResult() != null) {
                    brc.setCurrentProfile(profileResult.getResult());
                }
            }
        }
    }
}
Also used : Site(org.broadleafcommerce.common.site.domain.Site) Set(java.util.Set) ArrayList(java.util.ArrayList) Catalog(org.broadleafcommerce.common.site.domain.Catalog) AdminUser(org.broadleafcommerce.openadmin.server.security.domain.AdminUser) ExtensionResultHolder(org.broadleafcommerce.common.extension.ExtensionResultHolder)

Example 14 with AdminUser

use of org.broadleafcommerce.openadmin.server.security.domain.AdminUser in project BroadleafCommerce by BroadleafCommerce.

the class AdminBasicEntityController method addAuditableDisplayField.

private void addAuditableDisplayField(EntityForm entityForm, Field userField) {
    Field displayField = buildAuditableDisplayField(userField);
    AdminUser user = adminUserDao.readAdminUserById(Long.parseLong(userField.getValue()));
    String userName = user == null ? null : user.getName();
    displayField.setValue(userName);
    FieldGroup auditGroup = entityForm.findGroup("AdminAuditable_Audit");
    if (auditGroup != null) {
        auditGroup.addField(displayField);
    }
}
Also used : Field(org.broadleafcommerce.openadmin.web.form.entity.Field) FieldGroup(org.broadleafcommerce.openadmin.web.form.entity.FieldGroup) AdminUser(org.broadleafcommerce.openadmin.server.security.domain.AdminUser)

Example 15 with AdminUser

use of org.broadleafcommerce.openadmin.server.security.domain.AdminUser in project BroadleafCommerce by BroadleafCommerce.

the class AdminUserTest method testAdminUserSave.

@Test(groups = { "testAdminUserSave" }, dataProvider = "setupAdminUser", dataProviderClass = AdminUserDataProvider.class)
@Rollback(true)
public void testAdminUserSave(AdminUser user) throws Exception {
    AdminUser newUser = adminSecurityService.saveAdminUser(user);
    AdminUser userFromDB = adminSecurityService.readAdminUserById(newUser.getId());
    assert (userFromDB != null);
}
Also used : AdminUser(org.broadleafcommerce.openadmin.server.security.domain.AdminUser) Test(org.testng.annotations.Test) Rollback(org.springframework.test.annotation.Rollback)

Aggregations

AdminUser (org.broadleafcommerce.openadmin.server.security.domain.AdminUser)24 Transactional (org.springframework.transaction.annotation.Transactional)6 HashMap (java.util.HashMap)4 GenericResponse (org.broadleafcommerce.common.service.GenericResponse)4 ArrayList (java.util.ArrayList)3 Site (org.broadleafcommerce.common.site.domain.Site)3 Entity (org.broadleafcommerce.openadmin.dto.Entity)3 ValidationException (org.broadleafcommerce.openadmin.server.service.ValidationException)3 Set (java.util.Set)2 ServiceException (org.broadleafcommerce.common.exception.ServiceException)2 ExtensionResultHolder (org.broadleafcommerce.common.extension.ExtensionResultHolder)2 FieldMetadata (org.broadleafcommerce.openadmin.dto.FieldMetadata)2 PersistencePerspective (org.broadleafcommerce.openadmin.dto.PersistencePerspective)2 AdminRole (org.broadleafcommerce.openadmin.server.security.domain.AdminRole)2 AdminUserImpl (org.broadleafcommerce.openadmin.server.security.domain.AdminUserImpl)2 ForgotPasswordSecurityToken (org.broadleafcommerce.openadmin.server.security.domain.ForgotPasswordSecurityToken)2 Authentication (org.springframework.security.core.Authentication)2 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 TimeZone (java.util.TimeZone)1