Roberto Sánchez
2014-01-22 1a0d1f15efa2b4cbdc6dd30b5a85b111d0599b63
#396 feature - Added session timeout and responsive layour untill 1600px
6 files modified
changed files
securis/src/main/java/net/curisit/securis/db/Pack.java patch | view | blame | history
securis/src/main/java/net/curisit/securis/services/OrganizationResource.java patch | view | blame | history
securis/src/main/java/net/curisit/securis/services/PackResource.java patch | view | blame | history
securis/src/main/resources/static/css/securis.css patch | view | blame | history
securis/src/main/resources/static/js/licenses.js patch | view | blame | history
securis/src/main/resources/static/js/main.js patch | view | blame | history
securis/src/main/java/net/curisit/securis/db/Pack.java
....@@ -19,6 +19,7 @@
1919
2020 import org.codehaus.jackson.annotate.JsonAutoDetect;
2121 import org.codehaus.jackson.annotate.JsonIgnore;
22
+import org.codehaus.jackson.annotate.JsonIgnoreProperties;
2223 import org.codehaus.jackson.annotate.JsonProperty;
2324 import org.codehaus.jackson.map.annotate.JsonSerialize;
2425
....@@ -30,6 +31,7 @@
3031 @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
3132 @Entity
3233 @Table(name = "pack")
34
+@JsonIgnoreProperties(ignoreUnknown = true)
3335 @NamedQueries(
3436 { @NamedQuery(name = "list-packs", query = "SELECT pa FROM Pack pa"),//
3537 @NamedQuery(name = "list-packs-by-orgs", query = "SELECT pa FROM Pack pa where pa.organization.id in :list_ids") })
....@@ -222,7 +224,7 @@
222224
223225 @JsonProperty("created_by_name")
224226 public String getCreatedByname() {
225
- return createdBy == null ? null : String.format("%s %s", createdBy.getFirstName(), createdBy.getFirstName());
227
+ return createdBy == null ? null : String.format("%s %s (%s)", createdBy.getFirstName(), createdBy.getLastName(), createdBy.getUsername());
226228 }
227229
228230 @JsonProperty("licensetype_code")
securis/src/main/java/net/curisit/securis/services/OrganizationResource.java
....@@ -113,12 +113,12 @@
113113 // }
114114
115115 EntityManager em = emProvider.get();
116
- Organization lt = em.find(Organization.class, Integer.parseInt(orgid));
117
- if (lt == null) {
116
+ Organization org = em.find(Organization.class, Integer.parseInt(orgid));
117
+ if (org == null) {
118118 log.error("Organization with id {} not found in DB", orgid);
119
- return Response.status(Status.NOT_FOUND).build();
119
+ return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Organization not found, id: " + orgid).build();
120120 }
121
- return Response.ok(lt).build();
121
+ return Response.ok(org).build();
122122 }
123123
124124 private boolean isCyclicalRelationship(int currentId, Organization parent) {
securis/src/main/java/net/curisit/securis/services/PackResource.java
....@@ -9,11 +9,9 @@
99 import javax.inject.Provider;
1010 import javax.persistence.EntityManager;
1111 import javax.persistence.TypedQuery;
12
-import javax.servlet.http.HttpServletRequest;
1312 import javax.ws.rs.Consumes;
1413 import javax.ws.rs.DELETE;
1514 import javax.ws.rs.GET;
16
-import javax.ws.rs.HeaderParam;
1715 import javax.ws.rs.POST;
1816 import javax.ws.rs.PUT;
1917 import javax.ws.rs.Path;
....@@ -26,7 +24,10 @@
2624
2725 import net.curisit.integrity.commons.Utils;
2826 import net.curisit.securis.DefaultExceptionHandler;
27
+import net.curisit.securis.db.LicenseType;
28
+import net.curisit.securis.db.Organization;
2929 import net.curisit.securis.db.Pack;
30
+import net.curisit.securis.db.User;
3031 import net.curisit.securis.security.BasicSecurityContext;
3132 import net.curisit.securis.security.Securable;
3233 import net.curisit.securis.utils.TokenHelper;
....@@ -78,7 +79,6 @@
7879 q = em.createNamedQuery("list-packs-by-orgs", Pack.class);
7980 if (bsc.getOrganizationsIds() == null)
8081 Response.ok().build();
81
- // log.info("Getting only {} orgs for user: {}", securityContext.getOrganizationsIds(), securityContext.getUserPrincipal());
8282 q.setParameter("list_ids", bsc.getOrganizationsIds());
8383 }
8484
....@@ -130,10 +130,32 @@
130130 @Produces(
131131 { MediaType.APPLICATION_JSON })
132132 @Transactional
133
- public Response create(Pack pack, @HeaderParam(TokenHelper.TOKEN_HEADER_PÀRAM) String token) {
133
+ public Response create(Pack pack, @Context BasicSecurityContext bsc) {
134134 log.info("Creating new pack");
135135 EntityManager em = emProvider.get();
136136
137
+ Organization org = null;
138
+ if (pack.getOrgId() != null) {
139
+ org = em.find(Organization.class, pack.getOrgId());
140
+ if (org == null) {
141
+ log.error("Organization pack with id {} not found in DB", pack.getOrgId());
142
+ return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Pack organization not found with ID: " + pack.getOrgId()).build();
143
+ }
144
+ }
145
+ LicenseType lt = null;
146
+ if (pack.getLicTypeId() != null) {
147
+ lt = em.find(LicenseType.class, pack.getLicTypeId());
148
+ if (lt == null) {
149
+ log.error("Pack license type with id {} not found in DB", pack.getLicTypeId());
150
+ return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Pack license type not found with ID: " + pack.getLicTypeId()).build();
151
+ }
152
+ }
153
+
154
+ User user = em.find(User.class, bsc.getUserPrincipal().getName());
155
+
156
+ pack.setCreatedBy(user);
157
+ pack.setLicenseType(lt);
158
+ pack.setOrganization(org);
137159 pack.setCreationTimestamp(new Date());
138160 em.persist(pack);
139161
....@@ -149,11 +171,34 @@
149171 @Consumes(MediaType.APPLICATION_JSON)
150172 @Produces(
151173 { MediaType.APPLICATION_JSON })
152
- public Response modify(Pack pack, @PathParam("packId") String packId, @HeaderParam(TokenHelper.TOKEN_HEADER_PÀRAM) String token) {
174
+ public Response modify(Pack pack, @PathParam("packId") String packId) {
153175 log.info("Modifying pack with id: {}", packId);
154176 EntityManager em = emProvider.get();
177
+ Pack currentPack = em.find(Pack.class, Integer.parseInt(packId));
155178
156
- em.persist(pack);
179
+ Organization org = null;
180
+ if (pack.getOrgId() != null) {
181
+ org = em.find(Organization.class, pack.getOrgId());
182
+ if (org == null) {
183
+ log.error("Organization pack with id {} not found in DB", pack.getOrgId());
184
+ return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Pack organization not found with ID: " + pack.getOrgId()).build();
185
+ }
186
+ }
187
+ LicenseType lt = null;
188
+ if (pack.getLicTypeId() != null) {
189
+ lt = em.find(LicenseType.class, pack.getLicTypeId());
190
+ if (lt == null) {
191
+ log.error("Pack license type with id {} not found in DB", pack.getLicTypeId());
192
+ return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Pack license type not found with ID: " + pack.getLicTypeId()).build();
193
+ }
194
+ }
195
+ currentPack.setLicenseType(lt);
196
+ currentPack.setOrganization(org);
197
+ currentPack.setCode(pack.getCode());
198
+ currentPack.setComments(pack.getComments());
199
+ currentPack.setNumLicenses(pack.getNumLicenses());
200
+
201
+ em.persist(currentPack);
157202
158203 return Response.ok(pack).build();
159204 }
....@@ -165,7 +210,7 @@
165210 @Transactional
166211 @Produces(
167212 { MediaType.APPLICATION_JSON })
168
- public Response delete(@PathParam("packId") String packId, @Context HttpServletRequest request) {
213
+ public Response delete(@PathParam("packId") String packId) {
169214 log.info("Deleting pack with id: {}", packId);
170215 EntityManager em = emProvider.get();
171216 Pack org = em.find(Pack.class, Integer.parseInt(packId));
securis/src/main/resources/static/css/securis.css
....@@ -2,6 +2,19 @@
22 padding-top: 50px;
33 padding-bottom: 20px;
44 }
5
+
6
+@media (min-width: 1400px) {
7
+ .container {
8
+ width: 1350px !important;
9
+ }
10
+}
11
+
12
+@media (min-width: 1600px) {
13
+ .container {
14
+ width: 1550px !important;
15
+ }
16
+}
17
+
518 a {
619 cursor: default !important;
720 }
securis/src/main/resources/static/js/licenses.js
....@@ -102,6 +102,7 @@
102102
103103 $scope.save = function() {
104104 var _success = function() {
105
+ if (!$scope.isNew) $scope.showForm = false;
105106 $scope.packs = packResource.query();
106107 }
107108 packResource.save($scope.pack, _success)
securis/src/main/resources/static/js/main.js
....@@ -28,7 +28,21 @@
2828 return rejection.status === 401 /* Unauthorized */;
2929 }
3030 return {
31
-
31
+ 'request': function(config) {
32
+ var la = $store.get('last_access');
33
+ var now = new Date().getTime();
34
+ if (la !== null) {
35
+ if (now > (la + 1800000)) { // Session timeout is 1/2 hour
36
+ $store.clear();
37
+ $location.path('/login');
38
+ BootstrapDialog.alert('Session has expired');
39
+ } else {
40
+ console.log('Last access recent');
41
+ }
42
+ }
43
+ $store.set('last_access', now);
44
+ return config || $q.when(config);
45
+ },
3246 'responseError': function(rejection) {
3347 // do something on error
3448 if (isUnauthorizedAccess(rejection)) {