Project

General

Profile

« Previous | Next » 

Revision 38493

[maven-release-plugin] copy for tag dnet-modular-ui-3.0.6

View differences:

modules/dnet-modular-ui/tags/dnet-modular-ui-3.0.6/deploy.info
1
{"type_source": "SVN", "goal": "package -U -T 4C source:jar", "url": "http://svn-public.driver.research-infrastructures.eu/driver/dnet40/modules/dnet-modular-ui/trunk/", "deploy_repository": "dnet4-snapshots", "version": "4", "mail": "sandro.labruzzo@isti.cnr.it,michele.artini@isti.cnr.it, claudio.atzori@isti.cnr.it, alessia.bardi@isti.cnr.it", "deploy_repository_url": "http://maven.research-infrastructures.eu/nexus/content/repositories/dnet4-snapshots", "name": "dnet-modular-ui"}
modules/dnet-modular-ui/tags/dnet-modular-ui-3.0.6/src/test/java/eu/dnetlib/functionality/modular/ui/users/SimpleSSOAuthorizationManagerTest.java
1
package eu.dnetlib.functionality.modular.ui.users;
2

  
3
import static org.junit.Assert.*;
4

  
5
import org.junit.Before;
6
import org.junit.Test;
7
import org.springframework.core.io.ClassPathResource;
8

  
9
public class SimpleSSOAuthorizationManagerTest {
10
	
11
	private final static String PAYLOAD = "{\"uid\":\"michele.artini\",\"fullname\":\"Michele Artini\",\"email\":\"michele.artini@isti.cnr.it\"}";
12
	private final static String SIGNATURE = "89f7a05d39d7a1e6489506c0a27f6087cf4ca0c7f0298c29d61464f5522be146363e8ad63312cc3d7fdcf5b5f1ff7b26e64ed1009b52b6562deebbd267dc6f49e25714f54a8cd2936db6b15e27e9dfc7ab762728d33449e8734101265bbb8b70e5efe2845d5ae2da6e43f25ab75e531fa6cc15e31497bb344b1cca6d687ecf2501c407316423c3eecbe98df43a0721b63f3a1a07fc1e7d75855cc6dc9dce18817b008d60fb4b225d462755d5671fdd01d3c7b08d5d039524e45a78a808377a3cc44b13c0c8e314aa1893e88cd32120e8beeacf5df8412c8228c1e8aa046a159ea1d6a36de160456f32001e23978b1b2d15490a07943d95a56d9dfd0f7bc6b4c6";
13

  
14
	private SimpleSSOAuthorizationManager manager = new SimpleSSOAuthorizationManager();
15
	
16
	
17
	@Before
18
	public void setup() throws Exception {
19
		manager.setPubKeyAlgo("RSA");
20
		manager.setPubKeyFile(new ClassPathResource("/eu/dnetlib/functionality/modular/ui/users/pubkey.der"));
21
		manager.setSignatureAlgo("SHA1withRSA");
22
		manager.init();
23
	}
24
	@Test
25
	public void testIsValidMessage() {
26
		assertTrue(manager.isValidMessage(PAYLOAD, SIGNATURE));
27
		assertFalse(manager.isValidMessage(PAYLOAD.toLowerCase(), SIGNATURE));
28
		assertFalse(manager.isValidMessage(PAYLOAD + "123", SIGNATURE));
29
		assertFalse(manager.isValidMessage(PAYLOAD, SIGNATURE + "123"));
30
		assertFalse(manager.isValidMessage(PAYLOAD + PAYLOAD, SIGNATURE));
31
		assertFalse(manager.isValidMessage("aaa", "aaa"));
32
		assertFalse(manager.isValidMessage(null, SIGNATURE));
33
		assertFalse(manager.isValidMessage(PAYLOAD, null));
34
		assertFalse(manager.isValidMessage("", SIGNATURE));
35
		assertFalse(manager.isValidMessage(PAYLOAD, ""));
36
		assertFalse(manager.isValidMessage(null, ""));
37
		assertFalse(manager.isValidMessage("", null));
38
		assertFalse(manager.isValidMessage("", ""));
39
		assertFalse(manager.isValidMessage(null, null));
40
	}
41

  
42
}
modules/dnet-modular-ui/tags/dnet-modular-ui-3.0.6/src/main/java/eu/dnetlib/functionality/modular/ui/InfoController.java
1
package eu.dnetlib.functionality.modular.ui;
2

  
3
import java.io.IOException;
4
import java.lang.management.ManagementFactory;
5
import java.lang.management.RuntimeMXBean;
6
import java.util.ArrayList;
7
import java.util.Collections;
8
import java.util.Comparator;
9
import java.util.HashMap;
10
import java.util.List;
11
import java.util.Map;
12
import java.util.Map.Entry;
13

  
14
import javax.servlet.http.HttpServletRequest;
15
import javax.servlet.http.HttpServletResponse;
16

  
17
import org.apache.commons.logging.Log;
18
import org.apache.commons.logging.LogFactory;
19
import org.apache.maven.model.Model;
20
import org.apache.maven.model.Parent;
21
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
22
import org.springframework.beans.factory.annotation.Required;
23
import org.springframework.context.ResourceLoaderAware;
24
import org.springframework.core.io.Resource;
25
import org.springframework.core.io.ResourceLoader;
26
import org.springframework.core.io.support.ResourcePatternUtils;
27
import org.springframework.ui.ModelMap;
28

  
29
import com.google.common.collect.Lists;
30
import com.google.common.collect.Maps;
31

  
32
import eu.dnetlib.miscutils.datetime.DateUtils;
33
import eu.dnetlib.miscutils.datetime.HumanTime;
34

  
35
public class InfoController extends ModuleEntryPoint implements ResourceLoaderAware {
36

  
37
	private String hostname;
38
	private String port;
39
	private String context;
40

  
41
	private ResourceLoader resourceLoader;
42

  
43
	private static final Log log = LogFactory.getLog(InfoController.class);
44

  
45
	@Override
46
	protected void initialize(final ModelMap map, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
47
		final RuntimeMXBean mxbean = ManagementFactory.getRuntimeMXBean();
48

  
49
		final Map<String, Map<String, String>> info = Maps.newLinkedHashMap();
50
		info.put("General", getGeneralInfo(mxbean));
51
		info.put("JVM", getJvmInfo(mxbean));
52
		info.put("Libraries and arguments", getLibInfo(mxbean));
53
		info.put("System properties", getSysInfo(mxbean));
54

  
55
		map.addAttribute("info", info);
56
		map.addAttribute("modules", getModules());
57

  
58
	}
59

  
60
	@SuppressWarnings("unchecked")
61
	private List<Map<String, Object>> getModules() throws IOException {
62
		final Map<String, Map<String, Map<String, Object>>> modules = Maps.newLinkedHashMap();
63

  
64
		final MavenXpp3Reader reader = new MavenXpp3Reader();
65
		for (Resource res : ResourcePatternUtils.getResourcePatternResolver(resourceLoader).getResources("classpath*:/META-INF/**/pom.xml")) {
66
			try {
67
				final Model model = reader.read(res.getInputStream());
68

  
69
				final String name = model.getArtifactId();
70

  
71
				String groupId = model.getGroupId();
72
				for (Parent parent = model.getParent(); groupId == null && model.getParent() != null; parent = model.getParent()) {
73
					groupId = parent.getGroupId();
74
				}
75

  
76
				String version = model.getVersion();
77
				for (Parent parent = model.getParent(); version == null && model.getParent() != null; parent = model.getParent()) {
78
					version = parent.getVersion();
79
				}
80

  
81
				if (!modules.containsKey(groupId)) {
82
					modules.put(groupId, new HashMap<String, Map<String, Object>>());
83
				}
84
				if (!modules.get(groupId).containsKey(name)) {
85
					final Map<String, Object> map = Maps.newHashMap();
86
					map.put("group", groupId);
87
					map.put("name", name);
88
					map.put("files", new ArrayList<String>());
89
					map.put("versions", new ArrayList<String>());
90
					modules.get(groupId).put(name, map);
91
				} else {
92
					// Artifact already found
93
					modules.get(groupId).get(name).put("warning", "1");
94
				}
95
				((List<String>) modules.get(groupId).get(name).get("versions")).add(version);
96
				((List<String>) modules.get(groupId).get(name).get("files")).add(res.getURI().toString());
97
			} catch (Exception e) {
98
				log.error("Error evaluating pom: " + res.getURI());
99
				log.debug("-- ERROR --", e);
100
			}
101
		}
102

  
103
		final List<Map<String, Object>> list = Lists.newArrayList();
104
		for (Entry<String, Map<String, Map<String, Object>>> e : modules.entrySet()) {
105
			for (Entry<String, Map<String, Object>> e1 : e.getValue().entrySet()) {
106
				list.add(e1.getValue());
107
			}
108
		}
109

  
110
		Collections.sort(list, new Comparator<Map<String, Object>>() {
111

  
112
			@Override
113
			public int compare(final Map<String, Object> o1, final Map<String, Object> o2) {
114
				if (o1.get("group").equals(o2.get("group"))) {
115
					return o1.get("name").toString().compareTo(o2.get("name").toString());
116
				} else {
117
					return o1.get("group").toString().compareTo(o2.get("group").toString());
118
				}
119
			}
120
		});
121

  
122
		return list;
123
	}
124

  
125
	private Map<String, String> getSysInfo(final RuntimeMXBean mxbean) {
126
		return mxbean.getSystemProperties();
127
	}
128

  
129
	private Map<String, String> getGeneralInfo(final RuntimeMXBean mxbean) {
130
		final Map<String, String> genInfo = Maps.newLinkedHashMap();
131
		genInfo.put("Hostname", hostname);
132
		genInfo.put("Port", port);
133
		genInfo.put("Context", context);
134
		genInfo.put("Uptime", HumanTime.exactly(mxbean.getUptime()));
135
		genInfo.put("Start Time", DateUtils.calculate_ISO8601(mxbean.getStartTime()));
136
		return genInfo;
137
	}
138

  
139
	private Map<String, String> getJvmInfo(final RuntimeMXBean mxbean) {
140
		final Map<String, String> jvmInfo = Maps.newLinkedHashMap();
141
		jvmInfo.put("JVM Name", mxbean.getVmName());
142
		jvmInfo.put("JVM Vendor", mxbean.getVmVendor());
143
		jvmInfo.put("JVM Version", mxbean.getVmVersion());
144
		jvmInfo.put("JVM Spec Name", mxbean.getSpecName());
145
		jvmInfo.put("JVM Spec Vendor", mxbean.getSpecVendor());
146
		jvmInfo.put("JVM Spec Version", mxbean.getSpecVersion());
147
		jvmInfo.put("Running JVM Name", mxbean.getName());
148
		jvmInfo.put("Management Spec Version", mxbean.getManagementSpecVersion());
149
		return jvmInfo;
150
	}
151

  
152
	private Map<String, String> getLibInfo(final RuntimeMXBean mxbean) {
153
		final Map<String, String> libInfo = Maps.newLinkedHashMap();
154
		libInfo.put("Classpath", mxbean.getClassPath().replaceAll(":", " : "));
155
		libInfo.put("Boot ClassPath", mxbean.getBootClassPath().replaceAll(":", " : "));
156
		libInfo.put("Input arguments", mxbean.getInputArguments().toString());
157
		libInfo.put("Library Path", mxbean.getLibraryPath().replaceAll(":", " : "));
158
		return libInfo;
159
	}
160

  
161
	public String getHostname() {
162
		return hostname;
163
	}
164

  
165
	@Required
166
	public void setHostname(final String hostname) {
167
		this.hostname = hostname;
168
	}
169

  
170
	public String getPort() {
171
		return port;
172
	}
173

  
174
	@Required
175
	public void setPort(final String port) {
176
		this.port = port;
177
	}
178

  
179
	public String getContext() {
180
		return context;
181
	}
182

  
183
	@Required
184
	public void setContext(final String context) {
185
		this.context = context;
186
	}
187

  
188
	@Override
189
	public void setResourceLoader(final ResourceLoader resourceLoader) {
190
		this.resourceLoader = resourceLoader;
191
	}
192
}
modules/dnet-modular-ui/tags/dnet-modular-ui-3.0.6/src/main/java/eu/dnetlib/functionality/modular/ui/EntryPointsAggregator.java
1
package eu.dnetlib.functionality.modular.ui;
2

  
3
import java.util.Collections;
4
import java.util.HashMap;
5
import java.util.List;
6
import java.util.Map;
7

  
8
import org.springframework.beans.factory.annotation.Autowired;
9

  
10
import com.google.common.collect.Lists;
11
import com.google.common.collect.Sets;
12

  
13
import eu.dnetlib.functionality.modular.ui.users.AccessLimited;
14
import eu.dnetlib.functionality.modular.ui.users.PermissionLevel;
15
import eu.dnetlib.functionality.modular.ui.users.User;
16

  
17
public class EntryPointsAggregator {
18
	
19
	@Autowired(required=false)
20
	private List<ModuleEntryPoint> entryPoints = Lists.newArrayList();;
21
	
22
	@Autowired(required=false)
23
	private List<AbstractMenu> otherMenus = Lists.newArrayList();
24

  
25
	public List<ModuleEntryPoint> getEntryPoints() {
26
		return entryPoints;
27
	}
28

  
29
	public void setEntryPoints(List<ModuleEntryPoint> entryPoints) {
30
		this.entryPoints = entryPoints;
31
	}
32
		
33
	public List<AbstractMenu> getMenus(User user) {
34
		final Map<String, ModulesMenu> map = new HashMap<String, ModulesMenu>();
35
		
36
		for (ModuleEntryPoint entry : entryPoints) {
37
			if (entry.isValidMenuEntry() && verifyAuthorization(entry, user)) {
38
				final String group = entry.getGroup();
39
				if (!map.containsKey(group)) {
40
					map.put(group, new ModulesMenu(group));
41
				}
42
				map.get(group).addEntry(entry);
43
			}
44
		}
45
		final List<AbstractMenu> items = Lists.newArrayList();
46
		
47
		for (AbstractMenu menu : otherMenus) {
48
			if (menu instanceof AccessLimited) {
49
				 if (verifyAuthorization((AccessLimited) menu, user) && menu.getEntries().size() > 0) {
50
					 items.add(menu);
51
				 }
52
			} else if (menu.getEntries().size() > 0) {
53
				items.add(menu);
54
			}
55
		}
56

  
57
		for (ModulesMenu item : map.values()) {
58
			item.complete();
59
			items.add(item);
60
		}
61
	
62
		Collections.sort(items);
63
		return items;
64
	}
65
	
66
	private boolean verifyAuthorization(AccessLimited entry, User user) {
67
		if (user.getPermissionLevels().contains(PermissionLevel.SUPER_ADMIN)) return true;
68
		
69
		return (Sets.intersection(user.getPermissionLevels(), entry.getPermissionLevels()).size() > 0);
70
	}
71
	
72
}
modules/dnet-modular-ui/tags/dnet-modular-ui-3.0.6/src/main/java/eu/dnetlib/functionality/modular/ui/UsersInternalController.java
1
package eu.dnetlib.functionality.modular.ui;
2

  
3
import java.io.IOException;
4
import java.util.Collections;
5
import java.util.List;
6
import java.util.Map;
7
import java.util.Set;
8

  
9
import javax.annotation.Resource;
10
import javax.servlet.http.HttpServletResponse;
11

  
12
import org.apache.commons.logging.Log;
13
import org.apache.commons.logging.LogFactory;
14
import org.springframework.stereotype.Controller;
15
import org.springframework.web.bind.annotation.RequestBody;
16
import org.springframework.web.bind.annotation.RequestMapping;
17
import org.springframework.web.bind.annotation.RequestMethod;
18
import org.springframework.web.bind.annotation.ResponseBody;
19

  
20
import com.google.common.collect.Lists;
21
import com.google.common.collect.Maps;
22

  
23
import eu.dnetlib.functionality.modular.ui.users.AuthorizationDAO;
24
import eu.dnetlib.functionality.modular.ui.users.PermissionLevel;
25
import eu.dnetlib.functionality.modular.ui.users.User;
26

  
27
@Controller
28
public class UsersInternalController {
29
	
30
	@Resource(name="modularUiAuthorizationDao")
31
	private AuthorizationDAO dao;
32
	
33
	private static final Log log = LogFactory.getLog(UsersInternalController.class);
34
	
35
	@RequestMapping(value = "/ui/users.get")
36
	public @ResponseBody List<User> listUsers(HttpServletResponse response) throws IOException {
37
		final List<User> list = Lists.newArrayList();
38
		for (Map.Entry<String, Set<PermissionLevel>> e : dao.getPermissionLevels().entrySet()) {
39
			final User user = new User(e.getKey());
40
			user.setPermissionLevels(e.getValue());
41
			list.add(user);
42
		}
43
		Collections.sort(list);
44
		
45
		return list;
46
	}
47

  
48
	@RequestMapping(value = "/ui/saveusers.do", method=RequestMethod.POST)
49
	public @ResponseBody boolean updateUsers(@RequestBody final List<User> users) {
50
		
51
		log.info("Saving " + users.size() + " user(s)");
52
		final Map<String, Set<PermissionLevel>> map = Maps.newHashMap();
53
		for (User u : users) {
54
			map.put(u.getId(), u.getPermissionLevels());
55
		}
56
		dao.updatePermissionLevels(map);
57
		return true;
58
	}
59

  
60
}
modules/dnet-modular-ui/tags/dnet-modular-ui-3.0.6/src/main/java/eu/dnetlib/functionality/modular/ui/ContainerPropertiesController.java
1
package eu.dnetlib.functionality.modular.ui;
2

  
3
import java.io.IOException;
4
import java.util.Map;
5
import java.util.Map.Entry;
6
import java.util.Properties;
7
import java.util.TreeMap;
8

  
9
import javax.servlet.http.HttpServletRequest;
10
import javax.servlet.http.HttpServletResponse;
11

  
12
import org.springframework.beans.factory.annotation.Autowired;
13
import org.springframework.context.ResourceLoaderAware;
14
import org.springframework.core.io.Resource;
15
import org.springframework.core.io.ResourceLoader;
16
import org.springframework.core.io.support.ResourcePatternUtils;
17
import org.springframework.ui.ModelMap;
18

  
19
import com.google.common.collect.Maps;
20

  
21
import eu.dnetlib.conf.PropertyFetcher;
22
import eu.dnetlib.miscutils.collections.Pair;
23

  
24
/**
25
 * Modular UI that displays collected properties and shows winning ones.
26
 *
27
 * @author andrea
28
 *
29
 */
30
public class ContainerPropertiesController extends ModuleEntryPoint implements ResourceLoaderAware {
31

  
32
	@Autowired
33
	private PropertyFetcher propertyFetcher;
34

  
35
	private Properties propertyFetcherProps;
36

  
37
	private ResourceLoader resourceLoader;
38

  
39
	@Override
40
	protected void initialize(final ModelMap map, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
41
		propertyFetcherProps = propertyFetcher.getProps();
42
		map.addAttribute("properties", fetchProperties());
43
	}
44

  
45
	private Map<String, Map<String, Pair<String, Boolean>>> fetchProperties() throws IOException {
46
		// Map structure: { propertyKey | [PropertyValue | <Propertyfile | isChecked>] }
47
		final Map<String, Map<String, Pair<String, Boolean>>> propertiesMap = Maps.newTreeMap();
48

  
49
		// loop over all *.properties files
50
		for (Resource propFile : ResourcePatternUtils.getResourcePatternResolver(resourceLoader).getResources("classpath*:/eu/dnetlib/**/*.properties")) {
51
			Properties properties = new Properties();
52
			properties.load(propFile.getInputStream());
53

  
54
			// loop over all properties set within a file
55
			for (Entry<Object, Object> e : properties.entrySet()) {
56
				Map<String, Pair<String, Boolean>> propValues;
57
				if (propertiesMap.containsKey(e.getKey())) {
58
					propValues = propertiesMap.get(e.getKey());
59
				} else {
60
					propValues = new TreeMap<String, Pair<String, Boolean>>();
61
				}
62

  
63
				Pair<String, Boolean> pair = new Pair<String, Boolean>(propFile.getFilename(), isWinning((String) e.getKey(), (String) e.getValue()));
64
				propValues.put((String) e.getValue(), pair);
65
				propertiesMap.put((String) e.getKey(), propValues);
66
			}
67
		}
68

  
69
		return propertiesMap;
70
	}
71

  
72
	/**
73
	 * Checks whether a given property-value is the one currently in use.
74
	 *
75
	 * @param prop
76
	 *            The property key
77
	 * @param value
78
	 *            The property value
79
	 * @return true/false
80
	 */
81
	private Boolean isWinning(final String prop, final String value) {
82
		String winningPropertyValue = propertyFetcherProps.getProperty(prop);
83
		if (value.equals(winningPropertyValue)) {
84
			return true;
85
		} else {
86
			return false;
87
		}
88
	}
89

  
90
	public ResourceLoader getResourceLoader() {
91
		return resourceLoader;
92
	}
93

  
94
	@Override
95
	public void setResourceLoader(final ResourceLoader resourceLoader) {
96
		this.resourceLoader = resourceLoader;
97
	}
98
}
modules/dnet-modular-ui/tags/dnet-modular-ui-3.0.6/src/main/java/eu/dnetlib/functionality/modular/ui/UsersController.java
1
package eu.dnetlib.functionality.modular.ui;
2

  
3
import java.util.List;
4
import java.util.Map;
5

  
6
import javax.servlet.http.HttpServletRequest;
7
import javax.servlet.http.HttpServletResponse;
8

  
9
import org.springframework.ui.ModelMap;
10

  
11
import com.google.common.collect.Lists;
12
import com.google.common.collect.Maps;
13

  
14
import eu.dnetlib.functionality.modular.ui.users.PermissionLevel;
15

  
16
public class UsersController extends ModuleEntryPoint {
17

  
18
	private List<Map<String, String>> listAvailableLevels = Lists.newArrayList();; 
19
		
20
	@Override
21
	protected void initialize(ModelMap map, HttpServletRequest request,	HttpServletResponse response) throws Exception {
22
		map.addAttribute("availableLevels", listPermissionLevels());
23
	}
24
	
25
	private List<Map<String, String>> listPermissionLevels() {
26
		if (listAvailableLevels.isEmpty()) {
27
			for (PermissionLevel level : PermissionLevel.values()) {
28
				final Map<String, String> map = Maps.newHashMap();
29
				map.put("level", level.toString());
30
				map.put("label", level.getLabel());
31
				map.put("details", level.getDetails());
32
				listAvailableLevels.add(map);
33
			}
34
		}
35
		return listAvailableLevels;
36
	}
37
	
38
}
modules/dnet-modular-ui/tags/dnet-modular-ui-3.0.6/src/main/java/eu/dnetlib/functionality/modular/ui/error/ErrorMessage.java
1
package eu.dnetlib.functionality.modular.ui.error;
2

  
3
import org.apache.commons.lang.exception.ExceptionUtils;
4

  
5
public class ErrorMessage {
6
	private String message;
7
	private String stacktrace;
8
	
9
	public ErrorMessage() {}
10
	
11
	public static ErrorMessage newInstance(final Exception e) {
12
		return new ErrorMessage(e.getMessage(), ExceptionUtils.getStackTrace(e));
13
	}
14
 	
15
	public ErrorMessage(final String message, final String stacktrace) {
16
    	this.message = message;
17
    	this.stacktrace = stacktrace;
18
    }
19

  
20
	public String getMessage() {
21
		return message;
22
	}
23

  
24
	public void setMessage(final String message) {
25
		this.message = message;
26
	}
27

  
28
	public String getStacktrace() {
29
		return stacktrace;
30
	}
31

  
32
	public void setStacktrace(final String stacktrace) {
33
		this.stacktrace = stacktrace;
34
	}
35
}
modules/dnet-modular-ui/tags/dnet-modular-ui-3.0.6/src/main/java/eu/dnetlib/functionality/modular/ui/AbstractAjaxController.java
1
package eu.dnetlib.functionality.modular.ui;
2

  
3
import org.springframework.http.HttpStatus;
4
import org.springframework.web.bind.annotation.ExceptionHandler;
5
import org.springframework.web.bind.annotation.ResponseBody;
6
import org.springframework.web.bind.annotation.ResponseStatus;
7

  
8
import eu.dnetlib.functionality.modular.ui.error.ErrorMessage;
9

  
10
public abstract class AbstractAjaxController {
11
	
12
	@ExceptionHandler(Exception.class)
13
	@ResponseStatus(value=HttpStatus.INTERNAL_SERVER_ERROR)
14
	public @ResponseBody ErrorMessage handleException(final Exception e) {
15
		return ErrorMessage.newInstance(e);
16
	}
17

  
18
}
modules/dnet-modular-ui/tags/dnet-modular-ui-3.0.6/src/main/java/eu/dnetlib/functionality/modular/ui/utils/ShutdownUtils.java
1
package eu.dnetlib.functionality.modular.ui.utils;
2

  
3
import java.util.List;
4

  
5
import org.apache.commons.logging.Log;
6
import org.apache.commons.logging.LogFactory;
7
import org.springframework.beans.factory.annotation.Autowired;
8

  
9
import com.google.common.collect.Lists;
10

  
11
import eu.dnetlib.enabling.common.Stoppable;
12
import eu.dnetlib.enabling.common.StoppableDetails;
13
import eu.dnetlib.enabling.common.StoppableDetails.StopStatus;
14

  
15
public class ShutdownUtils {
16

  
17
	@Autowired(required=false)
18
	private List<Stoppable> stoppables = Lists.newArrayList();
19
		
20
	private StopStatus status = StopStatus.RUNNING;
21
	
22
	private static final Log log = LogFactory.getLog(ShutdownUtils.class);
23
	
24
	public  List<StoppableDetails> listStoppableDetails() {
25
		final List<StoppableDetails> list = Lists.newArrayList();
26
		
27
		for (Stoppable s : stoppables) {
28
			list.add(s.getStopDetails());
29
		}
30
		
31
		return list;
32
	}
33
	
34
	public void stopAll() {
35
		this.status = StopStatus.STOPPING;
36
		
37
		for (Stoppable s : stoppables) {
38
			final StoppableDetails info = s.getStopDetails();
39
			if (info.getStatus() == StopStatus.RUNNING) {
40
				log.info("Stopping " + info.getName());
41
				s.stop();
42
			}
43
		}
44
	}
45
	
46
	public StopStatus currentStatus() {
47
		if (status == StopStatus.STOPPING) {
48
			int running = 0;
49
			for (Stoppable s : stoppables) {
50
				final StoppableDetails info = s.getStopDetails();
51
				if (info.getStatus() != StopStatus.STOPPED) {
52
					running++;
53
				}
54
			}
55
			if (running == 0) {
56
				status = StopStatus.STOPPED;
57
			}
58
		}
59
		return status;
60
	}
61
}
modules/dnet-modular-ui/tags/dnet-modular-ui-3.0.6/src/main/java/eu/dnetlib/functionality/modular/ui/ModuleEntryPoint.java
1
package eu.dnetlib.functionality.modular.ui;
2

  
3
import java.net.URLEncoder;
4

  
5
import javax.annotation.Resource;
6
import javax.servlet.http.HttpServletRequest;
7
import javax.servlet.http.HttpServletResponse;
8

  
9
import org.apache.commons.lang.StringUtils;
10
import org.springframework.beans.factory.BeanNameAware;
11
import org.springframework.beans.factory.annotation.Required;
12
import org.springframework.beans.factory.annotation.Value;
13
import org.springframework.ui.ModelMap;
14
import org.springframework.web.servlet.ModelAndView;
15
import org.springframework.web.servlet.mvc.Controller;
16
import org.springframework.web.servlet.view.RedirectView;
17

  
18
import eu.dnetlib.functionality.modular.ui.users.AuthorizationManager;
19
import eu.dnetlib.functionality.modular.ui.users.User;
20
import eu.dnetlib.functionality.modular.ui.utils.ShutdownUtils;
21

  
22
public abstract class ModuleEntryPoint extends MenuEntry implements Controller, BeanNameAware {
23

  
24
	private String beanName;
25

  
26
	private boolean validMenuEntry = true;
27

  
28
	private String group;
29
	private int groupOrder = 50;
30

  
31
	@Value("${dnet.modular.ui.authentication.url}")
32
	private String authenticationUrl;
33

  
34
	@Value("${dnet.modular.ui.logout.url}")
35
	private String logoutUrl;
36

  
37
	@Value("${dnet.modular.ui.ribbon.environment}")
38
	private String environment;
39

  
40
	@Value("${dnet.modular.ui.ribbon.accent}")
41
	private String ribbonAccent;
42

  
43
	@Resource
44
	protected EntryPointsAggregator aggregator;
45

  
46
	@Resource
47
	private ShutdownUtils shutdownUtils;
48

  
49
	@Resource(name = "modularUiAuthorizationManager")
50
	protected AuthorizationManager authorizationManager;
51

  
52
	@Override
53
	public ModelAndView handleRequest(final HttpServletRequest request, final HttpServletResponse response) throws Exception {
54

  
55
		final User user = authorizationManager.obtainUserDetails(request);
56
		if (user != null) {
57
			final ModelAndView mv = new ModelAndView();
58
			final ModelMap map = mv.getModelMap();
59
			map.addAttribute("ui_menu", getMenu());
60
			map.addAttribute("ui_title", getTitle());
61
			map.addAttribute("ui_description", getDescription());
62
			map.addAttribute("ui_group", getGroup());
63
			map.addAttribute("ui_modules", aggregator.getMenus(user));
64
			map.addAttribute("environment", environment);
65
			map.addAttribute("ribbonAccent", ribbonAccent);
66

  
67
			switch (shutdownUtils.currentStatus()) {
68
			case STOPPING:
69
				map.addAttribute("ui_navbar_class", "navbar-system-stopping");
70
				map.addAttribute("ui_message", "stopping system");
71
				break;
72
			case STOPPED:
73
				map.addAttribute("ui_navbar_class", "navbar-system-stopped");
74
				map.addAttribute("ui_message", "system stopped");
75
				break;
76
			default:
77
				map.addAttribute("ui_navbar_class", "navbar-inverse");
78
				break;
79
			}
80

  
81
			String baseUrl = "";
82
			for (int i = 1; i < StringUtils.countMatches(beanName, "/"); i++) {
83
				baseUrl += "/..";
84
			}
85
			if (baseUrl.length() > 0) {
86
				baseUrl = baseUrl.substring(1);
87
			}
88

  
89
			map.addAttribute("ui_baseUrl", baseUrl);
90

  
91
			if ((logoutUrl != null) && !logoutUrl.isEmpty()) {
92
				map.addAttribute("ui_logoutUrl", logoutUrl);
93
			}
94

  
95
			map.addAttribute("ui_user", user);
96

  
97
			initialize(map, request, response);
98
			return mv;
99
		} else {
100
			final StringBuffer url = request.getRequestURL();
101
			final String queryString = request.getQueryString();
102
			if (queryString != null) {
103
				url.append('?');
104
				url.append(queryString);
105
			}
106
			return new ModelAndView(new RedirectView(authenticationUrl + "?url=" + URLEncoder.encode(url.toString(), "UTF-8")));
107
		}
108
	}
109

  
110
	abstract protected void initialize(ModelMap map, HttpServletRequest request, HttpServletResponse response) throws Exception;
111

  
112
	public String getBeanName() {
113
		return beanName;
114
	}
115

  
116
	@Override
117
	public void setBeanName(final String beanName) {
118
		this.beanName = beanName;
119
	}
120

  
121
	public String getGroup() {
122
		return group;
123
	}
124

  
125
	@Required
126
	public void setGroup(final String group) {
127
		this.group = group;
128
	}
129

  
130
	@Override
131
	public String getRelativeUrl() {
132
		return beanName;
133
	}
134

  
135
	public boolean isValidMenuEntry() {
136
		return validMenuEntry;
137
	}
138

  
139
	public void setValidMenuEntry(final boolean validMenuEntry) {
140
		this.validMenuEntry = validMenuEntry;
141
	}
142

  
143
	public int getGroupOrder() {
144
		return groupOrder;
145
	}
146

  
147
	public void setGroupOrder(final int groupOrder) {
148
		this.groupOrder = groupOrder;
149
	}
150

  
151
}
modules/dnet-modular-ui/tags/dnet-modular-ui-3.0.6/src/main/java/eu/dnetlib/functionality/modular/ui/users/PermissionLevel.java
1
package eu.dnetlib.functionality.modular.ui.users;
2

  
3
public enum PermissionLevel {
4
	SUPER_ADMIN("Super admin", "Authenticated user with ALL management rights"), 
5
	DS_ADMIN ("datasource administrator", "Authenticated user that can manage datasources"), 
6
	WF_ADMIN("workflow administrator", "Authenticated user that can manage workflows"),
7
	IS_ADMIN("information administrator", "Authenticated user that can update IS profiles"),
8
	USER("simple user", "Authenticated user with no management rights"), 
9
	GUEST ("guest", "Anonymous user");
10

  
11
	private String label;
12
	private String details;
13
	
14
	private PermissionLevel(final String label, final String details) {
15
		this.label = label;
16
		this.details = details;
17
	}
18

  
19
	public String getLabel() {
20
		return label;
21
	}
22

  
23
	public String getDetails() {
24
		return details;
25
	}
26

  
27

  
28
}
modules/dnet-modular-ui/tags/dnet-modular-ui-3.0.6/src/main/java/eu/dnetlib/functionality/modular/ui/users/AuthorizationDAO.java
1
package eu.dnetlib.functionality.modular.ui.users;
2

  
3
import java.util.Map;
4
import java.util.Set;
5

  
6
public interface AuthorizationDAO {
7
	void updatePermissionLevels(Map<String, Set<PermissionLevel>> map);
8
	Map<String, Set<PermissionLevel>> getPermissionLevels();
9
	Set<PermissionLevel> getPermissionLevels(String uid);
10
}
modules/dnet-modular-ui/tags/dnet-modular-ui-3.0.6/src/main/java/eu/dnetlib/functionality/modular/ui/users/MongoAuthorizationDAO.java
1
package eu.dnetlib.functionality.modular.ui.users;
2

  
3
import java.util.HashSet;
4
import java.util.List;
5
import java.util.Map;
6
import java.util.Map.Entry;
7
import java.util.Set;
8

  
9
import org.apache.commons.logging.Log;
10
import org.apache.commons.logging.LogFactory;
11
import org.springframework.beans.factory.annotation.Required;
12

  
13
import com.google.common.base.Joiner;
14
import com.google.common.base.Splitter;
15
import com.google.common.collect.Lists;
16
import com.google.common.collect.Maps;
17
import com.mongodb.BasicDBObject;
18
import com.mongodb.BasicDBObjectBuilder;
19
import com.mongodb.DB;
20
import com.mongodb.DBCollection;
21
import com.mongodb.DBCursor;
22
import com.mongodb.DBObject;
23

  
24
public class MongoAuthorizationDAO implements AuthorizationDAO {
25
	
26
	private DB db;
27

  
28
	private static final String AUTH_COLL = "users";
29

  
30

  
31
	private static final Log log = LogFactory.getLog(MongoAuthorizationDAO.class);
32
	
33
	@Override
34
	public void updatePermissionLevels(Map<String, Set<PermissionLevel>> map) {
35
		final DBCollection coll = db.getCollection(AUTH_COLL);
36
		final List<DBObject> list = Lists.newArrayList();
37

  
38
		for (Entry<String, Set<PermissionLevel>> e : map.entrySet()) {
39
			final Map<String, String> m = Maps.newHashMap();
40
			m.put("uid" , e.getKey());
41
			m.put("levels", serializeLevels(e.getValue()));
42
			list.add(BasicDBObjectBuilder.start(m).get());
43
		}
44
		coll.remove(new BasicDBObject());
45
		coll.insert(list);
46
	}
47
	
48
	@Override
49
	public Map<String, Set<PermissionLevel>> getPermissionLevels() {
50
		final DBCollection coll = db.getCollection(AUTH_COLL);
51
		final DBCursor cur = coll.find();
52
		
53
		final Map<String, Set<PermissionLevel>> res = Maps.newHashMap();
54
		while (cur.hasNext()) {
55
			final DBObject o = cur.next();
56
			res.put((String) o.get("uid"), readLevels(o));
57
		}
58
		
59
		return res;
60
	}	
61
	
62
	@Override
63
	public Set<PermissionLevel> getPermissionLevels(String uid) {
64
		final DBCollection coll = db.getCollection(AUTH_COLL);
65
		
66
		final DBObject obj = coll.findOne(new BasicDBObject("uid", uid));
67
		
68
		return readLevels(obj);
69
	}
70

  
71
	private Set<PermissionLevel> readLevels(final DBObject obj) {
72
		final Set<PermissionLevel> set = new HashSet<PermissionLevel>();
73
		
74
		if (obj != null) {
75
			final Object levels = obj.get("levels");
76
			if (levels != null) {
77
				for (String s : Splitter.on(",").omitEmptyStrings().trimResults().split(levels.toString())) {
78
					try {
79
						set.add(PermissionLevel.valueOf(s));
80
					} catch (Throwable e) {
81
						log.error("Invalid permissionLevel: " + s);
82
					}
83
				}
84
			}
85
		}
86
		return set;
87
	}
88
	
89
	private String serializeLevels(Set<PermissionLevel> levels) {
90
		return Joiner.on(",").skipNulls().join(levels);
91
	}
92
	
93
	public DB getDb() {
94
		return db;
95
	}
96

  
97
	@Required
98
	public void setDb(DB db) {
99
		this.db = db;
100
	}
101

  
102
}
modules/dnet-modular-ui/tags/dnet-modular-ui-3.0.6/src/main/java/eu/dnetlib/functionality/modular/ui/users/MockAuthorizationManager.java
1
package eu.dnetlib.functionality.modular.ui.users;
2

  
3
import javax.servlet.http.HttpServletRequest;
4

  
5
import com.google.common.collect.Sets;
6

  
7
public class MockAuthorizationManager implements AuthorizationManager {
8

  
9
	@Override
10
	public User obtainUserDetails(HttpServletRequest request) {
11
		final User userMock = new User();
12
		
13
		userMock.setId("mock");
14
		userMock.setFullname("Mock User");
15
		userMock.setPermissionLevels(Sets.newHashSet(PermissionLevel.SUPER_ADMIN));
16
		userMock.setEmail("mock@user.foo");
17
		return userMock;
18
	}
19

  
20
}
modules/dnet-modular-ui/tags/dnet-modular-ui-3.0.6/src/main/java/eu/dnetlib/functionality/modular/ui/users/SimpleAuthorizationManager.java
1
package eu.dnetlib.functionality.modular.ui.users;
2

  
3
import java.security.Principal;
4

  
5
import javax.servlet.http.HttpServletRequest;
6

  
7
import org.springframework.beans.factory.annotation.Required;
8

  
9
import com.google.common.collect.Sets;
10

  
11
public class SimpleAuthorizationManager implements AuthorizationManager {
12
	
13
	
14
	private AuthorizationDAO authorizationDAO;
15
	
16
	private String defaultSuperAdmin;
17
	
18
	@Override
19
	public User obtainUserDetails(final HttpServletRequest request) {
20
		final Principal principal = request.getUserPrincipal();
21
		
22
		final User user = new User();
23
		
24
		if (principal != null) {
25
	        final String username = principal.getName();
26
	        if (username != null) {
27
	        	user.setId(username);
28
	        	user.setFullname(username);
29
	        	user.setPermissionLevels(authorizationDAO.getPermissionLevels(username));
30
	        	if (username.equals(getDefaultSuperAdmin())) {
31
	        		user.getPermissionLevels().add(PermissionLevel.SUPER_ADMIN);
32
	        	}
33
	        } else {
34
	        	user.setId("anonymous");
35
	        	user.setFullname("anonymous");
36
	        	user.setPermissionLevels(Sets.newHashSet(PermissionLevel.GUEST));
37
	        }
38
	    }
39
		
40
		return user;
41
	}
42

  
43
	public AuthorizationDAO getAuthorizationDAO() {
44
		return authorizationDAO;
45
	}
46

  
47
	@Required
48
	public void setAuthorizationDAO(AuthorizationDAO authorizationDAO) {
49
		this.authorizationDAO = authorizationDAO;
50
	}
51

  
52
	public String getDefaultSuperAdmin() {
53
		return defaultSuperAdmin;
54
	}
55

  
56
	@Required
57
	public void setDefaultSuperAdmin(String defaultSuperAdmin) {
58
		this.defaultSuperAdmin = defaultSuperAdmin;
59
	}
60

  
61
}
modules/dnet-modular-ui/tags/dnet-modular-ui-3.0.6/src/main/java/eu/dnetlib/functionality/modular/ui/users/AccessLimited.java
1
package eu.dnetlib.functionality.modular.ui.users;
2

  
3
import java.util.Set;
4

  
5
public interface AccessLimited {
6
	public Set<PermissionLevel> getPermissionLevels();
7
}
modules/dnet-modular-ui/tags/dnet-modular-ui-3.0.6/src/main/java/eu/dnetlib/functionality/modular/ui/users/SimpleSSOAuthorizationManager.java
1
package eu.dnetlib.functionality.modular.ui.users;
2

  
3
import java.net.URLDecoder;
4
import java.security.KeyFactory;
5
import java.security.PublicKey;
6
import java.security.Signature;
7
import java.security.spec.KeySpec;
8
import java.security.spec.X509EncodedKeySpec;
9
import java.util.Map;
10

  
11
import javax.servlet.http.Cookie;
12
import javax.servlet.http.HttpServletRequest;
13

  
14
import org.apache.commons.codec.binary.Base64;
15
import org.apache.commons.codec.binary.Hex;
16
import org.apache.commons.io.IOUtils;
17
import org.apache.commons.logging.Log;
18
import org.apache.commons.logging.LogFactory;
19
import org.springframework.beans.factory.annotation.Required;
20
import org.springframework.core.io.ClassPathResource;
21
import org.springframework.core.io.Resource;
22

  
23
import com.google.gson.Gson;
24

  
25
public class SimpleSSOAuthorizationManager implements AuthorizationManager {
26

  
27
	private static final Log log = LogFactory.getLog(SimpleSSOAuthorizationManager.class);
28
		
29
	private Resource pubKeyFile = new ClassPathResource("/eu/dnetlib/functionality/modular/ui/users/pubkey.der");
30
	private String pubKeyAlgo = "RSA";
31
	private String signatureAlgo = "SHA1withRSA";
32
	private PublicKey publicKey;
33
	private AuthorizationDAO authorizationDAO;
34
	private String defaultSuperAdmin;
35

  
36
	@Override
37
	public User obtainUserDetails(final HttpServletRequest request) {
38

  
39
		if (request.getCookies() != null) {
40
			for (Cookie cookie : request.getCookies()) {
41
				if (cookie.getName().equalsIgnoreCase("rinfra-user")) {
42
					try {
43
						return processCookie(cookie.getValue());
44
					} catch (Exception e) {
45
						log.error("Error processing cookie: " + cookie.getValue(), e);
46
						return null;
47
					}
48
				}
49
			}
50
		}
51
		return null;
52
	}
53

  
54
	private User processCookie(final String s) throws Exception {
55
		if (s == null || s.isEmpty()) {
56
			return null;
57
		}
58
		final Gson gson = new Gson();
59

  
60
		final Map<?,?> map = gson.fromJson(new String(Base64.decodeBase64(URLDecoder.decode(s.trim(), "UTF-8"))), Map.class);
61
		final String message = (String) map.get("payload");
62
		final String signature = (String) map.get("signature");
63
		if (isValidMessage(message, signature)) {
64
			final Map<?,?> userMap = gson.fromJson(message, Map.class);
65
			if (userMap.containsKey("uid")) {
66
				final String uid = (String) userMap.get("uid");
67
				final User user = new User(uid);
68
				user.setEmail((String) userMap.get("email"));
69
				user.setFullname(userMap.containsKey("fullname") ? (String) userMap.get("fullname") : uid);
70
				user.setPermissionLevels(authorizationDAO.getPermissionLevels(uid));
71
				
72
				if (isDefaultSuperAdmin(uid)) {
73
					user.getPermissionLevels().add(PermissionLevel.SUPER_ADMIN);
74
				}
75
				return user;
76
			}
77
		}
78
		return null;
79
	}
80

  
81
	private boolean isDefaultSuperAdmin(final String uid) {
82
		return (uid != null && !uid.isEmpty() && uid.equals(getDefaultSuperAdmin()));
83
	}
84

  
85
	protected boolean isValidMessage(final String message, final String signature) {
86
		log.info("checking message " + message + " with sig " + signature);
87
		if (message == null || message.isEmpty() || signature == null || signature.isEmpty()) {
88
			log.error("Null  or empty values in message or signature");
89
			return false;
90
		}
91
		
92
		try {
93
			final Signature sg = Signature.getInstance(getSignatureAlgo());
94
			sg.initVerify(getPublicKey());
95
			sg.update(message.getBytes());
96
			return sg.verify(Hex.decodeHex(signature.toCharArray()));
97
		} catch(Exception e) {
98
			log.error("Error verifyng signature", e);
99
			return false;
100
		}
101
	}
102

  
103
	public void init() throws Exception {
104
		final byte[] keyBytes = IOUtils.toByteArray(getPubKeyFile().getInputStream());
105
		final KeySpec spec = new X509EncodedKeySpec(keyBytes);
106
		
107
		setPublicKey(KeyFactory.getInstance(getPubKeyAlgo()).generatePublic(spec));
108
	}
109

  
110
	public Resource getPubKeyFile() {
111
		return pubKeyFile;
112
	}
113
	
114
	@Required
115
	public void setPubKeyFile(Resource pubKeyFile) {
116
		this.pubKeyFile = pubKeyFile;
117
	}
118

  
119
	public String getPubKeyAlgo() {
120
		return pubKeyAlgo;
121
	}
122

  
123
	@Required
124
	public void setPubKeyAlgo(String pubKeyAlgo) {
125
		this.pubKeyAlgo = pubKeyAlgo;
126
	}
127

  
128
	public String getSignatureAlgo() {
129
		return signatureAlgo;
130
	}
131

  
132
	@Required
133
	public void setSignatureAlgo(String signatureAlgo) {
134
		this.signatureAlgo = signatureAlgo;
135
	}
136

  
137
	public PublicKey getPublicKey() {
138
		return publicKey;
139
	}
140

  
141
	public void setPublicKey(PublicKey publicKey) {
142
		this.publicKey = publicKey;
143
	}
144

  
145
	public AuthorizationDAO getAuthorizationDAO() {
146
		return authorizationDAO;
147
	}
148

  
149
	@Required
150
	public void setAuthorizationDAO(AuthorizationDAO authorizationDAO) {
151
		this.authorizationDAO = authorizationDAO;
152
	}
153

  
154
	public String getDefaultSuperAdmin() {
155
		return defaultSuperAdmin;
156
	}
157
	
158
	@Required
159
	public void setDefaultSuperAdmin(String defaultSuperAdmin) {
160
		this.defaultSuperAdmin = defaultSuperAdmin;
161
	}
162

  
163
}
modules/dnet-modular-ui/tags/dnet-modular-ui-3.0.6/src/main/java/eu/dnetlib/functionality/modular/ui/users/AuthorizationManager.java
1
package eu.dnetlib.functionality.modular.ui.users;
2

  
3
import javax.servlet.http.HttpServletRequest;
4

  
5
public interface AuthorizationManager {
6
	User obtainUserDetails(HttpServletRequest request);
7
}
modules/dnet-modular-ui/tags/dnet-modular-ui-3.0.6/src/main/java/eu/dnetlib/functionality/modular/ui/users/User.java
1
package eu.dnetlib.functionality.modular.ui.users;
2

  
3
import java.util.Set;
4

  
5
public class User implements Comparable<User> {
6
	private String id;
7
	private String fullname;
8
	private String email;
9
	private Set<PermissionLevel> permissionLevels;
10
	
11
	public User() {}
12
	
13
	public User(final String id) {
14
		this.id = id;
15
	}
16
	
17
	public String getId() {
18
		return id;
19
	}
20
	public void setId(String id) {
21
		this.id = id;
22
	}
23
	public String getFullname() {
24
		return fullname;
25
	}
26
	public void setFullname(String fullname) {
27
		this.fullname = fullname;
28
	}
29
	public String getEmail() {
30
		return email;
31
	}
32
	public void setEmail(String email) {
33
		this.email = email;
34
	}
35
	public Set<PermissionLevel> getPermissionLevels() {
36
		return permissionLevels;
37
	}
38
	public void setPermissionLevels(Set<PermissionLevel> permissionLevels) {
39
		this.permissionLevels = permissionLevels;
40
	}
41
	
42
	@Override
43
	public int compareTo(final User o) {
44
		return getId().compareTo(o.getId());
45
	}
46
	
47
	
48
}
modules/dnet-modular-ui/tags/dnet-modular-ui-3.0.6/src/main/java/eu/dnetlib/functionality/modular/ui/MenuEntry.java
1
package eu.dnetlib.functionality.modular.ui;
2

  
3
import java.util.Set;
4

  
5
import org.apache.commons.lang.math.NumberUtils;
6
import org.springframework.beans.factory.annotation.Required;
7

  
8
import eu.dnetlib.functionality.modular.ui.users.AccessLimited;
9
import eu.dnetlib.functionality.modular.ui.users.PermissionLevel;
10

  
11
public abstract class MenuEntry implements Comparable<MenuEntry>, AccessLimited {
12

  
13
	private String menu;
14
	private String title;
15
	private String description;
16
	private int order = 50;
17
	private Set<PermissionLevel> permissionLevels;
18
		
19
	@Override
20
	public int compareTo(MenuEntry o) {
21
		return NumberUtils.compare(this.getOrder(), o.getOrder());
22
	}
23
	
24
	abstract public String getRelativeUrl();
25
	
26
	public String getMenu() {
27
		return menu;
28
	}
29
	
30
	@Required
31
	public void setMenu(String menu) {
32
		this.menu = menu;
33
	}
34

  
35
	public String getTitle() {
36
		return title;
37
	}
38
	@Required
39
	public void setTitle(String title) {
40
		this.title = title;
41
	}
42

  
43
	public String getDescription() {
44
		return description;
45
	}
46
	@Required
47
	public void setDescription(String description) {
48
		this.description = description;
49
	}
50

  
51
	@Override
52
	public Set<PermissionLevel> getPermissionLevels() {
53
		return permissionLevels;
54
	}
55

  
56
	@Required
57
	public void setPermissionLevels(Set<PermissionLevel> permissionLevels) {
58
		this.permissionLevels = permissionLevels;
59
	}
60
	
61
	public int getOrder() {
62
		return order;
63
	}
64

  
65
	public void setOrder(int order) {
66
		this.order = order;
67
	}
68
	
69
}
modules/dnet-modular-ui/tags/dnet-modular-ui-3.0.6/src/main/java/eu/dnetlib/functionality/modular/ui/UserDetailsController.java
1
package eu.dnetlib.functionality.modular.ui;
2

  
3
import javax.servlet.http.HttpServletRequest;
4
import javax.servlet.http.HttpServletResponse;
5

  
6
import org.springframework.ui.ModelMap;
7

  
8
public class UserDetailsController extends ModuleEntryPoint {
9

  
10
	@Override
11
	protected void initialize(ModelMap map, HttpServletRequest request,	HttpServletResponse response) throws Exception {}
12

  
13
}
modules/dnet-modular-ui/tags/dnet-modular-ui-3.0.6/src/main/java/eu/dnetlib/functionality/modular/ui/MainController.java
1
package eu.dnetlib.functionality.modular.ui;
2

  
3
import javax.servlet.http.HttpServletRequest;
4
import javax.servlet.http.HttpServletResponse;
5

  
6
import org.springframework.ui.ModelMap;
7

  
8
public class MainController extends ModuleEntryPoint {
9

  
10
	@Override
11
	protected void initialize(final ModelMap map, final HttpServletRequest request, final HttpServletResponse response) {}
12

  
13
}
modules/dnet-modular-ui/tags/dnet-modular-ui-3.0.6/src/main/java/eu/dnetlib/functionality/modular/ui/AbstractMenu.java
1
package eu.dnetlib.functionality.modular.ui;
2

  
3
import java.util.List;
4

  
5
import org.apache.commons.lang.math.NumberUtils;
6
import org.springframework.beans.factory.annotation.Required;
7

  
8
public abstract class AbstractMenu implements Comparable<AbstractMenu> {
9
	private String title;		
10

  
11
	abstract public int getOrder();
12

  
13
	abstract public List<? extends MenuEntry> getEntries();
14
	
15
	@Override
16
	public int compareTo(final AbstractMenu menu) {
17
		return NumberUtils.compare(getOrder(), menu.getOrder());
18
	}
19

  
20
	public String getTitle() {
21
		return title;
22
	}
23
	
24
	@Required
25
	public void setTitle(String title) {
26
		this.title = title;
27
	}
28
}
29

  
30

  
31

  
modules/dnet-modular-ui/tags/dnet-modular-ui-3.0.6/src/main/java/eu/dnetlib/functionality/modular/ui/PrepareShutdownInternalController.java
1
package eu.dnetlib.functionality.modular.ui;
2

  
3
import java.util.List;
4

  
5
import javax.annotation.Resource;
6

  
7
import org.springframework.stereotype.Controller;
8
import org.springframework.web.bind.annotation.RequestMapping;
9
import org.springframework.web.bind.annotation.ResponseBody;
10

  
11
import eu.dnetlib.enabling.common.StoppableDetails;
12
import eu.dnetlib.functionality.modular.ui.utils.ShutdownUtils;
13

  
14
@Controller
15
public class PrepareShutdownInternalController {
16

  
17
	@Resource
18
	private ShutdownUtils shutdownUtils;
19

  
20
	@RequestMapping("/ui/shutdown/listStoppableDetails.json")
21
	public @ResponseBody List<StoppableDetails> listStoppableDetails() {
22
		return shutdownUtils.listStoppableDetails();
23
	}
24
	
25
	@RequestMapping("/ui/shutdown/stopAll.do")
26
	public @ResponseBody boolean stopAll() {
27
		shutdownUtils.stopAll();
28
		return true;
29
	}
30
	
31
}
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff