use of org.craftercms.studio.api.v1.exception.SiteNotFoundException in project studio by craftercms.
the class HeadersAuthenticationProvider method upsertUserGroup.
protected boolean upsertUserGroup(String groupName, String username, AuthenticationChain authenticationChain) throws SiteNotFoundException {
GroupDAO groupDao = authenticationChain.getGroupDao();
UserDAO userDao = authenticationChain.getUserDao();
AuditServiceInternal auditServiceInternal = authenticationChain.getAuditServiceInternal();
SiteService siteService = authenticationChain.getSiteService();
StudioConfiguration studioConfiguration = authenticationChain.getStudioConfiguration();
SiteFeed siteFeed = siteService.getSite(studioConfiguration.getProperty(CONFIGURATION_GLOBAL_SYSTEM_SITE));
try {
Map<String, Object> params = new HashMap<>();
params.put(ORG_ID, DEFAULT_ORGANIZATION_ID);
params.put(GROUP_NAME, groupName);
params.put(GROUP_DESCRIPTION, "Externally managed group - " + groupName);
groupDao.createGroup(params);
} catch (Exception e) {
logger.debug("Error creating group", e);
}
Map<String, Object> params = new HashMap<String, Object>();
params.put(GROUP_NAME, groupName);
Group group = groupDao.getGroupByName(params);
if (group != null) {
List<String> usernames = new ArrayList<String>();
params = new HashMap<>();
params.put(USER_ID, -1);
params.put(USERNAME, username);
User user = userDao.getUserByIdOrUsername(params);
List<Long> users = new ArrayList<Long>();
users.add(user.getId());
params = new HashMap<>();
params.put(USER_IDS, users);
params.put(GROUP_ID, group.getId());
try {
groupDao.addGroupMembers(params);
AuditLog auditLog = auditServiceInternal.createAuditLogEntry();
auditLog.setOperation(OPERATION_ADD_MEMBERS);
auditLog.setSiteId(siteFeed.getId());
auditLog.setActorId(username);
auditLog.setPrimaryTargetId(group.getGroupName() + ":" + user.getUsername());
auditLog.setPrimaryTargetType(TARGET_TYPE_USER);
auditLog.setPrimaryTargetValue(user.getUsername());
auditServiceInternal.insertAuditLog(auditLog);
} catch (Exception e) {
logger.debug("Unknown database error", e);
}
}
return true;
}
use of org.craftercms.studio.api.v1.exception.SiteNotFoundException in project studio by craftercms.
the class UserServiceImpl method getUserSites.
@Override
@HasPermission(type = DefaultPermission.class, action = "read_users")
public List<Site> getUserSites(long userId, String username) throws ServiceLayerException, UserNotFoundException {
List<Site> sites = new ArrayList<>();
Set<String> allSites = siteService.getAllAvailableSites();
List<Group> userGroups = userServiceInternal.getUserGroups(userId, username);
boolean isSysAdmin = userGroups.stream().anyMatch(group -> group.getGroupName().equals(SYSTEM_ADMIN_GROUP));
// Iterate all sites. If the user has any of the site groups, it has access to the site
for (String siteId : allSites) {
List<String> siteGroups = groupServiceInternal.getSiteGroups(siteId);
if (isSysAdmin || userGroups.stream().anyMatch(userGroup -> siteGroups.contains(userGroup.getGroupName()))) {
try {
SiteFeed siteFeed = siteService.getSite(siteId);
Site site = new Site();
site.setSiteId(siteFeed.getSiteId());
site.setDesc(siteFeed.getDescription());
sites.add(site);
} catch (SiteNotFoundException e) {
logger.error("Site not found: {0}", e, siteId);
}
}
}
return sites;
}
use of org.craftercms.studio.api.v1.exception.SiteNotFoundException in project studio by craftercms.
the class SiteRepositoryUpgradePipelineImpl method execute.
/**
* {@inheritDoc}
*/
@Override
public void execute(final String site) throws UpgradeException {
String gitLockKey = SITE_SANDBOX_REPOSITORY_GIT_LOCK.replaceAll(PATTERN_SITE, site);
generalLockService.lock(gitLockKey);
try {
clusterSandboxRepoSyncTask.execute(site);
GitRepositoryHelper helper = GitRepositoryHelper.getHelper(studioConfiguration, securityService, userServiceInternal, encryptor, generalLockService, retryingRepositoryOperationFacade);
Repository repository = helper.getRepository(site, GitRepositories.SANDBOX);
String sandboxBranch = siteSandboxBranch;
if (repository != null) {
Git git = new Git(repository);
try {
if (!isEmpty()) {
SiteFeed siteFeed = siteService.getSite(site);
if (!StringUtils.isEmpty(siteFeed.getSandboxBranch())) {
sandboxBranch = siteFeed.getSandboxBranch();
}
createTemporaryBranch(site, git);
checkoutBranch(siteUpgradeBranch, git);
super.execute(site);
checkoutBranch(sandboxBranch, git);
mergeTemporaryBranch(repository, git);
deleteTemporaryBranch(git);
}
} catch (GitAPIException | IOException | SiteNotFoundException e) {
throw new UpgradeException("Error branching or merging upgrade branch for site " + site, e);
} finally {
if (!isEmpty()) {
try {
checkoutBranch(sandboxBranch, git);
} catch (GitAPIException e) {
logger.error("Error cleaning up repo for site " + site, e);
}
}
git.close();
}
}
} catch (CryptoException e) {
throw new UpgradeException("Unexpected error upgrading site " + site, e);
} finally {
generalLockService.unlock(gitLockKey);
}
}
Aggregations