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());
}
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);
}
}
}
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());
}
}
}
}
}
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);
}
}
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);
}
Aggregations