@Test public void testGetUsernameWithUserDetails() { UserDetails details = populateSecurityContext(); String user = m_service.getUsername(); assertNotNull("user should not be null", user); assertEquals("user name", details.getUsername(), user); }
protected String getUsername() { SecurityContext context = SecurityContextHolder.getContext(); Assert.state(context != null, "No security context found when calling SecurityContextHolder.getContext()"); org.springframework.security.core.Authentication auth = context.getAuthentication(); Assert.state(auth != null, "No Authentication object found when calling getAuthentication on our SecurityContext object"); Object obj = auth.getPrincipal(); Assert.state(obj != null, "No principal object found when calling getPrincipal on our Authentication object"); if (obj instanceof UserDetails) { return ((UserDetails)obj).getUsername(); } else { throw new IllegalStateException("principal should always be instanceof UserDetails"); } }
DefaultSurveillanceService implements SurveillanceService, InitializingBean { protected String getUsername() { SecurityContext context = SecurityContextHolder.getContext(); Assert.state(context != null, "No security context found when calling SecurityContextHolder.getContext()"); org.springframework.security.core.Authentication auth = context.getAuthentication(); Assert.state(auth != null, "No Authentication object found when calling getAuthentication on our SecurityContext object"); Object obj = auth.getPrincipal(); Assert.state(obj != null, "No principal object found when calling getPrincipal on our Authentication object"); if (obj instanceof UserDetails) { return ((UserDetails)obj).getUsername(); } else { throw new IllegalStateException("principal should always be instanceof UserDetails"); } } }
DefaultSurveillanceService implements SurveillanceService, InitializingBean { protected String getUsername() { SecurityContext context = SecurityContextHolder.getContext(); Assert.state(context != null, "No security context found when calling SecurityContextHolder.getContext()"); org.springframework.security.core.Authentication auth = context.getAuthentication(); Assert.state(auth != null, "No Authentication object found when calling getAuthentication on our SecurityContext object"); Object obj = auth.getPrincipal(); Assert.state(obj != null, "No principal object found when calling getPrincipal on our Authentication object"); if (obj instanceof UserDetails) { return ((UserDetails)obj).getUsername(); } else { throw new IllegalStateException("principal should always be instanceof UserDetails"); } }  }
DefaultSurveillanceService implements SurveillanceService, InitializingBean { protected String getUsername() { SecurityContext context = SecurityContextHolder.getContext(); Assert.state(context != null, "No security context found when calling SecurityContextHolder.getContext()"); org.springframework.security.core.Authentication auth = context.getAuthentication(); Assert.state(auth != null, "No Authentication object found when calling getAuthentication on our SecurityContext object"); Object obj = auth.getPrincipal(); Assert.state(obj != null, "No principal object found when calling getPrincipal on our Authentication object"); if (obj instanceof UserDetails) { return ((UserDetails)obj).getUsername(); } else { throw new IllegalStateException("principal should always be instanceof UserDetails"); } }  SurveillanceData getSurveillanceData(); Alarm[] getAlarmsForSet(SurveillanceSet set); String[] getNodeNames(SurveillanceSet set); String[][] getResources(SurveillanceSet set); String[][] getChildResources(String id); String[][] getPrefabGraphs(String id); Notification[] getNotificationsForSet(SurveillanceSet set); NodeRtc[] getRtcForSet(SurveillanceSet set); @Override void afterPropertiesSet(); void setNodeDao(NodeDao nodeDao); void setNotificationDao(NotificationDao notifDao); void setResourceDao(ResourceDao resourceDao); void setGraphDao(GraphDao graphDao); org.opennms.web.svclayer.SurveillanceService getWebSurveillanceService(); void setWebSurveillanceService(org.opennms.web.svclayer.SurveillanceService webSurveillanceService); SurveillanceViewConfigDao getSurveillanceViewConfigDao(); void setSurveillanceViewConfigDao(SurveillanceViewConfigDao surveillanceViewConfigDao); CategoryDao getCategoryDao(); void setCategoryDao(CategoryDao categoryDao); AlarmDao getAlarmDao(); void setAlarmDao(AlarmDao alarmDao); RtcService getRtcService(); void setRtcService(RtcService rtcService); GroupDao getGroupDao(); void setGroupDao(GroupDao groupDao); OutageDao getOutageDao(); void setOutageDao(OutageDao outageDao); }
DefaultSurveillanceService implements SurveillanceService, InitializingBean { protected String getUsername() { SecurityContext context = SecurityContextHolder.getContext(); Assert.state(context != null, "No security context found when calling SecurityContextHolder.getContext()"); org.springframework.security.core.Authentication auth = context.getAuthentication(); Assert.state(auth != null, "No Authentication object found when calling getAuthentication on our SecurityContext object"); Object obj = auth.getPrincipal(); Assert.state(obj != null, "No principal object found when calling getPrincipal on our Authentication object"); if (obj instanceof UserDetails) { return ((UserDetails)obj).getUsername(); } else { throw new IllegalStateException("principal should always be instanceof UserDetails"); } }  SurveillanceData getSurveillanceData(); Alarm[] getAlarmsForSet(SurveillanceSet set); String[] getNodeNames(SurveillanceSet set); String[][] getResources(SurveillanceSet set); String[][] getChildResources(String id); String[][] getPrefabGraphs(String id); Notification[] getNotificationsForSet(SurveillanceSet set); NodeRtc[] getRtcForSet(SurveillanceSet set); @Override void afterPropertiesSet(); void setNodeDao(NodeDao nodeDao); void setNotificationDao(NotificationDao notifDao); void setResourceDao(ResourceDao resourceDao); void setGraphDao(GraphDao graphDao); org.opennms.web.svclayer.SurveillanceService getWebSurveillanceService(); void setWebSurveillanceService(org.opennms.web.svclayer.SurveillanceService webSurveillanceService); SurveillanceViewConfigDao getSurveillanceViewConfigDao(); void setSurveillanceViewConfigDao(SurveillanceViewConfigDao surveillanceViewConfigDao); CategoryDao getCategoryDao(); void setCategoryDao(CategoryDao categoryDao); AlarmDao getAlarmDao(); void setAlarmDao(AlarmDao alarmDao); RtcService getRtcService(); void setRtcService(RtcService rtcService); GroupDao getGroupDao(); void setGroupDao(GroupDao groupDao); OutageDao getOutageDao(); void setOutageDao(OutageDao outageDao);  }