target
stringlengths
20
113k
src_fm
stringlengths
11
86.3k
src_fm_fc
stringlengths
21
86.4k
src_fm_fc_co
stringlengths
30
86.4k
src_fm_fc_ms
stringlengths
42
86.8k
src_fm_fc_ms_ff
stringlengths
43
86.8k
@Test public void testGetApplicationRolesForApplication() { List<RoleImpl> applicationRoles = coreService.getApplicationRolesForApplication(2); assertEquals(1, applicationRoles.size()); assertEquals("user", applicationRoles.get(0).getName()); }
public List<RoleImpl> getApplicationRolesForApplication(Integer applicationId) { return roleRepository.findByApplicationId(applicationId); }
CoreService { public List<RoleImpl> getApplicationRolesForApplication(Integer applicationId) { return roleRepository.findByApplicationId(applicationId); } }
CoreService { public List<RoleImpl> getApplicationRolesForApplication(Integer applicationId) { return roleRepository.findByApplicationId(applicationId); } }
CoreService { public List<RoleImpl> getApplicationRolesForApplication(Integer applicationId) { return roleRepository.findByApplicationId(applicationId); } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
CoreService { public List<RoleImpl> getApplicationRolesForApplication(Integer applicationId) { return roleRepository.findByApplicationId(applicationId); } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
@Test public void testGetApplicationRootFolder() { assertEquals(new File(rootPath + "/applications"), coreService.getApplicationRootFolder(environment)); }
protected File getApplicationRootFolder(Environment environment) { return PlatformProperties.get(getPlatformConfig(environment)).getApplicationDir(); }
CoreService { protected File getApplicationRootFolder(Environment environment) { return PlatformProperties.get(getPlatformConfig(environment)).getApplicationDir(); } }
CoreService { protected File getApplicationRootFolder(Environment environment) { return PlatformProperties.get(getPlatformConfig(environment)).getApplicationDir(); } }
CoreService { protected File getApplicationRootFolder(Environment environment) { return PlatformProperties.get(getPlatformConfig(environment)).getApplicationDir(); } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
CoreService { protected File getApplicationRootFolder(Environment environment) { return PlatformProperties.get(getPlatformConfig(environment)).getApplicationDir(); } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
@Test public void testFileCount() { assertTrue("fileCount(upload, 1, 2)"); assertFalse("fileCount(upload, 1, 0)"); assertFalse("fileCount(upload, 3, 2)"); }
public static boolean fileCount(List<FormUpload> fUpload, int minCount, int maxCount) { return fileCountMin(fUpload, minCount) && fileCountMax(fUpload, maxCount); }
RuleValidation { public static boolean fileCount(List<FormUpload> fUpload, int minCount, int maxCount) { return fileCountMin(fUpload, minCount) && fileCountMax(fUpload, maxCount); } }
RuleValidation { public static boolean fileCount(List<FormUpload> fUpload, int minCount, int maxCount) { return fileCountMin(fUpload, minCount) && fileCountMax(fUpload, maxCount); } RuleValidation(Request container); }
RuleValidation { public static boolean fileCount(List<FormUpload> fUpload, int minCount, int maxCount) { return fileCountMin(fUpload, minCount) && fileCountMax(fUpload, maxCount); } RuleValidation(Request container); Map<String, List<FormUpload>> getFileParams(Map<String, List<FormUpload>> formUploads); boolean validate(String rule); static boolean string(String string); static boolean captcha(String value, String result); static boolean email(String string); static boolean equals(String string1, String string2); static boolean number(String string); static boolean number(String string, char separator); static boolean numberFractionDigits(String string, int digits, int fraction); static boolean number(String string, char separator, int digits, int fraction); static boolean regExp(String string, String regex); static boolean size(Object item, int size); static boolean sizeMax(Object item, int max); static boolean sizeMin(Object item, int min); static boolean sizeMinMax(Object item, int min, int max); static boolean fileType(List<FormUpload> fUpload, String types); static boolean fileSize(List<FormUpload> fUpload, String minSize, String maxSize); static boolean fileSizeMin(List<FormUpload> fUpload, String minSize); static boolean fileSizeMax(List<FormUpload> fUpload, String maxSize); static boolean fileCountMin(List<FormUpload> fUpload, int count); static boolean fileCountMax(List<FormUpload> fUpload, int count); static boolean fileCount(List<FormUpload> fUpload, int minCount, int maxCount); }
RuleValidation { public static boolean fileCount(List<FormUpload> fUpload, int minCount, int maxCount) { return fileCountMin(fUpload, minCount) && fileCountMax(fUpload, maxCount); } RuleValidation(Request container); Map<String, List<FormUpload>> getFileParams(Map<String, List<FormUpload>> formUploads); boolean validate(String rule); static boolean string(String string); static boolean captcha(String value, String result); static boolean email(String string); static boolean equals(String string1, String string2); static boolean number(String string); static boolean number(String string, char separator); static boolean numberFractionDigits(String string, int digits, int fraction); static boolean number(String string, char separator, int digits, int fraction); static boolean regExp(String string, String regex); static boolean size(Object item, int size); static boolean sizeMax(Object item, int max); static boolean sizeMin(Object item, int min); static boolean sizeMinMax(Object item, int min, int max); static boolean fileType(List<FormUpload> fUpload, String types); static boolean fileSize(List<FormUpload> fUpload, String minSize, String maxSize); static boolean fileSizeMin(List<FormUpload> fUpload, String minSize); static boolean fileSizeMax(List<FormUpload> fUpload, String maxSize); static boolean fileCountMin(List<FormUpload> fUpload, int count); static boolean fileCountMax(List<FormUpload> fUpload, int count); static boolean fileCount(List<FormUpload> fUpload, int minCount, int maxCount); static final List<String> SHORT_RULES; }
@Test @Ignore public void testGetApplications() { }
public List<ApplicationImpl> getApplications() { return applicationRepository.findAll(); }
CoreService { public List<ApplicationImpl> getApplications() { return applicationRepository.findAll(); } }
CoreService { public List<ApplicationImpl> getApplications() { return applicationRepository.findAll(); } }
CoreService { public List<ApplicationImpl> getApplications() { return applicationRepository.findAll(); } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
CoreService { public List<ApplicationImpl> getApplications() { return applicationRepository.findAll(); } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
@Test @Ignore public void testGetApplicationSubjects() { }
public Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site) { List<ApplicationSubject> applicationSubjects = new ArrayList<>(); ApplicationImpl application = applicationRepository.findOne(applicationId); List<SubjectImpl> subjects = subjectRepository.findSubjectsForApplication(applicationId); String siteTimeZone = site.getProperties().getString(Platform.Property.TIME_ZONE); for (SubjectImpl subject : subjects) { initializeSubject(subject); subject.getApplicationroles(application); if (UserType.GLOBAL_GROUP.equals(subject.getUserType())) { List<SubjectImpl> membersOfGroup = ldapService.getMembersOfGroup(site, subject.getAuthName()); for (SubjectImpl ldapSubject : membersOfGroup) { String timeZone = subject.getTimeZone(); if (null == timeZone) { timeZone = siteTimeZone; } ldapSubject.setTimeZone(timeZone); ldapSubject.setLanguage(subject.getLanguage()); ldapSubject.getGroups().addAll(subject.getGroups()); ApplicationSubject ps = getApplicationSubject(application, ldapSubject); applicationSubjects.add(ps); } } else { ApplicationSubject ps = getApplicationSubject(application, subject); applicationSubjects.add(ps); } } return applicationSubjects; }
CoreService { public Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site) { List<ApplicationSubject> applicationSubjects = new ArrayList<>(); ApplicationImpl application = applicationRepository.findOne(applicationId); List<SubjectImpl> subjects = subjectRepository.findSubjectsForApplication(applicationId); String siteTimeZone = site.getProperties().getString(Platform.Property.TIME_ZONE); for (SubjectImpl subject : subjects) { initializeSubject(subject); subject.getApplicationroles(application); if (UserType.GLOBAL_GROUP.equals(subject.getUserType())) { List<SubjectImpl> membersOfGroup = ldapService.getMembersOfGroup(site, subject.getAuthName()); for (SubjectImpl ldapSubject : membersOfGroup) { String timeZone = subject.getTimeZone(); if (null == timeZone) { timeZone = siteTimeZone; } ldapSubject.setTimeZone(timeZone); ldapSubject.setLanguage(subject.getLanguage()); ldapSubject.getGroups().addAll(subject.getGroups()); ApplicationSubject ps = getApplicationSubject(application, ldapSubject); applicationSubjects.add(ps); } } else { ApplicationSubject ps = getApplicationSubject(application, subject); applicationSubjects.add(ps); } } return applicationSubjects; } }
CoreService { public Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site) { List<ApplicationSubject> applicationSubjects = new ArrayList<>(); ApplicationImpl application = applicationRepository.findOne(applicationId); List<SubjectImpl> subjects = subjectRepository.findSubjectsForApplication(applicationId); String siteTimeZone = site.getProperties().getString(Platform.Property.TIME_ZONE); for (SubjectImpl subject : subjects) { initializeSubject(subject); subject.getApplicationroles(application); if (UserType.GLOBAL_GROUP.equals(subject.getUserType())) { List<SubjectImpl> membersOfGroup = ldapService.getMembersOfGroup(site, subject.getAuthName()); for (SubjectImpl ldapSubject : membersOfGroup) { String timeZone = subject.getTimeZone(); if (null == timeZone) { timeZone = siteTimeZone; } ldapSubject.setTimeZone(timeZone); ldapSubject.setLanguage(subject.getLanguage()); ldapSubject.getGroups().addAll(subject.getGroups()); ApplicationSubject ps = getApplicationSubject(application, ldapSubject); applicationSubjects.add(ps); } } else { ApplicationSubject ps = getApplicationSubject(application, subject); applicationSubjects.add(ps); } } return applicationSubjects; } }
CoreService { public Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site) { List<ApplicationSubject> applicationSubjects = new ArrayList<>(); ApplicationImpl application = applicationRepository.findOne(applicationId); List<SubjectImpl> subjects = subjectRepository.findSubjectsForApplication(applicationId); String siteTimeZone = site.getProperties().getString(Platform.Property.TIME_ZONE); for (SubjectImpl subject : subjects) { initializeSubject(subject); subject.getApplicationroles(application); if (UserType.GLOBAL_GROUP.equals(subject.getUserType())) { List<SubjectImpl> membersOfGroup = ldapService.getMembersOfGroup(site, subject.getAuthName()); for (SubjectImpl ldapSubject : membersOfGroup) { String timeZone = subject.getTimeZone(); if (null == timeZone) { timeZone = siteTimeZone; } ldapSubject.setTimeZone(timeZone); ldapSubject.setLanguage(subject.getLanguage()); ldapSubject.getGroups().addAll(subject.getGroups()); ApplicationSubject ps = getApplicationSubject(application, ldapSubject); applicationSubjects.add(ps); } } else { ApplicationSubject ps = getApplicationSubject(application, subject); applicationSubjects.add(ps); } } return applicationSubjects; } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
CoreService { public Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site) { List<ApplicationSubject> applicationSubjects = new ArrayList<>(); ApplicationImpl application = applicationRepository.findOne(applicationId); List<SubjectImpl> subjects = subjectRepository.findSubjectsForApplication(applicationId); String siteTimeZone = site.getProperties().getString(Platform.Property.TIME_ZONE); for (SubjectImpl subject : subjects) { initializeSubject(subject); subject.getApplicationroles(application); if (UserType.GLOBAL_GROUP.equals(subject.getUserType())) { List<SubjectImpl> membersOfGroup = ldapService.getMembersOfGroup(site, subject.getAuthName()); for (SubjectImpl ldapSubject : membersOfGroup) { String timeZone = subject.getTimeZone(); if (null == timeZone) { timeZone = siteTimeZone; } ldapSubject.setTimeZone(timeZone); ldapSubject.setLanguage(subject.getLanguage()); ldapSubject.getGroups().addAll(subject.getGroups()); ApplicationSubject ps = getApplicationSubject(application, ldapSubject); applicationSubjects.add(ps); } } else { ApplicationSubject ps = getApplicationSubject(application, subject); applicationSubjects.add(ps); } } return applicationSubjects; } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
@Test public void testGetPropertiesIntegerInteger() { Iterable<PropertyImpl> properties = coreService.getProperties(1, 1); Iterator<PropertyImpl> iterator = properties.iterator(); PropertyImpl prop = iterator.next(); assertEquals("platform.site.site-1.application.manager.foo", prop.getName()); assertEquals("bar", prop.getString()); iterator.next(); assertFalse(iterator.hasNext()); }
private Page<PropertyImpl> getProperties(String prefix, Pageable pageable) { SearchQuery<PropertyImpl> query = new SearchQuery<PropertyImpl>(PropertyImpl.class); query.like("name", prefix + "%"); query.notLike("name", prefix + "%.%"); Page<PropertyImpl> page = propertyRepository.search(query, pageable); return page; }
CoreService { private Page<PropertyImpl> getProperties(String prefix, Pageable pageable) { SearchQuery<PropertyImpl> query = new SearchQuery<PropertyImpl>(PropertyImpl.class); query.like("name", prefix + "%"); query.notLike("name", prefix + "%.%"); Page<PropertyImpl> page = propertyRepository.search(query, pageable); return page; } }
CoreService { private Page<PropertyImpl> getProperties(String prefix, Pageable pageable) { SearchQuery<PropertyImpl> query = new SearchQuery<PropertyImpl>(PropertyImpl.class); query.like("name", prefix + "%"); query.notLike("name", prefix + "%.%"); Page<PropertyImpl> page = propertyRepository.search(query, pageable); return page; } }
CoreService { private Page<PropertyImpl> getProperties(String prefix, Pageable pageable) { SearchQuery<PropertyImpl> query = new SearchQuery<PropertyImpl>(PropertyImpl.class); query.like("name", prefix + "%"); query.notLike("name", prefix + "%.%"); Page<PropertyImpl> page = propertyRepository.search(query, pageable); return page; } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
CoreService { private Page<PropertyImpl> getProperties(String prefix, Pageable pageable) { SearchQuery<PropertyImpl> query = new SearchQuery<PropertyImpl>(PropertyImpl.class); query.like("name", prefix + "%"); query.notLike("name", prefix + "%.%"); Page<PropertyImpl> page = propertyRepository.search(query, pageable); return page; } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
@Test public void testGetPropertiesStringString() { Iterable<PropertyImpl> properties = coreService.getProperties("site-1", "manager"); Iterator<PropertyImpl> iterator = properties.iterator(); PropertyImpl prop = iterator.next(); assertEquals("platform.site.site-1.application.manager.foo", prop.getName()); assertEquals("bar", prop.getString()); iterator.next(); assertFalse(iterator.hasNext()); }
private Page<PropertyImpl> getProperties(String prefix, Pageable pageable) { SearchQuery<PropertyImpl> query = new SearchQuery<PropertyImpl>(PropertyImpl.class); query.like("name", prefix + "%"); query.notLike("name", prefix + "%.%"); Page<PropertyImpl> page = propertyRepository.search(query, pageable); return page; }
CoreService { private Page<PropertyImpl> getProperties(String prefix, Pageable pageable) { SearchQuery<PropertyImpl> query = new SearchQuery<PropertyImpl>(PropertyImpl.class); query.like("name", prefix + "%"); query.notLike("name", prefix + "%.%"); Page<PropertyImpl> page = propertyRepository.search(query, pageable); return page; } }
CoreService { private Page<PropertyImpl> getProperties(String prefix, Pageable pageable) { SearchQuery<PropertyImpl> query = new SearchQuery<PropertyImpl>(PropertyImpl.class); query.like("name", prefix + "%"); query.notLike("name", prefix + "%.%"); Page<PropertyImpl> page = propertyRepository.search(query, pageable); return page; } }
CoreService { private Page<PropertyImpl> getProperties(String prefix, Pageable pageable) { SearchQuery<PropertyImpl> query = new SearchQuery<PropertyImpl>(PropertyImpl.class); query.like("name", prefix + "%"); query.notLike("name", prefix + "%.%"); Page<PropertyImpl> page = propertyRepository.search(query, pageable); return page; } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
CoreService { private Page<PropertyImpl> getProperties(String prefix, Pageable pageable) { SearchQuery<PropertyImpl> query = new SearchQuery<PropertyImpl>(PropertyImpl.class); query.like("name", prefix + "%"); query.notLike("name", prefix + "%.%"); Page<PropertyImpl> page = propertyRepository.search(query, pageable); return page; } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
@Test @Ignore public void testGetProperty() { }
public PropertyImpl getProperty(String propertyId) { return propertyRepository.findOne(propertyId); }
CoreService { public PropertyImpl getProperty(String propertyId) { return propertyRepository.findOne(propertyId); } }
CoreService { public PropertyImpl getProperty(String propertyId) { return propertyRepository.findOne(propertyId); } }
CoreService { public PropertyImpl getProperty(String propertyId) { return propertyRepository.findOne(propertyId); } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
CoreService { public PropertyImpl getProperty(String propertyId) { return propertyRepository.findOne(propertyId); } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
@Test public void testGetSite() { SiteImpl site = coreService.getSite(1); assertNotNull(site); assertEquals(Integer.valueOf(1), site.getId()); }
public SiteImpl getSite(Integer id) { SiteImpl site = siteRepository.findOne(id); initSite(site); return site; }
CoreService { public SiteImpl getSite(Integer id) { SiteImpl site = siteRepository.findOne(id); initSite(site); return site; } }
CoreService { public SiteImpl getSite(Integer id) { SiteImpl site = siteRepository.findOne(id); initSite(site); return site; } }
CoreService { public SiteImpl getSite(Integer id) { SiteImpl site = siteRepository.findOne(id); initSite(site); return site; } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
CoreService { public SiteImpl getSite(Integer id) { SiteImpl site = siteRepository.findOne(id); initSite(site); return site; } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
@Test public void testGetSiteByName() { SiteImpl site = coreService.getSiteByName("site-1"); assertNotNull(site); assertEquals(Integer.valueOf(1), site.getId()); assertEquals("site-1", site.getName()); }
public SiteImpl getSiteByName(String name) { SiteImpl site = siteRepository.findByName(name); initSite(site); return site; }
CoreService { public SiteImpl getSiteByName(String name) { SiteImpl site = siteRepository.findByName(name); initSite(site); return site; } }
CoreService { public SiteImpl getSiteByName(String name) { SiteImpl site = siteRepository.findByName(name); initSite(site); return site; } }
CoreService { public SiteImpl getSiteByName(String name) { SiteImpl site = siteRepository.findByName(name); initSite(site); return site; } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
CoreService { public SiteImpl getSiteByName(String name) { SiteImpl site = siteRepository.findByName(name); initSite(site); return site; } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
@Test public void testGetSiteIds() { List<Integer> siteIds = coreService.getSiteIds(); assertEquals(2, siteIds.size()); assertEquals(Integer.valueOf(1), siteIds.get(0)); assertEquals(Integer.valueOf(4), siteIds.get(1)); }
protected List<Integer> getSiteIds() { return siteRepository.getSiteIds(); }
CoreService { protected List<Integer> getSiteIds() { return siteRepository.getSiteIds(); } }
CoreService { protected List<Integer> getSiteIds() { return siteRepository.getSiteIds(); } }
CoreService { protected List<Integer> getSiteIds() { return siteRepository.getSiteIds(); } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
CoreService { protected List<Integer> getSiteIds() { return siteRepository.getSiteIds(); } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
@Test public void testGetSites() { List<SiteImpl> sites = coreService.getSites(); assertEquals(2, sites.size()); assertEquals("site-1", sites.get(0).getName()); assertEquals("example", sites.get(1).getName()); }
public List<SiteImpl> getSites() { return siteRepository.findAll(); }
CoreService { public List<SiteImpl> getSites() { return siteRepository.findAll(); } }
CoreService { public List<SiteImpl> getSites() { return siteRepository.findAll(); } }
CoreService { public List<SiteImpl> getSites() { return siteRepository.findAll(); } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
CoreService { public List<SiteImpl> getSites() { return siteRepository.findAll(); } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
@Test public void testGetSubjectByEmail() { Subject subject = coreService.getSubjectByEmail("[email protected]"); assertEquals(Integer.valueOf(1), subject.getId()); }
public Subject getSubjectByEmail(String email) { return subjectRepository.findByEmail(email); }
CoreService { public Subject getSubjectByEmail(String email) { return subjectRepository.findByEmail(email); } }
CoreService { public Subject getSubjectByEmail(String email) { return subjectRepository.findByEmail(email); } }
CoreService { public Subject getSubjectByEmail(String email) { return subjectRepository.findByEmail(email); } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
CoreService { public Subject getSubjectByEmail(String email) { return subjectRepository.findByEmail(email); } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
@Test public void testFileCountMin() { assertTrue("fileCountMin(upload, 1)"); assertFalse("fileCountMin(upload, 5)"); assertFalse("fileCountMin(upload, 3)"); }
public static boolean fileCountMin(List<FormUpload> fUpload, int count) { return getNumberOfFiles(fUpload) >= count; }
RuleValidation { public static boolean fileCountMin(List<FormUpload> fUpload, int count) { return getNumberOfFiles(fUpload) >= count; } }
RuleValidation { public static boolean fileCountMin(List<FormUpload> fUpload, int count) { return getNumberOfFiles(fUpload) >= count; } RuleValidation(Request container); }
RuleValidation { public static boolean fileCountMin(List<FormUpload> fUpload, int count) { return getNumberOfFiles(fUpload) >= count; } RuleValidation(Request container); Map<String, List<FormUpload>> getFileParams(Map<String, List<FormUpload>> formUploads); boolean validate(String rule); static boolean string(String string); static boolean captcha(String value, String result); static boolean email(String string); static boolean equals(String string1, String string2); static boolean number(String string); static boolean number(String string, char separator); static boolean numberFractionDigits(String string, int digits, int fraction); static boolean number(String string, char separator, int digits, int fraction); static boolean regExp(String string, String regex); static boolean size(Object item, int size); static boolean sizeMax(Object item, int max); static boolean sizeMin(Object item, int min); static boolean sizeMinMax(Object item, int min, int max); static boolean fileType(List<FormUpload> fUpload, String types); static boolean fileSize(List<FormUpload> fUpload, String minSize, String maxSize); static boolean fileSizeMin(List<FormUpload> fUpload, String minSize); static boolean fileSizeMax(List<FormUpload> fUpload, String maxSize); static boolean fileCountMin(List<FormUpload> fUpload, int count); static boolean fileCountMax(List<FormUpload> fUpload, int count); static boolean fileCount(List<FormUpload> fUpload, int minCount, int maxCount); }
RuleValidation { public static boolean fileCountMin(List<FormUpload> fUpload, int count) { return getNumberOfFiles(fUpload) >= count; } RuleValidation(Request container); Map<String, List<FormUpload>> getFileParams(Map<String, List<FormUpload>> formUploads); boolean validate(String rule); static boolean string(String string); static boolean captcha(String value, String result); static boolean email(String string); static boolean equals(String string1, String string2); static boolean number(String string); static boolean number(String string, char separator); static boolean numberFractionDigits(String string, int digits, int fraction); static boolean number(String string, char separator, int digits, int fraction); static boolean regExp(String string, String regex); static boolean size(Object item, int size); static boolean sizeMax(Object item, int max); static boolean sizeMin(Object item, int min); static boolean sizeMinMax(Object item, int min, int max); static boolean fileType(List<FormUpload> fUpload, String types); static boolean fileSize(List<FormUpload> fUpload, String minSize, String maxSize); static boolean fileSizeMin(List<FormUpload> fUpload, String minSize); static boolean fileSizeMax(List<FormUpload> fUpload, String maxSize); static boolean fileCountMin(List<FormUpload> fUpload, int count); static boolean fileCountMax(List<FormUpload> fUpload, int count); static boolean fileCount(List<FormUpload> fUpload, int minCount, int maxCount); static final List<String> SHORT_RULES; }
@Test public void testGetSubjectById() { Subject subject = coreService.getSubjectById(1, false); assertEquals(Integer.valueOf(1), subject.getId()); }
public Subject getSubjectById(Integer id, boolean initialize) { SubjectImpl subject = subjectRepository.findOne(id); if (initialize) { initializeSubject(subject); } return subject; }
CoreService { public Subject getSubjectById(Integer id, boolean initialize) { SubjectImpl subject = subjectRepository.findOne(id); if (initialize) { initializeSubject(subject); } return subject; } }
CoreService { public Subject getSubjectById(Integer id, boolean initialize) { SubjectImpl subject = subjectRepository.findOne(id); if (initialize) { initializeSubject(subject); } return subject; } }
CoreService { public Subject getSubjectById(Integer id, boolean initialize) { SubjectImpl subject = subjectRepository.findOne(id); if (initialize) { initializeSubject(subject); } return subject; } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
CoreService { public Subject getSubjectById(Integer id, boolean initialize) { SubjectImpl subject = subjectRepository.findOne(id); if (initialize) { initializeSubject(subject); } return subject; } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
@Test public void testGetSubjectByName() { Subject subject = coreService.getSubjectByName("subject-1", false); assertEquals(Integer.valueOf(1), subject.getId()); }
public SubjectImpl getSubjectByName(String name, boolean initialize) { SubjectImpl subject = subjectRepository.findByName(name); if (initialize) { initializeSubject(subject); } return subject; }
CoreService { public SubjectImpl getSubjectByName(String name, boolean initialize) { SubjectImpl subject = subjectRepository.findByName(name); if (initialize) { initializeSubject(subject); } return subject; } }
CoreService { public SubjectImpl getSubjectByName(String name, boolean initialize) { SubjectImpl subject = subjectRepository.findByName(name); if (initialize) { initializeSubject(subject); } return subject; } }
CoreService { public SubjectImpl getSubjectByName(String name, boolean initialize) { SubjectImpl subject = subjectRepository.findByName(name); if (initialize) { initializeSubject(subject); } return subject; } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
CoreService { public SubjectImpl getSubjectByName(String name, boolean initialize) { SubjectImpl subject = subjectRepository.findByName(name); if (initialize) { initializeSubject(subject); } return subject; } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
@Test public void testGetSubjects() { List<SubjectImpl> subjects = coreService.getSubjects(); assertEquals(3, subjects.size()); assertEquals("subject-1", subjects.get(0).getName()); assertEquals("subject-2", subjects.get(1).getName()); assertEquals("subject-3", subjects.get(2).getName()); }
public List<SubjectImpl> getSubjects() { return subjectRepository.findAll(); }
CoreService { public List<SubjectImpl> getSubjects() { return subjectRepository.findAll(); } }
CoreService { public List<SubjectImpl> getSubjects() { return subjectRepository.findAll(); } }
CoreService { public List<SubjectImpl> getSubjects() { return subjectRepository.findAll(); } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
CoreService { public List<SubjectImpl> getSubjects() { return subjectRepository.findAll(); } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
@Test public void testLoginPrincipalWithGroup() { servletRequest.addUserRole("subject-1"); Mockito.when(environment.getServletRequest()).thenReturn(servletRequest); Principal principal = Mockito.mock(Principal.class); boolean success = coreService.login(environment, principal); assertTrue(success); Mockito.verify(environment).setSubject(Mockito.any(SubjectImpl.class)); logout(); }
public boolean login(Environment env, Principal principal) { SubjectImpl loginSubject = null; SubjectImpl subject = getSubjectByName(principal.getName(), false); if (null != subject) { if (verifySubject(UserType.GLOBAL_USER.equals(subject.getUserType()), subject, env, "{} must be a global user!")) { LOGGER.info("user {} found", principal.getName()); loginSubject = subject; } } else { LOGGER.info("Subject authentication failed. Trying to authenticate based on LDAP group membership."); loginSubject = new SubjectImpl(); loginSubject.setName(principal.getName()); boolean hasAnyRole = false; List<SubjectImpl> globalGroups = getSubjectsByType(UserType.GLOBAL_GROUP); HttpServletRequest request = ((DefaultEnvironment) env).getServletRequest(); for (Subject globalGroup : globalGroups) { if (request.isUserInRole(globalGroup.getName())) { LOGGER.info("user '{}' belongs to group '{}'", principal.getName(), globalGroup.getName()); hasAnyRole = true; for (Group group : globalGroup.getGroups()) { initGroup(group); if (!loginSubject.getGroups().contains(group)) { loginSubject.getGroups().add(group); loginSubject.setLanguage(globalGroup.getLanguage()); loginSubject.setRealname(globalGroup.getName()); } } } } if (hasAnyRole) { LOGGER.info("User '{}' successfully authenticated.", principal.getName()); } else { loginSubject = null; LOGGER.error("No valid group membership found for user '{}'", principal.getName()); } } return login(env, loginSubject); }
CoreService { public boolean login(Environment env, Principal principal) { SubjectImpl loginSubject = null; SubjectImpl subject = getSubjectByName(principal.getName(), false); if (null != subject) { if (verifySubject(UserType.GLOBAL_USER.equals(subject.getUserType()), subject, env, "{} must be a global user!")) { LOGGER.info("user {} found", principal.getName()); loginSubject = subject; } } else { LOGGER.info("Subject authentication failed. Trying to authenticate based on LDAP group membership."); loginSubject = new SubjectImpl(); loginSubject.setName(principal.getName()); boolean hasAnyRole = false; List<SubjectImpl> globalGroups = getSubjectsByType(UserType.GLOBAL_GROUP); HttpServletRequest request = ((DefaultEnvironment) env).getServletRequest(); for (Subject globalGroup : globalGroups) { if (request.isUserInRole(globalGroup.getName())) { LOGGER.info("user '{}' belongs to group '{}'", principal.getName(), globalGroup.getName()); hasAnyRole = true; for (Group group : globalGroup.getGroups()) { initGroup(group); if (!loginSubject.getGroups().contains(group)) { loginSubject.getGroups().add(group); loginSubject.setLanguage(globalGroup.getLanguage()); loginSubject.setRealname(globalGroup.getName()); } } } } if (hasAnyRole) { LOGGER.info("User '{}' successfully authenticated.", principal.getName()); } else { loginSubject = null; LOGGER.error("No valid group membership found for user '{}'", principal.getName()); } } return login(env, loginSubject); } }
CoreService { public boolean login(Environment env, Principal principal) { SubjectImpl loginSubject = null; SubjectImpl subject = getSubjectByName(principal.getName(), false); if (null != subject) { if (verifySubject(UserType.GLOBAL_USER.equals(subject.getUserType()), subject, env, "{} must be a global user!")) { LOGGER.info("user {} found", principal.getName()); loginSubject = subject; } } else { LOGGER.info("Subject authentication failed. Trying to authenticate based on LDAP group membership."); loginSubject = new SubjectImpl(); loginSubject.setName(principal.getName()); boolean hasAnyRole = false; List<SubjectImpl> globalGroups = getSubjectsByType(UserType.GLOBAL_GROUP); HttpServletRequest request = ((DefaultEnvironment) env).getServletRequest(); for (Subject globalGroup : globalGroups) { if (request.isUserInRole(globalGroup.getName())) { LOGGER.info("user '{}' belongs to group '{}'", principal.getName(), globalGroup.getName()); hasAnyRole = true; for (Group group : globalGroup.getGroups()) { initGroup(group); if (!loginSubject.getGroups().contains(group)) { loginSubject.getGroups().add(group); loginSubject.setLanguage(globalGroup.getLanguage()); loginSubject.setRealname(globalGroup.getName()); } } } } if (hasAnyRole) { LOGGER.info("User '{}' successfully authenticated.", principal.getName()); } else { loginSubject = null; LOGGER.error("No valid group membership found for user '{}'", principal.getName()); } } return login(env, loginSubject); } }
CoreService { public boolean login(Environment env, Principal principal) { SubjectImpl loginSubject = null; SubjectImpl subject = getSubjectByName(principal.getName(), false); if (null != subject) { if (verifySubject(UserType.GLOBAL_USER.equals(subject.getUserType()), subject, env, "{} must be a global user!")) { LOGGER.info("user {} found", principal.getName()); loginSubject = subject; } } else { LOGGER.info("Subject authentication failed. Trying to authenticate based on LDAP group membership."); loginSubject = new SubjectImpl(); loginSubject.setName(principal.getName()); boolean hasAnyRole = false; List<SubjectImpl> globalGroups = getSubjectsByType(UserType.GLOBAL_GROUP); HttpServletRequest request = ((DefaultEnvironment) env).getServletRequest(); for (Subject globalGroup : globalGroups) { if (request.isUserInRole(globalGroup.getName())) { LOGGER.info("user '{}' belongs to group '{}'", principal.getName(), globalGroup.getName()); hasAnyRole = true; for (Group group : globalGroup.getGroups()) { initGroup(group); if (!loginSubject.getGroups().contains(group)) { loginSubject.getGroups().add(group); loginSubject.setLanguage(globalGroup.getLanguage()); loginSubject.setRealname(globalGroup.getName()); } } } } if (hasAnyRole) { LOGGER.info("User '{}' successfully authenticated.", principal.getName()); } else { loginSubject = null; LOGGER.error("No valid group membership found for user '{}'", principal.getName()); } } return login(env, loginSubject); } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
CoreService { public boolean login(Environment env, Principal principal) { SubjectImpl loginSubject = null; SubjectImpl subject = getSubjectByName(principal.getName(), false); if (null != subject) { if (verifySubject(UserType.GLOBAL_USER.equals(subject.getUserType()), subject, env, "{} must be a global user!")) { LOGGER.info("user {} found", principal.getName()); loginSubject = subject; } } else { LOGGER.info("Subject authentication failed. Trying to authenticate based on LDAP group membership."); loginSubject = new SubjectImpl(); loginSubject.setName(principal.getName()); boolean hasAnyRole = false; List<SubjectImpl> globalGroups = getSubjectsByType(UserType.GLOBAL_GROUP); HttpServletRequest request = ((DefaultEnvironment) env).getServletRequest(); for (Subject globalGroup : globalGroups) { if (request.isUserInRole(globalGroup.getName())) { LOGGER.info("user '{}' belongs to group '{}'", principal.getName(), globalGroup.getName()); hasAnyRole = true; for (Group group : globalGroup.getGroups()) { initGroup(group); if (!loginSubject.getGroups().contains(group)) { loginSubject.getGroups().add(group); loginSubject.setLanguage(globalGroup.getLanguage()); loginSubject.setRealname(globalGroup.getName()); } } } } if (hasAnyRole) { LOGGER.info("User '{}' successfully authenticated.", principal.getName()); } else { loginSubject = null; LOGGER.error("No valid group membership found for user '{}'", principal.getName()); } } return login(env, loginSubject); } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
@Test public void testLoginGroup() { SubjectImpl authSubject = new SubjectImpl(); authSubject.setDigest(AppNGTestDataProvider.DIGEST); authSubject.setSalt(AppNGTestDataProvider.SALT); authSubject.setEmail("[email protected]"); authSubject.setTimeZone(TimeZone.getDefault().getDisplayName()); authSubject.setLanguage(Locale.ENGLISH.getLanguage()); authSubject.setName("johndoe"); authSubject.setRealname("John Doe"); boolean success = coreService.loginGroup(environment, authSubject, "test", 1); assertTrue(success); ArgumentCaptor<Subject> subjectCaptor = ArgumentCaptor.forClass(Subject.class); Mockito.verify(environment).setSubject(subjectCaptor.capture()); Subject subject = subjectCaptor.getValue(); Assert.assertEquals(authSubject.getEmail(), subject.getEmail()); Assert.assertEquals(authSubject.getLanguage(), subject.getLanguage()); Assert.assertEquals(authSubject.getTimeZone(), subject.getTimeZone()); Assert.assertEquals(authSubject.getAuthName(), subject.getName()); Assert.assertEquals(authSubject.getRealname(), subject.getRealname()); logout(); }
public boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId) { Group group = groupRepository.getGroup(groupId); if (null != group) { if (isValidPassword(authSubject, password)) { SubjectImpl subject = new SubjectImpl(); subject.getGroups().add(group); subject.setLanguage(authSubject.getLanguage()); subject.setTimeZone(authSubject.getTimeZone()); subject.setRealname(authSubject.getRealname()); subject.setName(authSubject.getAuthName()); subject.setEmail(authSubject.getEmail()); return login(env, subject); } } else { LOGGER.warn("no such group: {}", groupId); } return false; }
CoreService { public boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId) { Group group = groupRepository.getGroup(groupId); if (null != group) { if (isValidPassword(authSubject, password)) { SubjectImpl subject = new SubjectImpl(); subject.getGroups().add(group); subject.setLanguage(authSubject.getLanguage()); subject.setTimeZone(authSubject.getTimeZone()); subject.setRealname(authSubject.getRealname()); subject.setName(authSubject.getAuthName()); subject.setEmail(authSubject.getEmail()); return login(env, subject); } } else { LOGGER.warn("no such group: {}", groupId); } return false; } }
CoreService { public boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId) { Group group = groupRepository.getGroup(groupId); if (null != group) { if (isValidPassword(authSubject, password)) { SubjectImpl subject = new SubjectImpl(); subject.getGroups().add(group); subject.setLanguage(authSubject.getLanguage()); subject.setTimeZone(authSubject.getTimeZone()); subject.setRealname(authSubject.getRealname()); subject.setName(authSubject.getAuthName()); subject.setEmail(authSubject.getEmail()); return login(env, subject); } } else { LOGGER.warn("no such group: {}", groupId); } return false; } }
CoreService { public boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId) { Group group = groupRepository.getGroup(groupId); if (null != group) { if (isValidPassword(authSubject, password)) { SubjectImpl subject = new SubjectImpl(); subject.getGroups().add(group); subject.setLanguage(authSubject.getLanguage()); subject.setTimeZone(authSubject.getTimeZone()); subject.setRealname(authSubject.getRealname()); subject.setName(authSubject.getAuthName()); subject.setEmail(authSubject.getEmail()); return login(env, subject); } } else { LOGGER.warn("no such group: {}", groupId); } return false; } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
CoreService { public boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId) { Group group = groupRepository.getGroup(groupId); if (null != group) { if (isValidPassword(authSubject, password)) { SubjectImpl subject = new SubjectImpl(); subject.getGroups().add(group); subject.setLanguage(authSubject.getLanguage()); subject.setTimeZone(authSubject.getTimeZone()); subject.setRealname(authSubject.getRealname()); subject.setName(authSubject.getAuthName()); subject.setEmail(authSubject.getEmail()); return login(env, subject); } } else { LOGGER.warn("no such group: {}", groupId); } return false; } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
@Test public void testLogin() { boolean success = coreService.login(null, environment, "subject-3", "test"); assertTrue(success); Mockito.verify(environment).setSubject(Mockito.any(SubjectImpl.class)); SubjectImpl subject = coreService.getSubjectByName("subject-3", true); assertNotNull(subject.getLastLogin()); assertFalse(subject.isLocked()); assertNotNull(envSubject); assertFalse(envSubject.isLocked()); logout(); }
public boolean login(Environment env, Principal principal) { SubjectImpl loginSubject = null; SubjectImpl subject = getSubjectByName(principal.getName(), false); if (null != subject) { if (verifySubject(UserType.GLOBAL_USER.equals(subject.getUserType()), subject, env, "{} must be a global user!")) { LOGGER.info("user {} found", principal.getName()); loginSubject = subject; } } else { LOGGER.info("Subject authentication failed. Trying to authenticate based on LDAP group membership."); loginSubject = new SubjectImpl(); loginSubject.setName(principal.getName()); boolean hasAnyRole = false; List<SubjectImpl> globalGroups = getSubjectsByType(UserType.GLOBAL_GROUP); HttpServletRequest request = ((DefaultEnvironment) env).getServletRequest(); for (Subject globalGroup : globalGroups) { if (request.isUserInRole(globalGroup.getName())) { LOGGER.info("user '{}' belongs to group '{}'", principal.getName(), globalGroup.getName()); hasAnyRole = true; for (Group group : globalGroup.getGroups()) { initGroup(group); if (!loginSubject.getGroups().contains(group)) { loginSubject.getGroups().add(group); loginSubject.setLanguage(globalGroup.getLanguage()); loginSubject.setRealname(globalGroup.getName()); } } } } if (hasAnyRole) { LOGGER.info("User '{}' successfully authenticated.", principal.getName()); } else { loginSubject = null; LOGGER.error("No valid group membership found for user '{}'", principal.getName()); } } return login(env, loginSubject); }
CoreService { public boolean login(Environment env, Principal principal) { SubjectImpl loginSubject = null; SubjectImpl subject = getSubjectByName(principal.getName(), false); if (null != subject) { if (verifySubject(UserType.GLOBAL_USER.equals(subject.getUserType()), subject, env, "{} must be a global user!")) { LOGGER.info("user {} found", principal.getName()); loginSubject = subject; } } else { LOGGER.info("Subject authentication failed. Trying to authenticate based on LDAP group membership."); loginSubject = new SubjectImpl(); loginSubject.setName(principal.getName()); boolean hasAnyRole = false; List<SubjectImpl> globalGroups = getSubjectsByType(UserType.GLOBAL_GROUP); HttpServletRequest request = ((DefaultEnvironment) env).getServletRequest(); for (Subject globalGroup : globalGroups) { if (request.isUserInRole(globalGroup.getName())) { LOGGER.info("user '{}' belongs to group '{}'", principal.getName(), globalGroup.getName()); hasAnyRole = true; for (Group group : globalGroup.getGroups()) { initGroup(group); if (!loginSubject.getGroups().contains(group)) { loginSubject.getGroups().add(group); loginSubject.setLanguage(globalGroup.getLanguage()); loginSubject.setRealname(globalGroup.getName()); } } } } if (hasAnyRole) { LOGGER.info("User '{}' successfully authenticated.", principal.getName()); } else { loginSubject = null; LOGGER.error("No valid group membership found for user '{}'", principal.getName()); } } return login(env, loginSubject); } }
CoreService { public boolean login(Environment env, Principal principal) { SubjectImpl loginSubject = null; SubjectImpl subject = getSubjectByName(principal.getName(), false); if (null != subject) { if (verifySubject(UserType.GLOBAL_USER.equals(subject.getUserType()), subject, env, "{} must be a global user!")) { LOGGER.info("user {} found", principal.getName()); loginSubject = subject; } } else { LOGGER.info("Subject authentication failed. Trying to authenticate based on LDAP group membership."); loginSubject = new SubjectImpl(); loginSubject.setName(principal.getName()); boolean hasAnyRole = false; List<SubjectImpl> globalGroups = getSubjectsByType(UserType.GLOBAL_GROUP); HttpServletRequest request = ((DefaultEnvironment) env).getServletRequest(); for (Subject globalGroup : globalGroups) { if (request.isUserInRole(globalGroup.getName())) { LOGGER.info("user '{}' belongs to group '{}'", principal.getName(), globalGroup.getName()); hasAnyRole = true; for (Group group : globalGroup.getGroups()) { initGroup(group); if (!loginSubject.getGroups().contains(group)) { loginSubject.getGroups().add(group); loginSubject.setLanguage(globalGroup.getLanguage()); loginSubject.setRealname(globalGroup.getName()); } } } } if (hasAnyRole) { LOGGER.info("User '{}' successfully authenticated.", principal.getName()); } else { loginSubject = null; LOGGER.error("No valid group membership found for user '{}'", principal.getName()); } } return login(env, loginSubject); } }
CoreService { public boolean login(Environment env, Principal principal) { SubjectImpl loginSubject = null; SubjectImpl subject = getSubjectByName(principal.getName(), false); if (null != subject) { if (verifySubject(UserType.GLOBAL_USER.equals(subject.getUserType()), subject, env, "{} must be a global user!")) { LOGGER.info("user {} found", principal.getName()); loginSubject = subject; } } else { LOGGER.info("Subject authentication failed. Trying to authenticate based on LDAP group membership."); loginSubject = new SubjectImpl(); loginSubject.setName(principal.getName()); boolean hasAnyRole = false; List<SubjectImpl> globalGroups = getSubjectsByType(UserType.GLOBAL_GROUP); HttpServletRequest request = ((DefaultEnvironment) env).getServletRequest(); for (Subject globalGroup : globalGroups) { if (request.isUserInRole(globalGroup.getName())) { LOGGER.info("user '{}' belongs to group '{}'", principal.getName(), globalGroup.getName()); hasAnyRole = true; for (Group group : globalGroup.getGroups()) { initGroup(group); if (!loginSubject.getGroups().contains(group)) { loginSubject.getGroups().add(group); loginSubject.setLanguage(globalGroup.getLanguage()); loginSubject.setRealname(globalGroup.getName()); } } } } if (hasAnyRole) { LOGGER.info("User '{}' successfully authenticated.", principal.getName()); } else { loginSubject = null; LOGGER.error("No valid group membership found for user '{}'", principal.getName()); } } return login(env, loginSubject); } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
CoreService { public boolean login(Environment env, Principal principal) { SubjectImpl loginSubject = null; SubjectImpl subject = getSubjectByName(principal.getName(), false); if (null != subject) { if (verifySubject(UserType.GLOBAL_USER.equals(subject.getUserType()), subject, env, "{} must be a global user!")) { LOGGER.info("user {} found", principal.getName()); loginSubject = subject; } } else { LOGGER.info("Subject authentication failed. Trying to authenticate based on LDAP group membership."); loginSubject = new SubjectImpl(); loginSubject.setName(principal.getName()); boolean hasAnyRole = false; List<SubjectImpl> globalGroups = getSubjectsByType(UserType.GLOBAL_GROUP); HttpServletRequest request = ((DefaultEnvironment) env).getServletRequest(); for (Subject globalGroup : globalGroups) { if (request.isUserInRole(globalGroup.getName())) { LOGGER.info("user '{}' belongs to group '{}'", principal.getName(), globalGroup.getName()); hasAnyRole = true; for (Group group : globalGroup.getGroups()) { initGroup(group); if (!loginSubject.getGroups().contains(group)) { loginSubject.getGroups().add(group); loginSubject.setLanguage(globalGroup.getLanguage()); loginSubject.setRealname(globalGroup.getName()); } } } } if (hasAnyRole) { LOGGER.info("User '{}' successfully authenticated.", principal.getName()); } else { loginSubject = null; LOGGER.error("No valid group membership found for user '{}'", principal.getName()); } } return login(env, loginSubject); } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
@Test public void testProvideApplication() throws URISyntaxException, BusinessException { RepositoryImpl repository = new RepositoryImpl(); repository.setActive(true); repository.setName("testrepo"); repository.setRepositoryMode(RepositoryMode.STABLE); repository.setRepositoryType(RepositoryType.LOCAL); URI uri = getClass().getClassLoader().getResource("zip").toURI(); repository.setUri(uri); coreService.createRepository(repository); String applicationName = "demo-application"; String applicationVersion = "1.5.2"; String applicationTimestamp = "2012-11-27-1305"; String appngVersion = "1.0.0-M1"; coreService.installPackage(repository.getId(), applicationName, applicationVersion, applicationTimestamp, true, false, true); Application application = coreService.findApplicationByName(applicationName); ((ApplicationImpl) application).setDisplayName("a cool display name"); validateApplication(appngVersion, applicationName, applicationVersion, applicationTimestamp, application); assertEquals("bar", application.getProperties().getString("foo")); Property property = ((PropertyHolder) application.getProperties()).getProperty("foo"); assertEquals("a foo property", property.getDescription()); assertEquals(Property.Type.TEXT, property.getType()); Property multiline = ((PropertyHolder) application.getProperties()).getProperty("clobValue"); assertEquals(Property.Type.MULTILINE, multiline.getType()); assertEquals("a\nb\nc", application.getProperties().getClob("clobValue")); }
private ApplicationImpl provideApplication(PackageArchive applicationArchive, boolean isFileBased, boolean isPrivileged, boolean isHidden, FieldProcessor fp, boolean updateHiddenAndPrivileged) throws BusinessException { ApplicationInfo applicationInfo = (ApplicationInfo) applicationArchive.getPackageInfo(); String applicationName = applicationInfo.getName(); String applicationVersion = applicationInfo.getVersion(); File outputDir = getApplicationFolder(null, applicationName); ApplicationImpl application = applicationRepository.findByName(applicationName); if (null == application) { LOGGER.info("deploying application {}-{}", applicationName, applicationVersion); application = RepositoryImpl.getApplication(applicationInfo); application.setFileBased(isFileBased); application.setPrivileged(isPrivileged); application.setHidden(isHidden); createApplication(application, applicationInfo, fp); } else { LOGGER.info("updating application {}-{}", applicationName, applicationVersion); if (updateHiddenAndPrivileged) { application.setPrivileged(isPrivileged); application.setHidden(isHidden); } RepositoryImpl.getApplication(application, applicationInfo); } updateApplication(application, applicationArchive, outputDir); return application; }
CoreService { private ApplicationImpl provideApplication(PackageArchive applicationArchive, boolean isFileBased, boolean isPrivileged, boolean isHidden, FieldProcessor fp, boolean updateHiddenAndPrivileged) throws BusinessException { ApplicationInfo applicationInfo = (ApplicationInfo) applicationArchive.getPackageInfo(); String applicationName = applicationInfo.getName(); String applicationVersion = applicationInfo.getVersion(); File outputDir = getApplicationFolder(null, applicationName); ApplicationImpl application = applicationRepository.findByName(applicationName); if (null == application) { LOGGER.info("deploying application {}-{}", applicationName, applicationVersion); application = RepositoryImpl.getApplication(applicationInfo); application.setFileBased(isFileBased); application.setPrivileged(isPrivileged); application.setHidden(isHidden); createApplication(application, applicationInfo, fp); } else { LOGGER.info("updating application {}-{}", applicationName, applicationVersion); if (updateHiddenAndPrivileged) { application.setPrivileged(isPrivileged); application.setHidden(isHidden); } RepositoryImpl.getApplication(application, applicationInfo); } updateApplication(application, applicationArchive, outputDir); return application; } }
CoreService { private ApplicationImpl provideApplication(PackageArchive applicationArchive, boolean isFileBased, boolean isPrivileged, boolean isHidden, FieldProcessor fp, boolean updateHiddenAndPrivileged) throws BusinessException { ApplicationInfo applicationInfo = (ApplicationInfo) applicationArchive.getPackageInfo(); String applicationName = applicationInfo.getName(); String applicationVersion = applicationInfo.getVersion(); File outputDir = getApplicationFolder(null, applicationName); ApplicationImpl application = applicationRepository.findByName(applicationName); if (null == application) { LOGGER.info("deploying application {}-{}", applicationName, applicationVersion); application = RepositoryImpl.getApplication(applicationInfo); application.setFileBased(isFileBased); application.setPrivileged(isPrivileged); application.setHidden(isHidden); createApplication(application, applicationInfo, fp); } else { LOGGER.info("updating application {}-{}", applicationName, applicationVersion); if (updateHiddenAndPrivileged) { application.setPrivileged(isPrivileged); application.setHidden(isHidden); } RepositoryImpl.getApplication(application, applicationInfo); } updateApplication(application, applicationArchive, outputDir); return application; } }
CoreService { private ApplicationImpl provideApplication(PackageArchive applicationArchive, boolean isFileBased, boolean isPrivileged, boolean isHidden, FieldProcessor fp, boolean updateHiddenAndPrivileged) throws BusinessException { ApplicationInfo applicationInfo = (ApplicationInfo) applicationArchive.getPackageInfo(); String applicationName = applicationInfo.getName(); String applicationVersion = applicationInfo.getVersion(); File outputDir = getApplicationFolder(null, applicationName); ApplicationImpl application = applicationRepository.findByName(applicationName); if (null == application) { LOGGER.info("deploying application {}-{}", applicationName, applicationVersion); application = RepositoryImpl.getApplication(applicationInfo); application.setFileBased(isFileBased); application.setPrivileged(isPrivileged); application.setHidden(isHidden); createApplication(application, applicationInfo, fp); } else { LOGGER.info("updating application {}-{}", applicationName, applicationVersion); if (updateHiddenAndPrivileged) { application.setPrivileged(isPrivileged); application.setHidden(isHidden); } RepositoryImpl.getApplication(application, applicationInfo); } updateApplication(application, applicationArchive, outputDir); return application; } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
CoreService { private ApplicationImpl provideApplication(PackageArchive applicationArchive, boolean isFileBased, boolean isPrivileged, boolean isHidden, FieldProcessor fp, boolean updateHiddenAndPrivileged) throws BusinessException { ApplicationInfo applicationInfo = (ApplicationInfo) applicationArchive.getPackageInfo(); String applicationName = applicationInfo.getName(); String applicationVersion = applicationInfo.getVersion(); File outputDir = getApplicationFolder(null, applicationName); ApplicationImpl application = applicationRepository.findByName(applicationName); if (null == application) { LOGGER.info("deploying application {}-{}", applicationName, applicationVersion); application = RepositoryImpl.getApplication(applicationInfo); application.setFileBased(isFileBased); application.setPrivileged(isPrivileged); application.setHidden(isHidden); createApplication(application, applicationInfo, fp); } else { LOGGER.info("updating application {}-{}", applicationName, applicationVersion); if (updateHiddenAndPrivileged) { application.setPrivileged(isPrivileged); application.setHidden(isHidden); } RepositoryImpl.getApplication(application, applicationInfo); } updateApplication(application, applicationArchive, outputDir); return application; } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
@Test(expected = BusinessException.class) public void testReloadRepository() throws BusinessException { coreService.reloadRepository(1); }
protected void reloadRepository(Integer repositoryId) throws BusinessException { if (null != repositoryId) { RepositoryImpl repository = repoRepository.findOne(repositoryId); if (null != repository) { try { repository.reload(); } catch (Exception e) { throw new BusinessException("Unable to reload repository with ID " + repositoryId, e); } } } }
CoreService { protected void reloadRepository(Integer repositoryId) throws BusinessException { if (null != repositoryId) { RepositoryImpl repository = repoRepository.findOne(repositoryId); if (null != repository) { try { repository.reload(); } catch (Exception e) { throw new BusinessException("Unable to reload repository with ID " + repositoryId, e); } } } } }
CoreService { protected void reloadRepository(Integer repositoryId) throws BusinessException { if (null != repositoryId) { RepositoryImpl repository = repoRepository.findOne(repositoryId); if (null != repository) { try { repository.reload(); } catch (Exception e) { throw new BusinessException("Unable to reload repository with ID " + repositoryId, e); } } } } }
CoreService { protected void reloadRepository(Integer repositoryId) throws BusinessException { if (null != repositoryId) { RepositoryImpl repository = repoRepository.findOne(repositoryId); if (null != repository) { try { repository.reload(); } catch (Exception e) { throw new BusinessException("Unable to reload repository with ID " + repositoryId, e); } } } } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
CoreService { protected void reloadRepository(Integer repositoryId) throws BusinessException { if (null != repositoryId) { RepositoryImpl repository = repoRepository.findOne(repositoryId); if (null != repository) { try { repository.reload(); } catch (Exception e) { throw new BusinessException("Unable to reload repository with ID " + repositoryId, e); } } } } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
@Test @Ignore public void testResetConnection() { }
public void resetConnection(FieldProcessor fp, Integer conId) { SiteApplication siteApplication = siteApplicationRepository.findByDatabaseConnectionId(conId); if (null != siteApplication) { String databasePrefix = getPlatform(true, false).getString(Platform.Property.DATABASE_PREFIX); databaseService.resetApplicationConnection(siteApplication, databasePrefix); } }
CoreService { public void resetConnection(FieldProcessor fp, Integer conId) { SiteApplication siteApplication = siteApplicationRepository.findByDatabaseConnectionId(conId); if (null != siteApplication) { String databasePrefix = getPlatform(true, false).getString(Platform.Property.DATABASE_PREFIX); databaseService.resetApplicationConnection(siteApplication, databasePrefix); } } }
CoreService { public void resetConnection(FieldProcessor fp, Integer conId) { SiteApplication siteApplication = siteApplicationRepository.findByDatabaseConnectionId(conId); if (null != siteApplication) { String databasePrefix = getPlatform(true, false).getString(Platform.Property.DATABASE_PREFIX); databaseService.resetApplicationConnection(siteApplication, databasePrefix); } } }
CoreService { public void resetConnection(FieldProcessor fp, Integer conId) { SiteApplication siteApplication = siteApplicationRepository.findByDatabaseConnectionId(conId); if (null != siteApplication) { String databasePrefix = getPlatform(true, false).getString(Platform.Property.DATABASE_PREFIX); databaseService.resetApplicationConnection(siteApplication, databasePrefix); } } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
CoreService { public void resetConnection(FieldProcessor fp, Integer conId) { SiteApplication siteApplication = siteApplicationRepository.findByDatabaseConnectionId(conId); if (null != siteApplication) { String databasePrefix = getPlatform(true, false).getString(Platform.Property.DATABASE_PREFIX); databaseService.resetApplicationConnection(siteApplication, databasePrefix); } } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
@Test public void testResetPassword() { AuthSubject subject = coreService.getSubjectByName("subject-3", true); String currentDigest = subject.getDigest(); String currentSalt = subject.getSalt(); SaltedDigest saltedDigest = new SaltedDigestSha1(); if (null == currentSalt) { currentSalt = saltedDigest.getSalt(); subject.setSalt(currentSalt); } String hash = saltedDigest.getDigest(subject.getEmail(), currentSalt); coreService.resetPassword(subject, new DefaultPasswordPolicy(), subject.getEmail(), hash); assertNull(subject.getSalt()); assertNotEquals(subject.getDigest(), currentDigest); assertTrue(subject.getDigest().startsWith(BCryptPasswordHandler.getPrefix())); }
public byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash) { SubjectImpl subject = getSubjectByName(authSubject.getAuthName(), false); if (canSubjectResetPassword(subject)) { PasswordHandler passwordHandler = getPasswordHandler(authSubject); if (passwordHandler.isValidPasswordResetDigest(hash)) { LOGGER.debug("setting new password for {}", email); String password = passwordPolicy.generatePassword(); getDefaultPasswordHandler(authSubject).applyPassword(password); subject.setDigest(authSubject.getDigest()); subject.setSalt(null); subject.setPasswordLastChanged(new Date()); subject.setPasswordChangePolicy(PasswordChangePolicy.MAY); return password.getBytes(); } else { LOGGER.debug("hash did not match, not setting new password for '{}'", authSubject.getAuthName()); } } else { LOGGER.debug("{} does not exist, is locked or must not change password!", authSubject.getAuthName()); } return null; }
CoreService { public byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash) { SubjectImpl subject = getSubjectByName(authSubject.getAuthName(), false); if (canSubjectResetPassword(subject)) { PasswordHandler passwordHandler = getPasswordHandler(authSubject); if (passwordHandler.isValidPasswordResetDigest(hash)) { LOGGER.debug("setting new password for {}", email); String password = passwordPolicy.generatePassword(); getDefaultPasswordHandler(authSubject).applyPassword(password); subject.setDigest(authSubject.getDigest()); subject.setSalt(null); subject.setPasswordLastChanged(new Date()); subject.setPasswordChangePolicy(PasswordChangePolicy.MAY); return password.getBytes(); } else { LOGGER.debug("hash did not match, not setting new password for '{}'", authSubject.getAuthName()); } } else { LOGGER.debug("{} does not exist, is locked or must not change password!", authSubject.getAuthName()); } return null; } }
CoreService { public byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash) { SubjectImpl subject = getSubjectByName(authSubject.getAuthName(), false); if (canSubjectResetPassword(subject)) { PasswordHandler passwordHandler = getPasswordHandler(authSubject); if (passwordHandler.isValidPasswordResetDigest(hash)) { LOGGER.debug("setting new password for {}", email); String password = passwordPolicy.generatePassword(); getDefaultPasswordHandler(authSubject).applyPassword(password); subject.setDigest(authSubject.getDigest()); subject.setSalt(null); subject.setPasswordLastChanged(new Date()); subject.setPasswordChangePolicy(PasswordChangePolicy.MAY); return password.getBytes(); } else { LOGGER.debug("hash did not match, not setting new password for '{}'", authSubject.getAuthName()); } } else { LOGGER.debug("{} does not exist, is locked or must not change password!", authSubject.getAuthName()); } return null; } }
CoreService { public byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash) { SubjectImpl subject = getSubjectByName(authSubject.getAuthName(), false); if (canSubjectResetPassword(subject)) { PasswordHandler passwordHandler = getPasswordHandler(authSubject); if (passwordHandler.isValidPasswordResetDigest(hash)) { LOGGER.debug("setting new password for {}", email); String password = passwordPolicy.generatePassword(); getDefaultPasswordHandler(authSubject).applyPassword(password); subject.setDigest(authSubject.getDigest()); subject.setSalt(null); subject.setPasswordLastChanged(new Date()); subject.setPasswordChangePolicy(PasswordChangePolicy.MAY); return password.getBytes(); } else { LOGGER.debug("hash did not match, not setting new password for '{}'", authSubject.getAuthName()); } } else { LOGGER.debug("{} does not exist, is locked or must not change password!", authSubject.getAuthName()); } return null; } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
CoreService { public byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash) { SubjectImpl subject = getSubjectByName(authSubject.getAuthName(), false); if (canSubjectResetPassword(subject)) { PasswordHandler passwordHandler = getPasswordHandler(authSubject); if (passwordHandler.isValidPasswordResetDigest(hash)) { LOGGER.debug("setting new password for {}", email); String password = passwordPolicy.generatePassword(); getDefaultPasswordHandler(authSubject).applyPassword(password); subject.setDigest(authSubject.getDigest()); subject.setSalt(null); subject.setPasswordLastChanged(new Date()); subject.setPasswordChangePolicy(PasswordChangePolicy.MAY); return password.getBytes(); } else { LOGGER.debug("hash did not match, not setting new password for '{}'", authSubject.getAuthName()); } } else { LOGGER.debug("{} does not exist, is locked or must not change password!", authSubject.getAuthName()); } return null; } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
@Test public void testFileCountMax() { assertTrue("fileCountMax(upload, 3)"); assertFalse("fileCountMax(upload, 1)"); assertFalse("fileCountMax(upload, 0)"); }
public static boolean fileCountMax(List<FormUpload> fUpload, int count) { return getNumberOfFiles(fUpload) <= count; }
RuleValidation { public static boolean fileCountMax(List<FormUpload> fUpload, int count) { return getNumberOfFiles(fUpload) <= count; } }
RuleValidation { public static boolean fileCountMax(List<FormUpload> fUpload, int count) { return getNumberOfFiles(fUpload) <= count; } RuleValidation(Request container); }
RuleValidation { public static boolean fileCountMax(List<FormUpload> fUpload, int count) { return getNumberOfFiles(fUpload) <= count; } RuleValidation(Request container); Map<String, List<FormUpload>> getFileParams(Map<String, List<FormUpload>> formUploads); boolean validate(String rule); static boolean string(String string); static boolean captcha(String value, String result); static boolean email(String string); static boolean equals(String string1, String string2); static boolean number(String string); static boolean number(String string, char separator); static boolean numberFractionDigits(String string, int digits, int fraction); static boolean number(String string, char separator, int digits, int fraction); static boolean regExp(String string, String regex); static boolean size(Object item, int size); static boolean sizeMax(Object item, int max); static boolean sizeMin(Object item, int min); static boolean sizeMinMax(Object item, int min, int max); static boolean fileType(List<FormUpload> fUpload, String types); static boolean fileSize(List<FormUpload> fUpload, String minSize, String maxSize); static boolean fileSizeMin(List<FormUpload> fUpload, String minSize); static boolean fileSizeMax(List<FormUpload> fUpload, String maxSize); static boolean fileCountMin(List<FormUpload> fUpload, int count); static boolean fileCountMax(List<FormUpload> fUpload, int count); static boolean fileCount(List<FormUpload> fUpload, int minCount, int maxCount); }
RuleValidation { public static boolean fileCountMax(List<FormUpload> fUpload, int count) { return getNumberOfFiles(fUpload) <= count; } RuleValidation(Request container); Map<String, List<FormUpload>> getFileParams(Map<String, List<FormUpload>> formUploads); boolean validate(String rule); static boolean string(String string); static boolean captcha(String value, String result); static boolean email(String string); static boolean equals(String string1, String string2); static boolean number(String string); static boolean number(String string, char separator); static boolean numberFractionDigits(String string, int digits, int fraction); static boolean number(String string, char separator, int digits, int fraction); static boolean regExp(String string, String regex); static boolean size(Object item, int size); static boolean sizeMax(Object item, int max); static boolean sizeMin(Object item, int min); static boolean sizeMinMax(Object item, int min, int max); static boolean fileType(List<FormUpload> fUpload, String types); static boolean fileSize(List<FormUpload> fUpload, String minSize, String maxSize); static boolean fileSizeMin(List<FormUpload> fUpload, String minSize); static boolean fileSizeMax(List<FormUpload> fUpload, String maxSize); static boolean fileCountMin(List<FormUpload> fUpload, int count); static boolean fileCountMax(List<FormUpload> fUpload, int count); static boolean fileCount(List<FormUpload> fUpload, int minCount, int maxCount); static final List<String> SHORT_RULES; }
@Test public void testRestoreSubject() { Subject subject = coreService.restoreSubject("subject-1"); assertTrue(subject.isAuthenticated()); assertNull(subject.getDigest()); assertNull(subject.getSalt()); }
public Subject restoreSubject(String name) { SubjectImpl subject = getSubjectByName(name, true); if (null != subject) { initAuthenticatedSubject(subject); LOGGER.trace("successfully restored subject '{}'", subject.getName()); } else { LOGGER.error("can not restore subject '{}'", name); } return subject; }
CoreService { public Subject restoreSubject(String name) { SubjectImpl subject = getSubjectByName(name, true); if (null != subject) { initAuthenticatedSubject(subject); LOGGER.trace("successfully restored subject '{}'", subject.getName()); } else { LOGGER.error("can not restore subject '{}'", name); } return subject; } }
CoreService { public Subject restoreSubject(String name) { SubjectImpl subject = getSubjectByName(name, true); if (null != subject) { initAuthenticatedSubject(subject); LOGGER.trace("successfully restored subject '{}'", subject.getName()); } else { LOGGER.error("can not restore subject '{}'", name); } return subject; } }
CoreService { public Subject restoreSubject(String name) { SubjectImpl subject = getSubjectByName(name, true); if (null != subject) { initAuthenticatedSubject(subject); LOGGER.trace("successfully restored subject '{}'", subject.getName()); } else { LOGGER.error("can not restore subject '{}'", name); } return subject; } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
CoreService { public Subject restoreSubject(String name) { SubjectImpl subject = getSubjectByName(name, true); if (null != subject) { initAuthenticatedSubject(subject); LOGGER.trace("successfully restored subject '{}'", subject.getName()); } else { LOGGER.error("can not restore subject '{}'", name); } return subject; } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
@Test public void testSaveProperties() { List<Property> props = new ArrayList<>(); PropertyImpl a = new PropertyImpl("foobaz.a", "a"); PropertyImpl b = new PropertyImpl("foobaz.b", "b"); props.add(a); props.add(b); coreService.saveProperties(new PropertyHolder("foobaz.", props)); assertEquals(a, coreService.getProperty("foobaz.a")); assertEquals(b, coreService.getProperty("foobaz.b")); }
protected void saveProperties(Properties properties) { Set<String> propertyNames = properties.getPropertyNames(); PropertyHolder propertyHolder = (PropertyHolder) properties; propertyNames.forEach(name -> saveProperty((PropertyImpl) propertyHolder.getProperty(name))); }
CoreService { protected void saveProperties(Properties properties) { Set<String> propertyNames = properties.getPropertyNames(); PropertyHolder propertyHolder = (PropertyHolder) properties; propertyNames.forEach(name -> saveProperty((PropertyImpl) propertyHolder.getProperty(name))); } }
CoreService { protected void saveProperties(Properties properties) { Set<String> propertyNames = properties.getPropertyNames(); PropertyHolder propertyHolder = (PropertyHolder) properties; propertyNames.forEach(name -> saveProperty((PropertyImpl) propertyHolder.getProperty(name))); } }
CoreService { protected void saveProperties(Properties properties) { Set<String> propertyNames = properties.getPropertyNames(); PropertyHolder propertyHolder = (PropertyHolder) properties; propertyNames.forEach(name -> saveProperty((PropertyImpl) propertyHolder.getProperty(name))); } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
CoreService { protected void saveProperties(Properties properties) { Set<String> propertyNames = properties.getPropertyNames(); PropertyHolder propertyHolder = (PropertyHolder) properties; propertyNames.forEach(name -> saveProperty((PropertyImpl) propertyHolder.getProperty(name))); } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
@Test public void testSaveProperty() { PropertyImpl property = coreService.saveProperty(new PropertyImpl("prop1", "value")); assertNotNull(property); assertNotNull(property.getVersion()); assertEquals("prop1", property.getId()); assertEquals("value", property.getString()); }
public PropertyImpl saveProperty(PropertyImpl property) { return propertyRepository.save(property); }
CoreService { public PropertyImpl saveProperty(PropertyImpl property) { return propertyRepository.save(property); } }
CoreService { public PropertyImpl saveProperty(PropertyImpl property) { return propertyRepository.save(property); } }
CoreService { public PropertyImpl saveProperty(PropertyImpl property) { return propertyRepository.save(property); } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
CoreService { public PropertyImpl saveProperty(PropertyImpl property) { return propertyRepository.save(property); } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
@Test @Ignore public void testShutdownSite() { }
public SiteImpl shutdownSite(Environment env, String siteName) { return shutdownSite(env, siteName, false); }
CoreService { public SiteImpl shutdownSite(Environment env, String siteName) { return shutdownSite(env, siteName, false); } }
CoreService { public SiteImpl shutdownSite(Environment env, String siteName) { return shutdownSite(env, siteName, false); } }
CoreService { public SiteImpl shutdownSite(Environment env, String siteName) { return shutdownSite(env, siteName, false); } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
CoreService { public SiteImpl shutdownSite(Environment env, String siteName) { return shutdownSite(env, siteName, false); } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
@Test @Ignore public void testSynchronizeApplicationResources() { }
protected void synchronizeApplicationResources(Environment env, Application application, boolean isFileBased) throws BusinessException { String convertDirection = ""; try { Application currentApplication = applicationRepository.findOne(application.getId()); File applicationFolder = getApplicationFolder(env, currentApplication); if (currentApplication.isFileBased() && !isFileBased) { convertDirection = "filebased to database"; LOGGER.info("application '{}' is beeing converted from {}", currentApplication.getName(), convertDirection); Resources resources = getResources(currentApplication, null, getApplicationRootFolder(env)); writeApplicationResources(currentApplication, false, null, resources.getResources()); deleteApplicationResources(application, applicationFolder); } else if (!currentApplication.isFileBased() && isFileBased) { convertDirection = "database to filebased"; LOGGER.info("application '{}' is beeing converted from {}", currentApplication.getName(), convertDirection); Resources resources = getResources(currentApplication, applicationFolder, null); writeApplicationResources(currentApplication, true, applicationFolder, resources.getResources()); deleteApplicationResources(currentApplication, applicationFolder); } } catch (InvalidConfigurationException e) { throw new BusinessException("error while transforming application '" + application.getName() + "' from " + convertDirection + ", application is in an erroneous state", e); } }
CoreService { protected void synchronizeApplicationResources(Environment env, Application application, boolean isFileBased) throws BusinessException { String convertDirection = ""; try { Application currentApplication = applicationRepository.findOne(application.getId()); File applicationFolder = getApplicationFolder(env, currentApplication); if (currentApplication.isFileBased() && !isFileBased) { convertDirection = "filebased to database"; LOGGER.info("application '{}' is beeing converted from {}", currentApplication.getName(), convertDirection); Resources resources = getResources(currentApplication, null, getApplicationRootFolder(env)); writeApplicationResources(currentApplication, false, null, resources.getResources()); deleteApplicationResources(application, applicationFolder); } else if (!currentApplication.isFileBased() && isFileBased) { convertDirection = "database to filebased"; LOGGER.info("application '{}' is beeing converted from {}", currentApplication.getName(), convertDirection); Resources resources = getResources(currentApplication, applicationFolder, null); writeApplicationResources(currentApplication, true, applicationFolder, resources.getResources()); deleteApplicationResources(currentApplication, applicationFolder); } } catch (InvalidConfigurationException e) { throw new BusinessException("error while transforming application '" + application.getName() + "' from " + convertDirection + ", application is in an erroneous state", e); } } }
CoreService { protected void synchronizeApplicationResources(Environment env, Application application, boolean isFileBased) throws BusinessException { String convertDirection = ""; try { Application currentApplication = applicationRepository.findOne(application.getId()); File applicationFolder = getApplicationFolder(env, currentApplication); if (currentApplication.isFileBased() && !isFileBased) { convertDirection = "filebased to database"; LOGGER.info("application '{}' is beeing converted from {}", currentApplication.getName(), convertDirection); Resources resources = getResources(currentApplication, null, getApplicationRootFolder(env)); writeApplicationResources(currentApplication, false, null, resources.getResources()); deleteApplicationResources(application, applicationFolder); } else if (!currentApplication.isFileBased() && isFileBased) { convertDirection = "database to filebased"; LOGGER.info("application '{}' is beeing converted from {}", currentApplication.getName(), convertDirection); Resources resources = getResources(currentApplication, applicationFolder, null); writeApplicationResources(currentApplication, true, applicationFolder, resources.getResources()); deleteApplicationResources(currentApplication, applicationFolder); } } catch (InvalidConfigurationException e) { throw new BusinessException("error while transforming application '" + application.getName() + "' from " + convertDirection + ", application is in an erroneous state", e); } } }
CoreService { protected void synchronizeApplicationResources(Environment env, Application application, boolean isFileBased) throws BusinessException { String convertDirection = ""; try { Application currentApplication = applicationRepository.findOne(application.getId()); File applicationFolder = getApplicationFolder(env, currentApplication); if (currentApplication.isFileBased() && !isFileBased) { convertDirection = "filebased to database"; LOGGER.info("application '{}' is beeing converted from {}", currentApplication.getName(), convertDirection); Resources resources = getResources(currentApplication, null, getApplicationRootFolder(env)); writeApplicationResources(currentApplication, false, null, resources.getResources()); deleteApplicationResources(application, applicationFolder); } else if (!currentApplication.isFileBased() && isFileBased) { convertDirection = "database to filebased"; LOGGER.info("application '{}' is beeing converted from {}", currentApplication.getName(), convertDirection); Resources resources = getResources(currentApplication, applicationFolder, null); writeApplicationResources(currentApplication, true, applicationFolder, resources.getResources()); deleteApplicationResources(currentApplication, applicationFolder); } } catch (InvalidConfigurationException e) { throw new BusinessException("error while transforming application '" + application.getName() + "' from " + convertDirection + ", application is in an erroneous state", e); } } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
CoreService { protected void synchronizeApplicationResources(Environment env, Application application, boolean isFileBased) throws BusinessException { String convertDirection = ""; try { Application currentApplication = applicationRepository.findOne(application.getId()); File applicationFolder = getApplicationFolder(env, currentApplication); if (currentApplication.isFileBased() && !isFileBased) { convertDirection = "filebased to database"; LOGGER.info("application '{}' is beeing converted from {}", currentApplication.getName(), convertDirection); Resources resources = getResources(currentApplication, null, getApplicationRootFolder(env)); writeApplicationResources(currentApplication, false, null, resources.getResources()); deleteApplicationResources(application, applicationFolder); } else if (!currentApplication.isFileBased() && isFileBased) { convertDirection = "database to filebased"; LOGGER.info("application '{}' is beeing converted from {}", currentApplication.getName(), convertDirection); Resources resources = getResources(currentApplication, applicationFolder, null); writeApplicationResources(currentApplication, true, applicationFolder, resources.getResources()); deleteApplicationResources(currentApplication, applicationFolder); } } catch (InvalidConfigurationException e) { throw new BusinessException("error while transforming application '" + application.getName() + "' from " + convertDirection + ", application is in an erroneous state", e); } } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
@Test public void testUnlinkApplicationFromSiteIntegerString() { MigrationStatus migrationStatus = coreService.unlinkApplicationFromSite(1, 1); assertEquals(MigrationStatus.NO_DB_SUPPORTED, migrationStatus); }
protected MigrationStatus unlinkApplicationFromSite(SiteApplication siteApplication) { Site site = siteApplication.getSite(); ((SiteImpl) site).getSiteApplications().remove(siteApplication); siteApplicationRepository.delete(siteApplication); deleteApplicationPropertiesFromSite(site, siteApplication.getApplication()); DatabaseConnection databaseConnection = siteApplication.getDatabaseConnection(); MigrationStatus status = MigrationStatus.NO_DB_SUPPORTED; if (null != databaseConnection) { databaseConnectionRepository.delete(databaseConnection); status = databaseService.dropDataBaseAndUser(databaseConnection); } String applicationName = siteApplication.getApplication().getName(); LOGGER.info("unlinking application {} from site {}, status of database-connection is {}", applicationName, site.getName(), status); auditableListener.createEvent(Type.INFO, String.format("Removed application %s from site %s", applicationName, site.getName())); if (MigrationStatus.DB_MIGRATED.equals(status)) { auditableListener.createEvent(Type.INFO, String.format("Dropped database %s and user %s", databaseConnection.getJdbcUrl(), databaseConnection.getUserName())); } else if (MigrationStatus.ERROR.equals(status)) { auditableListener.createEvent(Type.ERROR, String.format("Error while dropping database %s and user %s", databaseConnection.getJdbcUrl(), databaseConnection.getUserName())); } return status; }
CoreService { protected MigrationStatus unlinkApplicationFromSite(SiteApplication siteApplication) { Site site = siteApplication.getSite(); ((SiteImpl) site).getSiteApplications().remove(siteApplication); siteApplicationRepository.delete(siteApplication); deleteApplicationPropertiesFromSite(site, siteApplication.getApplication()); DatabaseConnection databaseConnection = siteApplication.getDatabaseConnection(); MigrationStatus status = MigrationStatus.NO_DB_SUPPORTED; if (null != databaseConnection) { databaseConnectionRepository.delete(databaseConnection); status = databaseService.dropDataBaseAndUser(databaseConnection); } String applicationName = siteApplication.getApplication().getName(); LOGGER.info("unlinking application {} from site {}, status of database-connection is {}", applicationName, site.getName(), status); auditableListener.createEvent(Type.INFO, String.format("Removed application %s from site %s", applicationName, site.getName())); if (MigrationStatus.DB_MIGRATED.equals(status)) { auditableListener.createEvent(Type.INFO, String.format("Dropped database %s and user %s", databaseConnection.getJdbcUrl(), databaseConnection.getUserName())); } else if (MigrationStatus.ERROR.equals(status)) { auditableListener.createEvent(Type.ERROR, String.format("Error while dropping database %s and user %s", databaseConnection.getJdbcUrl(), databaseConnection.getUserName())); } return status; } }
CoreService { protected MigrationStatus unlinkApplicationFromSite(SiteApplication siteApplication) { Site site = siteApplication.getSite(); ((SiteImpl) site).getSiteApplications().remove(siteApplication); siteApplicationRepository.delete(siteApplication); deleteApplicationPropertiesFromSite(site, siteApplication.getApplication()); DatabaseConnection databaseConnection = siteApplication.getDatabaseConnection(); MigrationStatus status = MigrationStatus.NO_DB_SUPPORTED; if (null != databaseConnection) { databaseConnectionRepository.delete(databaseConnection); status = databaseService.dropDataBaseAndUser(databaseConnection); } String applicationName = siteApplication.getApplication().getName(); LOGGER.info("unlinking application {} from site {}, status of database-connection is {}", applicationName, site.getName(), status); auditableListener.createEvent(Type.INFO, String.format("Removed application %s from site %s", applicationName, site.getName())); if (MigrationStatus.DB_MIGRATED.equals(status)) { auditableListener.createEvent(Type.INFO, String.format("Dropped database %s and user %s", databaseConnection.getJdbcUrl(), databaseConnection.getUserName())); } else if (MigrationStatus.ERROR.equals(status)) { auditableListener.createEvent(Type.ERROR, String.format("Error while dropping database %s and user %s", databaseConnection.getJdbcUrl(), databaseConnection.getUserName())); } return status; } }
CoreService { protected MigrationStatus unlinkApplicationFromSite(SiteApplication siteApplication) { Site site = siteApplication.getSite(); ((SiteImpl) site).getSiteApplications().remove(siteApplication); siteApplicationRepository.delete(siteApplication); deleteApplicationPropertiesFromSite(site, siteApplication.getApplication()); DatabaseConnection databaseConnection = siteApplication.getDatabaseConnection(); MigrationStatus status = MigrationStatus.NO_DB_SUPPORTED; if (null != databaseConnection) { databaseConnectionRepository.delete(databaseConnection); status = databaseService.dropDataBaseAndUser(databaseConnection); } String applicationName = siteApplication.getApplication().getName(); LOGGER.info("unlinking application {} from site {}, status of database-connection is {}", applicationName, site.getName(), status); auditableListener.createEvent(Type.INFO, String.format("Removed application %s from site %s", applicationName, site.getName())); if (MigrationStatus.DB_MIGRATED.equals(status)) { auditableListener.createEvent(Type.INFO, String.format("Dropped database %s and user %s", databaseConnection.getJdbcUrl(), databaseConnection.getUserName())); } else if (MigrationStatus.ERROR.equals(status)) { auditableListener.createEvent(Type.ERROR, String.format("Error while dropping database %s and user %s", databaseConnection.getJdbcUrl(), databaseConnection.getUserName())); } return status; } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
CoreService { protected MigrationStatus unlinkApplicationFromSite(SiteApplication siteApplication) { Site site = siteApplication.getSite(); ((SiteImpl) site).getSiteApplications().remove(siteApplication); siteApplicationRepository.delete(siteApplication); deleteApplicationPropertiesFromSite(site, siteApplication.getApplication()); DatabaseConnection databaseConnection = siteApplication.getDatabaseConnection(); MigrationStatus status = MigrationStatus.NO_DB_SUPPORTED; if (null != databaseConnection) { databaseConnectionRepository.delete(databaseConnection); status = databaseService.dropDataBaseAndUser(databaseConnection); } String applicationName = siteApplication.getApplication().getName(); LOGGER.info("unlinking application {} from site {}, status of database-connection is {}", applicationName, site.getName(), status); auditableListener.createEvent(Type.INFO, String.format("Removed application %s from site %s", applicationName, site.getName())); if (MigrationStatus.DB_MIGRATED.equals(status)) { auditableListener.createEvent(Type.INFO, String.format("Dropped database %s and user %s", databaseConnection.getJdbcUrl(), databaseConnection.getUserName())); } else if (MigrationStatus.ERROR.equals(status)) { auditableListener.createEvent(Type.ERROR, String.format("Error while dropping database %s and user %s", databaseConnection.getJdbcUrl(), databaseConnection.getUserName())); } return status; } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
@Test @Ignore public void testUnsetReloadRequired() { }
public void unsetReloadRequired(SiteApplication siteApplication) { siteApplication.setReloadRequired(false); siteApplicationRepository.findOne(siteApplication.getSiteApplicationId()).setReloadRequired(false); }
CoreService { public void unsetReloadRequired(SiteApplication siteApplication) { siteApplication.setReloadRequired(false); siteApplicationRepository.findOne(siteApplication.getSiteApplicationId()).setReloadRequired(false); } }
CoreService { public void unsetReloadRequired(SiteApplication siteApplication) { siteApplication.setReloadRequired(false); siteApplicationRepository.findOne(siteApplication.getSiteApplicationId()).setReloadRequired(false); } }
CoreService { public void unsetReloadRequired(SiteApplication siteApplication) { siteApplication.setReloadRequired(false); siteApplicationRepository.findOne(siteApplication.getSiteApplicationId()).setReloadRequired(false); } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
CoreService { public void unsetReloadRequired(SiteApplication siteApplication) { siteApplication.setReloadRequired(false); siteApplicationRepository.findOne(siteApplication.getSiteApplicationId()).setReloadRequired(false); } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
@Test public void testUpdatePassword() throws BusinessException { SubjectImpl subject = coreService.getSubjectByName("subject-3", false); PasswordPolicy dummyPolicy = new ConfigurablePasswordPolicy() { public ValidationResult validatePassword(String username, char[] currentPassword, char[] password) { return new ValidationResult(true, null); } }; ValidationResult updatePassword = coreService.updatePassword(dummyPolicy, "test".toCharArray(), "foobar".toCharArray(), subject); assertTrue(updatePassword.isValid()); }
public PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject) { PasswordPolicy.ValidationResult validationResult = policy.validatePassword(currentSubject.getAuthName(), currentPassword, password); if (validationResult.isValid()) { PasswordHandler passwordHandler = getDefaultPasswordHandler(currentSubject); passwordHandler.applyPassword(new String(password)); } return validationResult; }
CoreService { public PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject) { PasswordPolicy.ValidationResult validationResult = policy.validatePassword(currentSubject.getAuthName(), currentPassword, password); if (validationResult.isValid()) { PasswordHandler passwordHandler = getDefaultPasswordHandler(currentSubject); passwordHandler.applyPassword(new String(password)); } return validationResult; } }
CoreService { public PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject) { PasswordPolicy.ValidationResult validationResult = policy.validatePassword(currentSubject.getAuthName(), currentPassword, password); if (validationResult.isValid()) { PasswordHandler passwordHandler = getDefaultPasswordHandler(currentSubject); passwordHandler.applyPassword(new String(password)); } return validationResult; } }
CoreService { public PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject) { PasswordPolicy.ValidationResult validationResult = policy.validatePassword(currentSubject.getAuthName(), currentPassword, password); if (validationResult.isValid()) { PasswordHandler passwordHandler = getDefaultPasswordHandler(currentSubject); passwordHandler.applyPassword(new String(password)); } return validationResult; } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
CoreService { public PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject) { PasswordPolicy.ValidationResult validationResult = policy.validatePassword(currentSubject.getAuthName(), currentPassword, password); if (validationResult.isValid()) { PasswordHandler passwordHandler = getDefaultPasswordHandler(currentSubject); passwordHandler.applyPassword(new String(password)); } return validationResult; } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
@Test @Ignore public void testUpdateSubject() { }
public SubjectImpl updateSubject(SubjectImpl subject) { return subjectRepository.save(subject); }
CoreService { public SubjectImpl updateSubject(SubjectImpl subject) { return subjectRepository.save(subject); } }
CoreService { public SubjectImpl updateSubject(SubjectImpl subject) { return subjectRepository.save(subject); } }
CoreService { public SubjectImpl updateSubject(SubjectImpl subject) { return subjectRepository.save(subject); } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
CoreService { public SubjectImpl updateSubject(SubjectImpl subject) { return subjectRepository.save(subject); } Subject createSubject(SubjectImpl subject); PropertyHolder getPlatformProperties(); PlatformProperties initPlatformConfig(java.util.Properties defaultOverrides, String rootPath, Boolean devMode, boolean persist, boolean tempOverrides); Page<PropertyImpl> getProperties(String siteName, String applicationName); Page<PropertyImpl> getProperties(String siteName, String applicationName, Pageable pageable); PropertyImpl createProperty(Integer siteId, Integer applicationId, PropertyImpl property); SiteImpl getSite(Integer id); SiteImpl getSiteByName(String name); void saveSite(SiteImpl site); PropertyImpl saveProperty(PropertyImpl property); List<SubjectImpl> getSubjectsByType(UserType type); boolean isValidPassword(AuthSubject authSubject, String password); @Deprecated PasswordHandler getPasswordHandler(AuthSubject authSubject); PasswordHandler getDefaultPasswordHandler(AuthSubject authSubject); Subject restoreSubject(String name); boolean login(Environment env, Principal principal); boolean login(Environment env, String digest, int digestMaxValidity); boolean login(Site site, Environment env, String username, String password); boolean loginGroup(Environment env, AuthSubject authSubject, String password, Integer groupId); void logoutSubject(Environment env); PropertyImpl getProperty(String propertyId); void createSite(SiteImpl site); MigrationStatus assignApplicationToSite(SiteImpl site, Application application, boolean createProperties); PermissionImpl getPermission(String application, String name); PermissionImpl savePermission(PermissionImpl p); RepositoryImpl createRepository(RepositoryImpl repository); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased, FieldProcessor fp, boolean updateHiddenAndPrivileged); PackageInfo installPackage(final Integer repositoryId, final String name, final String version, String timestamp, final boolean isPrivileged, final boolean isHidden, final boolean isFileBased); Template provideTemplate(Integer repositoryId, String templateName, String templateVersion, String templateTimestamp); Integer deleteTemplate(String name); File getApplicationFolder(Environment env, String applicationName); byte[] resetPassword(AuthSubject authSubject, PasswordPolicy passwordPolicy, String email, String hash); String forgotPassword(AuthSubject authSubject); SubjectImpl updateSubject(SubjectImpl subject); AccessibleApplication findApplicationByName(String name); void updateApplication(ApplicationImpl application, boolean isFileBased); List<? extends Group> getGroups(); void deleteSite(String name, FieldProcessor fp); void setSiteActive(String name, boolean active); void deleteSite(Environment env, SiteImpl site); void cleanupSite(Environment env, SiteImpl site, boolean sendDeletedEvent); void deleteProperty(PropertyImpl prop); @Transactional(propagation = Propagation.REQUIRES_NEW) MigrationStatus unlinkApplicationFromSite(Integer siteId, Integer applicationId); void saveRole(RoleImpl role); void deleteRole(Role role); void deleteApplication(String applicationName, FieldProcessor fp); void deletePermission(Permission permission); void addApplicationRolesToGroup(String groupName, String applicationName, List<String> applicationRoleNames, boolean clear); void addGroupsToSubject(String userName, List<String> groupNames, boolean clear); List<DatabaseConnection> getDatabaseConnectionsForSite(Integer siteId); Page<DatabaseConnection> getDatabaseConnections(Integer siteId, FieldProcessor fp); DatabaseConnection getDatabaseConnection(Integer dcId, boolean clearPassword); PasswordPolicy.ValidationResult updatePassword(PasswordPolicy policy, char[] currentPassword, char[] password, SubjectImpl currentSubject); @Deprecated Boolean updatePassword(char[] password, char[] passwordConfirmation, SubjectImpl currentSubject); void resetConnection(FieldProcessor fp, Integer conId); GroupImpl createGroup(GroupImpl group); void deleteGroup(GroupImpl group); void deleteApplicationRepository(org.appng.core.model.Repository repository); void deleteSubject(Subject subject); SiteImpl shutdownSite(Environment env, String siteName); SiteImpl shutdownSite(Environment env, String siteName, boolean removeFromSiteMap); void unsetReloadRequired(SiteApplication siteApplication); void setSiteStartUpTime(SiteImpl site, Date date); Collection<ApplicationSubject> getApplicationSubjects(Integer applicationId, Site site); SubjectImpl getSubjectByName(String name, boolean initialize); Subject getSubjectById(Integer id, boolean initialize); org.appng.core.model.Repository getApplicationRepositoryByName(String repositoryName); void saveRepository(RepositoryImpl repo); List<ApplicationImpl> getApplications(); List<RoleImpl> getApplicationRolesForApplication(Integer applicationId); List<RoleImpl> getApplicationRoles(); List<RepositoryImpl> getApplicationRepositories(); List<SiteImpl> getSites(); List<SubjectImpl> getSubjects(); GroupImpl getGroupByName(String name); GroupImpl getGroupByName(String name, boolean init); void updateGroup(GroupImpl group); Subject getSubjectByEmail(String email); int addPermissions(String applicationName, String roleName, List<String> permissionNames); int removePermissions(String applicationName, String roleName, List<String> permissionNames); Role getApplicationRoleForApplication(Integer applicationId, String roleName); RoleImpl getApplicationRoleForApplication(String applicationName, String roleName); RoleImpl initRole(RoleImpl role); List<? extends Permission> getPermissionsForApplication(Integer applicationId); Site getGrantingSite(String grantedSite, String grantedApplication); Map<String, String> getCacheStatistics(Integer siteId); List<CachedResponse> getCacheEntries(Integer siteId); void expireCacheElement(Integer siteId, String cacheElement); int expireCacheElementsStartingWith(Integer siteId, String cacheElementPrefix); void clearCacheStatistics(Integer siteId); void clearCache(Integer siteId); Application getApplicationForConnection(DatabaseConnection dbc); DatabaseConnection getDatabaseConnection(SiteImpl site, ApplicationImpl application); SiteApplication getSiteApplication(String site, String application); SiteApplication getSiteApplicationWithGrantedSites(String site, String application); SiteApplication grantApplicationForSites(String site, String application, List<String> siteNames); void createEvent(Type type, String message, HttpSession session); void createEvent(Type type, String message, Object... args); void setSiteReloadCount(SiteImpl site); }
@Test public void testInitDatabase() throws Exception { String jdbcUrl = "jdbc:hsqldb:mem:testInitDatabase"; Properties platformProperties = getProperties(DatabaseType.HSQL, jdbcUrl, "sa", "", JDBCDriver.class.getName()); DatabaseConnection platformConnection = databaseService.initDatabase(platformProperties); StringBuilder dbInfo = new StringBuilder(); Assert.assertTrue(platformConnection.testConnection(dbInfo, true)); Assert.assertTrue(dbInfo.toString().startsWith("HSQL Database Engine")); String rootName = "appNG Root Database"; Assert.assertEquals(rootName, platformConnection.getDescription()); Assert.assertEquals(DatabaseType.HSQL, platformConnection.getType()); validateSchemaVersion(platformConnection, "4.2.1"); DatabaseConnection mssql = new DatabaseConnection(DatabaseType.MSSQL, rootName, "", "".getBytes()); mssql.setName(rootName); mssql.setActive(false); databaseConnectionRepository.save(mssql); databaseService.setActiveConnection(platformConnection, false); List<DatabaseConnection> connections = databaseConnectionRepository.findAll(); Assert.assertEquals(4, connections.size()); for (DatabaseConnection connection : connections) { switch (connection.getType()) { case HSQL: Assert.assertTrue(connection.isActive()); break; default: Assert.assertFalse(connection.isActive()); break; } } }
@Transactional public DatabaseConnection initDatabase(java.util.Properties config, boolean managed, boolean setActive) { DatabaseConnection platformConnection = initDatabase(config); MigrationInfoService statusComplete = platformConnection.getMigrationInfoService(); if (setActive && statusComplete != null && null != statusComplete.current()) { platformConnection.setManaged(managed); platformConnection = setActiveConnection(platformConnection, true); platformConnection.setMigrationInfoService(statusComplete); } return platformConnection; }
DatabaseService extends MigrationService { @Transactional public DatabaseConnection initDatabase(java.util.Properties config, boolean managed, boolean setActive) { DatabaseConnection platformConnection = initDatabase(config); MigrationInfoService statusComplete = platformConnection.getMigrationInfoService(); if (setActive && statusComplete != null && null != statusComplete.current()) { platformConnection.setManaged(managed); platformConnection = setActiveConnection(platformConnection, true); platformConnection.setMigrationInfoService(statusComplete); } return platformConnection; } }
DatabaseService extends MigrationService { @Transactional public DatabaseConnection initDatabase(java.util.Properties config, boolean managed, boolean setActive) { DatabaseConnection platformConnection = initDatabase(config); MigrationInfoService statusComplete = platformConnection.getMigrationInfoService(); if (setActive && statusComplete != null && null != statusComplete.current()) { platformConnection.setManaged(managed); platformConnection = setActiveConnection(platformConnection, true); platformConnection.setMigrationInfoService(statusComplete); } return platformConnection; } }
DatabaseService extends MigrationService { @Transactional public DatabaseConnection initDatabase(java.util.Properties config, boolean managed, boolean setActive) { DatabaseConnection platformConnection = initDatabase(config); MigrationInfoService statusComplete = platformConnection.getMigrationInfoService(); if (setActive && statusComplete != null && null != statusComplete.current()) { platformConnection.setManaged(managed); platformConnection = setActiveConnection(platformConnection, true); platformConnection.setMigrationInfoService(statusComplete); } return platformConnection; } void resetApplicationConnection(SiteApplication siteApplication, String databasePrefix); @Transactional DatabaseConnection initDatabase(java.util.Properties config, boolean managed, boolean setActive); @Transactional DatabaseConnection setActiveConnection(DatabaseConnection rootConnection, boolean changeManagedState); DatabaseConnection getRootConnectionOfType(DatabaseType type); @Transactional MigrationStatus manageApplicationConnection(SiteApplication siteApplication, File sqlFolder, String databasePrefix); @Transactional void save(DatabaseConnection databaseConnection); }
DatabaseService extends MigrationService { @Transactional public DatabaseConnection initDatabase(java.util.Properties config, boolean managed, boolean setActive) { DatabaseConnection platformConnection = initDatabase(config); MigrationInfoService statusComplete = platformConnection.getMigrationInfoService(); if (setActive && statusComplete != null && null != statusComplete.current()) { platformConnection.setManaged(managed); platformConnection = setActiveConnection(platformConnection, true); platformConnection.setMigrationInfoService(statusComplete); } return platformConnection; } void resetApplicationConnection(SiteApplication siteApplication, String databasePrefix); @Transactional DatabaseConnection initDatabase(java.util.Properties config, boolean managed, boolean setActive); @Transactional DatabaseConnection setActiveConnection(DatabaseConnection rootConnection, boolean changeManagedState); DatabaseConnection getRootConnectionOfType(DatabaseType type); @Transactional MigrationStatus manageApplicationConnection(SiteApplication siteApplication, File sqlFolder, String databasePrefix); @Transactional void save(DatabaseConnection databaseConnection); }
@Test public void testString() { assertTrue("string(foo)"); assertTrue("string(bar)"); assertFalse("string(foobar)"); assertTrue("string('foobar')"); }
public static boolean string(String string) { return regExp(string, EXP_STRING); }
RuleValidation { public static boolean string(String string) { return regExp(string, EXP_STRING); } }
RuleValidation { public static boolean string(String string) { return regExp(string, EXP_STRING); } RuleValidation(Request container); }
RuleValidation { public static boolean string(String string) { return regExp(string, EXP_STRING); } RuleValidation(Request container); Map<String, List<FormUpload>> getFileParams(Map<String, List<FormUpload>> formUploads); boolean validate(String rule); static boolean string(String string); static boolean captcha(String value, String result); static boolean email(String string); static boolean equals(String string1, String string2); static boolean number(String string); static boolean number(String string, char separator); static boolean numberFractionDigits(String string, int digits, int fraction); static boolean number(String string, char separator, int digits, int fraction); static boolean regExp(String string, String regex); static boolean size(Object item, int size); static boolean sizeMax(Object item, int max); static boolean sizeMin(Object item, int min); static boolean sizeMinMax(Object item, int min, int max); static boolean fileType(List<FormUpload> fUpload, String types); static boolean fileSize(List<FormUpload> fUpload, String minSize, String maxSize); static boolean fileSizeMin(List<FormUpload> fUpload, String minSize); static boolean fileSizeMax(List<FormUpload> fUpload, String maxSize); static boolean fileCountMin(List<FormUpload> fUpload, int count); static boolean fileCountMax(List<FormUpload> fUpload, int count); static boolean fileCount(List<FormUpload> fUpload, int minCount, int maxCount); }
RuleValidation { public static boolean string(String string) { return regExp(string, EXP_STRING); } RuleValidation(Request container); Map<String, List<FormUpload>> getFileParams(Map<String, List<FormUpload>> formUploads); boolean validate(String rule); static boolean string(String string); static boolean captcha(String value, String result); static boolean email(String string); static boolean equals(String string1, String string2); static boolean number(String string); static boolean number(String string, char separator); static boolean numberFractionDigits(String string, int digits, int fraction); static boolean number(String string, char separator, int digits, int fraction); static boolean regExp(String string, String regex); static boolean size(Object item, int size); static boolean sizeMax(Object item, int max); static boolean sizeMin(Object item, int min); static boolean sizeMinMax(Object item, int min, int max); static boolean fileType(List<FormUpload> fUpload, String types); static boolean fileSize(List<FormUpload> fUpload, String minSize, String maxSize); static boolean fileSizeMin(List<FormUpload> fUpload, String minSize); static boolean fileSizeMax(List<FormUpload> fUpload, String maxSize); static boolean fileCountMin(List<FormUpload> fUpload, int count); static boolean fileCountMax(List<FormUpload> fUpload, int count); static boolean fileCount(List<FormUpload> fUpload, int minCount, int maxCount); static final List<String> SHORT_RULES; }
@Test public void testUserName() { Application app = Mockito.mock(Application.class); Site site = Mockito.mock(Site.class); Mockito.when(site.getId()).thenReturn(1234); Mockito.when(app.getId()).thenReturn(1234); String userName = databaseService.getUserName(site, app); Assert.assertTrue(userName.length() <= 16); }
protected String getUserName(Site site, Application application) { return "site" + site.getId() + "app" + application.getId(); }
DatabaseService extends MigrationService { protected String getUserName(Site site, Application application) { return "site" + site.getId() + "app" + application.getId(); } }
DatabaseService extends MigrationService { protected String getUserName(Site site, Application application) { return "site" + site.getId() + "app" + application.getId(); } }
DatabaseService extends MigrationService { protected String getUserName(Site site, Application application) { return "site" + site.getId() + "app" + application.getId(); } void resetApplicationConnection(SiteApplication siteApplication, String databasePrefix); @Transactional DatabaseConnection initDatabase(java.util.Properties config, boolean managed, boolean setActive); @Transactional DatabaseConnection setActiveConnection(DatabaseConnection rootConnection, boolean changeManagedState); DatabaseConnection getRootConnectionOfType(DatabaseType type); @Transactional MigrationStatus manageApplicationConnection(SiteApplication siteApplication, File sqlFolder, String databasePrefix); @Transactional void save(DatabaseConnection databaseConnection); }
DatabaseService extends MigrationService { protected String getUserName(Site site, Application application) { return "site" + site.getId() + "app" + application.getId(); } void resetApplicationConnection(SiteApplication siteApplication, String databasePrefix); @Transactional DatabaseConnection initDatabase(java.util.Properties config, boolean managed, boolean setActive); @Transactional DatabaseConnection setActiveConnection(DatabaseConnection rootConnection, boolean changeManagedState); DatabaseConnection getRootConnectionOfType(DatabaseType type); @Transactional MigrationStatus manageApplicationConnection(SiteApplication siteApplication, File sqlFolder, String databasePrefix); @Transactional void save(DatabaseConnection databaseConnection); }
@Test public void testLoginUserSucces() throws NamingException, IOException { boolean success; sitePropertyMocks.replace(LdapService.LDAP_PRINCIPAL_SCHEME, "DN"); sitePropertyMocks.put(LdapService.LDAP_USER_BASE_DN, "l=egypt"); sitePropertyMocks.put(LdapService.LDAP_ID_ATTRIBUTE, "uid"); setup("uid=aziz,l=egypt", "light", null, null); success = ldapService.loginUser(mockedSite, "aziz", "light".toCharArray()); Assert.assertTrue(success); sitePropertyMocks.replace(LdapService.LDAP_PRINCIPAL_SCHEME, "UPN"); sitePropertyMocks.replace(LdapService.LDAP_DOMAIN, "egypt"); setup("aziz@egypt", "light", null, null); success = ldapService.loginUser(mockedSite, "aziz", "light".toCharArray()); Assert.assertTrue(success); sitePropertyMocks.replace(LdapService.LDAP_PRINCIPAL_SCHEME, "SAM"); sitePropertyMocks.replace(LdapService.LDAP_DOMAIN, "egypt"); setup("egypt\\aziz", "light", null, null); success = ldapService.loginUser(mockedSite, "aziz", "light".toCharArray()); Assert.assertTrue(success); sitePropertyMocks.replace(LdapService.LDAP_PRINCIPAL_SCHEME, "bogus"); setup("aziz", "light", null, null); success = ldapService.loginUser(mockedSite, "aziz", "light".toCharArray()); Assert.assertTrue(success); }
public boolean loginUser(Site site, String username, char[] password) { LdapCredentials ldapCredentials = new LdapCredentials(site, username, password, false); TlsAwareLdapContext ctx = null; try { ctx = new TlsAwareLdapContext(ldapCredentials); return true; } catch (IOException | NamingException ex) { logException(ldapCredentials.ldapHost, ldapCredentials.principal, ex); } finally { closeContext(ctx); } return false; }
LdapService { public boolean loginUser(Site site, String username, char[] password) { LdapCredentials ldapCredentials = new LdapCredentials(site, username, password, false); TlsAwareLdapContext ctx = null; try { ctx = new TlsAwareLdapContext(ldapCredentials); return true; } catch (IOException | NamingException ex) { logException(ldapCredentials.ldapHost, ldapCredentials.principal, ex); } finally { closeContext(ctx); } return false; } }
LdapService { public boolean loginUser(Site site, String username, char[] password) { LdapCredentials ldapCredentials = new LdapCredentials(site, username, password, false); TlsAwareLdapContext ctx = null; try { ctx = new TlsAwareLdapContext(ldapCredentials); return true; } catch (IOException | NamingException ex) { logException(ldapCredentials.ldapHost, ldapCredentials.principal, ex); } finally { closeContext(ctx); } return false; } }
LdapService { public boolean loginUser(Site site, String username, char[] password) { LdapCredentials ldapCredentials = new LdapCredentials(site, username, password, false); TlsAwareLdapContext ctx = null; try { ctx = new TlsAwareLdapContext(ldapCredentials); return true; } catch (IOException | NamingException ex) { logException(ldapCredentials.ldapHost, ldapCredentials.principal, ex); } finally { closeContext(ctx); } return false; } void setLdapCtxFactory(String ldapCtxFactory); boolean loginUser(Site site, String username, char[] password); List<String> loginGroup(Site site, String username, char[] password, SubjectImpl subject, List<String> groupNames); List<SubjectImpl> getMembersOfGroup(Site site, String groupName); }
LdapService { public boolean loginUser(Site site, String username, char[] password) { LdapCredentials ldapCredentials = new LdapCredentials(site, username, password, false); TlsAwareLdapContext ctx = null; try { ctx = new TlsAwareLdapContext(ldapCredentials); return true; } catch (IOException | NamingException ex) { logException(ldapCredentials.ldapHost, ldapCredentials.principal, ex); } finally { closeContext(ctx); } return false; } void setLdapCtxFactory(String ldapCtxFactory); boolean loginUser(Site site, String username, char[] password); List<String> loginGroup(Site site, String username, char[] password, SubjectImpl subject, List<String> groupNames); List<SubjectImpl> getMembersOfGroup(Site site, String groupName); static final String LDAP_DOMAIN; static final String LDAP_GROUP_BASE_DN; static final String LDAP_HOST; static final String LDAP_ID_ATTRIBUTE; static final String LDAP_PASSWORD; static final String LDAP_PRINCIPAL_SCHEME; static final String LDAP_START_TLS; static final String LDAP_USER; static final String LDAP_USER_BASE_DN; }
@Test public void testLoginUserFailure() throws NamingException, IOException { boolean success; List<Exception> exList; Exception ex; LdapContextMock ldapContextMock; sitePropertyMocks.replace(LdapService.LDAP_PRINCIPAL_SCHEME, "SAM"); sitePropertyMocks.replace(LdapService.LDAP_DOMAIN, "egypt"); ldapContextMock = setup("bielefeld\\aziz", "light", null, null); success = ldapService.loginUser(mockedSite, "aziz", "light".toCharArray()); exList = ldapContextMock.exceptionHistory; ex = exList.size() > 0 ? exList.get(exList.size() - 1) : new Exception("Placeholder - nothing was thrown."); Assert.assertFalse(success); Assert.assertEquals(LdapContextMock.MSG_WRONG_USER, ex.getMessage()); sitePropertyMocks.replace(LdapService.LDAP_PRINCIPAL_SCHEME, "SAM"); sitePropertyMocks.replace(LdapService.LDAP_DOMAIN, "egypt"); ldapContextMock = setup("egypt\\aziz", "shadow", null, null); success = ldapService.loginUser(mockedSite, "aziz", "light".toCharArray()); Assert.assertFalse(success); exList = ldapContextMock.exceptionHistory; ex = exList.size() > 0 ? exList.get(exList.size() - 1) : new Exception("Placeholder - nothing was thrown."); Assert.assertFalse(success); Assert.assertEquals(LdapContextMock.MSG_WRONG_PASS, ex.getMessage()); }
public boolean loginUser(Site site, String username, char[] password) { LdapCredentials ldapCredentials = new LdapCredentials(site, username, password, false); TlsAwareLdapContext ctx = null; try { ctx = new TlsAwareLdapContext(ldapCredentials); return true; } catch (IOException | NamingException ex) { logException(ldapCredentials.ldapHost, ldapCredentials.principal, ex); } finally { closeContext(ctx); } return false; }
LdapService { public boolean loginUser(Site site, String username, char[] password) { LdapCredentials ldapCredentials = new LdapCredentials(site, username, password, false); TlsAwareLdapContext ctx = null; try { ctx = new TlsAwareLdapContext(ldapCredentials); return true; } catch (IOException | NamingException ex) { logException(ldapCredentials.ldapHost, ldapCredentials.principal, ex); } finally { closeContext(ctx); } return false; } }
LdapService { public boolean loginUser(Site site, String username, char[] password) { LdapCredentials ldapCredentials = new LdapCredentials(site, username, password, false); TlsAwareLdapContext ctx = null; try { ctx = new TlsAwareLdapContext(ldapCredentials); return true; } catch (IOException | NamingException ex) { logException(ldapCredentials.ldapHost, ldapCredentials.principal, ex); } finally { closeContext(ctx); } return false; } }
LdapService { public boolean loginUser(Site site, String username, char[] password) { LdapCredentials ldapCredentials = new LdapCredentials(site, username, password, false); TlsAwareLdapContext ctx = null; try { ctx = new TlsAwareLdapContext(ldapCredentials); return true; } catch (IOException | NamingException ex) { logException(ldapCredentials.ldapHost, ldapCredentials.principal, ex); } finally { closeContext(ctx); } return false; } void setLdapCtxFactory(String ldapCtxFactory); boolean loginUser(Site site, String username, char[] password); List<String> loginGroup(Site site, String username, char[] password, SubjectImpl subject, List<String> groupNames); List<SubjectImpl> getMembersOfGroup(Site site, String groupName); }
LdapService { public boolean loginUser(Site site, String username, char[] password) { LdapCredentials ldapCredentials = new LdapCredentials(site, username, password, false); TlsAwareLdapContext ctx = null; try { ctx = new TlsAwareLdapContext(ldapCredentials); return true; } catch (IOException | NamingException ex) { logException(ldapCredentials.ldapHost, ldapCredentials.principal, ex); } finally { closeContext(ctx); } return false; } void setLdapCtxFactory(String ldapCtxFactory); boolean loginUser(Site site, String username, char[] password); List<String> loginGroup(Site site, String username, char[] password, SubjectImpl subject, List<String> groupNames); List<SubjectImpl> getMembersOfGroup(Site site, String groupName); static final String LDAP_DOMAIN; static final String LDAP_GROUP_BASE_DN; static final String LDAP_HOST; static final String LDAP_ID_ATTRIBUTE; static final String LDAP_PASSWORD; static final String LDAP_PRINCIPAL_SCHEME; static final String LDAP_START_TLS; static final String LDAP_USER; static final String LDAP_USER_BASE_DN; }
@Test public void testLoginGroupExistent() throws NamingException, IOException { List<String> searchedGroups; List<String> resultGroups; sitePropertyMocks.replace(LdapService.LDAP_PRINCIPAL_SCHEME, "UPN"); sitePropertyMocks.replace(LdapService.LDAP_DOMAIN, "egypt"); sitePropertyMocks.put(LdapService.LDAP_USER, "mondoshawan"); sitePropertyMocks.put(LdapService.LDAP_PASSWORD, "stones"); sitePropertyMocks.put(LdapService.LDAP_USER_BASE_DN, "ou=users,l=egypt"); sitePropertyMocks.put(LdapService.LDAP_GROUP_BASE_DN, "ou=groups,l=egypt"); setup("aziz@egypt", "light", "mondoshawan@egypt", "stones"); searchedGroups = Arrays.asList(LdapContextMock.MOCKED_GROUP_NAME); resultGroups = ldapService.loginGroup(mockedSite, "aZiZ", "light".toCharArray(), mockedSubject, searchedGroups); Assert.assertArrayEquals(searchedGroups.toArray(new String[0]), resultGroups.toArray(new String[0])); }
public List<String> loginGroup(Site site, String username, char[] password, SubjectImpl subject, List<String> groupNames) { LdapCredentials ldapCredentials = new LdapCredentials(site, username, password, false); TlsAwareLdapContext ctx = null; try { ctx = new TlsAwareLdapContext(ldapCredentials); return getUserGroups(ctx.delegate, username, site, subject, groupNames); } catch (NamingException | IOException ex) { logException(ldapCredentials.ldapHost, ldapCredentials.principal, ex); } finally { closeContext(ctx); } return new ArrayList<>(); }
LdapService { public List<String> loginGroup(Site site, String username, char[] password, SubjectImpl subject, List<String> groupNames) { LdapCredentials ldapCredentials = new LdapCredentials(site, username, password, false); TlsAwareLdapContext ctx = null; try { ctx = new TlsAwareLdapContext(ldapCredentials); return getUserGroups(ctx.delegate, username, site, subject, groupNames); } catch (NamingException | IOException ex) { logException(ldapCredentials.ldapHost, ldapCredentials.principal, ex); } finally { closeContext(ctx); } return new ArrayList<>(); } }
LdapService { public List<String> loginGroup(Site site, String username, char[] password, SubjectImpl subject, List<String> groupNames) { LdapCredentials ldapCredentials = new LdapCredentials(site, username, password, false); TlsAwareLdapContext ctx = null; try { ctx = new TlsAwareLdapContext(ldapCredentials); return getUserGroups(ctx.delegate, username, site, subject, groupNames); } catch (NamingException | IOException ex) { logException(ldapCredentials.ldapHost, ldapCredentials.principal, ex); } finally { closeContext(ctx); } return new ArrayList<>(); } }
LdapService { public List<String> loginGroup(Site site, String username, char[] password, SubjectImpl subject, List<String> groupNames) { LdapCredentials ldapCredentials = new LdapCredentials(site, username, password, false); TlsAwareLdapContext ctx = null; try { ctx = new TlsAwareLdapContext(ldapCredentials); return getUserGroups(ctx.delegate, username, site, subject, groupNames); } catch (NamingException | IOException ex) { logException(ldapCredentials.ldapHost, ldapCredentials.principal, ex); } finally { closeContext(ctx); } return new ArrayList<>(); } void setLdapCtxFactory(String ldapCtxFactory); boolean loginUser(Site site, String username, char[] password); List<String> loginGroup(Site site, String username, char[] password, SubjectImpl subject, List<String> groupNames); List<SubjectImpl> getMembersOfGroup(Site site, String groupName); }
LdapService { public List<String> loginGroup(Site site, String username, char[] password, SubjectImpl subject, List<String> groupNames) { LdapCredentials ldapCredentials = new LdapCredentials(site, username, password, false); TlsAwareLdapContext ctx = null; try { ctx = new TlsAwareLdapContext(ldapCredentials); return getUserGroups(ctx.delegate, username, site, subject, groupNames); } catch (NamingException | IOException ex) { logException(ldapCredentials.ldapHost, ldapCredentials.principal, ex); } finally { closeContext(ctx); } return new ArrayList<>(); } void setLdapCtxFactory(String ldapCtxFactory); boolean loginUser(Site site, String username, char[] password); List<String> loginGroup(Site site, String username, char[] password, SubjectImpl subject, List<String> groupNames); List<SubjectImpl> getMembersOfGroup(Site site, String groupName); static final String LDAP_DOMAIN; static final String LDAP_GROUP_BASE_DN; static final String LDAP_HOST; static final String LDAP_ID_ATTRIBUTE; static final String LDAP_PASSWORD; static final String LDAP_PRINCIPAL_SCHEME; static final String LDAP_START_TLS; static final String LDAP_USER; static final String LDAP_USER_BASE_DN; }
@Test public void testLoginGroupExistentNoGroupBaseDn() throws NamingException, IOException { List<String> searchedGroups; List<String> resultGroups; sitePropertyMocks.replace(LdapService.LDAP_PRINCIPAL_SCHEME, "UPN"); sitePropertyMocks.replace(LdapService.LDAP_DOMAIN, "egypt"); sitePropertyMocks.put(LdapService.LDAP_USER, "mondoshawan"); sitePropertyMocks.put(LdapService.LDAP_PASSWORD, "stones"); sitePropertyMocks.put(LdapService.LDAP_USER_BASE_DN, "ou=users,l=egypt"); sitePropertyMocks.put(LdapService.LDAP_GROUP_BASE_DN, ""); setup("aziz@egypt", "light", "mondoshawan@egypt", "stones"); searchedGroups = Arrays.asList("cn=logingroup,ou=groups,l=egypt"); resultGroups = ldapService.loginGroup(mockedSite, "aZiZ", "light".toCharArray(), mockedSubject, searchedGroups); Assert.assertArrayEquals(searchedGroups.toArray(new String[0]), resultGroups.toArray(new String[0])); }
public List<String> loginGroup(Site site, String username, char[] password, SubjectImpl subject, List<String> groupNames) { LdapCredentials ldapCredentials = new LdapCredentials(site, username, password, false); TlsAwareLdapContext ctx = null; try { ctx = new TlsAwareLdapContext(ldapCredentials); return getUserGroups(ctx.delegate, username, site, subject, groupNames); } catch (NamingException | IOException ex) { logException(ldapCredentials.ldapHost, ldapCredentials.principal, ex); } finally { closeContext(ctx); } return new ArrayList<>(); }
LdapService { public List<String> loginGroup(Site site, String username, char[] password, SubjectImpl subject, List<String> groupNames) { LdapCredentials ldapCredentials = new LdapCredentials(site, username, password, false); TlsAwareLdapContext ctx = null; try { ctx = new TlsAwareLdapContext(ldapCredentials); return getUserGroups(ctx.delegate, username, site, subject, groupNames); } catch (NamingException | IOException ex) { logException(ldapCredentials.ldapHost, ldapCredentials.principal, ex); } finally { closeContext(ctx); } return new ArrayList<>(); } }
LdapService { public List<String> loginGroup(Site site, String username, char[] password, SubjectImpl subject, List<String> groupNames) { LdapCredentials ldapCredentials = new LdapCredentials(site, username, password, false); TlsAwareLdapContext ctx = null; try { ctx = new TlsAwareLdapContext(ldapCredentials); return getUserGroups(ctx.delegate, username, site, subject, groupNames); } catch (NamingException | IOException ex) { logException(ldapCredentials.ldapHost, ldapCredentials.principal, ex); } finally { closeContext(ctx); } return new ArrayList<>(); } }
LdapService { public List<String> loginGroup(Site site, String username, char[] password, SubjectImpl subject, List<String> groupNames) { LdapCredentials ldapCredentials = new LdapCredentials(site, username, password, false); TlsAwareLdapContext ctx = null; try { ctx = new TlsAwareLdapContext(ldapCredentials); return getUserGroups(ctx.delegate, username, site, subject, groupNames); } catch (NamingException | IOException ex) { logException(ldapCredentials.ldapHost, ldapCredentials.principal, ex); } finally { closeContext(ctx); } return new ArrayList<>(); } void setLdapCtxFactory(String ldapCtxFactory); boolean loginUser(Site site, String username, char[] password); List<String> loginGroup(Site site, String username, char[] password, SubjectImpl subject, List<String> groupNames); List<SubjectImpl> getMembersOfGroup(Site site, String groupName); }
LdapService { public List<String> loginGroup(Site site, String username, char[] password, SubjectImpl subject, List<String> groupNames) { LdapCredentials ldapCredentials = new LdapCredentials(site, username, password, false); TlsAwareLdapContext ctx = null; try { ctx = new TlsAwareLdapContext(ldapCredentials); return getUserGroups(ctx.delegate, username, site, subject, groupNames); } catch (NamingException | IOException ex) { logException(ldapCredentials.ldapHost, ldapCredentials.principal, ex); } finally { closeContext(ctx); } return new ArrayList<>(); } void setLdapCtxFactory(String ldapCtxFactory); boolean loginUser(Site site, String username, char[] password); List<String> loginGroup(Site site, String username, char[] password, SubjectImpl subject, List<String> groupNames); List<SubjectImpl> getMembersOfGroup(Site site, String groupName); static final String LDAP_DOMAIN; static final String LDAP_GROUP_BASE_DN; static final String LDAP_HOST; static final String LDAP_ID_ATTRIBUTE; static final String LDAP_PASSWORD; static final String LDAP_PRINCIPAL_SCHEME; static final String LDAP_START_TLS; static final String LDAP_USER; static final String LDAP_USER_BASE_DN; }
@Test public void testLoginGroupExistentServiceUserDirectDN() throws NamingException, IOException { List<String> searchedGroups; List<String> resultGroups; sitePropertyMocks.replace(LdapService.LDAP_PRINCIPAL_SCHEME, "UPN"); sitePropertyMocks.replace(LdapService.LDAP_DOMAIN, "egypt"); sitePropertyMocks.put(LdapService.LDAP_USER, "cn=mondoshawan,l=homeplanet"); sitePropertyMocks.put(LdapService.LDAP_PASSWORD, "stones"); sitePropertyMocks.put(LdapService.LDAP_USER_BASE_DN, "ou=users,l=egypt"); sitePropertyMocks.put(LdapService.LDAP_GROUP_BASE_DN, "ou=groups,l=egypt"); setup("aziz@egypt", "light", "cn=mondoshawan,l=homeplanet", "stones"); searchedGroups = Arrays.asList(LdapContextMock.MOCKED_GROUP_NAME); resultGroups = ldapService.loginGroup(mockedSite, "aziz", "light".toCharArray(), mockedSubject, searchedGroups); Assert.assertArrayEquals(searchedGroups.toArray(new String[0]), resultGroups.toArray(new String[0])); }
public List<String> loginGroup(Site site, String username, char[] password, SubjectImpl subject, List<String> groupNames) { LdapCredentials ldapCredentials = new LdapCredentials(site, username, password, false); TlsAwareLdapContext ctx = null; try { ctx = new TlsAwareLdapContext(ldapCredentials); return getUserGroups(ctx.delegate, username, site, subject, groupNames); } catch (NamingException | IOException ex) { logException(ldapCredentials.ldapHost, ldapCredentials.principal, ex); } finally { closeContext(ctx); } return new ArrayList<>(); }
LdapService { public List<String> loginGroup(Site site, String username, char[] password, SubjectImpl subject, List<String> groupNames) { LdapCredentials ldapCredentials = new LdapCredentials(site, username, password, false); TlsAwareLdapContext ctx = null; try { ctx = new TlsAwareLdapContext(ldapCredentials); return getUserGroups(ctx.delegate, username, site, subject, groupNames); } catch (NamingException | IOException ex) { logException(ldapCredentials.ldapHost, ldapCredentials.principal, ex); } finally { closeContext(ctx); } return new ArrayList<>(); } }
LdapService { public List<String> loginGroup(Site site, String username, char[] password, SubjectImpl subject, List<String> groupNames) { LdapCredentials ldapCredentials = new LdapCredentials(site, username, password, false); TlsAwareLdapContext ctx = null; try { ctx = new TlsAwareLdapContext(ldapCredentials); return getUserGroups(ctx.delegate, username, site, subject, groupNames); } catch (NamingException | IOException ex) { logException(ldapCredentials.ldapHost, ldapCredentials.principal, ex); } finally { closeContext(ctx); } return new ArrayList<>(); } }
LdapService { public List<String> loginGroup(Site site, String username, char[] password, SubjectImpl subject, List<String> groupNames) { LdapCredentials ldapCredentials = new LdapCredentials(site, username, password, false); TlsAwareLdapContext ctx = null; try { ctx = new TlsAwareLdapContext(ldapCredentials); return getUserGroups(ctx.delegate, username, site, subject, groupNames); } catch (NamingException | IOException ex) { logException(ldapCredentials.ldapHost, ldapCredentials.principal, ex); } finally { closeContext(ctx); } return new ArrayList<>(); } void setLdapCtxFactory(String ldapCtxFactory); boolean loginUser(Site site, String username, char[] password); List<String> loginGroup(Site site, String username, char[] password, SubjectImpl subject, List<String> groupNames); List<SubjectImpl> getMembersOfGroup(Site site, String groupName); }
LdapService { public List<String> loginGroup(Site site, String username, char[] password, SubjectImpl subject, List<String> groupNames) { LdapCredentials ldapCredentials = new LdapCredentials(site, username, password, false); TlsAwareLdapContext ctx = null; try { ctx = new TlsAwareLdapContext(ldapCredentials); return getUserGroups(ctx.delegate, username, site, subject, groupNames); } catch (NamingException | IOException ex) { logException(ldapCredentials.ldapHost, ldapCredentials.principal, ex); } finally { closeContext(ctx); } return new ArrayList<>(); } void setLdapCtxFactory(String ldapCtxFactory); boolean loginUser(Site site, String username, char[] password); List<String> loginGroup(Site site, String username, char[] password, SubjectImpl subject, List<String> groupNames); List<SubjectImpl> getMembersOfGroup(Site site, String groupName); static final String LDAP_DOMAIN; static final String LDAP_GROUP_BASE_DN; static final String LDAP_HOST; static final String LDAP_ID_ATTRIBUTE; static final String LDAP_PASSWORD; static final String LDAP_PRINCIPAL_SCHEME; static final String LDAP_START_TLS; static final String LDAP_USER; static final String LDAP_USER_BASE_DN; }
@Test public void testLoginGroupMissing() throws NamingException, IOException { List<String> searchedGroups; List<String> resultGroups; sitePropertyMocks.replace(LdapService.LDAP_PRINCIPAL_SCHEME, "UPN"); sitePropertyMocks.replace(LdapService.LDAP_DOMAIN, "egypt"); sitePropertyMocks.put(LdapService.LDAP_USER, "mondoshawan"); sitePropertyMocks.put(LdapService.LDAP_PASSWORD, "stones"); sitePropertyMocks.put(LdapService.LDAP_USER_BASE_DN, "ou=users,l=egypt"); sitePropertyMocks.put(LdapService.LDAP_GROUP_BASE_DN, "ou=groups,l=egypt"); setup("aziz@egypt", "light", "mondoshawan@egypt", "stones"); searchedGroups = Arrays.asList( "Well, if there's a bright center to the universe, you're on the usergroup that it's farthest from."); resultGroups = ldapService.loginGroup(mockedSite, "aziz", "light".toCharArray(), mockedSubject, searchedGroups); Assert.assertArrayEquals(new String[0], resultGroups.toArray(new String[0])); }
public List<String> loginGroup(Site site, String username, char[] password, SubjectImpl subject, List<String> groupNames) { LdapCredentials ldapCredentials = new LdapCredentials(site, username, password, false); TlsAwareLdapContext ctx = null; try { ctx = new TlsAwareLdapContext(ldapCredentials); return getUserGroups(ctx.delegate, username, site, subject, groupNames); } catch (NamingException | IOException ex) { logException(ldapCredentials.ldapHost, ldapCredentials.principal, ex); } finally { closeContext(ctx); } return new ArrayList<>(); }
LdapService { public List<String> loginGroup(Site site, String username, char[] password, SubjectImpl subject, List<String> groupNames) { LdapCredentials ldapCredentials = new LdapCredentials(site, username, password, false); TlsAwareLdapContext ctx = null; try { ctx = new TlsAwareLdapContext(ldapCredentials); return getUserGroups(ctx.delegate, username, site, subject, groupNames); } catch (NamingException | IOException ex) { logException(ldapCredentials.ldapHost, ldapCredentials.principal, ex); } finally { closeContext(ctx); } return new ArrayList<>(); } }
LdapService { public List<String> loginGroup(Site site, String username, char[] password, SubjectImpl subject, List<String> groupNames) { LdapCredentials ldapCredentials = new LdapCredentials(site, username, password, false); TlsAwareLdapContext ctx = null; try { ctx = new TlsAwareLdapContext(ldapCredentials); return getUserGroups(ctx.delegate, username, site, subject, groupNames); } catch (NamingException | IOException ex) { logException(ldapCredentials.ldapHost, ldapCredentials.principal, ex); } finally { closeContext(ctx); } return new ArrayList<>(); } }
LdapService { public List<String> loginGroup(Site site, String username, char[] password, SubjectImpl subject, List<String> groupNames) { LdapCredentials ldapCredentials = new LdapCredentials(site, username, password, false); TlsAwareLdapContext ctx = null; try { ctx = new TlsAwareLdapContext(ldapCredentials); return getUserGroups(ctx.delegate, username, site, subject, groupNames); } catch (NamingException | IOException ex) { logException(ldapCredentials.ldapHost, ldapCredentials.principal, ex); } finally { closeContext(ctx); } return new ArrayList<>(); } void setLdapCtxFactory(String ldapCtxFactory); boolean loginUser(Site site, String username, char[] password); List<String> loginGroup(Site site, String username, char[] password, SubjectImpl subject, List<String> groupNames); List<SubjectImpl> getMembersOfGroup(Site site, String groupName); }
LdapService { public List<String> loginGroup(Site site, String username, char[] password, SubjectImpl subject, List<String> groupNames) { LdapCredentials ldapCredentials = new LdapCredentials(site, username, password, false); TlsAwareLdapContext ctx = null; try { ctx = new TlsAwareLdapContext(ldapCredentials); return getUserGroups(ctx.delegate, username, site, subject, groupNames); } catch (NamingException | IOException ex) { logException(ldapCredentials.ldapHost, ldapCredentials.principal, ex); } finally { closeContext(ctx); } return new ArrayList<>(); } void setLdapCtxFactory(String ldapCtxFactory); boolean loginUser(Site site, String username, char[] password); List<String> loginGroup(Site site, String username, char[] password, SubjectImpl subject, List<String> groupNames); List<SubjectImpl> getMembersOfGroup(Site site, String groupName); static final String LDAP_DOMAIN; static final String LDAP_GROUP_BASE_DN; static final String LDAP_HOST; static final String LDAP_ID_ATTRIBUTE; static final String LDAP_PASSWORD; static final String LDAP_PRINCIPAL_SCHEME; static final String LDAP_START_TLS; static final String LDAP_USER; static final String LDAP_USER_BASE_DN; }
@Test public void testUsersOfGroup() throws NamingException, IOException { List<SubjectImpl> resultSubjects; String[] expectSubjNames = new String[] { "aziz", "aziz' brother" }; String[] expectSubjRealNames = new String[] { "Dummy", "Dummy" }; sitePropertyMocks.replace(LdapService.LDAP_PRINCIPAL_SCHEME, "UPN"); sitePropertyMocks.replace(LdapService.LDAP_DOMAIN, "egypt"); sitePropertyMocks.put(LdapService.LDAP_USER, "mondoshawan"); sitePropertyMocks.put(LdapService.LDAP_PASSWORD, "stones"); sitePropertyMocks.put(LdapService.LDAP_USER_BASE_DN, "ou=users,l=egypt"); sitePropertyMocks.put(LdapService.LDAP_GROUP_BASE_DN, "ou=groups,l=egypt"); setup("aziz@egypt", "light", "mondoshawan@egypt", "stones"); resultSubjects = ldapService.getMembersOfGroup(mockedSite, LdapContextMock.MOCKED_GROUP_NAME); Assert.assertEquals(resultSubjects.size(), 2); for (int idx = 0; idx < 2; idx++) { Assert.assertEquals(resultSubjects.get(idx).getName(), expectSubjNames[idx]); Assert.assertEquals(resultSubjects.get(idx).getRealname(), expectSubjRealNames[idx]); Assert.assertFalse(resultSubjects.get(idx).isAuthenticated()); } }
public List<SubjectImpl> getMembersOfGroup(Site site, String groupName) { List<SubjectImpl> subjects = new ArrayList<>(); String serviceUser = site.getProperties().getString(LDAP_USER); char[] servicePassword = site.getProperties().getString(LDAP_PASSWORD).toCharArray(); LdapCredentials ldapCredentials = new LdapCredentials(site, serviceUser, servicePassword, true); String groupBaseDn = site.getProperties().getString(LDAP_GROUP_BASE_DN); String idAttribute = site.getProperties().getString(LDAP_ID_ATTRIBUTE); String groupDn = getGroupDn(groupName, groupBaseDn); TlsAwareLdapContext ctx = null; try { ctx = new TlsAwareLdapContext(ldapCredentials); for (String member : getGroupMembers(ctx.delegate, groupDn)) { Attributes userAttrs = getUserAttributes(ctx.delegate, member, idAttribute); SubjectImpl ldapSubject = fillSubjectFromAttributes(new SubjectImpl(), idAttribute, userAttrs); subjects.add(ldapSubject); } } catch (IOException | NamingException ex) { logException(ldapCredentials.ldapHost, ldapCredentials.principal, ex); } finally { closeContext(ctx); } LOGGER.info("Found {} member(s) for group '{}'", subjects.size(), groupDn); return subjects; }
LdapService { public List<SubjectImpl> getMembersOfGroup(Site site, String groupName) { List<SubjectImpl> subjects = new ArrayList<>(); String serviceUser = site.getProperties().getString(LDAP_USER); char[] servicePassword = site.getProperties().getString(LDAP_PASSWORD).toCharArray(); LdapCredentials ldapCredentials = new LdapCredentials(site, serviceUser, servicePassword, true); String groupBaseDn = site.getProperties().getString(LDAP_GROUP_BASE_DN); String idAttribute = site.getProperties().getString(LDAP_ID_ATTRIBUTE); String groupDn = getGroupDn(groupName, groupBaseDn); TlsAwareLdapContext ctx = null; try { ctx = new TlsAwareLdapContext(ldapCredentials); for (String member : getGroupMembers(ctx.delegate, groupDn)) { Attributes userAttrs = getUserAttributes(ctx.delegate, member, idAttribute); SubjectImpl ldapSubject = fillSubjectFromAttributes(new SubjectImpl(), idAttribute, userAttrs); subjects.add(ldapSubject); } } catch (IOException | NamingException ex) { logException(ldapCredentials.ldapHost, ldapCredentials.principal, ex); } finally { closeContext(ctx); } LOGGER.info("Found {} member(s) for group '{}'", subjects.size(), groupDn); return subjects; } }
LdapService { public List<SubjectImpl> getMembersOfGroup(Site site, String groupName) { List<SubjectImpl> subjects = new ArrayList<>(); String serviceUser = site.getProperties().getString(LDAP_USER); char[] servicePassword = site.getProperties().getString(LDAP_PASSWORD).toCharArray(); LdapCredentials ldapCredentials = new LdapCredentials(site, serviceUser, servicePassword, true); String groupBaseDn = site.getProperties().getString(LDAP_GROUP_BASE_DN); String idAttribute = site.getProperties().getString(LDAP_ID_ATTRIBUTE); String groupDn = getGroupDn(groupName, groupBaseDn); TlsAwareLdapContext ctx = null; try { ctx = new TlsAwareLdapContext(ldapCredentials); for (String member : getGroupMembers(ctx.delegate, groupDn)) { Attributes userAttrs = getUserAttributes(ctx.delegate, member, idAttribute); SubjectImpl ldapSubject = fillSubjectFromAttributes(new SubjectImpl(), idAttribute, userAttrs); subjects.add(ldapSubject); } } catch (IOException | NamingException ex) { logException(ldapCredentials.ldapHost, ldapCredentials.principal, ex); } finally { closeContext(ctx); } LOGGER.info("Found {} member(s) for group '{}'", subjects.size(), groupDn); return subjects; } }
LdapService { public List<SubjectImpl> getMembersOfGroup(Site site, String groupName) { List<SubjectImpl> subjects = new ArrayList<>(); String serviceUser = site.getProperties().getString(LDAP_USER); char[] servicePassword = site.getProperties().getString(LDAP_PASSWORD).toCharArray(); LdapCredentials ldapCredentials = new LdapCredentials(site, serviceUser, servicePassword, true); String groupBaseDn = site.getProperties().getString(LDAP_GROUP_BASE_DN); String idAttribute = site.getProperties().getString(LDAP_ID_ATTRIBUTE); String groupDn = getGroupDn(groupName, groupBaseDn); TlsAwareLdapContext ctx = null; try { ctx = new TlsAwareLdapContext(ldapCredentials); for (String member : getGroupMembers(ctx.delegate, groupDn)) { Attributes userAttrs = getUserAttributes(ctx.delegate, member, idAttribute); SubjectImpl ldapSubject = fillSubjectFromAttributes(new SubjectImpl(), idAttribute, userAttrs); subjects.add(ldapSubject); } } catch (IOException | NamingException ex) { logException(ldapCredentials.ldapHost, ldapCredentials.principal, ex); } finally { closeContext(ctx); } LOGGER.info("Found {} member(s) for group '{}'", subjects.size(), groupDn); return subjects; } void setLdapCtxFactory(String ldapCtxFactory); boolean loginUser(Site site, String username, char[] password); List<String> loginGroup(Site site, String username, char[] password, SubjectImpl subject, List<String> groupNames); List<SubjectImpl> getMembersOfGroup(Site site, String groupName); }
LdapService { public List<SubjectImpl> getMembersOfGroup(Site site, String groupName) { List<SubjectImpl> subjects = new ArrayList<>(); String serviceUser = site.getProperties().getString(LDAP_USER); char[] servicePassword = site.getProperties().getString(LDAP_PASSWORD).toCharArray(); LdapCredentials ldapCredentials = new LdapCredentials(site, serviceUser, servicePassword, true); String groupBaseDn = site.getProperties().getString(LDAP_GROUP_BASE_DN); String idAttribute = site.getProperties().getString(LDAP_ID_ATTRIBUTE); String groupDn = getGroupDn(groupName, groupBaseDn); TlsAwareLdapContext ctx = null; try { ctx = new TlsAwareLdapContext(ldapCredentials); for (String member : getGroupMembers(ctx.delegate, groupDn)) { Attributes userAttrs = getUserAttributes(ctx.delegate, member, idAttribute); SubjectImpl ldapSubject = fillSubjectFromAttributes(new SubjectImpl(), idAttribute, userAttrs); subjects.add(ldapSubject); } } catch (IOException | NamingException ex) { logException(ldapCredentials.ldapHost, ldapCredentials.principal, ex); } finally { closeContext(ctx); } LOGGER.info("Found {} member(s) for group '{}'", subjects.size(), groupDn); return subjects; } void setLdapCtxFactory(String ldapCtxFactory); boolean loginUser(Site site, String username, char[] password); List<String> loginGroup(Site site, String username, char[] password, SubjectImpl subject, List<String> groupNames); List<SubjectImpl> getMembersOfGroup(Site site, String groupName); static final String LDAP_DOMAIN; static final String LDAP_GROUP_BASE_DN; static final String LDAP_HOST; static final String LDAP_ID_ATTRIBUTE; static final String LDAP_PASSWORD; static final String LDAP_PRINCIPAL_SCHEME; static final String LDAP_START_TLS; static final String LDAP_USER; static final String LDAP_USER_BASE_DN; }
@Test public void testLoginUserStartTls() throws NamingException, IOException { boolean success; sitePropertyMocks.replace(LdapService.LDAP_PRINCIPAL_SCHEME, "DN"); sitePropertyMocks.put(LdapService.LDAP_USER_BASE_DN, "l=egypt"); sitePropertyMocks.put(LdapService.LDAP_ID_ATTRIBUTE, "uid"); sitePropertyMocks.put(LdapService.LDAP_START_TLS, true); setup("uid=aziz,l=egypt", "light", null, null); success = ldapService.loginUser(mockedSite, "aziz", "light".toCharArray()); Assert.assertTrue(success); }
public boolean loginUser(Site site, String username, char[] password) { LdapCredentials ldapCredentials = new LdapCredentials(site, username, password, false); TlsAwareLdapContext ctx = null; try { ctx = new TlsAwareLdapContext(ldapCredentials); return true; } catch (IOException | NamingException ex) { logException(ldapCredentials.ldapHost, ldapCredentials.principal, ex); } finally { closeContext(ctx); } return false; }
LdapService { public boolean loginUser(Site site, String username, char[] password) { LdapCredentials ldapCredentials = new LdapCredentials(site, username, password, false); TlsAwareLdapContext ctx = null; try { ctx = new TlsAwareLdapContext(ldapCredentials); return true; } catch (IOException | NamingException ex) { logException(ldapCredentials.ldapHost, ldapCredentials.principal, ex); } finally { closeContext(ctx); } return false; } }
LdapService { public boolean loginUser(Site site, String username, char[] password) { LdapCredentials ldapCredentials = new LdapCredentials(site, username, password, false); TlsAwareLdapContext ctx = null; try { ctx = new TlsAwareLdapContext(ldapCredentials); return true; } catch (IOException | NamingException ex) { logException(ldapCredentials.ldapHost, ldapCredentials.principal, ex); } finally { closeContext(ctx); } return false; } }
LdapService { public boolean loginUser(Site site, String username, char[] password) { LdapCredentials ldapCredentials = new LdapCredentials(site, username, password, false); TlsAwareLdapContext ctx = null; try { ctx = new TlsAwareLdapContext(ldapCredentials); return true; } catch (IOException | NamingException ex) { logException(ldapCredentials.ldapHost, ldapCredentials.principal, ex); } finally { closeContext(ctx); } return false; } void setLdapCtxFactory(String ldapCtxFactory); boolean loginUser(Site site, String username, char[] password); List<String> loginGroup(Site site, String username, char[] password, SubjectImpl subject, List<String> groupNames); List<SubjectImpl> getMembersOfGroup(Site site, String groupName); }
LdapService { public boolean loginUser(Site site, String username, char[] password) { LdapCredentials ldapCredentials = new LdapCredentials(site, username, password, false); TlsAwareLdapContext ctx = null; try { ctx = new TlsAwareLdapContext(ldapCredentials); return true; } catch (IOException | NamingException ex) { logException(ldapCredentials.ldapHost, ldapCredentials.principal, ex); } finally { closeContext(ctx); } return false; } void setLdapCtxFactory(String ldapCtxFactory); boolean loginUser(Site site, String username, char[] password); List<String> loginGroup(Site site, String username, char[] password, SubjectImpl subject, List<String> groupNames); List<SubjectImpl> getMembersOfGroup(Site site, String groupName); static final String LDAP_DOMAIN; static final String LDAP_GROUP_BASE_DN; static final String LDAP_HOST; static final String LDAP_ID_ATTRIBUTE; static final String LDAP_PASSWORD; static final String LDAP_PRINCIPAL_SCHEME; static final String LDAP_START_TLS; static final String LDAP_USER; static final String LDAP_USER_BASE_DN; }
@Test public void testSign() throws IOException { byte[] cert = FileUtils.readFileToByteArray(certFile); byte[] key = FileUtils.readFileToByteArray(getFile("cert/appng-dev.pem")); Path repoPath = getFile("zip").toPath(); SignatureWrapper signRepo = Signer.signRepo(repoPath, new SignerConfig("Local", "a local test repository", "", key, cert, SigningAlgorithm.SHA512withRSA, PrivateKeyFormat.PEM)); StringWriter output = new StringWriter(); IOUtils.write(signRepo.getIndex(), output, StandardCharsets.UTF_8); String expected = FileUtils.readFileToString(indexFile, StandardCharsets.UTF_8); Assert.assertEquals(expected, output.toString()); byte[] expectedSig = FileUtils.readFileToByteArray(signatureFile); Assert.assertArrayEquals(expectedSig, signRepo.getSignature()); }
public static SignatureWrapper signRepo(Path repoPath, SignerConfig config) throws SigningException { String missingKey = config.hasMissingKey(); if (missingKey != null) throw new SigningException(ErrorType.SIGN, String.format("Missing configuration key '%s' in SignerConfig.", missingKey)); LOGGER.info("Signing repository '{}'", repoPath); try { Path[] pkgPaths = fileGlob(repoPath, "*.{jar,zip}"); Path releaseFilePath = repoPath.resolve("index"); LOGGER.info("Writing release file '{}'", releaseFilePath); try ( BufferedWriter releaseFileOut = Files.newBufferedWriter(releaseFilePath, config.getCharset(), StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)) { LOGGER.info("..adding repository attributes"); for (String key : BaseConfig.validRepoAttributes) { releaseFileOut.append(String.format("%s: %s\n", key, config.repoAttributes.get(key))); } releaseFileOut.append(String.format("%s\n", SignerConfig.RELEASE_FILE_DIGEST_SEPARATOR)); for (Path pkgPath : pkgPaths) { LOGGER.info("..adding message digest of package '{}'", pkgPath.getFileName()); byte[] hashRaw = config.getDigest().digest(Files.readAllBytes(pkgPath)); releaseFileOut .append(String.format("%s: %s\n", pkgPath.getFileName(), Hex.encodeHexString(hashRaw))); } releaseFileOut.close(); Signature sig = config.getSignature(); sig.update(Files.readAllBytes(releaseFilePath)); byte[] signed = sig.sign(); SignatureWrapper signatureWrapper = new SignatureWrapper(); signatureWrapper.setSignature(signed); signatureWrapper.setIndex(Files.readAllBytes(releaseFilePath)); return signatureWrapper; } } catch (IOException ioe) { throw new SigningException(ErrorType.SIGN, "IOException during repo signing. Please check the configured paths and masks.", ioe); } catch (SignatureException se) { throw new SigningException(ErrorType.SIGN, String.format( "SignatureException during repo signing. There is no plausible reason in this part of the code. You probably found a bug!"), se); } }
Signer { public static SignatureWrapper signRepo(Path repoPath, SignerConfig config) throws SigningException { String missingKey = config.hasMissingKey(); if (missingKey != null) throw new SigningException(ErrorType.SIGN, String.format("Missing configuration key '%s' in SignerConfig.", missingKey)); LOGGER.info("Signing repository '{}'", repoPath); try { Path[] pkgPaths = fileGlob(repoPath, "*.{jar,zip}"); Path releaseFilePath = repoPath.resolve("index"); LOGGER.info("Writing release file '{}'", releaseFilePath); try ( BufferedWriter releaseFileOut = Files.newBufferedWriter(releaseFilePath, config.getCharset(), StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)) { LOGGER.info("..adding repository attributes"); for (String key : BaseConfig.validRepoAttributes) { releaseFileOut.append(String.format("%s: %s\n", key, config.repoAttributes.get(key))); } releaseFileOut.append(String.format("%s\n", SignerConfig.RELEASE_FILE_DIGEST_SEPARATOR)); for (Path pkgPath : pkgPaths) { LOGGER.info("..adding message digest of package '{}'", pkgPath.getFileName()); byte[] hashRaw = config.getDigest().digest(Files.readAllBytes(pkgPath)); releaseFileOut .append(String.format("%s: %s\n", pkgPath.getFileName(), Hex.encodeHexString(hashRaw))); } releaseFileOut.close(); Signature sig = config.getSignature(); sig.update(Files.readAllBytes(releaseFilePath)); byte[] signed = sig.sign(); SignatureWrapper signatureWrapper = new SignatureWrapper(); signatureWrapper.setSignature(signed); signatureWrapper.setIndex(Files.readAllBytes(releaseFilePath)); return signatureWrapper; } } catch (IOException ioe) { throw new SigningException(ErrorType.SIGN, "IOException during repo signing. Please check the configured paths and masks.", ioe); } catch (SignatureException se) { throw new SigningException(ErrorType.SIGN, String.format( "SignatureException during repo signing. There is no plausible reason in this part of the code. You probably found a bug!"), se); } } }
Signer { public static SignatureWrapper signRepo(Path repoPath, SignerConfig config) throws SigningException { String missingKey = config.hasMissingKey(); if (missingKey != null) throw new SigningException(ErrorType.SIGN, String.format("Missing configuration key '%s' in SignerConfig.", missingKey)); LOGGER.info("Signing repository '{}'", repoPath); try { Path[] pkgPaths = fileGlob(repoPath, "*.{jar,zip}"); Path releaseFilePath = repoPath.resolve("index"); LOGGER.info("Writing release file '{}'", releaseFilePath); try ( BufferedWriter releaseFileOut = Files.newBufferedWriter(releaseFilePath, config.getCharset(), StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)) { LOGGER.info("..adding repository attributes"); for (String key : BaseConfig.validRepoAttributes) { releaseFileOut.append(String.format("%s: %s\n", key, config.repoAttributes.get(key))); } releaseFileOut.append(String.format("%s\n", SignerConfig.RELEASE_FILE_DIGEST_SEPARATOR)); for (Path pkgPath : pkgPaths) { LOGGER.info("..adding message digest of package '{}'", pkgPath.getFileName()); byte[] hashRaw = config.getDigest().digest(Files.readAllBytes(pkgPath)); releaseFileOut .append(String.format("%s: %s\n", pkgPath.getFileName(), Hex.encodeHexString(hashRaw))); } releaseFileOut.close(); Signature sig = config.getSignature(); sig.update(Files.readAllBytes(releaseFilePath)); byte[] signed = sig.sign(); SignatureWrapper signatureWrapper = new SignatureWrapper(); signatureWrapper.setSignature(signed); signatureWrapper.setIndex(Files.readAllBytes(releaseFilePath)); return signatureWrapper; } } catch (IOException ioe) { throw new SigningException(ErrorType.SIGN, "IOException during repo signing. Please check the configured paths and masks.", ioe); } catch (SignatureException se) { throw new SigningException(ErrorType.SIGN, String.format( "SignatureException during repo signing. There is no plausible reason in this part of the code. You probably found a bug!"), se); } } private Signer(ValidatorConfig config); }
Signer { public static SignatureWrapper signRepo(Path repoPath, SignerConfig config) throws SigningException { String missingKey = config.hasMissingKey(); if (missingKey != null) throw new SigningException(ErrorType.SIGN, String.format("Missing configuration key '%s' in SignerConfig.", missingKey)); LOGGER.info("Signing repository '{}'", repoPath); try { Path[] pkgPaths = fileGlob(repoPath, "*.{jar,zip}"); Path releaseFilePath = repoPath.resolve("index"); LOGGER.info("Writing release file '{}'", releaseFilePath); try ( BufferedWriter releaseFileOut = Files.newBufferedWriter(releaseFilePath, config.getCharset(), StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)) { LOGGER.info("..adding repository attributes"); for (String key : BaseConfig.validRepoAttributes) { releaseFileOut.append(String.format("%s: %s\n", key, config.repoAttributes.get(key))); } releaseFileOut.append(String.format("%s\n", SignerConfig.RELEASE_FILE_DIGEST_SEPARATOR)); for (Path pkgPath : pkgPaths) { LOGGER.info("..adding message digest of package '{}'", pkgPath.getFileName()); byte[] hashRaw = config.getDigest().digest(Files.readAllBytes(pkgPath)); releaseFileOut .append(String.format("%s: %s\n", pkgPath.getFileName(), Hex.encodeHexString(hashRaw))); } releaseFileOut.close(); Signature sig = config.getSignature(); sig.update(Files.readAllBytes(releaseFilePath)); byte[] signed = sig.sign(); SignatureWrapper signatureWrapper = new SignatureWrapper(); signatureWrapper.setSignature(signed); signatureWrapper.setIndex(Files.readAllBytes(releaseFilePath)); return signatureWrapper; } } catch (IOException ioe) { throw new SigningException(ErrorType.SIGN, "IOException during repo signing. Please check the configured paths and masks.", ioe); } catch (SignatureException se) { throw new SigningException(ErrorType.SIGN, String.format( "SignatureException during repo signing. There is no plausible reason in this part of the code. You probably found a bug!"), se); } } private Signer(ValidatorConfig config); static Signer getRepoValidator(ValidatorConfig config, byte[] indexFileData, byte[] signatureData); static Signer getRepoValidator(ValidatorConfig config, byte[] indexFileData, byte[] signatureData, Collection<X509Certificate> trustedCerts); boolean validatePackage(byte[] bytes, String packageName); static SignatureWrapper signRepo(Path repoPath, SignerConfig config); }
Signer { public static SignatureWrapper signRepo(Path repoPath, SignerConfig config) throws SigningException { String missingKey = config.hasMissingKey(); if (missingKey != null) throw new SigningException(ErrorType.SIGN, String.format("Missing configuration key '%s' in SignerConfig.", missingKey)); LOGGER.info("Signing repository '{}'", repoPath); try { Path[] pkgPaths = fileGlob(repoPath, "*.{jar,zip}"); Path releaseFilePath = repoPath.resolve("index"); LOGGER.info("Writing release file '{}'", releaseFilePath); try ( BufferedWriter releaseFileOut = Files.newBufferedWriter(releaseFilePath, config.getCharset(), StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)) { LOGGER.info("..adding repository attributes"); for (String key : BaseConfig.validRepoAttributes) { releaseFileOut.append(String.format("%s: %s\n", key, config.repoAttributes.get(key))); } releaseFileOut.append(String.format("%s\n", SignerConfig.RELEASE_FILE_DIGEST_SEPARATOR)); for (Path pkgPath : pkgPaths) { LOGGER.info("..adding message digest of package '{}'", pkgPath.getFileName()); byte[] hashRaw = config.getDigest().digest(Files.readAllBytes(pkgPath)); releaseFileOut .append(String.format("%s: %s\n", pkgPath.getFileName(), Hex.encodeHexString(hashRaw))); } releaseFileOut.close(); Signature sig = config.getSignature(); sig.update(Files.readAllBytes(releaseFilePath)); byte[] signed = sig.sign(); SignatureWrapper signatureWrapper = new SignatureWrapper(); signatureWrapper.setSignature(signed); signatureWrapper.setIndex(Files.readAllBytes(releaseFilePath)); return signatureWrapper; } } catch (IOException ioe) { throw new SigningException(ErrorType.SIGN, "IOException during repo signing. Please check the configured paths and masks.", ioe); } catch (SignatureException se) { throw new SigningException(ErrorType.SIGN, String.format( "SignatureException during repo signing. There is no plausible reason in this part of the code. You probably found a bug!"), se); } } private Signer(ValidatorConfig config); static Signer getRepoValidator(ValidatorConfig config, byte[] indexFileData, byte[] signatureData); static Signer getRepoValidator(ValidatorConfig config, byte[] indexFileData, byte[] signatureData, Collection<X509Certificate> trustedCerts); boolean validatePackage(byte[] bytes, String packageName); static SignatureWrapper signRepo(Path repoPath, SignerConfig config); }
@Test public void testCaptcha() { assertFalse("captcha(bar, SESSION.foobar)"); assertFalse("captcha(bar, SESSION['foobar'])"); assertTrue("captcha(5, SESSION.foobar)"); assertTrue("captcha(5, SESSION['foobar'])"); }
public static boolean captcha(String value, String result) { return StringUtils.equals(value, result); }
RuleValidation { public static boolean captcha(String value, String result) { return StringUtils.equals(value, result); } }
RuleValidation { public static boolean captcha(String value, String result) { return StringUtils.equals(value, result); } RuleValidation(Request container); }
RuleValidation { public static boolean captcha(String value, String result) { return StringUtils.equals(value, result); } RuleValidation(Request container); Map<String, List<FormUpload>> getFileParams(Map<String, List<FormUpload>> formUploads); boolean validate(String rule); static boolean string(String string); static boolean captcha(String value, String result); static boolean email(String string); static boolean equals(String string1, String string2); static boolean number(String string); static boolean number(String string, char separator); static boolean numberFractionDigits(String string, int digits, int fraction); static boolean number(String string, char separator, int digits, int fraction); static boolean regExp(String string, String regex); static boolean size(Object item, int size); static boolean sizeMax(Object item, int max); static boolean sizeMin(Object item, int min); static boolean sizeMinMax(Object item, int min, int max); static boolean fileType(List<FormUpload> fUpload, String types); static boolean fileSize(List<FormUpload> fUpload, String minSize, String maxSize); static boolean fileSizeMin(List<FormUpload> fUpload, String minSize); static boolean fileSizeMax(List<FormUpload> fUpload, String maxSize); static boolean fileCountMin(List<FormUpload> fUpload, int count); static boolean fileCountMax(List<FormUpload> fUpload, int count); static boolean fileCount(List<FormUpload> fUpload, int minCount, int maxCount); }
RuleValidation { public static boolean captcha(String value, String result) { return StringUtils.equals(value, result); } RuleValidation(Request container); Map<String, List<FormUpload>> getFileParams(Map<String, List<FormUpload>> formUploads); boolean validate(String rule); static boolean string(String string); static boolean captcha(String value, String result); static boolean email(String string); static boolean equals(String string1, String string2); static boolean number(String string); static boolean number(String string, char separator); static boolean numberFractionDigits(String string, int digits, int fraction); static boolean number(String string, char separator, int digits, int fraction); static boolean regExp(String string, String regex); static boolean size(Object item, int size); static boolean sizeMax(Object item, int max); static boolean sizeMin(Object item, int min); static boolean sizeMinMax(Object item, int min, int max); static boolean fileType(List<FormUpload> fUpload, String types); static boolean fileSize(List<FormUpload> fUpload, String minSize, String maxSize); static boolean fileSizeMin(List<FormUpload> fUpload, String minSize); static boolean fileSizeMax(List<FormUpload> fUpload, String maxSize); static boolean fileCountMin(List<FormUpload> fUpload, int count); static boolean fileCountMax(List<FormUpload> fUpload, int count); static boolean fileCount(List<FormUpload> fUpload, int minCount, int maxCount); static final List<String> SHORT_RULES; }
@Test(expected = SigningException.class) public void testVerfiyInvalidSignature() throws IOException { ValidatorConfig config = new ValidatorConfig(); config.setSigningCert(FileUtils.readFileToByteArray(certFile), SigningAlgorithm.SHA512withRSA); Signer.getRepoValidator(config, FileUtils.readFileToByteArray(indexFile), FileUtils.readFileToByteArray(indexFile)); }
public static Signer getRepoValidator(ValidatorConfig config, byte[] indexFileData, byte[] signatureData) throws SigningException { return getRepoValidator(config, indexFileData, signatureData, null); }
Signer { public static Signer getRepoValidator(ValidatorConfig config, byte[] indexFileData, byte[] signatureData) throws SigningException { return getRepoValidator(config, indexFileData, signatureData, null); } }
Signer { public static Signer getRepoValidator(ValidatorConfig config, byte[] indexFileData, byte[] signatureData) throws SigningException { return getRepoValidator(config, indexFileData, signatureData, null); } private Signer(ValidatorConfig config); }
Signer { public static Signer getRepoValidator(ValidatorConfig config, byte[] indexFileData, byte[] signatureData) throws SigningException { return getRepoValidator(config, indexFileData, signatureData, null); } private Signer(ValidatorConfig config); static Signer getRepoValidator(ValidatorConfig config, byte[] indexFileData, byte[] signatureData); static Signer getRepoValidator(ValidatorConfig config, byte[] indexFileData, byte[] signatureData, Collection<X509Certificate> trustedCerts); boolean validatePackage(byte[] bytes, String packageName); static SignatureWrapper signRepo(Path repoPath, SignerConfig config); }
Signer { public static Signer getRepoValidator(ValidatorConfig config, byte[] indexFileData, byte[] signatureData) throws SigningException { return getRepoValidator(config, indexFileData, signatureData, null); } private Signer(ValidatorConfig config); static Signer getRepoValidator(ValidatorConfig config, byte[] indexFileData, byte[] signatureData); static Signer getRepoValidator(ValidatorConfig config, byte[] indexFileData, byte[] signatureData, Collection<X509Certificate> trustedCerts); boolean validatePackage(byte[] bytes, String packageName); static SignatureWrapper signRepo(Path repoPath, SignerConfig config); }
@Test public void testValidPassword() { subject.setDigest(BCRYPT_DIGEST); PasswordHandler handler = new BCryptPasswordHandler(subject); assertTrue(handler.isValidPassword(PASSWORD)); }
public boolean isValidPassword(String password) { boolean isValid = BCrypt.checkpw(password, authSubject.getDigest()); return isValid; }
BCryptPasswordHandler implements PasswordHandler { public boolean isValidPassword(String password) { boolean isValid = BCrypt.checkpw(password, authSubject.getDigest()); return isValid; } }
BCryptPasswordHandler implements PasswordHandler { public boolean isValidPassword(String password) { boolean isValid = BCrypt.checkpw(password, authSubject.getDigest()); return isValid; } BCryptPasswordHandler(AuthSubject authSubject); }
BCryptPasswordHandler implements PasswordHandler { public boolean isValidPassword(String password) { boolean isValid = BCrypt.checkpw(password, authSubject.getDigest()); return isValid; } BCryptPasswordHandler(AuthSubject authSubject); void applyPassword(String password); boolean isValidPassword(String password); String calculatePasswordResetDigest(); boolean isValidPasswordResetDigest(String digest); void migrate(CoreService service, String password); static String getPrefix(); }
BCryptPasswordHandler implements PasswordHandler { public boolean isValidPassword(String password) { boolean isValid = BCrypt.checkpw(password, authSubject.getDigest()); return isValid; } BCryptPasswordHandler(AuthSubject authSubject); void applyPassword(String password); boolean isValidPassword(String password); String calculatePasswordResetDigest(); boolean isValidPasswordResetDigest(String digest); void migrate(CoreService service, String password); static String getPrefix(); }
@Test public void testInvalidPassword() { subject.setDigest(BCRYPT_DIGEST.substring(0, BCRYPT_DIGEST.length() - 1)); PasswordHandler handler = new BCryptPasswordHandler(subject); assertFalse(handler.isValidPassword(PASSWORD)); }
public boolean isValidPassword(String password) { boolean isValid = BCrypt.checkpw(password, authSubject.getDigest()); return isValid; }
BCryptPasswordHandler implements PasswordHandler { public boolean isValidPassword(String password) { boolean isValid = BCrypt.checkpw(password, authSubject.getDigest()); return isValid; } }
BCryptPasswordHandler implements PasswordHandler { public boolean isValidPassword(String password) { boolean isValid = BCrypt.checkpw(password, authSubject.getDigest()); return isValid; } BCryptPasswordHandler(AuthSubject authSubject); }
BCryptPasswordHandler implements PasswordHandler { public boolean isValidPassword(String password) { boolean isValid = BCrypt.checkpw(password, authSubject.getDigest()); return isValid; } BCryptPasswordHandler(AuthSubject authSubject); void applyPassword(String password); boolean isValidPassword(String password); String calculatePasswordResetDigest(); boolean isValidPasswordResetDigest(String digest); void migrate(CoreService service, String password); static String getPrefix(); }
BCryptPasswordHandler implements PasswordHandler { public boolean isValidPassword(String password) { boolean isValid = BCrypt.checkpw(password, authSubject.getDigest()); return isValid; } BCryptPasswordHandler(AuthSubject authSubject); void applyPassword(String password); boolean isValidPassword(String password); String calculatePasswordResetDigest(); boolean isValidPasswordResetDigest(String digest); void migrate(CoreService service, String password); static String getPrefix(); }
@Test public void testIsValidPasswordResetDigest() { testIsValidPasswordResetDigest(new BCryptPasswordHandler(subject)); }
public boolean isValidPasswordResetDigest(String digest) { String expectedDigest = new SaltedDigestSha1().getDigest(authSubject.getEmail(), authSubject.getSalt()); return expectedDigest.equals(digest); }
BCryptPasswordHandler implements PasswordHandler { public boolean isValidPasswordResetDigest(String digest) { String expectedDigest = new SaltedDigestSha1().getDigest(authSubject.getEmail(), authSubject.getSalt()); return expectedDigest.equals(digest); } }
BCryptPasswordHandler implements PasswordHandler { public boolean isValidPasswordResetDigest(String digest) { String expectedDigest = new SaltedDigestSha1().getDigest(authSubject.getEmail(), authSubject.getSalt()); return expectedDigest.equals(digest); } BCryptPasswordHandler(AuthSubject authSubject); }
BCryptPasswordHandler implements PasswordHandler { public boolean isValidPasswordResetDigest(String digest) { String expectedDigest = new SaltedDigestSha1().getDigest(authSubject.getEmail(), authSubject.getSalt()); return expectedDigest.equals(digest); } BCryptPasswordHandler(AuthSubject authSubject); void applyPassword(String password); boolean isValidPassword(String password); String calculatePasswordResetDigest(); boolean isValidPasswordResetDigest(String digest); void migrate(CoreService service, String password); static String getPrefix(); }
BCryptPasswordHandler implements PasswordHandler { public boolean isValidPasswordResetDigest(String digest) { String expectedDigest = new SaltedDigestSha1().getDigest(authSubject.getEmail(), authSubject.getSalt()); return expectedDigest.equals(digest); } BCryptPasswordHandler(AuthSubject authSubject); void applyPassword(String password); boolean isValidPassword(String password); String calculatePasswordResetDigest(); boolean isValidPasswordResetDigest(String digest); void migrate(CoreService service, String password); static String getPrefix(); }
@Test public void test() { String digest = DigestUtil.getDigest(username, sharedSecret); boolean isValid = new DigestValidator(digest,60).validate(sharedSecret); Assert.assertTrue("digest must be valid", isValid); }
public boolean validate(String sharedSecret) { if (!errors && setClientDate() && validateTimestamp() && validateHashedPart(sharedSecret)) { LOGGER.info("Digest successfully validated."); return true; } LOGGER.error("Digest validation failed."); return false; }
DigestValidator { public boolean validate(String sharedSecret) { if (!errors && setClientDate() && validateTimestamp() && validateHashedPart(sharedSecret)) { LOGGER.info("Digest successfully validated."); return true; } LOGGER.error("Digest validation failed."); return false; } }
DigestValidator { public boolean validate(String sharedSecret) { if (!errors && setClientDate() && validateTimestamp() && validateHashedPart(sharedSecret)) { LOGGER.info("Digest successfully validated."); return true; } LOGGER.error("Digest validation failed."); return false; } DigestValidator(String digest); DigestValidator(String digest, int maxOffsetMinutes); }
DigestValidator { public boolean validate(String sharedSecret) { if (!errors && setClientDate() && validateTimestamp() && validateHashedPart(sharedSecret)) { LOGGER.info("Digest successfully validated."); return true; } LOGGER.error("Digest validation failed."); return false; } DigestValidator(String digest); DigestValidator(String digest, int maxOffsetMinutes); boolean validate(String sharedSecret); String getUsername(); String getTimestamp(); String getUtcOffset(); }
DigestValidator { public boolean validate(String sharedSecret) { if (!errors && setClientDate() && validateTimestamp() && validateHashedPart(sharedSecret)) { LOGGER.info("Digest successfully validated."); return true; } LOGGER.error("Digest validation failed."); return false; } DigestValidator(String digest); DigestValidator(String digest, int maxOffsetMinutes); boolean validate(String sharedSecret); String getUsername(); String getTimestamp(); String getUtcOffset(); }
@Test public void testInvalid() { String digest = DigestUtil.getDigest(username, sharedSecret); boolean isValid = new DigestValidator(digest).validate("jinfizz"); Assert.assertFalse("digest must invalid", isValid); }
public boolean validate(String sharedSecret) { if (!errors && setClientDate() && validateTimestamp() && validateHashedPart(sharedSecret)) { LOGGER.info("Digest successfully validated."); return true; } LOGGER.error("Digest validation failed."); return false; }
DigestValidator { public boolean validate(String sharedSecret) { if (!errors && setClientDate() && validateTimestamp() && validateHashedPart(sharedSecret)) { LOGGER.info("Digest successfully validated."); return true; } LOGGER.error("Digest validation failed."); return false; } }
DigestValidator { public boolean validate(String sharedSecret) { if (!errors && setClientDate() && validateTimestamp() && validateHashedPart(sharedSecret)) { LOGGER.info("Digest successfully validated."); return true; } LOGGER.error("Digest validation failed."); return false; } DigestValidator(String digest); DigestValidator(String digest, int maxOffsetMinutes); }
DigestValidator { public boolean validate(String sharedSecret) { if (!errors && setClientDate() && validateTimestamp() && validateHashedPart(sharedSecret)) { LOGGER.info("Digest successfully validated."); return true; } LOGGER.error("Digest validation failed."); return false; } DigestValidator(String digest); DigestValidator(String digest, int maxOffsetMinutes); boolean validate(String sharedSecret); String getUsername(); String getTimestamp(); String getUtcOffset(); }
DigestValidator { public boolean validate(String sharedSecret) { if (!errors && setClientDate() && validateTimestamp() && validateHashedPart(sharedSecret)) { LOGGER.info("Digest successfully validated."); return true; } LOGGER.error("Digest validation failed."); return false; } DigestValidator(String digest); DigestValidator(String digest, int maxOffsetMinutes); boolean validate(String sharedSecret); String getUsername(); String getTimestamp(); String getUtcOffset(); }
@Test public void testGenerate() { for (int i = 0; i < 1000; i++) { String password = passwordPolicy.generatePassword(); assertValid(password); } }
public String generatePassword() { return random(6, LOWERCASE + UPPERCASE) + random(1, NUMBER) + random(1, PUNCT); }
DefaultPasswordPolicy implements PasswordPolicy { public String generatePassword() { return random(6, LOWERCASE + UPPERCASE) + random(1, NUMBER) + random(1, PUNCT); } }
DefaultPasswordPolicy implements PasswordPolicy { public String generatePassword() { return random(6, LOWERCASE + UPPERCASE) + random(1, NUMBER) + random(1, PUNCT); } @Deprecated DefaultPasswordPolicy(); @Deprecated DefaultPasswordPolicy(String regEx, String errorMessageKey); }
DefaultPasswordPolicy implements PasswordPolicy { public String generatePassword() { return random(6, LOWERCASE + UPPERCASE) + random(1, NUMBER) + random(1, PUNCT); } @Deprecated DefaultPasswordPolicy(); @Deprecated DefaultPasswordPolicy(String regEx, String errorMessageKey); @Override void configure(Properties platformConfig); boolean isValidPassword(char[] password); @Override ValidationResult validatePassword(String username, char[] currentPassword, char[] password); String getErrorMessageKey(); Pattern getPattern(); String generatePassword(); }
DefaultPasswordPolicy implements PasswordPolicy { public String generatePassword() { return random(6, LOWERCASE + UPPERCASE) + random(1, NUMBER) + random(1, PUNCT); } @Deprecated DefaultPasswordPolicy(); @Deprecated DefaultPasswordPolicy(String regEx, String errorMessageKey); @Override void configure(Properties platformConfig); boolean isValidPassword(char[] password); @Override ValidationResult validatePassword(String username, char[] currentPassword, char[] password); String getErrorMessageKey(); Pattern getPattern(); String generatePassword(); static final String REGEX; static final String ERROR_MSSG_KEY; }
@Test public void testComplexRegex() { String expression = "^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)" + "(?=.*[" + "\\x21-\\x2f" + "\\x3A-\\x40" + "\\x5b-\\x60" + "\\x7b-\\x7e" + "])" + "[\\x21-\\x7e]" + "{8,}$"; PasswordPolicy policy = new DefaultPasswordPolicy(expression, "dummy"); Assert.assertFalse(policy.isValidPassword("testtest".toCharArray())); Assert.assertFalse(policy.isValidPassword("TESTTEST".toCharArray())); Assert.assertFalse(policy.isValidPassword("12345678".toCharArray())); Assert.assertFalse(policy.isValidPassword("!!!!!!!!".toCharArray())); Assert.assertFalse(policy.isValidPassword("testTEST".toCharArray())); Assert.assertFalse(policy.isValidPassword("test1234".toCharArray())); Assert.assertFalse(policy.isValidPassword("test!!!!".toCharArray())); Assert.assertFalse(policy.isValidPassword("TEST1234".toCharArray())); Assert.assertFalse(policy.isValidPassword("TEST!!!!".toCharArray())); Assert.assertFalse(policy.isValidPassword("1234!!!!".toCharArray())); Assert.assertFalse(policy.isValidPassword("testTEST12".toCharArray())); Assert.assertFalse(policy.isValidPassword("testTEST!!".toCharArray())); Assert.assertFalse(policy.isValidPassword("test1234!!".toCharArray())); Assert.assertFalse(policy.isValidPassword("TEST1234!!".toCharArray())); Assert.assertFalse(policy.isValidPassword("Test!12".toCharArray())); Assert.assertFalse(policy.isValidPassword("Test12!".toCharArray())); Assert.assertFalse(policy.isValidPassword("12Test!".toCharArray())); Assert.assertFalse(policy.isValidPassword("12!Test".toCharArray())); Assert.assertFalse(policy.isValidPassword("!Test12".toCharArray())); Assert.assertFalse(policy.isValidPassword("!12Test".toCharArray())); Assert.assertTrue(policy.isValidPassword("teST12!!".toCharArray())); Assert.assertTrue(policy.isValidPassword("teST!!12".toCharArray())); Assert.assertTrue(policy.isValidPassword("TEst!!12".toCharArray())); Assert.assertTrue(policy.isValidPassword("TEst12!!".toCharArray())); Assert.assertTrue(policy.isValidPassword("12!!teST".toCharArray())); Assert.assertTrue(policy.isValidPassword("12!!TEst".toCharArray())); Assert.assertTrue(policy.isValidPassword("!!12teST".toCharArray())); Assert.assertTrue(policy.isValidPassword("!!12TEst".toCharArray())); }
public boolean isValidPassword(char[] password) { return pattern.matcher(new String(password)).matches(); }
DefaultPasswordPolicy implements PasswordPolicy { public boolean isValidPassword(char[] password) { return pattern.matcher(new String(password)).matches(); } }
DefaultPasswordPolicy implements PasswordPolicy { public boolean isValidPassword(char[] password) { return pattern.matcher(new String(password)).matches(); } @Deprecated DefaultPasswordPolicy(); @Deprecated DefaultPasswordPolicy(String regEx, String errorMessageKey); }
DefaultPasswordPolicy implements PasswordPolicy { public boolean isValidPassword(char[] password) { return pattern.matcher(new String(password)).matches(); } @Deprecated DefaultPasswordPolicy(); @Deprecated DefaultPasswordPolicy(String regEx, String errorMessageKey); @Override void configure(Properties platformConfig); boolean isValidPassword(char[] password); @Override ValidationResult validatePassword(String username, char[] currentPassword, char[] password); String getErrorMessageKey(); Pattern getPattern(); String generatePassword(); }
DefaultPasswordPolicy implements PasswordPolicy { public boolean isValidPassword(char[] password) { return pattern.matcher(new String(password)).matches(); } @Deprecated DefaultPasswordPolicy(); @Deprecated DefaultPasswordPolicy(String regEx, String errorMessageKey); @Override void configure(Properties platformConfig); boolean isValidPassword(char[] password); @Override ValidationResult validatePassword(String username, char[] currentPassword, char[] password); String getErrorMessageKey(); Pattern getPattern(); String generatePassword(); static final String REGEX; static final String ERROR_MSSG_KEY; }
@Test public void testSavePassword() { PasswordHandler handler = new Sha1PasswordHandler(subject); handler.applyPassword(PASSWORD); Assert.assertNotNull(subject.getDigest()); Assert.assertTrue(!subject.getDigest().startsWith(BCryptPasswordHandler.getPrefix())); Assert.assertNotNull(subject.getSalt()); }
public void applyPassword(String password) { String salt = saltedDigest.getSalt(); String digest = saltedDigest.getDigest(password, salt); authSubject.setSalt(salt); authSubject.setDigest(digest); authSubject.setPasswordLastChanged(new Date()); }
Sha1PasswordHandler implements PasswordHandler { public void applyPassword(String password) { String salt = saltedDigest.getSalt(); String digest = saltedDigest.getDigest(password, salt); authSubject.setSalt(salt); authSubject.setDigest(digest); authSubject.setPasswordLastChanged(new Date()); } }
Sha1PasswordHandler implements PasswordHandler { public void applyPassword(String password) { String salt = saltedDigest.getSalt(); String digest = saltedDigest.getDigest(password, salt); authSubject.setSalt(salt); authSubject.setDigest(digest); authSubject.setPasswordLastChanged(new Date()); } Sha1PasswordHandler(AuthSubject authSubject); }
Sha1PasswordHandler implements PasswordHandler { public void applyPassword(String password) { String salt = saltedDigest.getSalt(); String digest = saltedDigest.getDigest(password, salt); authSubject.setSalt(salt); authSubject.setDigest(digest); authSubject.setPasswordLastChanged(new Date()); } Sha1PasswordHandler(AuthSubject authSubject); void applyPassword(String password); boolean isValidPassword(String password); String calculatePasswordResetDigest(); boolean isValidPasswordResetDigest(String digest); void migrate(CoreService service, String password); }
Sha1PasswordHandler implements PasswordHandler { public void applyPassword(String password) { String salt = saltedDigest.getSalt(); String digest = saltedDigest.getDigest(password, salt); authSubject.setSalt(salt); authSubject.setDigest(digest); authSubject.setPasswordLastChanged(new Date()); } Sha1PasswordHandler(AuthSubject authSubject); void applyPassword(String password); boolean isValidPassword(String password); String calculatePasswordResetDigest(); boolean isValidPasswordResetDigest(String digest); void migrate(CoreService service, String password); }
@Test public void testValidPassword() { subject.setDigest(SHA1_DIGEST); subject.setSalt(SHA1_SALT); PasswordHandler handler = new Sha1PasswordHandler(subject); assertTrue(handler.isValidPassword(PASSWORD)); }
public boolean isValidPassword(String password) { String digest = saltedDigest.getDigest(password, authSubject.getSalt()); return digest.equals(authSubject.getDigest()); }
Sha1PasswordHandler implements PasswordHandler { public boolean isValidPassword(String password) { String digest = saltedDigest.getDigest(password, authSubject.getSalt()); return digest.equals(authSubject.getDigest()); } }
Sha1PasswordHandler implements PasswordHandler { public boolean isValidPassword(String password) { String digest = saltedDigest.getDigest(password, authSubject.getSalt()); return digest.equals(authSubject.getDigest()); } Sha1PasswordHandler(AuthSubject authSubject); }
Sha1PasswordHandler implements PasswordHandler { public boolean isValidPassword(String password) { String digest = saltedDigest.getDigest(password, authSubject.getSalt()); return digest.equals(authSubject.getDigest()); } Sha1PasswordHandler(AuthSubject authSubject); void applyPassword(String password); boolean isValidPassword(String password); String calculatePasswordResetDigest(); boolean isValidPasswordResetDigest(String digest); void migrate(CoreService service, String password); }
Sha1PasswordHandler implements PasswordHandler { public boolean isValidPassword(String password) { String digest = saltedDigest.getDigest(password, authSubject.getSalt()); return digest.equals(authSubject.getDigest()); } Sha1PasswordHandler(AuthSubject authSubject); void applyPassword(String password); boolean isValidPassword(String password); String calculatePasswordResetDigest(); boolean isValidPasswordResetDigest(String digest); void migrate(CoreService service, String password); }
@Test public void testEmail() { assertTrue("email('[email protected]')"); assertTrue("email('[email protected]')"); assertFalse("email('mm@aiticon')"); assertFalse("email('@aiticon.de')"); }
public static boolean email(String string) { return regExp(string, EMAIL_PATTERN); }
RuleValidation { public static boolean email(String string) { return regExp(string, EMAIL_PATTERN); } }
RuleValidation { public static boolean email(String string) { return regExp(string, EMAIL_PATTERN); } RuleValidation(Request container); }
RuleValidation { public static boolean email(String string) { return regExp(string, EMAIL_PATTERN); } RuleValidation(Request container); Map<String, List<FormUpload>> getFileParams(Map<String, List<FormUpload>> formUploads); boolean validate(String rule); static boolean string(String string); static boolean captcha(String value, String result); static boolean email(String string); static boolean equals(String string1, String string2); static boolean number(String string); static boolean number(String string, char separator); static boolean numberFractionDigits(String string, int digits, int fraction); static boolean number(String string, char separator, int digits, int fraction); static boolean regExp(String string, String regex); static boolean size(Object item, int size); static boolean sizeMax(Object item, int max); static boolean sizeMin(Object item, int min); static boolean sizeMinMax(Object item, int min, int max); static boolean fileType(List<FormUpload> fUpload, String types); static boolean fileSize(List<FormUpload> fUpload, String minSize, String maxSize); static boolean fileSizeMin(List<FormUpload> fUpload, String minSize); static boolean fileSizeMax(List<FormUpload> fUpload, String maxSize); static boolean fileCountMin(List<FormUpload> fUpload, int count); static boolean fileCountMax(List<FormUpload> fUpload, int count); static boolean fileCount(List<FormUpload> fUpload, int minCount, int maxCount); }
RuleValidation { public static boolean email(String string) { return regExp(string, EMAIL_PATTERN); } RuleValidation(Request container); Map<String, List<FormUpload>> getFileParams(Map<String, List<FormUpload>> formUploads); boolean validate(String rule); static boolean string(String string); static boolean captcha(String value, String result); static boolean email(String string); static boolean equals(String string1, String string2); static boolean number(String string); static boolean number(String string, char separator); static boolean numberFractionDigits(String string, int digits, int fraction); static boolean number(String string, char separator, int digits, int fraction); static boolean regExp(String string, String regex); static boolean size(Object item, int size); static boolean sizeMax(Object item, int max); static boolean sizeMin(Object item, int min); static boolean sizeMinMax(Object item, int min, int max); static boolean fileType(List<FormUpload> fUpload, String types); static boolean fileSize(List<FormUpload> fUpload, String minSize, String maxSize); static boolean fileSizeMin(List<FormUpload> fUpload, String minSize); static boolean fileSizeMax(List<FormUpload> fUpload, String maxSize); static boolean fileCountMin(List<FormUpload> fUpload, int count); static boolean fileCountMax(List<FormUpload> fUpload, int count); static boolean fileCount(List<FormUpload> fUpload, int minCount, int maxCount); static final List<String> SHORT_RULES; }
@Test public void testInvalidPassword() { subject.setDigest(SHA1_DIGEST.substring(1)); subject.setSalt(SHA1_SALT); PasswordHandler handler = new Sha1PasswordHandler(subject); assertFalse(handler.isValidPassword(PASSWORD)); }
public boolean isValidPassword(String password) { String digest = saltedDigest.getDigest(password, authSubject.getSalt()); return digest.equals(authSubject.getDigest()); }
Sha1PasswordHandler implements PasswordHandler { public boolean isValidPassword(String password) { String digest = saltedDigest.getDigest(password, authSubject.getSalt()); return digest.equals(authSubject.getDigest()); } }
Sha1PasswordHandler implements PasswordHandler { public boolean isValidPassword(String password) { String digest = saltedDigest.getDigest(password, authSubject.getSalt()); return digest.equals(authSubject.getDigest()); } Sha1PasswordHandler(AuthSubject authSubject); }
Sha1PasswordHandler implements PasswordHandler { public boolean isValidPassword(String password) { String digest = saltedDigest.getDigest(password, authSubject.getSalt()); return digest.equals(authSubject.getDigest()); } Sha1PasswordHandler(AuthSubject authSubject); void applyPassword(String password); boolean isValidPassword(String password); String calculatePasswordResetDigest(); boolean isValidPasswordResetDigest(String digest); void migrate(CoreService service, String password); }
Sha1PasswordHandler implements PasswordHandler { public boolean isValidPassword(String password) { String digest = saltedDigest.getDigest(password, authSubject.getSalt()); return digest.equals(authSubject.getDigest()); } Sha1PasswordHandler(AuthSubject authSubject); void applyPassword(String password); boolean isValidPassword(String password); String calculatePasswordResetDigest(); boolean isValidPasswordResetDigest(String digest); void migrate(CoreService service, String password); }
@Test public void testGetPasswordResetDigest() { subject.setSalt(SHA1_SALT); subject.setEmail(EMAIL); PasswordHandler handler = new Sha1PasswordHandler(subject); String digest = handler.calculatePasswordResetDigest(); Assert.assertEquals(SHA1_SALT, subject.getSalt()); Assert.assertEquals(SHA1_PW_RESET_DIGEST, digest); }
public String calculatePasswordResetDigest() { return saltedDigest.getDigest(authSubject.getEmail(), authSubject.getSalt()); }
Sha1PasswordHandler implements PasswordHandler { public String calculatePasswordResetDigest() { return saltedDigest.getDigest(authSubject.getEmail(), authSubject.getSalt()); } }
Sha1PasswordHandler implements PasswordHandler { public String calculatePasswordResetDigest() { return saltedDigest.getDigest(authSubject.getEmail(), authSubject.getSalt()); } Sha1PasswordHandler(AuthSubject authSubject); }
Sha1PasswordHandler implements PasswordHandler { public String calculatePasswordResetDigest() { return saltedDigest.getDigest(authSubject.getEmail(), authSubject.getSalt()); } Sha1PasswordHandler(AuthSubject authSubject); void applyPassword(String password); boolean isValidPassword(String password); String calculatePasswordResetDigest(); boolean isValidPasswordResetDigest(String digest); void migrate(CoreService service, String password); }
Sha1PasswordHandler implements PasswordHandler { public String calculatePasswordResetDigest() { return saltedDigest.getDigest(authSubject.getEmail(), authSubject.getSalt()); } Sha1PasswordHandler(AuthSubject authSubject); void applyPassword(String password); boolean isValidPassword(String password); String calculatePasswordResetDigest(); boolean isValidPasswordResetDigest(String digest); void migrate(CoreService service, String password); }
@Test public void testIsValidPasswordResetDigest() { testIsValidPasswordResetDigest(new Sha1PasswordHandler(subject)); }
public boolean isValidPasswordResetDigest(String digest) { return calculatePasswordResetDigest().equals(digest); }
Sha1PasswordHandler implements PasswordHandler { public boolean isValidPasswordResetDigest(String digest) { return calculatePasswordResetDigest().equals(digest); } }
Sha1PasswordHandler implements PasswordHandler { public boolean isValidPasswordResetDigest(String digest) { return calculatePasswordResetDigest().equals(digest); } Sha1PasswordHandler(AuthSubject authSubject); }
Sha1PasswordHandler implements PasswordHandler { public boolean isValidPasswordResetDigest(String digest) { return calculatePasswordResetDigest().equals(digest); } Sha1PasswordHandler(AuthSubject authSubject); void applyPassword(String password); boolean isValidPassword(String password); String calculatePasswordResetDigest(); boolean isValidPasswordResetDigest(String digest); void migrate(CoreService service, String password); }
Sha1PasswordHandler implements PasswordHandler { public boolean isValidPasswordResetDigest(String digest) { return calculatePasswordResetDigest().equals(digest); } Sha1PasswordHandler(AuthSubject authSubject); void applyPassword(String password); boolean isValidPassword(String password); String calculatePasswordResetDigest(); boolean isValidPasswordResetDigest(String digest); void migrate(CoreService service, String password); }
@Test public void testPasswords() { String username = "johndoe"; String currentPassword = "test"; assertFirstError(AllowedCharacterRule.ERROR_CODE, username, currentPassword, "TEst12!!ß"); assertFirstError(WhitespaceRule.ERROR_CODE, username, currentPassword, "TEst12!! "); assertFirstError(UsernameRule.ERROR_CODE, username, currentPassword, username + "12!O"); assertFirstError(HistoryRule.ERROR_CODE, username, "Test123!!", "Test123!!"); String noUpperCase = EnglishCharacterData.UpperCase.getErrorCode(); String noLowerCase = EnglishCharacterData.LowerCase.getErrorCode(); String noDigit = EnglishCharacterData.Digit.getErrorCode(); String noSpecial = EnglishCharacterData.Special.getErrorCode(); assertFirstError(noUpperCase, username, currentPassword, "testtest"); assertFirstError(noLowerCase, username, currentPassword, "TESTTEST"); assertFirstError(noLowerCase, username, currentPassword, "12345678"); assertFirstError(noLowerCase, username, currentPassword, "!!!!!!!!"); assertFirstError(noDigit, username, currentPassword, "testTEST"); assertFirstError(noUpperCase, username, currentPassword, "test1234"); assertFirstError(noUpperCase, username, currentPassword, "test!!!!"); assertFirstError(noLowerCase, username, currentPassword, "TEST1234"); assertFirstError(noLowerCase, username, currentPassword, "TEST!!!!"); assertFirstError(noLowerCase, username, currentPassword, "1234!!!!"); assertFirstError(noSpecial, username, currentPassword, "testTEST12"); assertFirstError(noSpecial, username, currentPassword, "testTEST12"); assertFirstError(noDigit, username, currentPassword, "testTEST!!"); assertFirstError(noUpperCase, username, currentPassword, "test1234!!"); assertFirstError(noLowerCase, username, currentPassword, "TEST1234!!"); String toShort = LengthRule.ERROR_CODE_MIN; assertFirstError(toShort, username, currentPassword, "Test!12"); assertFirstError(toShort, username, currentPassword, "Test12!"); assertFirstError(toShort, username, currentPassword, "12Test!"); assertFirstError(toShort, username, currentPassword, "12!Test"); assertFirstError(toShort, username, currentPassword, "!Test12"); assertFirstError(toShort, username, currentPassword, "!12Test"); Assert.assertTrue( policy.validatePassword(username, currentPassword.toCharArray(), "teST12!!".toCharArray()).isValid()); Assert.assertTrue( policy.validatePassword(username, currentPassword.toCharArray(), "teST!!12".toCharArray()).isValid()); Assert.assertTrue( policy.validatePassword(username, currentPassword.toCharArray(), "TEst!!12".toCharArray()).isValid()); Assert.assertTrue( policy.validatePassword(username, currentPassword.toCharArray(), "TEst12!!".toCharArray()).isValid()); Assert.assertTrue( policy.validatePassword(username, currentPassword.toCharArray(), "12!!teST".toCharArray()).isValid()); Assert.assertTrue( policy.validatePassword(username, currentPassword.toCharArray(), "12!!TEst".toCharArray()).isValid()); Assert.assertTrue( policy.validatePassword(username, currentPassword.toCharArray(), "!!12teST".toCharArray()).isValid()); Assert.assertTrue( policy.validatePassword(username, currentPassword.toCharArray(), "!!12TEst".toCharArray()).isValid()); }
@Override public ValidationResult validatePassword(String username, char[] currentPassword, char[] password) { PasswordData passwordData = null; if (null == username) { passwordData = new PasswordData(new String(password)); } else { List<Reference> references = new ArrayList<>(); if (null != currentPassword) { references.add(new HistoricalReference(new String(currentPassword))); } passwordData = new PasswordData(username, new String(password), references); } RuleResult validate = passwordValidator.validate(passwordData); List<MessageParam> messages = validate.getDetails().stream().map(d -> new MessageParam() { public String getMessageKey() { return ConfigurablePasswordPolicy.class.getSimpleName() + "." + d.getErrorCode(); } public Object[] getMessageArgs() { return d.getValues(); } }).collect(Collectors.toList()); return new ValidationResult(validate.isValid(), messages.toArray(new MessageParam[0])); }
ConfigurablePasswordPolicy implements PasswordPolicy { @Override public ValidationResult validatePassword(String username, char[] currentPassword, char[] password) { PasswordData passwordData = null; if (null == username) { passwordData = new PasswordData(new String(password)); } else { List<Reference> references = new ArrayList<>(); if (null != currentPassword) { references.add(new HistoricalReference(new String(currentPassword))); } passwordData = new PasswordData(username, new String(password), references); } RuleResult validate = passwordValidator.validate(passwordData); List<MessageParam> messages = validate.getDetails().stream().map(d -> new MessageParam() { public String getMessageKey() { return ConfigurablePasswordPolicy.class.getSimpleName() + "." + d.getErrorCode(); } public Object[] getMessageArgs() { return d.getValues(); } }).collect(Collectors.toList()); return new ValidationResult(validate.isValid(), messages.toArray(new MessageParam[0])); } }
ConfigurablePasswordPolicy implements PasswordPolicy { @Override public ValidationResult validatePassword(String username, char[] currentPassword, char[] password) { PasswordData passwordData = null; if (null == username) { passwordData = new PasswordData(new String(password)); } else { List<Reference> references = new ArrayList<>(); if (null != currentPassword) { references.add(new HistoricalReference(new String(currentPassword))); } passwordData = new PasswordData(username, new String(password), references); } RuleResult validate = passwordValidator.validate(passwordData); List<MessageParam> messages = validate.getDetails().stream().map(d -> new MessageParam() { public String getMessageKey() { return ConfigurablePasswordPolicy.class.getSimpleName() + "." + d.getErrorCode(); } public Object[] getMessageArgs() { return d.getValues(); } }).collect(Collectors.toList()); return new ValidationResult(validate.isValid(), messages.toArray(new MessageParam[0])); } }
ConfigurablePasswordPolicy implements PasswordPolicy { @Override public ValidationResult validatePassword(String username, char[] currentPassword, char[] password) { PasswordData passwordData = null; if (null == username) { passwordData = new PasswordData(new String(password)); } else { List<Reference> references = new ArrayList<>(); if (null != currentPassword) { references.add(new HistoricalReference(new String(currentPassword))); } passwordData = new PasswordData(username, new String(password), references); } RuleResult validate = passwordValidator.validate(passwordData); List<MessageParam> messages = validate.getDetails().stream().map(d -> new MessageParam() { public String getMessageKey() { return ConfigurablePasswordPolicy.class.getSimpleName() + "." + d.getErrorCode(); } public Object[] getMessageArgs() { return d.getValues(); } }).collect(Collectors.toList()); return new ValidationResult(validate.isValid(), messages.toArray(new MessageParam[0])); } @Override void configure(Properties platformProperties); boolean isValidPassword(char[] password); @Override ValidationResult validatePassword(String username, char[] currentPassword, char[] password); String getErrorMessageKey(); String generatePassword(); PasswordValidator getValidator(); }
ConfigurablePasswordPolicy implements PasswordPolicy { @Override public ValidationResult validatePassword(String username, char[] currentPassword, char[] password) { PasswordData passwordData = null; if (null == username) { passwordData = new PasswordData(new String(password)); } else { List<Reference> references = new ArrayList<>(); if (null != currentPassword) { references.add(new HistoricalReference(new String(currentPassword))); } passwordData = new PasswordData(username, new String(password), references); } RuleResult validate = passwordValidator.validate(passwordData); List<MessageParam> messages = validate.getDetails().stream().map(d -> new MessageParam() { public String getMessageKey() { return ConfigurablePasswordPolicy.class.getSimpleName() + "." + d.getErrorCode(); } public Object[] getMessageArgs() { return d.getValues(); } }).collect(Collectors.toList()); return new ValidationResult(validate.isValid(), messages.toArray(new MessageParam[0])); } @Override void configure(Properties platformProperties); boolean isValidPassword(char[] password); @Override ValidationResult validatePassword(String username, char[] currentPassword, char[] password); String getErrorMessageKey(); String generatePassword(); PasswordValidator getValidator(); }
@Test public void testSessionCreated() { sessionListener.sessionCreated(new HttpSessionEvent(session1)); addRequest(session1); addRequest(session1); Assert.assertEquals(2, ((Session) session1.getAttribute(SessionListener.META_DATA)).getRequests()); }
public void sessionCreated(HttpSessionEvent event) { createSession(event.getSession()); }
SessionListener implements ServletContextListener, HttpSessionListener, ServletRequestListener { public void sessionCreated(HttpSessionEvent event) { createSession(event.getSession()); } }
SessionListener implements ServletContextListener, HttpSessionListener, ServletRequestListener { public void sessionCreated(HttpSessionEvent event) { createSession(event.getSession()); } }
SessionListener implements ServletContextListener, HttpSessionListener, ServletRequestListener { public void sessionCreated(HttpSessionEvent event) { createSession(event.getSession()); } void contextInitialized(ServletContextEvent sce); void contextDestroyed(ServletContextEvent sce); void sessionCreated(HttpSessionEvent event); void sessionDestroyed(HttpSessionEvent event); void requestInitialized(ServletRequestEvent sre); void requestDestroyed(ServletRequestEvent sre); }
SessionListener implements ServletContextListener, HttpSessionListener, ServletRequestListener { public void sessionCreated(HttpSessionEvent event) { createSession(event.getSession()); } void contextInitialized(ServletContextEvent sce); void contextDestroyed(ServletContextEvent sce); void sessionCreated(HttpSessionEvent event); void sessionDestroyed(HttpSessionEvent event); void requestInitialized(ServletRequestEvent sre); void requestDestroyed(ServletRequestEvent sre); static final String SESSION_MANAGER; static final String META_DATA; }
@Test public void testSessionDestroyed() { sessionListener.sessionCreated(new HttpSessionEvent(session1)); addRequest(session1); sessionListener.sessionCreated(new HttpSessionEvent(session2)); addRequest(session2); sessionListener.sessionDestroyed(new HttpSessionEvent(session1)); Assert.assertNull(session1.getAttribute(SessionListener.META_DATA)); Assert.assertNotNull(session2.getAttribute(SessionListener.META_DATA)); }
public void sessionDestroyed(HttpSessionEvent event) { HttpSession httpSession = event.getSession(); Environment env = DefaultEnvironment.get(httpSession); if (env.isSubjectAuthenticated()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); ctx.getBean(CoreService.class).createEvent(Type.INFO, "session expired", httpSession); } Session session = getSession(httpSession); if (null != session) { LOGGER.info("Session destroyed: {} (created: {}, accessed: {}, requests: {}, domain: {}, user-agent: {})", session.getId(), DATE_PATTERN.format(session.getCreationTime()), DATE_PATTERN.format(session.getLastAccessedTime()), session.getRequests(), session.getDomain(), session.getUserAgent()); httpSession.removeAttribute(META_DATA); } else { LOGGER.info("Session destroyed: {} (created: {}, accessed: {})", httpSession.getId(), DATE_PATTERN.format(httpSession.getCreationTime()), DATE_PATTERN.format(httpSession.getLastAccessedTime())); } }
SessionListener implements ServletContextListener, HttpSessionListener, ServletRequestListener { public void sessionDestroyed(HttpSessionEvent event) { HttpSession httpSession = event.getSession(); Environment env = DefaultEnvironment.get(httpSession); if (env.isSubjectAuthenticated()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); ctx.getBean(CoreService.class).createEvent(Type.INFO, "session expired", httpSession); } Session session = getSession(httpSession); if (null != session) { LOGGER.info("Session destroyed: {} (created: {}, accessed: {}, requests: {}, domain: {}, user-agent: {})", session.getId(), DATE_PATTERN.format(session.getCreationTime()), DATE_PATTERN.format(session.getLastAccessedTime()), session.getRequests(), session.getDomain(), session.getUserAgent()); httpSession.removeAttribute(META_DATA); } else { LOGGER.info("Session destroyed: {} (created: {}, accessed: {})", httpSession.getId(), DATE_PATTERN.format(httpSession.getCreationTime()), DATE_PATTERN.format(httpSession.getLastAccessedTime())); } } }
SessionListener implements ServletContextListener, HttpSessionListener, ServletRequestListener { public void sessionDestroyed(HttpSessionEvent event) { HttpSession httpSession = event.getSession(); Environment env = DefaultEnvironment.get(httpSession); if (env.isSubjectAuthenticated()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); ctx.getBean(CoreService.class).createEvent(Type.INFO, "session expired", httpSession); } Session session = getSession(httpSession); if (null != session) { LOGGER.info("Session destroyed: {} (created: {}, accessed: {}, requests: {}, domain: {}, user-agent: {})", session.getId(), DATE_PATTERN.format(session.getCreationTime()), DATE_PATTERN.format(session.getLastAccessedTime()), session.getRequests(), session.getDomain(), session.getUserAgent()); httpSession.removeAttribute(META_DATA); } else { LOGGER.info("Session destroyed: {} (created: {}, accessed: {})", httpSession.getId(), DATE_PATTERN.format(httpSession.getCreationTime()), DATE_PATTERN.format(httpSession.getLastAccessedTime())); } } }
SessionListener implements ServletContextListener, HttpSessionListener, ServletRequestListener { public void sessionDestroyed(HttpSessionEvent event) { HttpSession httpSession = event.getSession(); Environment env = DefaultEnvironment.get(httpSession); if (env.isSubjectAuthenticated()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); ctx.getBean(CoreService.class).createEvent(Type.INFO, "session expired", httpSession); } Session session = getSession(httpSession); if (null != session) { LOGGER.info("Session destroyed: {} (created: {}, accessed: {}, requests: {}, domain: {}, user-agent: {})", session.getId(), DATE_PATTERN.format(session.getCreationTime()), DATE_PATTERN.format(session.getLastAccessedTime()), session.getRequests(), session.getDomain(), session.getUserAgent()); httpSession.removeAttribute(META_DATA); } else { LOGGER.info("Session destroyed: {} (created: {}, accessed: {})", httpSession.getId(), DATE_PATTERN.format(httpSession.getCreationTime()), DATE_PATTERN.format(httpSession.getLastAccessedTime())); } } void contextInitialized(ServletContextEvent sce); void contextDestroyed(ServletContextEvent sce); void sessionCreated(HttpSessionEvent event); void sessionDestroyed(HttpSessionEvent event); void requestInitialized(ServletRequestEvent sre); void requestDestroyed(ServletRequestEvent sre); }
SessionListener implements ServletContextListener, HttpSessionListener, ServletRequestListener { public void sessionDestroyed(HttpSessionEvent event) { HttpSession httpSession = event.getSession(); Environment env = DefaultEnvironment.get(httpSession); if (env.isSubjectAuthenticated()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); ctx.getBean(CoreService.class).createEvent(Type.INFO, "session expired", httpSession); } Session session = getSession(httpSession); if (null != session) { LOGGER.info("Session destroyed: {} (created: {}, accessed: {}, requests: {}, domain: {}, user-agent: {})", session.getId(), DATE_PATTERN.format(session.getCreationTime()), DATE_PATTERN.format(session.getLastAccessedTime()), session.getRequests(), session.getDomain(), session.getUserAgent()); httpSession.removeAttribute(META_DATA); } else { LOGGER.info("Session destroyed: {} (created: {}, accessed: {})", httpSession.getId(), DATE_PATTERN.format(httpSession.getCreationTime()), DATE_PATTERN.format(httpSession.getLastAccessedTime())); } } void contextInitialized(ServletContextEvent sce); void contextDestroyed(ServletContextEvent sce); void sessionCreated(HttpSessionEvent event); void sessionDestroyed(HttpSessionEvent event); void requestInitialized(ServletRequestEvent sre); void requestDestroyed(ServletRequestEvent sre); static final String SESSION_MANAGER; static final String META_DATA; }
@Test public void testAttachmentWebService() { when(base.request.getServletPath()).thenReturn("/services/manager/application1/webservice/foobar"); try { AttachmentWebservice attachmentWebservice = getAttachmentWebservice("attachment webservice call", "test.txt"); base.provider.registerBean("foobar", attachmentWebservice); doGet(base.request, base.response); Mockito.verify(base.response).setContentType(HttpHeaders.CONTENT_TYPE_TEXT_PLAIN); Mockito.verify(base.response).setHeader(Mockito.eq(HttpHeaders.CONTENT_DISPOSITION), Mockito.eq("attachment; filename=\"test.txt\"")); Assert.assertEquals("attachment webservice call", new String(base.out.toByteArray())); } catch (Exception e) { fail(e); } }
@Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } Controller(); }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } Controller(); void serveResource(HttpServletRequest request, HttpServletResponse response); @Override void init(); Wrapper getWrapper(); void setWrapper(Wrapper wrapper); JspHandler getJspHandler(); }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } Controller(); void serveResource(HttpServletRequest request, HttpServletResponse response); @Override void init(); Wrapper getWrapper(); void setWrapper(Wrapper wrapper); JspHandler getJspHandler(); }
@Test public void testAttachmentWebServiceNoFile() { when(base.request.getServletPath()).thenReturn("/services/manager/application1/webservice/foobar"); try { AttachmentWebservice attachmentWebservice = getAttachmentWebservice("attachment webservice call", "test.txt"); base.provider.registerBean("foobar", attachmentWebservice); doGet(base.request, base.response); Mockito.verify(base.response).setContentType(HttpHeaders.CONTENT_TYPE_TEXT_PLAIN); Assert.assertEquals("attachment webservice call", new String(base.out.toByteArray())); } catch (Exception e) { fail(e); } }
@Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } Controller(); }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } Controller(); void serveResource(HttpServletRequest request, HttpServletResponse response); @Override void init(); Wrapper getWrapper(); void setWrapper(Wrapper wrapper); JspHandler getJspHandler(); }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } Controller(); void serveResource(HttpServletRequest request, HttpServletResponse response); @Override void init(); Wrapper getWrapper(); void setWrapper(Wrapper wrapper); JspHandler getJspHandler(); }
@Test public void testWebservice() { prepareWebserice(HttpMethod.GET); try { doGet(base.request, base.response); Assert.assertEquals("GET webservice call", new String(base.out.toByteArray())); } catch (Exception e) { fail(e); } }
@Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } Controller(); }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } Controller(); void serveResource(HttpServletRequest request, HttpServletResponse response); @Override void init(); Wrapper getWrapper(); void setWrapper(Wrapper wrapper); JspHandler getJspHandler(); }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } Controller(); void serveResource(HttpServletRequest request, HttpServletResponse response); @Override void init(); Wrapper getWrapper(); void setWrapper(Wrapper wrapper); JspHandler getJspHandler(); }
@Test public void testWebservicePut() { prepareWebserice(HttpMethod.PUT); try { doPut(base.request, base.response); Assert.assertEquals("PUT webservice call", new String(base.out.toByteArray())); } catch (Exception e) { fail(e); } }
@Override protected void doPut(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (isServiceRequest(servletRequest)) { doGet(servletRequest, servletResponse); } else { LOGGER.debug("PUT not allowed for {}", servletRequest.getServletPath()); servletResponse.sendError(HttpStatus.FORBIDDEN.value()); } }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doPut(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (isServiceRequest(servletRequest)) { doGet(servletRequest, servletResponse); } else { LOGGER.debug("PUT not allowed for {}", servletRequest.getServletPath()); servletResponse.sendError(HttpStatus.FORBIDDEN.value()); } } }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doPut(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (isServiceRequest(servletRequest)) { doGet(servletRequest, servletResponse); } else { LOGGER.debug("PUT not allowed for {}", servletRequest.getServletPath()); servletResponse.sendError(HttpStatus.FORBIDDEN.value()); } } Controller(); }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doPut(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (isServiceRequest(servletRequest)) { doGet(servletRequest, servletResponse); } else { LOGGER.debug("PUT not allowed for {}", servletRequest.getServletPath()); servletResponse.sendError(HttpStatus.FORBIDDEN.value()); } } Controller(); void serveResource(HttpServletRequest request, HttpServletResponse response); @Override void init(); Wrapper getWrapper(); void setWrapper(Wrapper wrapper); JspHandler getJspHandler(); }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doPut(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (isServiceRequest(servletRequest)) { doGet(servletRequest, servletResponse); } else { LOGGER.debug("PUT not allowed for {}", servletRequest.getServletPath()); servletResponse.sendError(HttpStatus.FORBIDDEN.value()); } } Controller(); void serveResource(HttpServletRequest request, HttpServletResponse response); @Override void init(); Wrapper getWrapper(); void setWrapper(Wrapper wrapper); JspHandler getJspHandler(); }
@Test public void testEquals() { assertTrue("equals('a','a')"); assertTrue("equals('b','b')"); assertFalse("equals('a','A')"); assertFalse("equals('a',' A')"); }
public static boolean equals(String string1, String string2) { return StringUtils.equals(string1, string2); }
RuleValidation { public static boolean equals(String string1, String string2) { return StringUtils.equals(string1, string2); } }
RuleValidation { public static boolean equals(String string1, String string2) { return StringUtils.equals(string1, string2); } RuleValidation(Request container); }
RuleValidation { public static boolean equals(String string1, String string2) { return StringUtils.equals(string1, string2); } RuleValidation(Request container); Map<String, List<FormUpload>> getFileParams(Map<String, List<FormUpload>> formUploads); boolean validate(String rule); static boolean string(String string); static boolean captcha(String value, String result); static boolean email(String string); static boolean equals(String string1, String string2); static boolean number(String string); static boolean number(String string, char separator); static boolean numberFractionDigits(String string, int digits, int fraction); static boolean number(String string, char separator, int digits, int fraction); static boolean regExp(String string, String regex); static boolean size(Object item, int size); static boolean sizeMax(Object item, int max); static boolean sizeMin(Object item, int min); static boolean sizeMinMax(Object item, int min, int max); static boolean fileType(List<FormUpload> fUpload, String types); static boolean fileSize(List<FormUpload> fUpload, String minSize, String maxSize); static boolean fileSizeMin(List<FormUpload> fUpload, String minSize); static boolean fileSizeMax(List<FormUpload> fUpload, String maxSize); static boolean fileCountMin(List<FormUpload> fUpload, int count); static boolean fileCountMax(List<FormUpload> fUpload, int count); static boolean fileCount(List<FormUpload> fUpload, int minCount, int maxCount); }
RuleValidation { public static boolean equals(String string1, String string2) { return StringUtils.equals(string1, string2); } RuleValidation(Request container); Map<String, List<FormUpload>> getFileParams(Map<String, List<FormUpload>> formUploads); boolean validate(String rule); static boolean string(String string); static boolean captcha(String value, String result); static boolean email(String string); static boolean equals(String string1, String string2); static boolean number(String string); static boolean number(String string, char separator); static boolean numberFractionDigits(String string, int digits, int fraction); static boolean number(String string, char separator, int digits, int fraction); static boolean regExp(String string, String regex); static boolean size(Object item, int size); static boolean sizeMax(Object item, int max); static boolean sizeMin(Object item, int min); static boolean sizeMinMax(Object item, int min, int max); static boolean fileType(List<FormUpload> fUpload, String types); static boolean fileSize(List<FormUpload> fUpload, String minSize, String maxSize); static boolean fileSizeMin(List<FormUpload> fUpload, String minSize); static boolean fileSizeMax(List<FormUpload> fUpload, String maxSize); static boolean fileCountMin(List<FormUpload> fUpload, int count); static boolean fileCountMax(List<FormUpload> fUpload, int count); static boolean fileCount(List<FormUpload> fUpload, int minCount, int maxCount); static final List<String> SHORT_RULES; }
@Test public void testWebserviceDelete() { prepareWebserice(HttpMethod.DELETE); try { doDelete(base.request, base.response); Assert.assertEquals("DELETE webservice call", new String(base.out.toByteArray())); } catch (Exception e) { fail(e); } }
@Override protected void doDelete(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (isServiceRequest(servletRequest)) { doGet(servletRequest, servletResponse); } else { LOGGER.debug("DELETE not allowed for {}", servletRequest.getServletPath()); servletResponse.sendError(HttpStatus.FORBIDDEN.value()); } }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doDelete(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (isServiceRequest(servletRequest)) { doGet(servletRequest, servletResponse); } else { LOGGER.debug("DELETE not allowed for {}", servletRequest.getServletPath()); servletResponse.sendError(HttpStatus.FORBIDDEN.value()); } } }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doDelete(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (isServiceRequest(servletRequest)) { doGet(servletRequest, servletResponse); } else { LOGGER.debug("DELETE not allowed for {}", servletRequest.getServletPath()); servletResponse.sendError(HttpStatus.FORBIDDEN.value()); } } Controller(); }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doDelete(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (isServiceRequest(servletRequest)) { doGet(servletRequest, servletResponse); } else { LOGGER.debug("DELETE not allowed for {}", servletRequest.getServletPath()); servletResponse.sendError(HttpStatus.FORBIDDEN.value()); } } Controller(); void serveResource(HttpServletRequest request, HttpServletResponse response); @Override void init(); Wrapper getWrapper(); void setWrapper(Wrapper wrapper); JspHandler getJspHandler(); }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doDelete(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (isServiceRequest(servletRequest)) { doGet(servletRequest, servletResponse); } else { LOGGER.debug("DELETE not allowed for {}", servletRequest.getServletPath()); servletResponse.sendError(HttpStatus.FORBIDDEN.value()); } } Controller(); void serveResource(HttpServletRequest request, HttpServletResponse response); @Override void init(); Wrapper getWrapper(); void setWrapper(Wrapper wrapper); JspHandler getJspHandler(); }
@Test public void testMonitoring() { prepareMonitoring("/health"); try { doGet(base.request, base.response); String actual = new String(base.out.toByteArray()); Mockito.verify(base.response).setContentType(HttpHeaders.CONTENT_TYPE_APPLICATION_JSON); Assert.assertTrue(actual.contains("\"name\" : \"manager\"")); Assert.assertTrue(actual.contains("\"state\" : \"STARTED\"")); } catch (Exception e) { fail(e); } }
@Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } Controller(); }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } Controller(); void serveResource(HttpServletRequest request, HttpServletResponse response); @Override void init(); Wrapper getWrapper(); void setWrapper(Wrapper wrapper); JspHandler getJspHandler(); }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } Controller(); void serveResource(HttpServletRequest request, HttpServletResponse response); @Override void init(); Wrapper getWrapper(); void setWrapper(Wrapper wrapper); JspHandler getJspHandler(); }
@Test public void testMonitoringSystem() { prepareMonitoring("/health/system"); try { doGet(base.request, base.response); String actual = new String(base.out.toByteArray()); Assert.assertTrue(actual.contains("java.runtime.name")); Assert.assertTrue(actual.contains("java.runtime.version")); } catch (Exception e) { fail(e); } }
@Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } Controller(); }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } Controller(); void serveResource(HttpServletRequest request, HttpServletResponse response); @Override void init(); Wrapper getWrapper(); void setWrapper(Wrapper wrapper); JspHandler getJspHandler(); }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } Controller(); void serveResource(HttpServletRequest request, HttpServletResponse response); @Override void init(); Wrapper getWrapper(); void setWrapper(Wrapper wrapper); JspHandler getJspHandler(); }
@Test public void testMonitoringEnv() { prepareMonitoring("/health/environment"); try { doGet(base.request, base.response); String actual = new String(base.out.toByteArray()); if (OperatingSystem.isLinux()) { Assert.assertTrue(actual.contains("LANG")); Assert.assertTrue(actual.contains("USER")); } else if (OperatingSystem.isWindows()) { Assert.assertTrue(actual.contains("USERNAME")); Assert.assertTrue(actual.contains("Path")); } } catch (Exception e) { fail(e); } }
@Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } Controller(); }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } Controller(); void serveResource(HttpServletRequest request, HttpServletResponse response); @Override void init(); Wrapper getWrapper(); void setWrapper(Wrapper wrapper); JspHandler getJspHandler(); }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } Controller(); void serveResource(HttpServletRequest request, HttpServletResponse response); @Override void init(); Wrapper getWrapper(); void setWrapper(Wrapper wrapper); JspHandler getJspHandler(); }
@Test public void testStaticFromRepository() { when(base.request.getServletPath()).thenReturn("/assets/test.txt"); try { doGet(base.request, base.response); String actual = new String(base.out.toByteArray()); Assert.assertEquals("/repository/manager/www/assets/test.txt", actual); } catch (Exception e) { fail(e); } }
@Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } Controller(); }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } Controller(); void serveResource(HttpServletRequest request, HttpServletResponse response); @Override void init(); Wrapper getWrapper(); void setWrapper(Wrapper wrapper); JspHandler getJspHandler(); }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } Controller(); void serveResource(HttpServletRequest request, HttpServletResponse response); @Override void init(); Wrapper getWrapper(); void setWrapper(Wrapper wrapper); JspHandler getJspHandler(); }
@Test public void testStatic() { when(base.request.getServletPath()).thenReturn("/test.txt"); try { doGet(base.request, base.response); String actual = new String(base.out.toByteArray()); Assert.assertEquals("/test.txt", actual); } catch (Exception e) { fail(e); } }
@Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } Controller(); }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } Controller(); void serveResource(HttpServletRequest request, HttpServletResponse response); @Override void init(); Wrapper getWrapper(); void setWrapper(Wrapper wrapper); JspHandler getJspHandler(); }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } Controller(); void serveResource(HttpServletRequest request, HttpServletResponse response); @Override void init(); Wrapper getWrapper(); void setWrapper(Wrapper wrapper); JspHandler getJspHandler(); }
@Test public void testStaticPut() { when(base.request.getServletPath()).thenReturn("/test.txt"); try { doPut(base.request, base.response); Assert.assertEquals(0, base.out.toByteArray().length); Mockito.verify(base.response).sendError(HttpStatus.FORBIDDEN.value()); } catch (Exception e) { fail(e); } }
@Override protected void doPut(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (isServiceRequest(servletRequest)) { doGet(servletRequest, servletResponse); } else { LOGGER.debug("PUT not allowed for {}", servletRequest.getServletPath()); servletResponse.sendError(HttpStatus.FORBIDDEN.value()); } }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doPut(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (isServiceRequest(servletRequest)) { doGet(servletRequest, servletResponse); } else { LOGGER.debug("PUT not allowed for {}", servletRequest.getServletPath()); servletResponse.sendError(HttpStatus.FORBIDDEN.value()); } } }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doPut(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (isServiceRequest(servletRequest)) { doGet(servletRequest, servletResponse); } else { LOGGER.debug("PUT not allowed for {}", servletRequest.getServletPath()); servletResponse.sendError(HttpStatus.FORBIDDEN.value()); } } Controller(); }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doPut(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (isServiceRequest(servletRequest)) { doGet(servletRequest, servletResponse); } else { LOGGER.debug("PUT not allowed for {}", servletRequest.getServletPath()); servletResponse.sendError(HttpStatus.FORBIDDEN.value()); } } Controller(); void serveResource(HttpServletRequest request, HttpServletResponse response); @Override void init(); Wrapper getWrapper(); void setWrapper(Wrapper wrapper); JspHandler getJspHandler(); }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doPut(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (isServiceRequest(servletRequest)) { doGet(servletRequest, servletResponse); } else { LOGGER.debug("PUT not allowed for {}", servletRequest.getServletPath()); servletResponse.sendError(HttpStatus.FORBIDDEN.value()); } } Controller(); void serveResource(HttpServletRequest request, HttpServletResponse response); @Override void init(); Wrapper getWrapper(); void setWrapper(Wrapper wrapper); JspHandler getJspHandler(); }
@Test public void testStaticDelete() { when(base.request.getServletPath()).thenReturn("/test.txt"); try { doDelete(base.request, base.response); Assert.assertEquals(0, base.out.toByteArray().length); Mockito.verify(base.response).sendError(HttpStatus.FORBIDDEN.value()); } catch (Exception e) { fail(e); } }
@Override protected void doDelete(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (isServiceRequest(servletRequest)) { doGet(servletRequest, servletResponse); } else { LOGGER.debug("DELETE not allowed for {}", servletRequest.getServletPath()); servletResponse.sendError(HttpStatus.FORBIDDEN.value()); } }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doDelete(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (isServiceRequest(servletRequest)) { doGet(servletRequest, servletResponse); } else { LOGGER.debug("DELETE not allowed for {}", servletRequest.getServletPath()); servletResponse.sendError(HttpStatus.FORBIDDEN.value()); } } }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doDelete(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (isServiceRequest(servletRequest)) { doGet(servletRequest, servletResponse); } else { LOGGER.debug("DELETE not allowed for {}", servletRequest.getServletPath()); servletResponse.sendError(HttpStatus.FORBIDDEN.value()); } } Controller(); }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doDelete(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (isServiceRequest(servletRequest)) { doGet(servletRequest, servletResponse); } else { LOGGER.debug("DELETE not allowed for {}", servletRequest.getServletPath()); servletResponse.sendError(HttpStatus.FORBIDDEN.value()); } } Controller(); void serveResource(HttpServletRequest request, HttpServletResponse response); @Override void init(); Wrapper getWrapper(); void setWrapper(Wrapper wrapper); JspHandler getJspHandler(); }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doDelete(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (isServiceRequest(servletRequest)) { doGet(servletRequest, servletResponse); } else { LOGGER.debug("DELETE not allowed for {}", servletRequest.getServletPath()); servletResponse.sendError(HttpStatus.FORBIDDEN.value()); } } Controller(); void serveResource(HttpServletRequest request, HttpServletResponse response); @Override void init(); Wrapper getWrapper(); void setWrapper(Wrapper wrapper); JspHandler getJspHandler(); }
@Test public void testTemplate() { when(base.request.getServletPath()).thenReturn("/template/assets/test.txt"); try { doGet(base.request, base.response); String actual = new String(base.out.toByteArray()); Assert.assertEquals("/repository/manager/www/template/assets/test.txt", actual); } catch (Exception e) { fail(e); } }
@Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } Controller(); }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } Controller(); void serveResource(HttpServletRequest request, HttpServletResponse response); @Override void init(); Wrapper getWrapper(); void setWrapper(Wrapper wrapper); JspHandler getJspHandler(); }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } Controller(); void serveResource(HttpServletRequest request, HttpServletResponse response); @Override void init(); Wrapper getWrapper(); void setWrapper(Wrapper wrapper); JspHandler getJspHandler(); }
@Test public void testTemplateWithTemplateInPath() { when(base.request.getServletPath()).thenReturn("/template/resources/template/test.txt"); try { doGet(base.request, base.response); String actual = new String(base.out.toByteArray()); Assert.assertEquals("/repository/manager/www/template/resources/template/test.txt", actual); } catch (Exception e) { Assert.fail(e.getMessage()); } }
@Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } Controller(); }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } Controller(); void serveResource(HttpServletRequest request, HttpServletResponse response); @Override void init(); Wrapper getWrapper(); void setWrapper(Wrapper wrapper); JspHandler getJspHandler(); }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } Controller(); void serveResource(HttpServletRequest request, HttpServletResponse response); @Override void init(); Wrapper getWrapper(); void setWrapper(Wrapper wrapper); JspHandler getJspHandler(); }
@Test public void testRegExp() { assertTrue("regExp('abc','[a-z]+')"); assertFalse("regExp('abc','[a-z]{4,}')"); }
public static boolean regExp(String string, String regex) { return string.matches(regex); }
RuleValidation { public static boolean regExp(String string, String regex) { return string.matches(regex); } }
RuleValidation { public static boolean regExp(String string, String regex) { return string.matches(regex); } RuleValidation(Request container); }
RuleValidation { public static boolean regExp(String string, String regex) { return string.matches(regex); } RuleValidation(Request container); Map<String, List<FormUpload>> getFileParams(Map<String, List<FormUpload>> formUploads); boolean validate(String rule); static boolean string(String string); static boolean captcha(String value, String result); static boolean email(String string); static boolean equals(String string1, String string2); static boolean number(String string); static boolean number(String string, char separator); static boolean numberFractionDigits(String string, int digits, int fraction); static boolean number(String string, char separator, int digits, int fraction); static boolean regExp(String string, String regex); static boolean size(Object item, int size); static boolean sizeMax(Object item, int max); static boolean sizeMin(Object item, int min); static boolean sizeMinMax(Object item, int min, int max); static boolean fileType(List<FormUpload> fUpload, String types); static boolean fileSize(List<FormUpload> fUpload, String minSize, String maxSize); static boolean fileSizeMin(List<FormUpload> fUpload, String minSize); static boolean fileSizeMax(List<FormUpload> fUpload, String maxSize); static boolean fileCountMin(List<FormUpload> fUpload, int count); static boolean fileCountMax(List<FormUpload> fUpload, int count); static boolean fileCount(List<FormUpload> fUpload, int minCount, int maxCount); }
RuleValidation { public static boolean regExp(String string, String regex) { return string.matches(regex); } RuleValidation(Request container); Map<String, List<FormUpload>> getFileParams(Map<String, List<FormUpload>> formUploads); boolean validate(String rule); static boolean string(String string); static boolean captcha(String value, String result); static boolean email(String string); static boolean equals(String string1, String string2); static boolean number(String string); static boolean number(String string, char separator); static boolean numberFractionDigits(String string, int digits, int fraction); static boolean number(String string, char separator, int digits, int fraction); static boolean regExp(String string, String regex); static boolean size(Object item, int size); static boolean sizeMax(Object item, int max); static boolean sizeMin(Object item, int min); static boolean sizeMinMax(Object item, int min, int max); static boolean fileType(List<FormUpload> fUpload, String types); static boolean fileSize(List<FormUpload> fUpload, String minSize, String maxSize); static boolean fileSizeMin(List<FormUpload> fUpload, String minSize); static boolean fileSizeMax(List<FormUpload> fUpload, String maxSize); static boolean fileCountMin(List<FormUpload> fUpload, int count); static boolean fileCountMax(List<FormUpload> fUpload, int count); static boolean fileCount(List<FormUpload> fUpload, int minCount, int maxCount); static final List<String> SHORT_RULES; }
@Test public void testTemplateResourceFromApplication() { when(base.request.getServletPath()).thenReturn("/template_dummy-application/test.txt"); try { doGet(base.request, base.response); String actual = new String(base.out.toByteArray()); Assert.assertEquals("/WEB-INF/cache/platform/manager/dummy-application/resources/test.txt", actual); } catch (Exception e) { Assert.fail(e.getMessage()); } }
@Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } Controller(); }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } Controller(); void serveResource(HttpServletRequest request, HttpServletResponse response); @Override void init(); Wrapper getWrapper(); void setWrapper(Wrapper wrapper); JspHandler getJspHandler(); }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } Controller(); void serveResource(HttpServletRequest request, HttpServletResponse response); @Override void init(); Wrapper getWrapper(); void setWrapper(Wrapper wrapper); JspHandler getJspHandler(); }
@Test public void testDoc() { String rootPath = base.platformProperties.getString("platform.platformRootPath"); String wwwRootPath = rootPath + File.separator + "repository" + File.separator + "manager" + File.separator + "www"; String realPath = new File(new File("").getAbsoluteFile(), wwwRootPath).getAbsolutePath(); when(base.request.getServletPath()).thenReturn("/de/test"); when(base.ctx.getRealPath("/repository/manager/www")).thenReturn(realPath); final String jspCalled = "JSP called"; try { jspHandler = Mockito.mock(JspHandler.class); Answer<Void> jspAnswer = new Answer<Void>() { public Void answer(InvocationOnMock invocation) throws Throwable { HttpServletResponse httpServletResponse = (HttpServletResponse) invocation.getArguments()[1]; httpServletResponse.getOutputStream().write(jspCalled.getBytes()); return null; } }; Mockito.doAnswer(jspAnswer).when(jspHandler).handle(isA(HttpServletRequest.class), isA(HttpServletResponse.class), isA(Environment.class), isA(Site.class), isA(PathInfo.class)); doGet(base.request, base.response); Assert.assertEquals(jspCalled, new String(base.out.toByteArray())); } catch (Exception e) { StringWriter writer = new StringWriter(); e.printStackTrace(new PrintWriter(writer)); Assert.fail(writer.toString()); } }
@Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } Controller(); }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } Controller(); void serveResource(HttpServletRequest request, HttpServletResponse response); @Override void init(); Wrapper getWrapper(); void setWrapper(Wrapper wrapper); JspHandler getJspHandler(); }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } Controller(); void serveResource(HttpServletRequest request, HttpServletResponse response); @Override void init(); Wrapper getWrapper(); void setWrapper(Wrapper wrapper); JspHandler getJspHandler(); }
@Test public void testErrorPage() { when(base.request.getServletPath()).thenReturn("/errorpage"); try { doGet(base.request, base.response); verify(base.request).getRequestDispatcher("/de/fehler.jsp"); verify(base.request).setAttribute(RequestHandler.FORWARDED, Boolean.TRUE); verify(base.dispatcher).forward(base.request, base.response); } catch (Exception e) { Assert.fail(e.getMessage()); } }
@Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } Controller(); }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } Controller(); void serveResource(HttpServletRequest request, HttpServletResponse response); @Override void init(); Wrapper getWrapper(); void setWrapper(Wrapper wrapper); JspHandler getJspHandler(); }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } Controller(); void serveResource(HttpServletRequest request, HttpServletResponse response); @Override void init(); Wrapper getWrapper(); void setWrapper(Wrapper wrapper); JspHandler getJspHandler(); }
@Test public void testErrorDoc() { when(base.request.getServletPath()).thenReturn("/errorpage"); try { when(base.request.getAttribute(RequestDispatcher.ERROR_REQUEST_URI)).thenReturn("/de/foobar"); doGet(base.request, base.response); verify(base.request).getRequestDispatcher("/de/fehler.jsp"); verify(base.request).setAttribute(RequestHandler.FORWARDED, Boolean.TRUE); verify(base.dispatcher).forward(base.request, base.response); } catch (Exception e) { Assert.fail(e.getMessage()); } }
@Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } Controller(); }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } Controller(); void serveResource(HttpServletRequest request, HttpServletResponse response); @Override void init(); Wrapper getWrapper(); void setWrapper(Wrapper wrapper); JspHandler getJspHandler(); }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } Controller(); void serveResource(HttpServletRequest request, HttpServletResponse response); @Override void init(); Wrapper getWrapper(); void setWrapper(Wrapper wrapper); JspHandler getJspHandler(); }
@Test public void testRoot() { when(base.request.getServletPath()).thenReturn(""); try { doGet(base.request, base.response); verify(base.response).setStatus(301); verify(base.response).setHeader(HttpHeaders.LOCATION, "/de/index"); } catch (Exception e) { Assert.fail(e.getMessage()); } }
@Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } Controller(); }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } Controller(); void serveResource(HttpServletRequest request, HttpServletResponse response); @Override void init(); Wrapper getWrapper(); void setWrapper(Wrapper wrapper); JspHandler getJspHandler(); }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } Controller(); void serveResource(HttpServletRequest request, HttpServletResponse response); @Override void init(); Wrapper getWrapper(); void setWrapper(Wrapper wrapper); JspHandler getJspHandler(); }
@Test public void testRootWithPath() { when(base.request.getServletPath()).thenReturn("/de"); try { doGet(base.request, base.response); verify(base.response).setStatus(301); verify(base.response).setHeader(HttpHeaders.LOCATION, "/de/index"); } catch (Exception e) { Assert.fail(e.getMessage()); } }
@Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } Controller(); }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } Controller(); void serveResource(HttpServletRequest request, HttpServletResponse response); @Override void init(); Wrapper getWrapper(); void setWrapper(Wrapper wrapper); JspHandler getJspHandler(); }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } Controller(); void serveResource(HttpServletRequest request, HttpServletResponse response); @Override void init(); Wrapper getWrapper(); void setWrapper(Wrapper wrapper); JspHandler getJspHandler(); }
@Test public void testDocNoSite() { when(base.request.getServerName()).thenReturn("localhost"); when(base.request.getServletPath()).thenReturn("/de"); try { doGet(base.request, base.response); verify(base.response).getStatus(); } catch (Exception e) { Assert.fail(e.getMessage()); } }
@Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } Controller(); }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } Controller(); void serveResource(HttpServletRequest request, HttpServletResponse response); @Override void init(); Wrapper getWrapper(); void setWrapper(Wrapper wrapper); JspHandler getJspHandler(); }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } Controller(); void serveResource(HttpServletRequest request, HttpServletResponse response); @Override void init(); Wrapper getWrapper(); void setWrapper(Wrapper wrapper); JspHandler getJspHandler(); }
@Test public void testJsp() throws ServletException { jspHandler = Mockito.mock(JspHandler.class); when(base.request.getServletPath()).thenReturn("/foo/bar.jsp"); try { when(base.request.getAttribute(RequestHandler.FORWARDED)).thenReturn(Boolean.TRUE); doGet(base.request, base.response); verify(jspHandler).handle(Mockito.eq(base.request), Mockito.eq(base.response), Mockito.eq(env), Mockito.eq(base.siteMap.get("manager")), Mockito.any(PathInfo.class)); } catch (Exception e) { Assert.fail(e.getMessage()); } }
@Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } Controller(); }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } Controller(); void serveResource(HttpServletRequest request, HttpServletResponse response); @Override void init(); Wrapper getWrapper(); void setWrapper(Wrapper wrapper); JspHandler getJspHandler(); }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } Controller(); void serveResource(HttpServletRequest request, HttpServletResponse response); @Override void init(); Wrapper getWrapper(); void setWrapper(Wrapper wrapper); JspHandler getJspHandler(); }
@Test public void testStaticForSite() { when(base.request.getServletPath()).thenReturn("/de/test.pdf"); try { doGet(base.request, base.response); Assert.assertEquals("/repository/manager/www/de/test.pdf", new String(base.out.toByteArray())); } catch (Exception e) { Assert.fail(e.getMessage()); } }
@Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } Controller(); }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } Controller(); void serveResource(HttpServletRequest request, HttpServletResponse response); @Override void init(); Wrapper getWrapper(); void setWrapper(Wrapper wrapper); JspHandler getJspHandler(); }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } Controller(); void serveResource(HttpServletRequest request, HttpServletResponse response); @Override void init(); Wrapper getWrapper(); void setWrapper(Wrapper wrapper); JspHandler getJspHandler(); }
@Test public void testStaticNoSite() { when(base.request.getServerName()).thenReturn("localhost"); when(base.request.getServletPath()).thenReturn("/repository/manager/www/de/test.txt"); try { doGet(base.request, base.response); Assert.assertEquals("/repository/manager/www/de/test.txt", new String(base.out.toByteArray())); } catch (Exception e) { Assert.fail(e.getMessage()); } }
@Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } Controller(); }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } Controller(); void serveResource(HttpServletRequest request, HttpServletResponse response); @Override void init(); Wrapper getWrapper(); void setWrapper(Wrapper wrapper); JspHandler getJspHandler(); }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } Controller(); void serveResource(HttpServletRequest request, HttpServletResponse response); @Override void init(); Wrapper getWrapper(); void setWrapper(Wrapper wrapper); JspHandler getJspHandler(); }
@Test public void testSize() { assertTrue("size(foo,3)"); assertFalse("size(foo,4)"); assertTrue("size(multifoo,4)"); assertFalse("size(multifoo,5)"); assertFalse("size(multibar,5)"); }
private static int size(Object item) { if (null == item) { return 0; } if (Collection.class.isAssignableFrom(item.getClass())) { return ((Collection<?>) item).size(); } if (CharSequence.class.isAssignableFrom(item.getClass())) { return ((CharSequence) item).length(); } throw new UnsupportedOperationException("can not invoke size() on object of type" + item.getClass().getName() + "!"); }
RuleValidation { private static int size(Object item) { if (null == item) { return 0; } if (Collection.class.isAssignableFrom(item.getClass())) { return ((Collection<?>) item).size(); } if (CharSequence.class.isAssignableFrom(item.getClass())) { return ((CharSequence) item).length(); } throw new UnsupportedOperationException("can not invoke size() on object of type" + item.getClass().getName() + "!"); } }
RuleValidation { private static int size(Object item) { if (null == item) { return 0; } if (Collection.class.isAssignableFrom(item.getClass())) { return ((Collection<?>) item).size(); } if (CharSequence.class.isAssignableFrom(item.getClass())) { return ((CharSequence) item).length(); } throw new UnsupportedOperationException("can not invoke size() on object of type" + item.getClass().getName() + "!"); } RuleValidation(Request container); }
RuleValidation { private static int size(Object item) { if (null == item) { return 0; } if (Collection.class.isAssignableFrom(item.getClass())) { return ((Collection<?>) item).size(); } if (CharSequence.class.isAssignableFrom(item.getClass())) { return ((CharSequence) item).length(); } throw new UnsupportedOperationException("can not invoke size() on object of type" + item.getClass().getName() + "!"); } RuleValidation(Request container); Map<String, List<FormUpload>> getFileParams(Map<String, List<FormUpload>> formUploads); boolean validate(String rule); static boolean string(String string); static boolean captcha(String value, String result); static boolean email(String string); static boolean equals(String string1, String string2); static boolean number(String string); static boolean number(String string, char separator); static boolean numberFractionDigits(String string, int digits, int fraction); static boolean number(String string, char separator, int digits, int fraction); static boolean regExp(String string, String regex); static boolean size(Object item, int size); static boolean sizeMax(Object item, int max); static boolean sizeMin(Object item, int min); static boolean sizeMinMax(Object item, int min, int max); static boolean fileType(List<FormUpload> fUpload, String types); static boolean fileSize(List<FormUpload> fUpload, String minSize, String maxSize); static boolean fileSizeMin(List<FormUpload> fUpload, String minSize); static boolean fileSizeMax(List<FormUpload> fUpload, String maxSize); static boolean fileCountMin(List<FormUpload> fUpload, int count); static boolean fileCountMax(List<FormUpload> fUpload, int count); static boolean fileCount(List<FormUpload> fUpload, int minCount, int maxCount); }
RuleValidation { private static int size(Object item) { if (null == item) { return 0; } if (Collection.class.isAssignableFrom(item.getClass())) { return ((Collection<?>) item).size(); } if (CharSequence.class.isAssignableFrom(item.getClass())) { return ((CharSequence) item).length(); } throw new UnsupportedOperationException("can not invoke size() on object of type" + item.getClass().getName() + "!"); } RuleValidation(Request container); Map<String, List<FormUpload>> getFileParams(Map<String, List<FormUpload>> formUploads); boolean validate(String rule); static boolean string(String string); static boolean captcha(String value, String result); static boolean email(String string); static boolean equals(String string1, String string2); static boolean number(String string); static boolean number(String string, char separator); static boolean numberFractionDigits(String string, int digits, int fraction); static boolean number(String string, char separator, int digits, int fraction); static boolean regExp(String string, String regex); static boolean size(Object item, int size); static boolean sizeMax(Object item, int max); static boolean sizeMin(Object item, int min); static boolean sizeMinMax(Object item, int min, int max); static boolean fileType(List<FormUpload> fUpload, String types); static boolean fileSize(List<FormUpload> fUpload, String minSize, String maxSize); static boolean fileSizeMin(List<FormUpload> fUpload, String minSize); static boolean fileSizeMax(List<FormUpload> fUpload, String maxSize); static boolean fileCountMin(List<FormUpload> fUpload, int count); static boolean fileCountMax(List<FormUpload> fUpload, int count); static boolean fileCount(List<FormUpload> fUpload, int minCount, int maxCount); static final List<String> SHORT_RULES; }
@Test public void testHead() throws IOException, ServletException { when(base.request.getServletPath()).thenReturn("/test.txt"); doHead(base.request, base.response); Assert.assertEquals(0, base.out.size()); }
protected void doHead(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { doGet(request, wrapResponseForHeadRequest(response)); }
Controller extends DefaultServlet implements ContainerServlet { protected void doHead(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { doGet(request, wrapResponseForHeadRequest(response)); } }
Controller extends DefaultServlet implements ContainerServlet { protected void doHead(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { doGet(request, wrapResponseForHeadRequest(response)); } Controller(); }
Controller extends DefaultServlet implements ContainerServlet { protected void doHead(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { doGet(request, wrapResponseForHeadRequest(response)); } Controller(); void serveResource(HttpServletRequest request, HttpServletResponse response); @Override void init(); Wrapper getWrapper(); void setWrapper(Wrapper wrapper); JspHandler getJspHandler(); }
Controller extends DefaultServlet implements ContainerServlet { protected void doHead(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { doGet(request, wrapResponseForHeadRequest(response)); } Controller(); void serveResource(HttpServletRequest request, HttpServletResponse response); @Override void init(); Wrapper getWrapper(); void setWrapper(Wrapper wrapper); JspHandler getJspHandler(); }
@Test public void testLoadingPage() { Mockito.when(base.ctx.getAttribute(PlatformStartup.APPNG_STARTED)).thenReturn(false); when(base.request.getServletPath()).thenReturn("/dummy"); try { doGet(base.request, base.response); String actual = new String(base.out.toByteArray()); Assert.assertEquals(new String(loadingScreen), actual); } catch (Exception e) { fail(e); } finally { Mockito.when(base.ctx.getAttribute(PlatformStartup.APPNG_STARTED)).thenReturn(true); } }
@Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } Controller(); }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } Controller(); void serveResource(HttpServletRequest request, HttpServletResponse response); @Override void init(); Wrapper getWrapper(); void setWrapper(Wrapper wrapper); JspHandler getJspHandler(); }
Controller extends DefaultServlet implements ContainerServlet { @Override protected void doGet(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { if (!Boolean.TRUE.equals(servletRequest.getServletContext().getAttribute(PlatformStartup.APPNG_STARTED))) { servletResponse.setStatus(HttpStatus.SERVICE_UNAVAILABLE.value()); servletResponse.setContentType(MediaType.TEXT_HTML_VALUE); servletResponse.setContentLength(loadingScreen.length); servletResponse.getOutputStream().write(loadingScreen); return; } String servletPath = servletRequest.getServletPath(); String serverName = servletRequest.getServerName(); Environment env = getEnvironment(servletRequest, servletResponse); String hostIdentifier = RequestUtil.getHostIdentifier(servletRequest, env); Site site = RequestUtil.getSiteByHost(env, hostIdentifier); Properties platformProperties = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG); Boolean allowPlainRequests = platformProperties.getBoolean(ALLOW_PLAIN_REQUESTS, true); if (site != null) { try { int requests = ((SiteImpl) site).addRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); PathInfo pathInfo = RequestUtil.getPathInfo(env, site, servletPath); if (pathInfo.isMonitoring()) { monitoringHandler.handle(servletRequest, servletResponse, env, site, pathInfo); } else { site = RequestUtil.waitForSite(env, site.getName()); if (site.hasState(SiteState.STARTED)) { boolean enforcePrimaryDomain = site.getProperties() .getBoolean(SiteProperties.ENFORCE_PRIMARY_DOMAIN, false); if (enforcePrimaryDomain) { String primaryDomain = site.getDomain(); if (!(primaryDomain.startsWith(SCHEME_HTTP + serverName)) || (primaryDomain.startsWith(SCHEME_HTTPS + serverName))) { Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, primaryDomain); } } setRequestAttributes(servletRequest, env, pathInfo); String templatePrefix = platformProperties.getString(Platform.Property.TEMPLATE_PREFIX); RequestHandler requestHandler = null; String appngData = platformProperties.getString(org.appng.api.Platform.Property.APPNG_DATA); File debugFolder = new File(appngData, "debug").getAbsoluteFile(); if (!(debugFolder.exists() || debugFolder.mkdirs())) { LOGGER.warn("Failed to create {}", debugFolder.getPath()); } if (("/".equals(servletPath)) || ("".equals(servletPath)) || (null == servletPath)) { if (!pathInfo.getDocumentDirectories().isEmpty()) { String defaultPage = site.getProperties().getString(SiteProperties.DEFAULT_PAGE); String target = pathInfo.getDocumentDirectories().get(0) + SLASH + defaultPage; Redirect.to(servletResponse, HttpServletResponse.SC_MOVED_PERMANENTLY, target); } else { LOGGER.warn("{} is empty for site {}, can not process request!", SiteProperties.DOCUMENT_DIR, site.getName()); } } else if (pathInfo.isStaticContent() || pathInfo.getServletPath().startsWith(templatePrefix) || pathInfo.isDocument()) { requestHandler = new StaticContentHandler(this); } else if (pathInfo.isGui()) { requestHandler = new GuiHandler(debugFolder); } else if (pathInfo.isService()) { ApplicationContext ctx = env.getAttribute(Scope.PLATFORM, Platform.Environment.CORE_PLATFORM_CONTEXT); MarshallService marshallService = ctx.getBean(MarshallService.class); PlatformTransformer platformTransformer = ctx.getBean(PlatformTransformer.class); requestHandler = new ServiceRequestHandler(marshallService, platformTransformer, debugFolder); } else if (pathInfo.isJsp()) { requestHandler = jspHandler; } else if (pathInfo.isMonitoring()) { requestHandler = monitoringHandler; } else if (ERRORPAGE.equals(servletPath)) { requestHandler = new ErrorPageHandler(); } else { if (allowPlainRequests && !pathInfo.isRepository()) { super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request {}", status, servletPath); } else { servletResponse.setStatus(HttpServletResponse.SC_NOT_FOUND); LOGGER.debug("was not an internal request, rejecting {}", servletPath); } } if (null != requestHandler) { if (site.hasState(SiteState.STARTED)) { requestHandler.handle(servletRequest, servletResponse, env, site, pathInfo); if (pathInfo.isGui() && servletRequest.isRequestedSessionIdValid()) { getEnvironment(servletRequest, servletResponse).setAttribute(SESSION, EnvironmentKeys.PREVIOUS_PATH, servletPath); } } else { LOGGER.error("site {} should be STARTED.", site); servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } } } else { LOGGER.error("timeout while waiting for site {}", site); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } } finally { if (null != site) { int requests = ((SiteImpl) site).removeRequest(); LOGGER.debug("site {} currently handles {} requests", site, requests); } } } else if (allowPlainRequests) { LOGGER.debug("no site found for request '{}'", servletPath); super.doGet(servletRequest, servletResponse); int status = servletResponse.getStatus(); LOGGER.debug("returned {} for request '{}'", status, servletPath); } else { LOGGER.debug("access to '{}' not allowed", servletPath); servletResponse.setStatus(HttpStatus.NOT_FOUND.value()); } } Controller(); void serveResource(HttpServletRequest request, HttpServletResponse response); @Override void init(); Wrapper getWrapper(); void setWrapper(Wrapper wrapper); JspHandler getJspHandler(); }
@Test public void testIsException() { String servletPath = "/foo/bar/lore/ipsum"; Assert.assertFalse(PageCacheFilter.isException("/foo/me", servletPath)); Assert.assertTrue(PageCacheFilter.isException(servletPath, servletPath)); Assert.assertTrue(PageCacheFilter.isException("/foo/bar/lore/", servletPath)); Assert.assertTrue(PageCacheFilter.isException("/foo/bar", servletPath)); Assert.assertTrue(PageCacheFilter.isException("/foo/", servletPath)); Assert.assertTrue(PageCacheFilter.isException("/", servletPath)); }
static boolean isException(String exceptionsProp, String servletPath) { if (null != exceptionsProp) { Set<String> exceptions = new HashSet<>(Arrays.asList(exceptionsProp.split(StringUtils.LF))); for (String e : exceptions) { if (servletPath.startsWith(e.trim())) { return true; } } } return false; }
PageCacheFilter implements javax.servlet.Filter { static boolean isException(String exceptionsProp, String servletPath) { if (null != exceptionsProp) { Set<String> exceptions = new HashSet<>(Arrays.asList(exceptionsProp.split(StringUtils.LF))); for (String e : exceptions) { if (servletPath.startsWith(e.trim())) { return true; } } } return false; } }
PageCacheFilter implements javax.servlet.Filter { static boolean isException(String exceptionsProp, String servletPath) { if (null != exceptionsProp) { Set<String> exceptions = new HashSet<>(Arrays.asList(exceptionsProp.split(StringUtils.LF))); for (String e : exceptions) { if (servletPath.startsWith(e.trim())) { return true; } } } return false; } }
PageCacheFilter implements javax.servlet.Filter { static boolean isException(String exceptionsProp, String servletPath) { if (null != exceptionsProp) { Set<String> exceptions = new HashSet<>(Arrays.asList(exceptionsProp.split(StringUtils.LF))); for (String e : exceptions) { if (servletPath.startsWith(e.trim())) { return true; } } } return false; } void init(FilterConfig filterConfig); void destroy(); void doFilter(ServletRequest request, ServletResponse response, FilterChain chain); }
PageCacheFilter implements javax.servlet.Filter { static boolean isException(String exceptionsProp, String servletPath) { if (null != exceptionsProp) { Set<String> exceptions = new HashSet<>(Arrays.asList(exceptionsProp.split(StringUtils.LF))); for (String e : exceptions) { if (servletPath.startsWith(e.trim())) { return true; } } } return false; } void init(FilterConfig filterConfig); void destroy(); void doFilter(ServletRequest request, ServletResponse response, FilterChain chain); }
@Test public void testGetExpireAfterSeconds() { Integer defaultCacheTime = Integer.valueOf(1800); Integer oneMin = Integer.valueOf(60); Integer tenMins = Integer.valueOf(600); Integer oneHour = Integer.valueOf(3600); Properties cachingTimes = new Properties(); String servletPath = "/foo/bar/lore/ipsum"; Integer expireAfterSeconds = PageCacheFilter.getExpireAfterSeconds(cachingTimes, false, servletPath, defaultCacheTime); Assert.assertEquals(defaultCacheTime, expireAfterSeconds); cachingTimes.put("", oneMin); expireAfterSeconds = PageCacheFilter.getExpireAfterSeconds(cachingTimes, false, servletPath, defaultCacheTime); Assert.assertEquals(oneMin, expireAfterSeconds); cachingTimes.put(servletPath, oneMin); expireAfterSeconds = PageCacheFilter.getExpireAfterSeconds(cachingTimes, false, servletPath, defaultCacheTime); Assert.assertEquals(oneMin, expireAfterSeconds); cachingTimes.clear(); cachingTimes.put("/foo/bar/lore", tenMins); expireAfterSeconds = PageCacheFilter.getExpireAfterSeconds(cachingTimes, false, servletPath, defaultCacheTime); Assert.assertEquals(tenMins, expireAfterSeconds); cachingTimes.clear(); cachingTimes.put("/foo", oneHour); expireAfterSeconds = PageCacheFilter.getExpireAfterSeconds(cachingTimes, false, servletPath, defaultCacheTime); Assert.assertEquals(oneHour, expireAfterSeconds); }
static Integer getExpireAfterSeconds(Properties cachingTimes, boolean antStylePathMatching, String servletPath, Integer defaultValue) { if (null != cachingTimes && !cachingTimes.isEmpty()) { if (antStylePathMatching) { for (Object path : cachingTimes.keySet()) { AntPathMatcher matcher = new AntPathMatcher(); if (matcher.match(path.toString(), servletPath)) { Object entry = cachingTimes.get(path); return Integer.valueOf(entry.toString().trim()); } } } else { String[] pathSegements = servletPath.split(Path.SEPARATOR); int len = pathSegements.length; while (len > 0) { String segment = StringUtils.join(Arrays.copyOfRange(pathSegements, 0, len--), Path.SEPARATOR); Object entry = cachingTimes.get(segment); if (null != entry) { return Integer.valueOf(entry.toString().trim()); } } } } return defaultValue; }
PageCacheFilter implements javax.servlet.Filter { static Integer getExpireAfterSeconds(Properties cachingTimes, boolean antStylePathMatching, String servletPath, Integer defaultValue) { if (null != cachingTimes && !cachingTimes.isEmpty()) { if (antStylePathMatching) { for (Object path : cachingTimes.keySet()) { AntPathMatcher matcher = new AntPathMatcher(); if (matcher.match(path.toString(), servletPath)) { Object entry = cachingTimes.get(path); return Integer.valueOf(entry.toString().trim()); } } } else { String[] pathSegements = servletPath.split(Path.SEPARATOR); int len = pathSegements.length; while (len > 0) { String segment = StringUtils.join(Arrays.copyOfRange(pathSegements, 0, len--), Path.SEPARATOR); Object entry = cachingTimes.get(segment); if (null != entry) { return Integer.valueOf(entry.toString().trim()); } } } } return defaultValue; } }
PageCacheFilter implements javax.servlet.Filter { static Integer getExpireAfterSeconds(Properties cachingTimes, boolean antStylePathMatching, String servletPath, Integer defaultValue) { if (null != cachingTimes && !cachingTimes.isEmpty()) { if (antStylePathMatching) { for (Object path : cachingTimes.keySet()) { AntPathMatcher matcher = new AntPathMatcher(); if (matcher.match(path.toString(), servletPath)) { Object entry = cachingTimes.get(path); return Integer.valueOf(entry.toString().trim()); } } } else { String[] pathSegements = servletPath.split(Path.SEPARATOR); int len = pathSegements.length; while (len > 0) { String segment = StringUtils.join(Arrays.copyOfRange(pathSegements, 0, len--), Path.SEPARATOR); Object entry = cachingTimes.get(segment); if (null != entry) { return Integer.valueOf(entry.toString().trim()); } } } } return defaultValue; } }
PageCacheFilter implements javax.servlet.Filter { static Integer getExpireAfterSeconds(Properties cachingTimes, boolean antStylePathMatching, String servletPath, Integer defaultValue) { if (null != cachingTimes && !cachingTimes.isEmpty()) { if (antStylePathMatching) { for (Object path : cachingTimes.keySet()) { AntPathMatcher matcher = new AntPathMatcher(); if (matcher.match(path.toString(), servletPath)) { Object entry = cachingTimes.get(path); return Integer.valueOf(entry.toString().trim()); } } } else { String[] pathSegements = servletPath.split(Path.SEPARATOR); int len = pathSegements.length; while (len > 0) { String segment = StringUtils.join(Arrays.copyOfRange(pathSegements, 0, len--), Path.SEPARATOR); Object entry = cachingTimes.get(segment); if (null != entry) { return Integer.valueOf(entry.toString().trim()); } } } } return defaultValue; } void init(FilterConfig filterConfig); void destroy(); void doFilter(ServletRequest request, ServletResponse response, FilterChain chain); }
PageCacheFilter implements javax.servlet.Filter { static Integer getExpireAfterSeconds(Properties cachingTimes, boolean antStylePathMatching, String servletPath, Integer defaultValue) { if (null != cachingTimes && !cachingTimes.isEmpty()) { if (antStylePathMatching) { for (Object path : cachingTimes.keySet()) { AntPathMatcher matcher = new AntPathMatcher(); if (matcher.match(path.toString(), servletPath)) { Object entry = cachingTimes.get(path); return Integer.valueOf(entry.toString().trim()); } } } else { String[] pathSegements = servletPath.split(Path.SEPARATOR); int len = pathSegements.length; while (len > 0) { String segment = StringUtils.join(Arrays.copyOfRange(pathSegements, 0, len--), Path.SEPARATOR); Object entry = cachingTimes.get(segment); if (null != entry) { return Integer.valueOf(entry.toString().trim()); } } } } return defaultValue; } void init(FilterConfig filterConfig); void destroy(); void doFilter(ServletRequest request, ServletResponse response, FilterChain chain); }
@Test public void testGetExpireAfterSecondsAntStyle() { Integer defaultCacheTime = Integer.valueOf(1800); Integer oneMin = Integer.valueOf(60); Integer tenMins = Integer.valueOf(600); Integer oneHour = Integer.valueOf(3600); Properties cachingTimes = new Properties(); String servletPath = "/foo/bar/lore/ipsum"; Integer expireAfterSeconds = PageCacheFilter.getExpireAfterSeconds(cachingTimes, true, servletPath, defaultCacheTime); Assert.assertEquals(defaultCacheTime, expireAfterSeconds); cachingTimes.put("/**", oneMin); expireAfterSeconds = PageCacheFilter.getExpireAfterSeconds(cachingTimes, true, servletPath, defaultCacheTime); Assert.assertEquals(oneMin, expireAfterSeconds); cachingTimes.put(servletPath, oneMin); expireAfterSeconds = PageCacheFilter.getExpireAfterSeconds(cachingTimes, true, servletPath, defaultCacheTime); Assert.assertEquals(oneMin, expireAfterSeconds); cachingTimes.clear(); cachingTimes.put("/foo/bar/lore/**", tenMins); expireAfterSeconds = PageCacheFilter.getExpireAfterSeconds(cachingTimes, true, servletPath, defaultCacheTime); Assert.assertEquals(tenMins, expireAfterSeconds); cachingTimes.clear(); cachingTimes.put("/foo/**", oneHour); expireAfterSeconds = PageCacheFilter.getExpireAfterSeconds(cachingTimes, true, servletPath, defaultCacheTime); Assert.assertEquals(oneHour, expireAfterSeconds); }
static Integer getExpireAfterSeconds(Properties cachingTimes, boolean antStylePathMatching, String servletPath, Integer defaultValue) { if (null != cachingTimes && !cachingTimes.isEmpty()) { if (antStylePathMatching) { for (Object path : cachingTimes.keySet()) { AntPathMatcher matcher = new AntPathMatcher(); if (matcher.match(path.toString(), servletPath)) { Object entry = cachingTimes.get(path); return Integer.valueOf(entry.toString().trim()); } } } else { String[] pathSegements = servletPath.split(Path.SEPARATOR); int len = pathSegements.length; while (len > 0) { String segment = StringUtils.join(Arrays.copyOfRange(pathSegements, 0, len--), Path.SEPARATOR); Object entry = cachingTimes.get(segment); if (null != entry) { return Integer.valueOf(entry.toString().trim()); } } } } return defaultValue; }
PageCacheFilter implements javax.servlet.Filter { static Integer getExpireAfterSeconds(Properties cachingTimes, boolean antStylePathMatching, String servletPath, Integer defaultValue) { if (null != cachingTimes && !cachingTimes.isEmpty()) { if (antStylePathMatching) { for (Object path : cachingTimes.keySet()) { AntPathMatcher matcher = new AntPathMatcher(); if (matcher.match(path.toString(), servletPath)) { Object entry = cachingTimes.get(path); return Integer.valueOf(entry.toString().trim()); } } } else { String[] pathSegements = servletPath.split(Path.SEPARATOR); int len = pathSegements.length; while (len > 0) { String segment = StringUtils.join(Arrays.copyOfRange(pathSegements, 0, len--), Path.SEPARATOR); Object entry = cachingTimes.get(segment); if (null != entry) { return Integer.valueOf(entry.toString().trim()); } } } } return defaultValue; } }
PageCacheFilter implements javax.servlet.Filter { static Integer getExpireAfterSeconds(Properties cachingTimes, boolean antStylePathMatching, String servletPath, Integer defaultValue) { if (null != cachingTimes && !cachingTimes.isEmpty()) { if (antStylePathMatching) { for (Object path : cachingTimes.keySet()) { AntPathMatcher matcher = new AntPathMatcher(); if (matcher.match(path.toString(), servletPath)) { Object entry = cachingTimes.get(path); return Integer.valueOf(entry.toString().trim()); } } } else { String[] pathSegements = servletPath.split(Path.SEPARATOR); int len = pathSegements.length; while (len > 0) { String segment = StringUtils.join(Arrays.copyOfRange(pathSegements, 0, len--), Path.SEPARATOR); Object entry = cachingTimes.get(segment); if (null != entry) { return Integer.valueOf(entry.toString().trim()); } } } } return defaultValue; } }
PageCacheFilter implements javax.servlet.Filter { static Integer getExpireAfterSeconds(Properties cachingTimes, boolean antStylePathMatching, String servletPath, Integer defaultValue) { if (null != cachingTimes && !cachingTimes.isEmpty()) { if (antStylePathMatching) { for (Object path : cachingTimes.keySet()) { AntPathMatcher matcher = new AntPathMatcher(); if (matcher.match(path.toString(), servletPath)) { Object entry = cachingTimes.get(path); return Integer.valueOf(entry.toString().trim()); } } } else { String[] pathSegements = servletPath.split(Path.SEPARATOR); int len = pathSegements.length; while (len > 0) { String segment = StringUtils.join(Arrays.copyOfRange(pathSegements, 0, len--), Path.SEPARATOR); Object entry = cachingTimes.get(segment); if (null != entry) { return Integer.valueOf(entry.toString().trim()); } } } } return defaultValue; } void init(FilterConfig filterConfig); void destroy(); void doFilter(ServletRequest request, ServletResponse response, FilterChain chain); }
PageCacheFilter implements javax.servlet.Filter { static Integer getExpireAfterSeconds(Properties cachingTimes, boolean antStylePathMatching, String servletPath, Integer defaultValue) { if (null != cachingTimes && !cachingTimes.isEmpty()) { if (antStylePathMatching) { for (Object path : cachingTimes.keySet()) { AntPathMatcher matcher = new AntPathMatcher(); if (matcher.match(path.toString(), servletPath)) { Object entry = cachingTimes.get(path); return Integer.valueOf(entry.toString().trim()); } } } else { String[] pathSegements = servletPath.split(Path.SEPARATOR); int len = pathSegements.length; while (len > 0) { String segment = StringUtils.join(Arrays.copyOfRange(pathSegements, 0, len--), Path.SEPARATOR); Object entry = cachingTimes.get(segment); if (null != entry) { return Integer.valueOf(entry.toString().trim()); } } } } return defaultValue; } void init(FilterConfig filterConfig); void destroy(); void doFilter(ServletRequest request, ServletResponse response, FilterChain chain); }
@Test public void testReplace() { Assert.assertEquals("<a href=\"/de/index\">", doReplace("<a href=\"/de/index.jsp\">")); Assert.assertEquals("<a href=\"/de/seite\">", doReplace("<a href=\"/en/page.jsp\">")); Assert.assertEquals("url='/de/seite'", doReplace("url='/en/page.jsp'")); Assert.assertEquals("url='/de/foo' '/en/bar'", doReplace("url='/de/foo.jsp' '/en/bar.jsp'")); Assert.assertEquals("/app", doReplace("/app")); }
protected String doReplace(List<RedirectRule> redirectRules, String sourcePath, String domain, String jspExtension, String content) { long startTime = System.currentTimeMillis(); int numRules = 0; if (null != redirectRules) { numRules = redirectRules.size(); for (RedirectRule rule : redirectRules) { content = rule.apply(content); if (LOGGER.isTraceEnabled()) { LOGGER.trace("{} has been applied", rule); } } } if (content.contains(jspExtension)) { Pattern domainPattern = getDomainPattern(domain, jspExtension); content = domainPattern.matcher(content).replaceAll("$1$2"); if (LOGGER.isTraceEnabled()) { LOGGER.trace("replace with pattern {} has been applied", domainPattern); } } if (LOGGER.isDebugEnabled()) { LOGGER.debug("handling JSP extensions for source '{}' took {}ms ({} redirect-rules processed)", sourcePath, System.currentTimeMillis() - startTime, numRules); } return content; }
JspExtensionFilter implements Filter { protected String doReplace(List<RedirectRule> redirectRules, String sourcePath, String domain, String jspExtension, String content) { long startTime = System.currentTimeMillis(); int numRules = 0; if (null != redirectRules) { numRules = redirectRules.size(); for (RedirectRule rule : redirectRules) { content = rule.apply(content); if (LOGGER.isTraceEnabled()) { LOGGER.trace("{} has been applied", rule); } } } if (content.contains(jspExtension)) { Pattern domainPattern = getDomainPattern(domain, jspExtension); content = domainPattern.matcher(content).replaceAll("$1$2"); if (LOGGER.isTraceEnabled()) { LOGGER.trace("replace with pattern {} has been applied", domainPattern); } } if (LOGGER.isDebugEnabled()) { LOGGER.debug("handling JSP extensions for source '{}' took {}ms ({} redirect-rules processed)", sourcePath, System.currentTimeMillis() - startTime, numRules); } return content; } }
JspExtensionFilter implements Filter { protected String doReplace(List<RedirectRule> redirectRules, String sourcePath, String domain, String jspExtension, String content) { long startTime = System.currentTimeMillis(); int numRules = 0; if (null != redirectRules) { numRules = redirectRules.size(); for (RedirectRule rule : redirectRules) { content = rule.apply(content); if (LOGGER.isTraceEnabled()) { LOGGER.trace("{} has been applied", rule); } } } if (content.contains(jspExtension)) { Pattern domainPattern = getDomainPattern(domain, jspExtension); content = domainPattern.matcher(content).replaceAll("$1$2"); if (LOGGER.isTraceEnabled()) { LOGGER.trace("replace with pattern {} has been applied", domainPattern); } } if (LOGGER.isDebugEnabled()) { LOGGER.debug("handling JSP extensions for source '{}' took {}ms ({} redirect-rules processed)", sourcePath, System.currentTimeMillis() - startTime, numRules); } return content; } JspExtensionFilter(); }
JspExtensionFilter implements Filter { protected String doReplace(List<RedirectRule> redirectRules, String sourcePath, String domain, String jspExtension, String content) { long startTime = System.currentTimeMillis(); int numRules = 0; if (null != redirectRules) { numRules = redirectRules.size(); for (RedirectRule rule : redirectRules) { content = rule.apply(content); if (LOGGER.isTraceEnabled()) { LOGGER.trace("{} has been applied", rule); } } } if (content.contains(jspExtension)) { Pattern domainPattern = getDomainPattern(domain, jspExtension); content = domainPattern.matcher(content).replaceAll("$1$2"); if (LOGGER.isTraceEnabled()) { LOGGER.trace("replace with pattern {} has been applied", domainPattern); } } if (LOGGER.isDebugEnabled()) { LOGGER.debug("handling JSP extensions for source '{}' took {}ms ({} redirect-rules processed)", sourcePath, System.currentTimeMillis() - startTime, numRules); } return content; } JspExtensionFilter(); void doFilter(ServletRequest request, ServletResponse response, FilterChain chain); void init(FilterConfig filterConfig); void destroy(); }
JspExtensionFilter implements Filter { protected String doReplace(List<RedirectRule> redirectRules, String sourcePath, String domain, String jspExtension, String content) { long startTime = System.currentTimeMillis(); int numRules = 0; if (null != redirectRules) { numRules = redirectRules.size(); for (RedirectRule rule : redirectRules) { content = rule.apply(content); if (LOGGER.isTraceEnabled()) { LOGGER.trace("{} has been applied", rule); } } } if (content.contains(jspExtension)) { Pattern domainPattern = getDomainPattern(domain, jspExtension); content = domainPattern.matcher(content).replaceAll("$1$2"); if (LOGGER.isTraceEnabled()) { LOGGER.trace("replace with pattern {} has been applied", domainPattern); } } if (LOGGER.isDebugEnabled()) { LOGGER.debug("handling JSP extensions for source '{}' took {}ms ({} redirect-rules processed)", sourcePath, System.currentTimeMillis() - startTime, numRules); } return content; } JspExtensionFilter(); void doFilter(ServletRequest request, ServletResponse response, FilterChain chain); void init(FilterConfig filterConfig); void destroy(); }
@Test public void testStripJsp() { assertUnchanged("<a href=\"/de/index\">"); assertUnchanged("<a href=\"/de/seite\">"); assertUnchanged("/de/foobar.jsp"); Assert.assertEquals("<a href=\"/de/foo\">", doReplace("<a href=\"/de/foo.jsp\">")); Assert.assertEquals("'/en/bar'", doReplace("'/en/bar.jsp'")); Assert.assertEquals("/de/index", doReplace("/en/index.jsp")); }
protected String doReplace(List<RedirectRule> redirectRules, String sourcePath, String domain, String jspExtension, String content) { long startTime = System.currentTimeMillis(); int numRules = 0; if (null != redirectRules) { numRules = redirectRules.size(); for (RedirectRule rule : redirectRules) { content = rule.apply(content); if (LOGGER.isTraceEnabled()) { LOGGER.trace("{} has been applied", rule); } } } if (content.contains(jspExtension)) { Pattern domainPattern = getDomainPattern(domain, jspExtension); content = domainPattern.matcher(content).replaceAll("$1$2"); if (LOGGER.isTraceEnabled()) { LOGGER.trace("replace with pattern {} has been applied", domainPattern); } } if (LOGGER.isDebugEnabled()) { LOGGER.debug("handling JSP extensions for source '{}' took {}ms ({} redirect-rules processed)", sourcePath, System.currentTimeMillis() - startTime, numRules); } return content; }
JspExtensionFilter implements Filter { protected String doReplace(List<RedirectRule> redirectRules, String sourcePath, String domain, String jspExtension, String content) { long startTime = System.currentTimeMillis(); int numRules = 0; if (null != redirectRules) { numRules = redirectRules.size(); for (RedirectRule rule : redirectRules) { content = rule.apply(content); if (LOGGER.isTraceEnabled()) { LOGGER.trace("{} has been applied", rule); } } } if (content.contains(jspExtension)) { Pattern domainPattern = getDomainPattern(domain, jspExtension); content = domainPattern.matcher(content).replaceAll("$1$2"); if (LOGGER.isTraceEnabled()) { LOGGER.trace("replace with pattern {} has been applied", domainPattern); } } if (LOGGER.isDebugEnabled()) { LOGGER.debug("handling JSP extensions for source '{}' took {}ms ({} redirect-rules processed)", sourcePath, System.currentTimeMillis() - startTime, numRules); } return content; } }
JspExtensionFilter implements Filter { protected String doReplace(List<RedirectRule> redirectRules, String sourcePath, String domain, String jspExtension, String content) { long startTime = System.currentTimeMillis(); int numRules = 0; if (null != redirectRules) { numRules = redirectRules.size(); for (RedirectRule rule : redirectRules) { content = rule.apply(content); if (LOGGER.isTraceEnabled()) { LOGGER.trace("{} has been applied", rule); } } } if (content.contains(jspExtension)) { Pattern domainPattern = getDomainPattern(domain, jspExtension); content = domainPattern.matcher(content).replaceAll("$1$2"); if (LOGGER.isTraceEnabled()) { LOGGER.trace("replace with pattern {} has been applied", domainPattern); } } if (LOGGER.isDebugEnabled()) { LOGGER.debug("handling JSP extensions for source '{}' took {}ms ({} redirect-rules processed)", sourcePath, System.currentTimeMillis() - startTime, numRules); } return content; } JspExtensionFilter(); }
JspExtensionFilter implements Filter { protected String doReplace(List<RedirectRule> redirectRules, String sourcePath, String domain, String jspExtension, String content) { long startTime = System.currentTimeMillis(); int numRules = 0; if (null != redirectRules) { numRules = redirectRules.size(); for (RedirectRule rule : redirectRules) { content = rule.apply(content); if (LOGGER.isTraceEnabled()) { LOGGER.trace("{} has been applied", rule); } } } if (content.contains(jspExtension)) { Pattern domainPattern = getDomainPattern(domain, jspExtension); content = domainPattern.matcher(content).replaceAll("$1$2"); if (LOGGER.isTraceEnabled()) { LOGGER.trace("replace with pattern {} has been applied", domainPattern); } } if (LOGGER.isDebugEnabled()) { LOGGER.debug("handling JSP extensions for source '{}' took {}ms ({} redirect-rules processed)", sourcePath, System.currentTimeMillis() - startTime, numRules); } return content; } JspExtensionFilter(); void doFilter(ServletRequest request, ServletResponse response, FilterChain chain); void init(FilterConfig filterConfig); void destroy(); }
JspExtensionFilter implements Filter { protected String doReplace(List<RedirectRule> redirectRules, String sourcePath, String domain, String jspExtension, String content) { long startTime = System.currentTimeMillis(); int numRules = 0; if (null != redirectRules) { numRules = redirectRules.size(); for (RedirectRule rule : redirectRules) { content = rule.apply(content); if (LOGGER.isTraceEnabled()) { LOGGER.trace("{} has been applied", rule); } } } if (content.contains(jspExtension)) { Pattern domainPattern = getDomainPattern(domain, jspExtension); content = domainPattern.matcher(content).replaceAll("$1$2"); if (LOGGER.isTraceEnabled()) { LOGGER.trace("replace with pattern {} has been applied", domainPattern); } } if (LOGGER.isDebugEnabled()) { LOGGER.debug("handling JSP extensions for source '{}' took {}ms ({} redirect-rules processed)", sourcePath, System.currentTimeMillis() - startTime, numRules); } return content; } JspExtensionFilter(); void doFilter(ServletRequest request, ServletResponse response, FilterChain chain); void init(FilterConfig filterConfig); void destroy(); }
@Test public void testReplaceDomain() { assertUnchanged("<a href=\"" + domain + "/de/seite\">"); assertUnchanged("<a href=\"" + domain + "/de/foo\">"); assertUnchanged("http: assertUnchanged("'http: Assert.assertEquals("url='" + domain + "/de/seite'", doReplace("url='" + domain + "/en/page.jsp'")); Assert.assertEquals("url='" + domain + "/de/foo'", doReplace("url='" + domain + "/de/foo.jsp'")); Assert.assertEquals(domain + "/de/foo", doReplace(domain + "/de/foo.jsp")); Assert.assertEquals("<a href=\"" + domain + "/de/seite\">", doReplace("<a href=\"" + domain + "/en/page.jsp\">")); assertUnchanged("http: }
protected String doReplace(List<RedirectRule> redirectRules, String sourcePath, String domain, String jspExtension, String content) { long startTime = System.currentTimeMillis(); int numRules = 0; if (null != redirectRules) { numRules = redirectRules.size(); for (RedirectRule rule : redirectRules) { content = rule.apply(content); if (LOGGER.isTraceEnabled()) { LOGGER.trace("{} has been applied", rule); } } } if (content.contains(jspExtension)) { Pattern domainPattern = getDomainPattern(domain, jspExtension); content = domainPattern.matcher(content).replaceAll("$1$2"); if (LOGGER.isTraceEnabled()) { LOGGER.trace("replace with pattern {} has been applied", domainPattern); } } if (LOGGER.isDebugEnabled()) { LOGGER.debug("handling JSP extensions for source '{}' took {}ms ({} redirect-rules processed)", sourcePath, System.currentTimeMillis() - startTime, numRules); } return content; }
JspExtensionFilter implements Filter { protected String doReplace(List<RedirectRule> redirectRules, String sourcePath, String domain, String jspExtension, String content) { long startTime = System.currentTimeMillis(); int numRules = 0; if (null != redirectRules) { numRules = redirectRules.size(); for (RedirectRule rule : redirectRules) { content = rule.apply(content); if (LOGGER.isTraceEnabled()) { LOGGER.trace("{} has been applied", rule); } } } if (content.contains(jspExtension)) { Pattern domainPattern = getDomainPattern(domain, jspExtension); content = domainPattern.matcher(content).replaceAll("$1$2"); if (LOGGER.isTraceEnabled()) { LOGGER.trace("replace with pattern {} has been applied", domainPattern); } } if (LOGGER.isDebugEnabled()) { LOGGER.debug("handling JSP extensions for source '{}' took {}ms ({} redirect-rules processed)", sourcePath, System.currentTimeMillis() - startTime, numRules); } return content; } }
JspExtensionFilter implements Filter { protected String doReplace(List<RedirectRule> redirectRules, String sourcePath, String domain, String jspExtension, String content) { long startTime = System.currentTimeMillis(); int numRules = 0; if (null != redirectRules) { numRules = redirectRules.size(); for (RedirectRule rule : redirectRules) { content = rule.apply(content); if (LOGGER.isTraceEnabled()) { LOGGER.trace("{} has been applied", rule); } } } if (content.contains(jspExtension)) { Pattern domainPattern = getDomainPattern(domain, jspExtension); content = domainPattern.matcher(content).replaceAll("$1$2"); if (LOGGER.isTraceEnabled()) { LOGGER.trace("replace with pattern {} has been applied", domainPattern); } } if (LOGGER.isDebugEnabled()) { LOGGER.debug("handling JSP extensions for source '{}' took {}ms ({} redirect-rules processed)", sourcePath, System.currentTimeMillis() - startTime, numRules); } return content; } JspExtensionFilter(); }
JspExtensionFilter implements Filter { protected String doReplace(List<RedirectRule> redirectRules, String sourcePath, String domain, String jspExtension, String content) { long startTime = System.currentTimeMillis(); int numRules = 0; if (null != redirectRules) { numRules = redirectRules.size(); for (RedirectRule rule : redirectRules) { content = rule.apply(content); if (LOGGER.isTraceEnabled()) { LOGGER.trace("{} has been applied", rule); } } } if (content.contains(jspExtension)) { Pattern domainPattern = getDomainPattern(domain, jspExtension); content = domainPattern.matcher(content).replaceAll("$1$2"); if (LOGGER.isTraceEnabled()) { LOGGER.trace("replace with pattern {} has been applied", domainPattern); } } if (LOGGER.isDebugEnabled()) { LOGGER.debug("handling JSP extensions for source '{}' took {}ms ({} redirect-rules processed)", sourcePath, System.currentTimeMillis() - startTime, numRules); } return content; } JspExtensionFilter(); void doFilter(ServletRequest request, ServletResponse response, FilterChain chain); void init(FilterConfig filterConfig); void destroy(); }
JspExtensionFilter implements Filter { protected String doReplace(List<RedirectRule> redirectRules, String sourcePath, String domain, String jspExtension, String content) { long startTime = System.currentTimeMillis(); int numRules = 0; if (null != redirectRules) { numRules = redirectRules.size(); for (RedirectRule rule : redirectRules) { content = rule.apply(content); if (LOGGER.isTraceEnabled()) { LOGGER.trace("{} has been applied", rule); } } } if (content.contains(jspExtension)) { Pattern domainPattern = getDomainPattern(domain, jspExtension); content = domainPattern.matcher(content).replaceAll("$1$2"); if (LOGGER.isTraceEnabled()) { LOGGER.trace("replace with pattern {} has been applied", domainPattern); } } if (LOGGER.isDebugEnabled()) { LOGGER.debug("handling JSP extensions for source '{}' took {}ms ({} redirect-rules processed)", sourcePath, System.currentTimeMillis() - startTime, numRules); } return content; } JspExtensionFilter(); void doFilter(ServletRequest request, ServletResponse response, FilterChain chain); void init(FilterConfig filterConfig); void destroy(); }
@Test public void testSystem() throws Exception { SiteImpl site = getSite(); PathInfo path = getPath(site, "/health/system"); DefaultEnvironment env = getEnv(); MockHttpServletResponse resp = new MockHttpServletResponse(); monitoringHandler.handle(getRequest(ctx), resp, env, site, path); String content = resp.getContentAsString(); Assert.assertTrue(content.contains("java.specification.name")); Assert.assertTrue(content.contains("java.specification.vendor")); Assert.assertTrue(content.contains("java.specification.version")); }
public void handle(HttpServletRequest servletRequest, HttpServletResponse servletResponse, Environment env, Site site, PathInfo pathInfo) throws ServletException, IOException { servletResponse.addHeader(HttpHeaders.WWW_AUTHENTICATE, BASIC_REALM); if (isAuthenticated(env, servletRequest)) { String pathsegment = pathInfo.getElementAt(2); Object result = null; if (null == pathsegment) { boolean details = "true".equalsIgnoreCase(servletRequest.getParameter("details")); result = getSiteInfo(site, details, servletResponse); } else if ("system".equals(pathsegment)) { result = new TreeMap<>(System.getProperties()); } else if ("environment".equals(pathsegment)) { result = new TreeMap<>(System.getenv()); } else if ("jars".equals(pathsegment)) { result = env.getAttribute(Scope.PLATFORM, site.getName() + "." + EnvironmentKeys.JAR_INFO_MAP); } else if ("platform".equals(pathsegment)) { result = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG + "." + JAR_INFO_MAP); } servletResponse.setContentType(MediaType.APPLICATION_JSON_VALUE); writer.writeValue(servletResponse.getOutputStream(), result); } else { servletResponse.setStatus(HttpStatus.UNAUTHORIZED.value()); } }
MonitoringHandler implements RequestHandler { public void handle(HttpServletRequest servletRequest, HttpServletResponse servletResponse, Environment env, Site site, PathInfo pathInfo) throws ServletException, IOException { servletResponse.addHeader(HttpHeaders.WWW_AUTHENTICATE, BASIC_REALM); if (isAuthenticated(env, servletRequest)) { String pathsegment = pathInfo.getElementAt(2); Object result = null; if (null == pathsegment) { boolean details = "true".equalsIgnoreCase(servletRequest.getParameter("details")); result = getSiteInfo(site, details, servletResponse); } else if ("system".equals(pathsegment)) { result = new TreeMap<>(System.getProperties()); } else if ("environment".equals(pathsegment)) { result = new TreeMap<>(System.getenv()); } else if ("jars".equals(pathsegment)) { result = env.getAttribute(Scope.PLATFORM, site.getName() + "." + EnvironmentKeys.JAR_INFO_MAP); } else if ("platform".equals(pathsegment)) { result = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG + "." + JAR_INFO_MAP); } servletResponse.setContentType(MediaType.APPLICATION_JSON_VALUE); writer.writeValue(servletResponse.getOutputStream(), result); } else { servletResponse.setStatus(HttpStatus.UNAUTHORIZED.value()); } } }
MonitoringHandler implements RequestHandler { public void handle(HttpServletRequest servletRequest, HttpServletResponse servletResponse, Environment env, Site site, PathInfo pathInfo) throws ServletException, IOException { servletResponse.addHeader(HttpHeaders.WWW_AUTHENTICATE, BASIC_REALM); if (isAuthenticated(env, servletRequest)) { String pathsegment = pathInfo.getElementAt(2); Object result = null; if (null == pathsegment) { boolean details = "true".equalsIgnoreCase(servletRequest.getParameter("details")); result = getSiteInfo(site, details, servletResponse); } else if ("system".equals(pathsegment)) { result = new TreeMap<>(System.getProperties()); } else if ("environment".equals(pathsegment)) { result = new TreeMap<>(System.getenv()); } else if ("jars".equals(pathsegment)) { result = env.getAttribute(Scope.PLATFORM, site.getName() + "." + EnvironmentKeys.JAR_INFO_MAP); } else if ("platform".equals(pathsegment)) { result = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG + "." + JAR_INFO_MAP); } servletResponse.setContentType(MediaType.APPLICATION_JSON_VALUE); writer.writeValue(servletResponse.getOutputStream(), result); } else { servletResponse.setStatus(HttpStatus.UNAUTHORIZED.value()); } } MonitoringHandler(); }
MonitoringHandler implements RequestHandler { public void handle(HttpServletRequest servletRequest, HttpServletResponse servletResponse, Environment env, Site site, PathInfo pathInfo) throws ServletException, IOException { servletResponse.addHeader(HttpHeaders.WWW_AUTHENTICATE, BASIC_REALM); if (isAuthenticated(env, servletRequest)) { String pathsegment = pathInfo.getElementAt(2); Object result = null; if (null == pathsegment) { boolean details = "true".equalsIgnoreCase(servletRequest.getParameter("details")); result = getSiteInfo(site, details, servletResponse); } else if ("system".equals(pathsegment)) { result = new TreeMap<>(System.getProperties()); } else if ("environment".equals(pathsegment)) { result = new TreeMap<>(System.getenv()); } else if ("jars".equals(pathsegment)) { result = env.getAttribute(Scope.PLATFORM, site.getName() + "." + EnvironmentKeys.JAR_INFO_MAP); } else if ("platform".equals(pathsegment)) { result = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG + "." + JAR_INFO_MAP); } servletResponse.setContentType(MediaType.APPLICATION_JSON_VALUE); writer.writeValue(servletResponse.getOutputStream(), result); } else { servletResponse.setStatus(HttpStatus.UNAUTHORIZED.value()); } } MonitoringHandler(); void handle(HttpServletRequest servletRequest, HttpServletResponse servletResponse, Environment env, Site site, PathInfo pathInfo); }
MonitoringHandler implements RequestHandler { public void handle(HttpServletRequest servletRequest, HttpServletResponse servletResponse, Environment env, Site site, PathInfo pathInfo) throws ServletException, IOException { servletResponse.addHeader(HttpHeaders.WWW_AUTHENTICATE, BASIC_REALM); if (isAuthenticated(env, servletRequest)) { String pathsegment = pathInfo.getElementAt(2); Object result = null; if (null == pathsegment) { boolean details = "true".equalsIgnoreCase(servletRequest.getParameter("details")); result = getSiteInfo(site, details, servletResponse); } else if ("system".equals(pathsegment)) { result = new TreeMap<>(System.getProperties()); } else if ("environment".equals(pathsegment)) { result = new TreeMap<>(System.getenv()); } else if ("jars".equals(pathsegment)) { result = env.getAttribute(Scope.PLATFORM, site.getName() + "." + EnvironmentKeys.JAR_INFO_MAP); } else if ("platform".equals(pathsegment)) { result = env.getAttribute(Scope.PLATFORM, Platform.Environment.PLATFORM_CONFIG + "." + JAR_INFO_MAP); } servletResponse.setContentType(MediaType.APPLICATION_JSON_VALUE); writer.writeValue(servletResponse.getOutputStream(), result); } else { servletResponse.setStatus(HttpStatus.UNAUTHORIZED.value()); } } MonitoringHandler(); void handle(HttpServletRequest servletRequest, HttpServletResponse servletResponse, Environment env, Site site, PathInfo pathInfo); }