@Test public void testFailsEventHandlingGracefully() { doThrow(RuntimeException.class) .when(registry) .registerUserProfileSelection("bobby", "profileFName1"); final ProfileSelectionEvent selectionEvent = new ProfileSelectionEvent(this, "validKey1", person, request); stickyMapper.onApplicationEvent(selectionEvent); verify(registry).registerUserProfileSelection("bobby", "profileFName1"); }
@Override public void onApplicationEvent(ProfileSelectionEvent event) { try { final String userName = event.getPerson().getUserName(); if (event.getPerson().isGuest()) { logger.warn( "Ignoring a profile selection event fired by guest user. " + "Should the Guest user be firing profile selections in your uPortal " + "implementation? Likely not."); return; } if (identitySwapperManager.isImpersonating(event.getRequest())) { logger.debug( "Ignoring selection of profile by key {} in the context of user {} because impersonated.", event.getRequestedProfileKey(), userName); return; } if (profileKeyForNoSelection != null && profileKeyForNoSelection.equals(event.getRequestedProfileKey())) { logger.trace( "Translating {} selection of profile key {} to apathy about profile selection.", userName, event.getRequestedProfileKey()); profileSelectionRegistry.registerUserProfileSelection(userName, null); return; } if (!immutableMappings.containsKey(event.getRequestedProfileKey())) { logger.warn( "User desired a profile by a key {} that does not map to any profile fname. Ignoring.", event.getRequestedProfileKey()); return; } final String profileFName = immutableMappings.get(event.getRequestedProfileKey()); logger.trace( "Storing {} selection of profile fname {} (keyed by profile key {})", userName, profileFName, event.getRequestedProfileKey()); profileSelectionRegistry.registerUserProfileSelection(userName, profileFName); } catch (final Exception e) { logger.error("Something went wrong handling profile selection event " + event); } }
StickyProfileMapperImpl implements IProfileMapper, ApplicationListener<ProfileSelectionEvent> { @Override public void onApplicationEvent(ProfileSelectionEvent event) { try { final String userName = event.getPerson().getUserName(); if (event.getPerson().isGuest()) { logger.warn( "Ignoring a profile selection event fired by guest user. " + "Should the Guest user be firing profile selections in your uPortal " + "implementation? Likely not."); return; } if (identitySwapperManager.isImpersonating(event.getRequest())) { logger.debug( "Ignoring selection of profile by key {} in the context of user {} because impersonated.", event.getRequestedProfileKey(), userName); return; } if (profileKeyForNoSelection != null && profileKeyForNoSelection.equals(event.getRequestedProfileKey())) { logger.trace( "Translating {} selection of profile key {} to apathy about profile selection.", userName, event.getRequestedProfileKey()); profileSelectionRegistry.registerUserProfileSelection(userName, null); return; } if (!immutableMappings.containsKey(event.getRequestedProfileKey())) { logger.warn( "User desired a profile by a key {} that does not map to any profile fname. Ignoring.", event.getRequestedProfileKey()); return; } final String profileFName = immutableMappings.get(event.getRequestedProfileKey()); logger.trace( "Storing {} selection of profile fname {} (keyed by profile key {})", userName, profileFName, event.getRequestedProfileKey()); profileSelectionRegistry.registerUserProfileSelection(userName, profileFName); } catch (final Exception e) { logger.error("Something went wrong handling profile selection event " + event); } } }
StickyProfileMapperImpl implements IProfileMapper, ApplicationListener<ProfileSelectionEvent> { @Override public void onApplicationEvent(ProfileSelectionEvent event) { try { final String userName = event.getPerson().getUserName(); if (event.getPerson().isGuest()) { logger.warn( "Ignoring a profile selection event fired by guest user. " + "Should the Guest user be firing profile selections in your uPortal " + "implementation? Likely not."); return; } if (identitySwapperManager.isImpersonating(event.getRequest())) { logger.debug( "Ignoring selection of profile by key {} in the context of user {} because impersonated.", event.getRequestedProfileKey(), userName); return; } if (profileKeyForNoSelection != null && profileKeyForNoSelection.equals(event.getRequestedProfileKey())) { logger.trace( "Translating {} selection of profile key {} to apathy about profile selection.", userName, event.getRequestedProfileKey()); profileSelectionRegistry.registerUserProfileSelection(userName, null); return; } if (!immutableMappings.containsKey(event.getRequestedProfileKey())) { logger.warn( "User desired a profile by a key {} that does not map to any profile fname. Ignoring.", event.getRequestedProfileKey()); return; } final String profileFName = immutableMappings.get(event.getRequestedProfileKey()); logger.trace( "Storing {} selection of profile fname {} (keyed by profile key {})", userName, profileFName, event.getRequestedProfileKey()); profileSelectionRegistry.registerUserProfileSelection(userName, profileFName); } catch (final Exception e) { logger.error("Something went wrong handling profile selection event " + event); } }  }
StickyProfileMapperImpl implements IProfileMapper, ApplicationListener<ProfileSelectionEvent> { @Override public void onApplicationEvent(ProfileSelectionEvent event) { try { final String userName = event.getPerson().getUserName(); if (event.getPerson().isGuest()) { logger.warn( "Ignoring a profile selection event fired by guest user. " + "Should the Guest user be firing profile selections in your uPortal " + "implementation? Likely not."); return; } if (identitySwapperManager.isImpersonating(event.getRequest())) { logger.debug( "Ignoring selection of profile by key {} in the context of user {} because impersonated.", event.getRequestedProfileKey(), userName); return; } if (profileKeyForNoSelection != null && profileKeyForNoSelection.equals(event.getRequestedProfileKey())) { logger.trace( "Translating {} selection of profile key {} to apathy about profile selection.", userName, event.getRequestedProfileKey()); profileSelectionRegistry.registerUserProfileSelection(userName, null); return; } if (!immutableMappings.containsKey(event.getRequestedProfileKey())) { logger.warn( "User desired a profile by a key {} that does not map to any profile fname. Ignoring.", event.getRequestedProfileKey()); return; } final String profileFName = immutableMappings.get(event.getRequestedProfileKey()); logger.trace( "Storing {} selection of profile fname {} (keyed by profile key {})", userName, profileFName, event.getRequestedProfileKey()); profileSelectionRegistry.registerUserProfileSelection(userName, profileFName); } catch (final Exception e) { logger.error("Something went wrong handling profile selection event " + event); } }  @PostConstruct void warnOnApathyKeyInMappings(); @Override void onApplicationEvent(ProfileSelectionEvent event); @Override String getProfileFname(IPerson person, HttpServletRequest request); @Autowired void setProfileSelectionRegistry(
            final IProfileSelectionRegistry profileSelectionRegistry); @Required void setMappings(Map<String, String> mappings); @Autowired void setIdentitySwapperManager(final IdentitySwapperManager manager); void setProfileKeyForNoSelection(final String profileKeyForNoSelection); }
StickyProfileMapperImpl implements IProfileMapper, ApplicationListener<ProfileSelectionEvent> { @Override public void onApplicationEvent(ProfileSelectionEvent event) { try { final String userName = event.getPerson().getUserName(); if (event.getPerson().isGuest()) { logger.warn( "Ignoring a profile selection event fired by guest user. " + "Should the Guest user be firing profile selections in your uPortal " + "implementation? Likely not."); return; } if (identitySwapperManager.isImpersonating(event.getRequest())) { logger.debug( "Ignoring selection of profile by key {} in the context of user {} because impersonated.", event.getRequestedProfileKey(), userName); return; } if (profileKeyForNoSelection != null && profileKeyForNoSelection.equals(event.getRequestedProfileKey())) { logger.trace( "Translating {} selection of profile key {} to apathy about profile selection.", userName, event.getRequestedProfileKey()); profileSelectionRegistry.registerUserProfileSelection(userName, null); return; } if (!immutableMappings.containsKey(event.getRequestedProfileKey())) { logger.warn( "User desired a profile by a key {} that does not map to any profile fname. Ignoring.", event.getRequestedProfileKey()); return; } final String profileFName = immutableMappings.get(event.getRequestedProfileKey()); logger.trace( "Storing {} selection of profile fname {} (keyed by profile key {})", userName, profileFName, event.getRequestedProfileKey()); profileSelectionRegistry.registerUserProfileSelection(userName, profileFName); } catch (final Exception e) { logger.error("Something went wrong handling profile selection event " + event); } }  @PostConstruct void warnOnApathyKeyInMappings(); @Override void onApplicationEvent(ProfileSelectionEvent event); @Override String getProfileFname(IPerson person, HttpServletRequest request); @Autowired void setProfileSelectionRegistry(
            final IProfileSelectionRegistry profileSelectionRegistry); @Required void setMappings(Map<String, String> mappings); @Autowired void setIdentitySwapperManager(final IdentitySwapperManager manager); void setProfileKeyForNoSelection(final String profileKeyForNoSelection);  }