public synchronized void synchronizeUserPrincipal(String name) throws SecurityException { setSynchronizing(true); try { feedbackLogger.debug("Synchronizing UserPrincipal({})", name); Entity userEntity = securityEntityManager.getEntity(JetspeedPrincipalType.USER, name); if (userEntity != null) { synchronizeEntity(userEntity, new HashMap<String,Set<String>>(), new HashMap<String,Map<String,String>>()); } else { throw new SecurityException(SecurityException.PRINCIPAL_DOES_NOT_EXIST.createScoped(JetspeedPrincipalType.USER, name)); } } finally { setSynchronizing(false); } }
protected JetspeedPrincipal synchronizeEntity(final Entity entity, final Map<String,Set<String>> processing, final Map<String,Map<String,String>> processed) throws SecurityException { JetspeedPrincipal principal = null; if (processing != null && processing.get(entity.getType()) != null && processing.get(entity.getType()).contains(entity.getId())) { // TODO: throw proper security exception type throw new IllegalStateException("Circular relationship detected for Entity type "+entity.getType()+" id: "+entity.getId()); } if (processed.get(entity.getType()) != null && processed.get(entity.getType()).containsKey(entity.getId())) { String principalName = processed.get(entity.getType()).get(entity.getId()); return principalName != null ? getJetspeedPrincipal(entity.getType(),principalName) : null; } feedbackLogger.debug("Synchronizing entity {} id: {}",entity.getType(),entity.getId()); // synchronize and collect Entity from relations first Set<JetspeedPrincipalAssociationReference> toAssociations = synchronizeEntityFromRelations(entity, processing, processed); // create or update entity itself including all its from associations principal = synchronizeEntity(entity, toAssociations); Map<String,String> entitiesMap = processed.get(entity.getType()); if (entitiesMap == null) { entitiesMap = new HashMap<String,String>(); processed.put(entity.getType(), entitiesMap); } entitiesMap.put(entity.getId(), entity.getId()); return principal; }
principal = principalName != null ? getJetspeedPrincipal(relatedEntity.getType(),principalName) : null; principal = synchronizeEntity(relatedEntity, processing, processed);
@Override protected boolean processSearchResult(Entity entity, int pageSize, int pageIndex, int index) { try { if (feedbackAfterSyncCount > 0 && index % feedbackAfterSyncCount == 0) { feedbackLogger.info("Synchronizing {}s - processed: {}", type, index); } synchronizeEntity(entity, processing, processed); } catch (SecurityException e) { setFeedback(e); return false; } return true; } };
public synchronized void synchronizePrincipalsByType(final String type) throws SecurityException setSynchronizing(true); try setSynchronizing(false);
protected JetspeedPrincipal synchronizeEntity(Entity entity, Set<JetspeedPrincipalAssociationReference> toAssociations) throws SecurityException JetspeedPrincipal principal = getJetspeedPrincipal(entity.getType(), entity.getId()); JetspeedPrincipalManager principalManager = principalManagerProvider.getManager(principalManagerProvider.getPrincipalType(entity.getType()));
@Override protected boolean processSearchResult(Entity entity, int pageSize, int pageIndex, int index) { try { if (feedbackAfterSyncCount > 0 && index % feedbackAfterSyncCount == 0) { feedbackLogger.info("Synchronizing {}s - processed: {}", type, index); } synchronizeEntity(entity, processing, processed); } catch (SecurityException e) { if (abortOnError) { feedbackLogger.error("Failed to synchronize {}: {}", type, entity.getInternalId()); setFeedback(e); return false; } feedbackLogger.warn("Failed to synchronize {}: {}", type, entity.getInternalId()); logger.error("Failed to synchronize "+type+": "+entity, e); return true; } return true; } };
public synchronized void synchronizeAll() throws SecurityException setSynchronizing(true); try setSynchronizing(false);