@Test public void testExecuteAsSystemAdmin() { final PersonModelView retPerson = new PersonModelView(); retPerson.setEntityId(PERSON_ID); final Date personLastAcceptedTOSDate = new Date(); retPerson.setLastAcceptedTermsOfService(personLastAcceptedTOSDate); context.checking(new Expectations() { { allowing(authentication).getPrincipal(); will(returnValue(null)); allowing(getPersonModelViewByAccountIdMapper).execute(ACCOUNT_ID); will(returnValue(retPerson)); allowing(toSAcceptanceStrategy).isValidTermsOfServiceAcceptanceDate(with(personLastAcceptedTOSDate)); will(returnValue(true)); allowing(systemAdminIdsMapper).execute(null); will(returnValue(Collections.singletonList(PERSON_ID))); } }); PrincipalActionContext actionContext = TestContextCreator.createPrincipalActionContext(null, ACCOUNT_ID, 0); PersonModelView result = (PersonModelView) sut.execute(actionContext); context.assertIsSatisfied(); assertTrue(result.getRoles().contains(Role.SYSTEM_ADMIN)); assertTrue(result.getTosAcceptance()); assertEquals(AuthenticationType.NOTSET, result.getAuthenticationType()); }
@Override public PersonModelView execute(final PrincipalActionContext inActionContext) { String accountId = inActionContext.getPrincipal().getAccountId(); PersonModelView person = getPersonModelViewByAccountIdMapper.execute(accountId); List<Long> systemAdminIds = systemAdminIdsMapper.execute(null); if (systemAdminIds.contains(person.getEntityId())) { log.debug("User " + accountId + " is a system administrator."); person.getRoles().add(Role.SYSTEM_ADMIN); } person.setTosAcceptance(toSAcceptanceStrategy.isValidTermsOfServiceAcceptanceDate(person .getLastAcceptedTermsOfService())); Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal(); if (principal instanceof ExtendedUserDetails) { person.setAuthenticationType(((ExtendedUserDetails) principal).getAuthenticationType()); } return person; }
GetCurrentPersonModelViewForStartupExecution implements ExecutionStrategy<PrincipalActionContext> { @Override public PersonModelView execute(final PrincipalActionContext inActionContext) { String accountId = inActionContext.getPrincipal().getAccountId(); PersonModelView person = getPersonModelViewByAccountIdMapper.execute(accountId); List<Long> systemAdminIds = systemAdminIdsMapper.execute(null); if (systemAdminIds.contains(person.getEntityId())) { log.debug("User " + accountId + " is a system administrator."); person.getRoles().add(Role.SYSTEM_ADMIN); } person.setTosAcceptance(toSAcceptanceStrategy.isValidTermsOfServiceAcceptanceDate(person .getLastAcceptedTermsOfService())); Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal(); if (principal instanceof ExtendedUserDetails) { person.setAuthenticationType(((ExtendedUserDetails) principal).getAuthenticationType()); } return person; } }
GetCurrentPersonModelViewForStartupExecution implements ExecutionStrategy<PrincipalActionContext> { @Override public PersonModelView execute(final PrincipalActionContext inActionContext) { String accountId = inActionContext.getPrincipal().getAccountId(); PersonModelView person = getPersonModelViewByAccountIdMapper.execute(accountId); List<Long> systemAdminIds = systemAdminIdsMapper.execute(null); if (systemAdminIds.contains(person.getEntityId())) { log.debug("User " + accountId + " is a system administrator."); person.getRoles().add(Role.SYSTEM_ADMIN); } person.setTosAcceptance(toSAcceptanceStrategy.isValidTermsOfServiceAcceptanceDate(person .getLastAcceptedTermsOfService())); Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal(); if (principal instanceof ExtendedUserDetails) { person.setAuthenticationType(((ExtendedUserDetails) principal).getAuthenticationType()); } return person; } GetCurrentPersonModelViewForStartupExecution(
            final DomainMapper<Serializable, List<Long>> inSystemAdminIdsMapper,
            final DomainMapper<String, PersonModelView> inGetPersonModelViewByAccountIdMapper,
            final TermsOfServiceAcceptanceStrategy inTosAcceptanceStrategy); }
GetCurrentPersonModelViewForStartupExecution implements ExecutionStrategy<PrincipalActionContext> { @Override public PersonModelView execute(final PrincipalActionContext inActionContext) { String accountId = inActionContext.getPrincipal().getAccountId(); PersonModelView person = getPersonModelViewByAccountIdMapper.execute(accountId); List<Long> systemAdminIds = systemAdminIdsMapper.execute(null); if (systemAdminIds.contains(person.getEntityId())) { log.debug("User " + accountId + " is a system administrator."); person.getRoles().add(Role.SYSTEM_ADMIN); } person.setTosAcceptance(toSAcceptanceStrategy.isValidTermsOfServiceAcceptanceDate(person .getLastAcceptedTermsOfService())); Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal(); if (principal instanceof ExtendedUserDetails) { person.setAuthenticationType(((ExtendedUserDetails) principal).getAuthenticationType()); } return person; } GetCurrentPersonModelViewForStartupExecution(
            final DomainMapper<Serializable, List<Long>> inSystemAdminIdsMapper,
            final DomainMapper<String, PersonModelView> inGetPersonModelViewByAccountIdMapper,
            final TermsOfServiceAcceptanceStrategy inTosAcceptanceStrategy); @Override PersonModelView execute(final PrincipalActionContext inActionContext); }
GetCurrentPersonModelViewForStartupExecution implements ExecutionStrategy<PrincipalActionContext> { @Override public PersonModelView execute(final PrincipalActionContext inActionContext) { String accountId = inActionContext.getPrincipal().getAccountId(); PersonModelView person = getPersonModelViewByAccountIdMapper.execute(accountId); List<Long> systemAdminIds = systemAdminIdsMapper.execute(null); if (systemAdminIds.contains(person.getEntityId())) { log.debug("User " + accountId + " is a system administrator."); person.getRoles().add(Role.SYSTEM_ADMIN); } person.setTosAcceptance(toSAcceptanceStrategy.isValidTermsOfServiceAcceptanceDate(person .getLastAcceptedTermsOfService())); Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal(); if (principal instanceof ExtendedUserDetails) { person.setAuthenticationType(((ExtendedUserDetails) principal).getAuthenticationType()); } return person; } GetCurrentPersonModelViewForStartupExecution(
            final DomainMapper<Serializable, List<Long>> inSystemAdminIdsMapper,
            final DomainMapper<String, PersonModelView> inGetPersonModelViewByAccountIdMapper,
            final TermsOfServiceAcceptanceStrategy inTosAcceptanceStrategy); @Override PersonModelView execute(final PrincipalActionContext inActionContext);  }