Revision 47892
Added by Alessia Bardi almost 7 years ago
modules/dnet-modular-ui/tags/dnet-modular-ui-3.0.14/deploy.info | ||
---|---|---|
1 |
{"type_source": "SVN", "goal": "package -U -T 4C source:jar", "url": "http://svn-public.driver.research-infrastructures.eu/driver/dnet45/modules/dnet-modular-ui/trunk/", "deploy_repository": "dnet45-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/dnet45-snapshots", "name": "dnet-modular-ui"} |
modules/dnet-modular-ui/tags/dnet-modular-ui-3.0.14/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.14/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.14/src/main/java/eu/dnetlib/functionality/modular/ui/DnetLogController.java | ||
---|---|---|
1 |
package eu.dnetlib.functionality.modular.ui; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
import java.util.Enumeration; |
|
5 |
|
|
6 |
import javax.servlet.http.HttpServletRequest; |
|
7 |
import javax.servlet.http.HttpServletResponse; |
|
8 |
|
|
9 |
import org.apache.log4j.FileAppender; |
|
10 |
import org.apache.log4j.LogManager; |
|
11 |
import org.apache.log4j.Logger; |
|
12 |
import org.springframework.ui.ModelMap; |
|
13 |
|
|
14 |
public class DnetLogController extends ModuleEntryPoint { |
|
15 |
|
|
16 |
@Override |
|
17 |
protected void initialize(final ModelMap map, final HttpServletRequest request, final HttpServletResponse response) throws Exception { |
|
18 |
map.addAttribute("logFile", getLogFileName()); |
|
19 |
} |
|
20 |
|
|
21 |
public static String getLogFileName() { |
|
22 |
final Logger logger = LogManager.getRootLogger(); |
|
23 |
final Enumeration<?> appenders = logger.getAllAppenders(); |
|
24 |
while (appenders.hasMoreElements()) { |
|
25 |
final Object app = appenders.nextElement(); |
|
26 |
if (app instanceof FileAppender) { return new File(((FileAppender) app).getFile()).getAbsolutePath(); } |
|
27 |
} |
|
28 |
return ""; |
|
29 |
} |
|
30 |
} |
modules/dnet-modular-ui/tags/dnet-modular-ui-3.0.14/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.14/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.14/src/main/java/eu/dnetlib/functionality/modular/ui/ContainerPropertiesController.java | ||
---|---|---|
1 |
package eu.dnetlib.functionality.modular.ui; |
|
2 |
|
|
3 |
import com.google.common.collect.Maps; |
|
4 |
import eu.dnetlib.conf.PropertyFetcher; |
|
5 |
import eu.dnetlib.conf.WebappContextPropertyLocationFactory; |
|
6 |
import org.apache.commons.logging.Log; |
|
7 |
import org.apache.commons.logging.LogFactory; |
|
8 |
import org.codehaus.jparsec.util.Lists; |
|
9 |
import org.springframework.beans.factory.annotation.Autowired; |
|
10 |
import org.springframework.core.io.Resource; |
|
11 |
import org.springframework.core.io.support.PathMatchingResourcePatternResolver; |
|
12 |
import org.springframework.core.io.support.ResourcePatternResolver; |
|
13 |
import org.springframework.ui.ModelMap; |
|
14 |
|
|
15 |
import javax.servlet.http.HttpServletRequest; |
|
16 |
import javax.servlet.http.HttpServletResponse; |
|
17 |
import java.io.IOException; |
|
18 |
import java.util.List; |
|
19 |
import java.util.Map; |
|
20 |
import java.util.Map.Entry; |
|
21 |
import java.util.Properties; |
|
22 |
|
|
23 |
/** |
|
24 |
* Modular UI that displays collected properties and shows winning ones. |
|
25 |
* |
|
26 |
* @author Andrea Mannocci |
|
27 |
*/ |
|
28 |
public class ContainerPropertiesController extends ModuleEntryPoint { |
|
29 |
|
|
30 |
private static final Log log = LogFactory.getLog(ContainerPropertiesController.class); |
|
31 |
|
|
32 |
private final ResourcePatternResolver pathResolver = new PathMatchingResourcePatternResolver(); |
|
33 |
|
|
34 |
@Autowired |
|
35 |
private PropertyFetcher propertyFetcher; |
|
36 |
|
|
37 |
private Properties propertyFetcherProps; |
|
38 |
|
|
39 |
@Autowired |
|
40 |
private WebappContextPropertyLocationFactory propertyLocations; |
|
41 |
|
|
42 |
@Override |
|
43 |
protected void initialize(final ModelMap map, final HttpServletRequest request, final HttpServletResponse response) throws Exception { |
|
44 |
propertyFetcherProps = propertyFetcher.getProps(); |
|
45 |
map.addAttribute("properties", fetchProperties()); |
|
46 |
} |
|
47 |
|
|
48 |
private Map<String, List<PropertyInfo>> fetchProperties() throws IOException { |
|
49 |
final Map<String, List<PropertyInfo>> propertiesMap = Maps.newTreeMap(); |
|
50 |
|
|
51 |
// cycle over all property locations know to dnet |
|
52 |
for (String location : propertyLocations.getLocations()) { |
|
53 |
log.debug(String.format("Loading properties from %s", location)); |
|
54 |
// loop over all *.properties files matching the location |
|
55 |
for (Resource propertyFile : pathResolver.getResources(location)) { |
|
56 |
Properties properties = new Properties(); |
|
57 |
log.debug(String.format("URL: %s", propertyFile.getURL())); |
|
58 |
properties.load(propertyFile.getInputStream()); |
|
59 |
|
|
60 |
// loop over all properties set within a property file file |
|
61 |
for (Entry<Object, Object> property : properties.entrySet()) { |
|
62 |
List<PropertyInfo> propertyInfoList; |
|
63 |
if (propertiesMap.containsKey(property.getKey())) { |
|
64 |
propertyInfoList = propertiesMap.get(property.getKey()); |
|
65 |
} else { |
|
66 |
propertyInfoList = Lists.arrayList(); |
|
67 |
} |
|
68 |
|
|
69 |
propertyInfoList.add(new PropertyInfo((String) property.getValue(), propertyFile.getFilename(), isWinning((String) property.getKey(), (String) property.getValue()))); |
|
70 |
propertiesMap.put((String) property.getKey(), propertyInfoList); |
|
71 |
} |
|
72 |
} |
|
73 |
} |
|
74 |
|
|
75 |
// Scans the Map just created for properties overridden externally (e.g. by Tomcat) |
|
76 |
/* for (String property : propertiesMap.keySet()) { |
|
77 |
List<PropertyInfo> propertyInfoList = propertiesMap.get(property); |
|
78 |
boolean isOverridden = true; |
|
79 |
for (PropertyInfo propInfo : propertyInfoList) { |
|
80 |
// Checks for a checker |
|
81 |
if (propInfo.isChecked) { |
|
82 |
isOverridden = false; |
|
83 |
} |
|
84 |
} |
|
85 |
|
|
86 |
// If none of the pairs has been checked, then the property has been overridden externally. |
|
87 |
if (isOverridden && propertyFetcherProps.getProperty(property) != null) { |
|
88 |
// Adds the current property value (which is the override) as the current one. |
|
89 |
propertyInfoList.add(new PropertyInfo(propertyFetcherProps.getProperty(property), "Overridden externally", true)); |
|
90 |
propertiesMap.put(property, propertyInfoList); |
|
91 |
} |
|
92 |
}*/ |
|
93 |
|
|
94 |
return propertiesMap; |
|
95 |
} |
|
96 |
|
|
97 |
/** |
|
98 |
* Checks whether a given property-value is the one currently in use. |
|
99 |
* |
|
100 |
* @param property The property key |
|
101 |
* @param value The property value |
|
102 |
* @return true/false |
|
103 |
*/ |
|
104 |
private Boolean isWinning(final String property, final String value) { |
|
105 |
String winningPropertyValue = propertyFetcherProps.getProperty(property); |
|
106 |
return value.equals(winningPropertyValue); |
|
107 |
} |
|
108 |
|
|
109 |
|
|
110 |
private class PropertyInfo { |
|
111 |
|
|
112 |
String value; |
|
113 |
String sourcePropertyFile; |
|
114 |
Boolean isChecked; |
|
115 |
|
|
116 |
public PropertyInfo(final String value, final String sourcePropertyFile, final Boolean isChecked) { |
|
117 |
this.value = value; |
|
118 |
this.sourcePropertyFile = sourcePropertyFile; |
|
119 |
this.isChecked = isChecked; |
|
120 |
} |
|
121 |
|
|
122 |
public String getValue() { |
|
123 |
return value; |
|
124 |
} |
|
125 |
|
|
126 |
public String getSourcePropertyFile() { |
|
127 |
return sourcePropertyFile; |
|
128 |
} |
|
129 |
|
|
130 |
public Boolean getIsChecked() { |
|
131 |
return isChecked; |
|
132 |
} |
|
133 |
} |
|
134 |
} |
modules/dnet-modular-ui/tags/dnet-modular-ui-3.0.14/src/main/java/eu/dnetlib/functionality/modular/ui/DnetLogAjaxController.java | ||
---|---|---|
1 |
package eu.dnetlib.functionality.modular.ui; |
|
2 |
|
|
3 |
import java.io.IOException; |
|
4 |
import java.util.Enumeration; |
|
5 |
import java.util.List; |
|
6 |
|
|
7 |
import javax.annotation.PostConstruct; |
|
8 |
|
|
9 |
import org.apache.commons.logging.Log; |
|
10 |
import org.apache.commons.logging.LogFactory; |
|
11 |
import org.apache.log4j.Level; |
|
12 |
import org.apache.log4j.LogManager; |
|
13 |
import org.apache.log4j.Logger; |
|
14 |
import org.springframework.stereotype.Controller; |
|
15 |
import org.springframework.web.bind.annotation.PathVariable; |
|
16 |
import org.springframework.web.bind.annotation.RequestMapping; |
|
17 |
import org.springframework.web.bind.annotation.ResponseBody; |
|
18 |
|
|
19 |
import eu.dnetlib.functionality.modular.ui.utils.LogLine; |
|
20 |
import eu.dnetlib.functionality.modular.ui.utils.LogUiAppender; |
|
21 |
|
|
22 |
@Controller |
|
23 |
public class DnetLogAjaxController { |
|
24 |
|
|
25 |
private LogUiAppender appender; |
|
26 |
|
|
27 |
private static final Log log = LogFactory.getLog(DnetLogAjaxController.class); |
|
28 |
|
|
29 |
@PostConstruct |
|
30 |
void init() throws IOException { |
|
31 |
this.appender = findLogUiAppender(); |
|
32 |
} |
|
33 |
|
|
34 |
private LogUiAppender findLogUiAppender() { |
|
35 |
final Logger logger = LogManager.getRootLogger(); |
|
36 |
final Enumeration<?> appenders = logger.getAllAppenders(); |
|
37 |
while (appenders.hasMoreElements()) { |
|
38 |
final Object app = appenders.nextElement(); |
|
39 |
if (app instanceof LogUiAppender) { |
|
40 |
log.info("An istance of LogUiAppender is already registered in log4j configuration."); |
|
41 |
return (LogUiAppender) app; |
|
42 |
} |
|
43 |
} |
|
44 |
|
|
45 |
final LogUiAppender app = new LogUiAppender(); |
|
46 |
LogManager.getRootLogger().addAppender(app); |
|
47 |
|
|
48 |
log.info("A new LogUiAppender has been registered in log4j configuration."); |
|
49 |
|
|
50 |
return app; |
|
51 |
} |
|
52 |
|
|
53 |
@RequestMapping(value = "/ui/log/tail/{n}") |
|
54 |
public @ResponseBody |
|
55 |
List<LogLine> tail_N(@PathVariable(value = "n") final int n) throws Exception { |
|
56 |
return appender.tail_N(n); |
|
57 |
} |
|
58 |
|
|
59 |
@RequestMapping(value = "/ui/log/continue/{after}") |
|
60 |
public @ResponseBody |
|
61 |
List<LogLine> tail_continue(@PathVariable(value = "after") final int after) throws Exception { |
|
62 |
return appender.tail_continue(after); |
|
63 |
} |
|
64 |
|
|
65 |
@RequestMapping(value = "/ui/log/level/{level}/{resource}") |
|
66 |
public @ResponseBody |
|
67 |
boolean updateLogLevel(@PathVariable(value = "level") final String level, @PathVariable(value = "resource") final String resource) throws Exception { |
|
68 |
if (resource != null && level != null) { |
|
69 |
LogManager.getLogger(resource).setLevel(Level.toLevel(level)); |
|
70 |
} |
|
71 |
return true; |
|
72 |
} |
|
73 |
|
|
74 |
} |
modules/dnet-modular-ui/tags/dnet-modular-ui-3.0.14/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.14/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.14/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.14/src/main/java/eu/dnetlib/functionality/modular/ui/utils/LogLine.java | ||
---|---|---|
1 |
package eu.dnetlib.functionality.modular.ui.utils; |
|
2 |
|
|
3 |
public class LogLine { |
|
4 |
|
|
5 |
private long id; |
|
6 |
private String level; |
|
7 |
private String name; |
|
8 |
private String date; |
|
9 |
private String message; |
|
10 |
private String stacktrace; |
|
11 |
|
|
12 |
public LogLine(final long id, final String level, final String name, final String date, final String message, final String stacktrace) { |
|
13 |
this.id = id; |
|
14 |
this.level = level; |
|
15 |
this.name = name; |
|
16 |
this.date = date; |
|
17 |
this.message = message; |
|
18 |
this.stacktrace = stacktrace; |
|
19 |
} |
|
20 |
|
|
21 |
public final long getId() { |
|
22 |
return id; |
|
23 |
} |
|
24 |
|
|
25 |
public final void setId(final long id) { |
|
26 |
this.id = id; |
|
27 |
} |
|
28 |
|
|
29 |
public final String getLevel() { |
|
30 |
return level; |
|
31 |
} |
|
32 |
|
|
33 |
public final void setLevel(final String level) { |
|
34 |
this.level = level; |
|
35 |
} |
|
36 |
|
|
37 |
public final String getName() { |
|
38 |
return name; |
|
39 |
} |
|
40 |
|
|
41 |
public final void setName(final String name) { |
|
42 |
this.name = name; |
|
43 |
} |
|
44 |
|
|
45 |
public final String getDate() { |
|
46 |
return date; |
|
47 |
} |
|
48 |
|
|
49 |
public final void setDate(final String date) { |
|
50 |
this.date = date; |
|
51 |
} |
|
52 |
|
|
53 |
public final String getMessage() { |
|
54 |
return message; |
|
55 |
} |
|
56 |
|
|
57 |
public final void setMessage(final String message) { |
|
58 |
this.message = message; |
|
59 |
} |
|
60 |
|
|
61 |
public final String getStacktrace() { |
|
62 |
return stacktrace; |
|
63 |
} |
|
64 |
|
|
65 |
public final void setStacktrace(final String stacktrace) { |
|
66 |
this.stacktrace = stacktrace; |
|
67 |
} |
|
68 |
|
|
69 |
} |
modules/dnet-modular-ui/tags/dnet-modular-ui-3.0.14/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 void resumeAll() { |
|
47 |
for (Stoppable s : stoppables) { |
|
48 |
final StoppableDetails info = s.getStopDetails(); |
|
49 |
if (info.getStatus() != StopStatus.RUNNING) { |
|
50 |
log.info("Resuming " + info.getName()); |
|
51 |
s.resume(); |
|
52 |
} |
|
53 |
} |
|
54 |
this.status = StopStatus.RUNNING; |
|
55 |
} |
|
56 |
|
|
57 |
public StopStatus currentStatus() { |
|
58 |
if (status == StopStatus.STOPPING) { |
|
59 |
int running = 0; |
|
60 |
for (Stoppable s : stoppables) { |
|
61 |
final StoppableDetails info = s.getStopDetails(); |
|
62 |
if (info.getStatus() != StopStatus.STOPPED) { |
|
63 |
running++; |
|
64 |
} |
|
65 |
} |
|
66 |
if (running == 0) { |
|
67 |
status = StopStatus.STOPPED; |
|
68 |
} |
|
69 |
} |
|
70 |
return status; |
|
71 |
} |
|
72 |
} |
modules/dnet-modular-ui/tags/dnet-modular-ui-3.0.14/src/main/java/eu/dnetlib/functionality/modular/ui/utils/LogUiAppender.java | ||
---|---|---|
1 |
package eu.dnetlib.functionality.modular.ui.utils; |
|
2 |
|
|
3 |
import java.text.SimpleDateFormat; |
|
4 |
import java.util.Date; |
|
5 |
import java.util.List; |
|
6 |
import java.util.concurrent.LinkedBlockingQueue; |
|
7 |
|
|
8 |
import org.apache.log4j.AppenderSkeleton; |
|
9 |
import org.apache.log4j.spi.LoggingEvent; |
|
10 |
|
|
11 |
import com.google.common.base.Joiner; |
|
12 |
import com.google.common.base.Predicate; |
|
13 |
import com.google.common.collect.Iterables; |
|
14 |
import com.google.common.collect.Lists; |
|
15 |
import com.google.common.collect.Queues; |
|
16 |
|
|
17 |
public class LogUiAppender extends AppenderSkeleton { |
|
18 |
|
|
19 |
public static final int MAX_LOGS_IN_QUEUE = 2000; |
|
20 |
|
|
21 |
private final LinkedBlockingQueue<LogLine> logQueue = Queues.newLinkedBlockingQueue(MAX_LOGS_IN_QUEUE); |
|
22 |
|
|
23 |
private int count = 0; |
|
24 |
|
|
25 |
private static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
|
26 |
|
|
27 |
@Override |
|
28 |
protected void append(final LoggingEvent event) { |
|
29 |
synchronized (logQueue) { |
|
30 |
if (logQueue.remainingCapacity() == 0) { |
|
31 |
logQueue.poll(); |
|
32 |
} |
|
33 |
try { |
|
34 |
final String date = dateFormat.format(new Date(event.getTimeStamp())); |
|
35 |
|
|
36 |
final String[] arr = event.getThrowableStrRep(); |
|
37 |
final String strace = arr != null && arr.length > 0 ? Joiner.on("\n").join(arr) : ""; |
|
38 |
|
|
39 |
logQueue.put(new LogLine(count++, event.getLevel().toString(), event.getLoggerName(), date, event.getRenderedMessage(), strace)); |
|
40 |
} catch (InterruptedException e) { |
|
41 |
throw new RuntimeException(e); |
|
42 |
} |
|
43 |
} |
|
44 |
} |
|
45 |
|
|
46 |
public List<LogLine> tail_N(final int n) throws Exception { |
|
47 |
synchronized (logQueue) { |
|
48 |
int qSize = logQueue.size(); |
|
49 |
|
|
50 |
if (n <= 0 || qSize == 0) { |
|
51 |
return Lists.newArrayList(); |
|
52 |
} else if (n < qSize) { |
|
53 |
return Lists.newArrayList(logQueue).subList(qSize - n, qSize); |
|
54 |
} else { |
|
55 |
return Lists.newArrayList(logQueue); |
|
56 |
} |
|
57 |
} |
|
58 |
} |
|
59 |
|
|
60 |
public List<LogLine> tail_continue(final int after) throws Exception { |
|
61 |
synchronized (logQueue) { |
|
62 |
return Lists.newArrayList(Iterables.filter(logQueue, new Predicate<LogLine>() { |
|
63 |
|
|
64 |
@Override |
|
65 |
public boolean apply(final LogLine ll) { |
|
66 |
return ll.getId() > after; |
|
67 |
} |
|
68 |
})); |
|
69 |
} |
|
70 |
} |
|
71 |
|
|
72 |
@Override |
|
73 |
public void close() {} |
|
74 |
|
|
75 |
@Override |
|
76 |
public boolean requiresLayout() { |
|
77 |
return false; |
|
78 |
} |
|
79 |
|
|
80 |
} |
modules/dnet-modular-ui/tags/dnet-modular-ui-3.0.14/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.14/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.14/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.14/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.14/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.14/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.14/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.14/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()); |
Also available in: Unified diff
[maven-release-plugin] copy for tag dnet-modular-ui-3.0.14