diff --git a/src/main/java/org/nrg/xapi/model/event/EventClassInfo.java b/src/main/java/org/nrg/xapi/model/event/EventClassInfo.java index 49d4f5759211d997f12815d0b2028db5e5e33216..f348ac0c824317618bda23387973161889706f81 100644 --- a/src/main/java/org/nrg/xapi/model/event/EventClassInfo.java +++ b/src/main/java/org/nrg/xapi/model/event/EventClassInfo.java @@ -3,11 +3,11 @@ package org.nrg.xapi.model.event; import com.fasterxml.jackson.annotation.JsonProperty; import com.google.common.collect.Lists; +import com.google.common.collect.Maps; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import org.nrg.framework.event.EventClass; -import org.python.google.common.collect.Maps; import org.springframework.core.annotation.AnnotationUtils; import java.lang.annotation.Annotation; diff --git a/src/main/java/org/nrg/xapi/model/event/EventHandlerFilterInfo.java b/src/main/java/org/nrg/xapi/model/event/EventHandlerFilterInfo.java index 59deaa003b3b7eb343d92c4c1cfac7f73303b46f..ee41ce712846b5a80678a571ef070cdf7c1b90d3 100644 --- a/src/main/java/org/nrg/xapi/model/event/EventHandlerFilterInfo.java +++ b/src/main/java/org/nrg/xapi/model/event/EventHandlerFilterInfo.java @@ -1,19 +1,10 @@ package org.nrg.xapi.model.event; import com.fasterxml.jackson.annotation.JsonProperty; -import com.google.common.collect.Lists; - import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; -import org.nrg.framework.event.EventClass; -import org.python.google.common.collect.Maps; -import org.springframework.core.annotation.AnnotationUtils; - -import java.lang.annotation.Annotation; -import java.util.Arrays; import java.util.List; -import java.util.Map; /** * The Class EventClassInfo. diff --git a/src/main/java/org/nrg/xapi/rest/settings/XnatPluginApi.java b/src/main/java/org/nrg/xapi/rest/settings/XnatPluginApi.java index 71e9471a2cacad604c878436d5d3139b8ae032f5..048692ebbb3bc21e62582f06878b38280a311694 100644 --- a/src/main/java/org/nrg/xapi/rest/settings/XnatPluginApi.java +++ b/src/main/java/org/nrg/xapi/rest/settings/XnatPluginApi.java @@ -5,10 +5,10 @@ import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiResponse; import io.swagger.annotations.ApiResponses; import org.nrg.framework.annotations.XapiRestController; +import org.nrg.framework.beans.XnatPluginBean; import org.nrg.xdat.rest.AbstractXapiRestController; import org.nrg.xdat.security.services.RoleHolder; import org.nrg.xdat.security.services.UserManagementServiceI; -import org.nrg.xnat.services.XnatAppInfo; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; @@ -26,9 +26,9 @@ import java.util.Properties; @RequestMapping(value = "/plugins") public class XnatPluginApi extends AbstractXapiRestController { @Autowired - public XnatPluginApi(final UserManagementServiceI userManagementService, final RoleHolder roleHolder, final XnatAppInfo appInfo) { + public XnatPluginApi(final UserManagementServiceI userManagementService, final RoleHolder roleHolder) throws IOException { super(userManagementService, roleHolder); - _appInfo = appInfo; + _plugins = XnatPluginBean.getXnatPluginBeans(); } @ApiOperation(value = "Returns a list of all of the installed and active XNAT plugins with their properties.", notes = "The maps returned from this call include all of the properties specified in the plugin's property file.", response = String.class, responseContainer = "Map") @@ -36,8 +36,8 @@ public class XnatPluginApi extends AbstractXapiRestController { @ApiResponse(code = 401, message = "Must be authenticated to access the XNAT REST API."), @ApiResponse(code = 500, message = "Unexpected error")}) @RequestMapping(produces = {MediaType.APPLICATION_JSON_VALUE}, method = {RequestMethod.GET}) - public ResponseEntity<Map<String, Properties>> getAllDataTypeSchemas() throws IOException { - return new ResponseEntity<>(_appInfo.getPluginProperties(), HttpStatus.OK); + public ResponseEntity<Map<String, XnatPluginBean>> getAllDataTypeSchemas() throws IOException { + return new ResponseEntity<>(_plugins, HttpStatus.OK); } @ApiOperation(value = "Returns the indicated XNAT plugin with its properties.", notes = "The map returned from this call include all of the properties specified in the plugin's property file.", response = Properties.class) @@ -46,13 +46,12 @@ public class XnatPluginApi extends AbstractXapiRestController { @ApiResponse(code = 404, message = "The requested resource wasn't found."), @ApiResponse(code = 500, message = "Unexpected error")}) @RequestMapping(value = "{plugin}", produces = {MediaType.APPLICATION_JSON_VALUE}, method = {RequestMethod.GET}) - public ResponseEntity<Properties> getRequestedDataTypeSchema(@PathVariable("plugin") final String plugin) throws IOException { - final Map<String, Properties> plugins = _appInfo.getPluginProperties(); - if (!plugins.containsKey(plugin)) { + public ResponseEntity<XnatPluginBean> getRequestedDataTypeSchema(@PathVariable("plugin") final String plugin) throws IOException { + if (!_plugins.containsKey(plugin)) { return new ResponseEntity<>(HttpStatus.NOT_FOUND); } - return new ResponseEntity<>(plugins.get(plugin), HttpStatus.OK); + return new ResponseEntity<>(_plugins.get(plugin), HttpStatus.OK); } - private final XnatAppInfo _appInfo; -} \ No newline at end of file + private final Map<String, XnatPluginBean> _plugins; +} diff --git a/src/main/java/org/nrg/xapi/rest/users/UsersApi.java b/src/main/java/org/nrg/xapi/rest/users/UsersApi.java index e3f1c8b08e69ade13b45c95d02166f5b33b9dfb4..499f9298ed34d58d7093c9cb6df593cf7915b446 100644 --- a/src/main/java/org/nrg/xapi/rest/users/UsersApi.java +++ b/src/main/java/org/nrg/xapi/rest/users/UsersApi.java @@ -40,6 +40,7 @@ import org.springframework.security.core.session.SessionRegistry; import org.springframework.security.core.userdetails.UserDetails; import org.springframework.web.bind.annotation.*; +import javax.servlet.http.HttpSession; import java.util.*; @Api(description = "User Management API") @@ -309,24 +310,31 @@ public class UsersApi extends AbstractXapiRestController { @ApiResponse(code = 404, message = "User not found."), @ApiResponse(code = 500, message = "An unexpected error occurred.")}) @RequestMapping(value = {"{username}", "active/{username}"}, produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.DELETE) - public ResponseEntity<List<String>> invalidateUser(@ApiParam(value = "The username of the user to invalidate.", required = true) @PathVariable("username") String username) throws NotFoundException { + public ResponseEntity<List<String>> invalidateUser(final HttpSession current, @ApiParam(value = "The username of the user to invalidate.", required = true) @PathVariable("username") final String username) throws NotFoundException { HttpStatus status = isPermitted(username); if (status != null) { return new ResponseEntity<>(status); } final UserI user; - try { - user = getUserManagementService().getUser(username); - if (user == null) { + final String currentSessionId; + if (StringUtils.equals(getSessionUser().getUsername(), username)) { + user = getSessionUser(); + currentSessionId = current.getId(); + } else { + try { + user = getUserManagementService().getUser(username); + if (user == null) { + return new ResponseEntity<>(HttpStatus.NOT_FOUND); + } + currentSessionId = null; + } catch (UserInitException e) { + _log.error("An error occurred initializing the user " + username, e); + return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); + } catch (UserNotFoundException e) { return new ResponseEntity<>(HttpStatus.NOT_FOUND); } - } catch (UserInitException e) { - _log.error("An error occurred initializing the user " + username, e); - return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); - } catch (UserNotFoundException e) { - return new ResponseEntity<>(HttpStatus.NOT_FOUND); } - Object located = locatePrincipalByUsername(user.getUsername()); + final Object located = locatePrincipalByUsername(user.getUsername()); if (located == null) { return new ResponseEntity<>(HttpStatus.NOT_MODIFIED); } @@ -336,8 +344,11 @@ public class UsersApi extends AbstractXapiRestController { } final List<String> sessionIds = new ArrayList<>(); for (final SessionInformation session : sessions) { - sessionIds.add(session.getSessionId()); - session.expireNow(); + final String sessionId = session.getSessionId(); + if (!StringUtils.equals(currentSessionId, sessionId)) { + sessionIds.add(sessionId); + session.expireNow(); + } } return new ResponseEntity<>(sessionIds, HttpStatus.OK); } diff --git a/src/main/java/org/nrg/xnat/configuration/WebConfig.java b/src/main/java/org/nrg/xnat/configuration/WebConfig.java index 2d7c20dde4ece52bcb896832f32a4b0db150e6f3..0046e1c8df5d0907091e5be2471cc1d0be6e1201 100644 --- a/src/main/java/org/nrg/xnat/configuration/WebConfig.java +++ b/src/main/java/org/nrg/xnat/configuration/WebConfig.java @@ -1,16 +1,23 @@ package org.nrg.xnat.configuration; import org.nrg.framework.annotations.XapiRestController; +import org.nrg.xdat.preferences.SiteConfigPreferences; import org.nrg.xnat.services.XnatAppInfo; import org.nrg.xnat.spawner.configuration.SpawnerConfig; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.MessageSource; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import org.springframework.context.support.ReloadableResourceBundleMessageSource; +import org.springframework.http.converter.HttpMessageConverter; +import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; +import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; +import org.springframework.http.converter.xml.MarshallingHttpMessageConverter; +import org.springframework.oxm.jaxb.Jaxb2Marshaller; import org.springframework.web.multipart.MultipartResolver; import org.springframework.web.multipart.support.StandardServletMultipartResolver; import org.springframework.web.servlet.ViewResolver; @@ -28,7 +35,11 @@ import springfox.documentation.spi.DocumentationType; import springfox.documentation.spring.web.plugins.Docket; import springfox.documentation.swagger2.annotations.EnableSwagger2; +import javax.xml.bind.Marshaller; +import java.util.HashMap; +import java.util.List; import java.util.Locale; +import java.util.Map; @Configuration @EnableWebMvc @@ -36,12 +47,23 @@ import java.util.Locale; @Import(SpawnerConfig.class) @ComponentScan({"org.nrg.xapi.rest", "org.nrg.xnat.spawner.controllers"}) public class WebConfig extends WebMvcConfigurerAdapter { + @Autowired + public void setJackson2ObjectMapperBuilder(final Jackson2ObjectMapperBuilder objectMapperBuilder) { + _objectMapperBuilder = objectMapperBuilder; + } + @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler("**/swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/"); registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/"); } + @Override + public void configureMessageConverters(final List<HttpMessageConverter<?>> converters) { + converters.add(new MappingJackson2HttpMessageConverter(_objectMapperBuilder.build())); + converters.add(new MarshallingHttpMessageConverter(_marshaller, _marshaller)); + } + @Bean public MultipartResolver multipartResolver() { return new StandardServletMultipartResolver(); @@ -91,4 +113,13 @@ public class WebConfig extends WebMvcConfigurerAdapter { } private static final Logger _log = LoggerFactory.getLogger(WebConfig.class); -} \ No newline at end of file + private static final Map<String, Object> MARSHALLER_PROPERTIES = new HashMap<String, Object>() {{ put(Marshaller.JAXB_FORMATTED_OUTPUT, true); }}; + + private Jackson2ObjectMapperBuilder _objectMapperBuilder; + + private final Jaxb2Marshaller _marshaller = new Jaxb2Marshaller() {{ + setClassesToBeBound(SiteConfigPreferences.class); + setMarshallerProperties(MARSHALLER_PROPERTIES); + }}; + +} diff --git a/src/main/java/org/nrg/xnat/initialization/PropertiesConfig.java b/src/main/java/org/nrg/xnat/initialization/PropertiesConfig.java index cbe258fb644cc1a337ad6a24e53349f711cd585a..c50fd234491db87f136037e0537ea9fd70c04c30 100644 --- a/src/main/java/org/nrg/xnat/initialization/PropertiesConfig.java +++ b/src/main/java/org/nrg/xnat/initialization/PropertiesConfig.java @@ -1,9 +1,9 @@ package org.nrg.xnat.initialization; +import com.google.common.base.Joiner; import org.apache.commons.configuration.ConfigurationException; import org.apache.commons.lang3.StringUtils; import org.nrg.framework.configuration.ConfigPaths; -import org.python.google.common.base.Joiner; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.context.annotation.Bean; diff --git a/src/main/java/org/nrg/xnat/initialization/RootConfig.java b/src/main/java/org/nrg/xnat/initialization/RootConfig.java index ec802fbac2d534f607eee116c9ea170cf6519bf8..629dc90860dec80889f342c8bcd5c6fb7ec47136 100644 --- a/src/main/java/org/nrg/xnat/initialization/RootConfig.java +++ b/src/main/java/org/nrg/xnat/initialization/RootConfig.java @@ -96,11 +96,6 @@ public class RootConfig { }}; } - @Bean - public MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter(final Jackson2ObjectMapperBuilder builder) { - return new MappingJackson2HttpMessageConverter(builder.build()); - } - @Bean public Jackson2ObjectMapperBuilder objectMapperBuilder() throws NrgServiceException { return new Jackson2ObjectMapperBuilder() @@ -117,24 +112,6 @@ public class RootConfig { return Beans.getMixIns(); } - @Bean - public MarshallingHttpMessageConverter marshallingMessageConverter() { - return new MarshallingHttpMessageConverter( - jaxb2Marshaller(), - jaxb2Marshaller() - ); - } - - @Bean - public Jaxb2Marshaller jaxb2Marshaller() { - Jaxb2Marshaller marshaller = new Jaxb2Marshaller(); - marshaller.setClassesToBeBound(SiteConfigPreferences.class); - final Map<String, Object> marshallerProperties = new HashMap<>(); - marshallerProperties.put(Marshaller.JAXB_FORMATTED_OUTPUT, true); - marshaller.setMarshallerProperties(marshallerProperties); - return marshaller; - } - @Bean public SerializerService serializerService(final Jackson2ObjectMapperBuilder objectMapperBuilder) { return new SerializerService(objectMapperBuilder); diff --git a/src/main/java/org/nrg/xnat/initialization/XnatWebAppInitializer.java b/src/main/java/org/nrg/xnat/initialization/XnatWebAppInitializer.java index 51b1ab3f530ddac964013130d64408b1c75c93c0..31da80161ed033ab379815617e2ffe52ff58c93a 100644 --- a/src/main/java/org/nrg/xnat/initialization/XnatWebAppInitializer.java +++ b/src/main/java/org/nrg/xnat/initialization/XnatWebAppInitializer.java @@ -116,7 +116,7 @@ public class XnatWebAppInitializer extends AbstractAnnotationConfigDispatcherSer private List<Class<?>> getPluginConfigs() { final List<Class<?>> configs = new ArrayList<>(); try { - for (final XnatPluginBean plugin : XnatPluginBean.findAllXnatPluginBeans()) { + for (final XnatPluginBean plugin : XnatPluginBean.getXnatPluginBeans().values()) { if (_log.isInfoEnabled()) { _log.info("Found plugin {} {}: {}", plugin.getId(), plugin.getName(), plugin.getDescription()); } diff --git a/src/main/java/org/nrg/xnat/restlet/resources/ScriptTriggerResource.java b/src/main/java/org/nrg/xnat/restlet/resources/ScriptTriggerResource.java index 93456ca78a68f4d34f24317c485d79173237b4db..e1886fec0f6457ad38ee48c223f8909761f826f0 100644 --- a/src/main/java/org/nrg/xnat/restlet/resources/ScriptTriggerResource.java +++ b/src/main/java/org/nrg/xnat/restlet/resources/ScriptTriggerResource.java @@ -1,5 +1,6 @@ package org.nrg.xnat.restlet.resources; +import com.google.common.collect.Sets; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import org.apache.commons.lang3.StringUtils; @@ -13,7 +14,6 @@ import org.nrg.xdat.XDAT; import org.nrg.xdat.security.helpers.Roles; import org.nrg.xft.XFTTable; import org.nrg.xft.security.UserI; -import org.python.google.common.collect.Sets; import org.restlet.Context; import org.restlet.data.*; import org.restlet.resource.Representation; @@ -354,7 +354,7 @@ public class ScriptTriggerResource extends AutomationResource { _log.info("Created a new trigger: " + trigger.toString()); } recordAutomationEvent(triggerId, getAssociation(), "Create", ScriptTrigger.class); - // Return thie trigger ID in the response test. The upload UI needs it + // Return the trigger ID in the response test. The upload UI needs it this.getResponse().setEntity(new StringRepresentation(triggerId)); } else { final String scriptId = jsonResults.getScriptId(); diff --git a/src/main/java/org/nrg/xnat/services/XnatAppInfo.java b/src/main/java/org/nrg/xnat/services/XnatAppInfo.java index e411df970bb279b5c77726c3ca8b2b20f5107be2..4559c9f87638c13e98326a5617c9a59457ca8a5c 100644 --- a/src/main/java/org/nrg/xnat/services/XnatAppInfo.java +++ b/src/main/java/org/nrg/xnat/services/XnatAppInfo.java @@ -5,7 +5,6 @@ import com.fasterxml.jackson.databind.node.ArrayNode; import org.nrg.framework.services.SerializerService; import org.nrg.prefs.exceptions.InvalidPreferenceName; import org.nrg.xdat.preferences.SiteConfigPreferences; -import org.python.google.common.collect.ImmutableMap; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.core.io.DefaultResourceLoader; @@ -141,11 +140,6 @@ public class XnatAppInfo { } return new HashMap<>(_foundPreferences); - -// for (final Resource resource : BasicXnatResourceLocator.getResources("classpath*:META-INF/xnat/**/*-plugin.properties")) { -// final Properties properties = PropertiesLoaderUtils.loadProperties(resource); -// _plugins.put(properties.getProperty("name"), properties); -// } } /** @@ -324,15 +318,6 @@ public class XnatAppInfo { return buffer.toString(); } - /** - * Returns the properties for all of the installed and active plugins in the deployed XNAT server. - * - * @return A map of all of the plugins installed on the server. - */ - public Map<String, Properties> getPluginProperties() throws IOException { - return ImmutableMap.copyOf(_plugins); - } - /** * Gets the path where XNAT found its primary configuration file. * @@ -463,5 +448,4 @@ public class XnatAppInfo { private final Properties _properties = new Properties(); private final Map<String, Map<String, String>> _attributes = new HashMap<>(); private boolean _initialized = false; - private final Map<String, Properties> _plugins = new HashMap<>(); }