rsanchez
2017-04-13 84588a793c9484f9182d253ed83ad11687a1d4f8
#3529 feature - Added new role for readonly
1 files deleted
1 files added
16 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/db/User.java patch | view | blame | history
securis/src/main/java/net/curisit/securis/services/ApiResource.java patch | view | blame | history
securis/src/main/java/net/curisit/securis/services/ApplicationResource.java patch | view | blame | history
securis/src/main/java/net/curisit/securis/services/LicenseResource.java patch | view | blame | history
securis/src/main/java/net/curisit/securis/services/LicenseTypeResource.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/java/net/curisit/securis/services/UserResource.java patch | view | blame | history
securis/src/main/webapp/bs-config.js patch | view | blame | history
securis/src/main/webapp/bs-config.json patch | view | blame | history
securis/src/main/webapp/index.html patch | view | blame | history
securis/src/main/webapp/jspm.browser.js patch | view | blame | history
securis/src/main/webapp/jspm.config.js patch | view | blame | history
securis/src/main/webapp/package.json patch | view | blame | history
securis/src/main/webapp/src/app/forms/user.form.component.ts patch | view | blame | history
securis/src/main/webapp/src/app/forms/user.form.html patch | view | blame | history
securis/src/main/webapp/src/main.ts patch | view | blame | history
securis/src/main/java/net/curisit/securis/db/Pack.java
....@@ -44,7 +44,7 @@
4444 @NamedQuery(name = "pack-by-code", query = "SELECT pa FROM Pack pa where pa.code = :code"), //
4545 @NamedQuery(name = "list-packs-by-lic-type", query = "SELECT pa FROM Pack pa where pa.licenseType.id = :lt_id"), //
4646 @NamedQuery(name = "list-packs-by-orgs-apps", query = "SELECT pa FROM Pack pa where pa.organization.id in :list_ids_org and pa.licenseType.application.id in :list_ids_app "), //
47
- @NamedQuery(name = "list-packs-by-orgs", query = "SELECT pa FROM Pack pa where pa.organization.id in :list_ids") })
47
+ @NamedQuery(name = "list-packs-by-apps", query = "SELECT pa FROM Pack pa where pa.licenseType.application.id in :list_ids_app ") })
4848 public class Pack implements Serializable {
4949
5050 private static final long serialVersionUID = 1L;
securis/src/main/java/net/curisit/securis/db/User.java
....@@ -294,7 +294,8 @@
294294 public static final int ADVANCE = 0x01;
295295 public static final int ADMIN = 0x02;
296296 public static final int BASIC = 0x04;
297
- public static final int[] ALL = new int[] { ADVANCE, ADMIN, BASIC };
297
+ public static final int API_CLIENT = 0x80;
298
+ public static final int[] ALL = new int[] { ADVANCE, ADMIN, BASIC }; // ALL except the special API client
298299 }
299300
300301 }
securis/src/main/java/net/curisit/securis/services/ApiResource.java
....@@ -35,6 +35,7 @@
3535 import net.curisit.securis.db.LicenseStatus;
3636 import net.curisit.securis.db.Pack;
3737 import net.curisit.securis.db.User;
38
+import net.curisit.securis.db.User.Rol;
3839 import net.curisit.securis.ioc.EnsureTransaction;
3940 import net.curisit.securis.security.BasicSecurityContext;
4041 import net.curisit.securis.security.Securable;
....@@ -111,7 +112,7 @@
111112 @POST
112113 @Path("/request")
113114 @Consumes(MediaType.APPLICATION_JSON)
114
- @Securable
115
+ @Securable(roles = Rol.API_CLIENT)
115116 @Produces({ MediaType.APPLICATION_JSON })
116117 @EnsureTransaction
117118 public Response createFromRequest(RequestBean request, @HeaderParam(LicenseManager.HEADER_LICENSE_NAME_OR_REFERENCE) String nameOrReference,
....@@ -135,7 +136,7 @@
135136 @POST
136137 @Path("/request")
137138 @Consumes(MediaType.MULTIPART_FORM_DATA)
138
- @Securable
139
+ @Securable(roles = Rol.API_CLIENT)
139140 @Produces({ MediaType.APPLICATION_JSON })
140141 @EnsureTransaction
141142 @SuppressWarnings("unchecked")
....@@ -168,7 +169,7 @@
168169 @POST
169170 @Path("/renew")
170171 @Consumes(MediaType.APPLICATION_JSON)
171
- @Securable
172
+ @Securable(roles = Rol.API_CLIENT)
172173 @Produces({ MediaType.APPLICATION_JSON })
173174 @EnsureTransaction
174175 public Response renewFromPreviousLicense(LicenseBean previousLic, @Context BasicSecurityContext bsc) throws IOException, SeCurisServiceException, SeCurisException {
....@@ -208,7 +209,7 @@
208209 @POST
209210 @Path("/validate")
210211 @Consumes(MediaType.APPLICATION_JSON)
211
- @Securable
212
+ @Securable(roles = Rol.API_CLIENT)
212213 @Produces({ MediaType.APPLICATION_JSON })
213214 @EnsureTransaction
214215 public Response validate(LicenseBean currentLic, @Context BasicSecurityContext bsc) throws IOException, SeCurisServiceException, SeCurisException {
....@@ -242,7 +243,7 @@
242243 @POST
243244 @Path("/renew")
244245 @Consumes(MediaType.MULTIPART_FORM_DATA)
245
- @Securable
246
+ @Securable(roles = Rol.API_CLIENT)
246247 @Produces({ MediaType.APPLICATION_JSON })
247248 @EnsureTransaction
248249 @SuppressWarnings("unchecked")
securis/src/main/java/net/curisit/securis/services/ApplicationResource.java
....@@ -32,6 +32,7 @@
3232 import net.curisit.securis.DefaultExceptionHandler;
3333 import net.curisit.securis.db.Application;
3434 import net.curisit.securis.db.ApplicationMetadata;
35
+import net.curisit.securis.db.User.Rol;
3536 import net.curisit.securis.ioc.EnsureTransaction;
3637 import net.curisit.securis.security.BasicSecurityContext;
3738 import net.curisit.securis.security.Securable;
....@@ -120,7 +121,7 @@
120121 @Consumes(MediaType.APPLICATION_JSON)
121122 @Produces({ MediaType.APPLICATION_JSON })
122123 @EnsureTransaction
123
- @Securable
124
+ @Securable(roles = Rol.ADMIN)
124125 @RolesAllowed(BasicSecurityContext.ROL_ADMIN)
125126 public Response create(Application app, @HeaderParam(TokenHelper.TOKEN_HEADER_PÀRAM) String token) {
126127 LOG.info("Creating new application");
....@@ -146,7 +147,7 @@
146147 @EnsureTransaction
147148 @Consumes(MediaType.APPLICATION_JSON)
148149 @Produces({ MediaType.APPLICATION_JSON })
149
- @Securable
150
+ @Securable(roles = Rol.ADMIN)
150151 @RolesAllowed(BasicSecurityContext.ROL_ADMIN)
151152 public Response modify(Application app, @PathParam("appid") String appid, @HeaderParam(TokenHelper.TOKEN_HEADER_PÀRAM) String token) {
152153 LOG.info("Modifying application with id: {}", appid);
....@@ -209,7 +210,7 @@
209210 @Path("/{appid}")
210211 @EnsureTransaction
211212 @Produces({ MediaType.APPLICATION_JSON })
212
- @Securable
213
+ @Securable(roles = Rol.ADMIN)
213214 @RolesAllowed(BasicSecurityContext.ROL_ADMIN)
214215 public Response delete(@PathParam("appid") String appid, @Context HttpServletRequest request) {
215216 LOG.info("Deleting app with id: {}", appid);
securis/src/main/java/net/curisit/securis/services/LicenseResource.java
....@@ -49,6 +49,7 @@
4949 import net.curisit.securis.db.Pack;
5050 import net.curisit.securis.db.PackStatus;
5151 import net.curisit.securis.db.User;
52
+import net.curisit.securis.db.User.Rol;
5253 import net.curisit.securis.ioc.EnsureTransaction;
5354 import net.curisit.securis.security.BasicSecurityContext;
5455 import net.curisit.securis.security.Securable;
....@@ -175,7 +176,7 @@
175176 @PUT
176177 @POST
177178 @Path("/{licId}/activate")
178
- @Securable
179
+ @Securable(roles = Rol.ADMIN | Rol.ADVANCE)
179180 @EnsureTransaction
180181 @Consumes(MediaType.APPLICATION_JSON)
181182 @Produces({ MediaType.APPLICATION_JSON })
....@@ -220,7 +221,7 @@
220221 @PUT
221222 @POST
222223 @Path("/{licId}/send")
223
- @Securable
224
+ @Securable(roles = Rol.ADMIN | Rol.ADVANCE)
224225 @EnsureTransaction
225226 @Consumes(MediaType.APPLICATION_JSON)
226227 @Produces({ MediaType.APPLICATION_JSON })
....@@ -274,7 +275,7 @@
274275 @PUT
275276 @POST
276277 @Path("/{licId}/cancel")
277
- @Securable
278
+ @Securable(roles = Rol.ADMIN | Rol.ADVANCE)
278279 @EnsureTransaction
279280 @Consumes(MediaType.APPLICATION_JSON)
280281 @Produces({ MediaType.APPLICATION_JSON })
....@@ -317,7 +318,7 @@
317318 @POST
318319 @Path("/")
319320 @Consumes(MediaType.APPLICATION_JSON)
320
- @Securable
321
+ @Securable(roles = Rol.ADMIN | Rol.ADVANCE)
321322 @Produces({ MediaType.APPLICATION_JSON })
322323 @EnsureTransaction
323324 public Response create(License lic, @Context BasicSecurityContext bsc) throws SeCurisServiceException {
....@@ -456,7 +457,7 @@
456457 @PUT
457458 @POST
458459 @Path("/{licId}")
459
- @Securable
460
+ @Securable(roles = Rol.ADMIN | Rol.ADVANCE)
460461 @EnsureTransaction
461462 @Consumes(MediaType.APPLICATION_JSON)
462463 @Produces({ MediaType.APPLICATION_JSON })
....@@ -506,7 +507,7 @@
506507 @DELETE
507508 @Path("/{licId}")
508509 @EnsureTransaction
509
- @Securable
510
+ @Securable(roles = Rol.ADMIN | Rol.ADVANCE)
510511 @Produces({ MediaType.APPLICATION_JSON })
511512 public Response delete(@PathParam("licId") Integer licId, @Context BasicSecurityContext bsc) throws SeCurisServiceException {
512513 LOG.info("Deleting license with id: {}", licId);
....@@ -536,7 +537,7 @@
536537 @POST
537538 @Path("/{licId}/block")
538539 @EnsureTransaction
539
- @Securable
540
+ @Securable(roles = Rol.ADMIN | Rol.ADVANCE)
540541 @Produces({ MediaType.APPLICATION_JSON })
541542 public Response block(@PathParam("licId") Integer licId, @Context BasicSecurityContext bsc) throws SeCurisServiceException {
542543 LOG.info("Blocking license with id: {}", licId);
....@@ -567,7 +568,7 @@
567568 @POST
568569 @Path("/{licId}/unblock")
569570 @EnsureTransaction
570
- @Securable
571
+ @Securable(roles = Rol.ADMIN | Rol.ADVANCE)
571572 @Produces({ MediaType.APPLICATION_JSON })
572573 public Response unblock(@PathParam("licId") Integer licId, @Context BasicSecurityContext bsc) throws SeCurisServiceException {
573574 LOG.info("Unblocking license with id: {}", licId);
securis/src/main/java/net/curisit/securis/services/LicenseTypeResource.java
....@@ -34,6 +34,7 @@
3434 import net.curisit.securis.db.Application;
3535 import net.curisit.securis.db.LicenseType;
3636 import net.curisit.securis.db.LicenseTypeMetadata;
37
+import net.curisit.securis.db.User.Rol;
3738 import net.curisit.securis.ioc.EnsureTransaction;
3839 import net.curisit.securis.security.BasicSecurityContext;
3940 import net.curisit.securis.security.Securable;
....@@ -115,7 +116,7 @@
115116 @Consumes(MediaType.APPLICATION_JSON)
116117 @Produces({ MediaType.APPLICATION_JSON })
117118 @EnsureTransaction
118
- @Securable
119
+ @Securable(roles = Rol.ADMIN)
119120 @RolesAllowed(BasicSecurityContext.ROL_ADMIN)
120121 public Response create(LicenseType lt, @HeaderParam(TokenHelper.TOKEN_HEADER_PÀRAM) String token) {
121122 LOG.info("Creating new license type");
....@@ -163,7 +164,7 @@
163164 @EnsureTransaction
164165 @Consumes(MediaType.APPLICATION_JSON)
165166 @Produces({ MediaType.APPLICATION_JSON })
166
- @Securable
167
+ @Securable(roles = Rol.ADMIN)
167168 @RolesAllowed(BasicSecurityContext.ROL_ADMIN)
168169 public Response modify(LicenseType lt, @PathParam("ltid") String ltid, @HeaderParam(TokenHelper.TOKEN_HEADER_PÀRAM) String token) {
169170 LOG.info("Modifying license type with id: {}", ltid);
....@@ -236,7 +237,7 @@
236237 @Path("/{ltid}")
237238 @EnsureTransaction
238239 @Produces({ MediaType.APPLICATION_JSON })
239
- @Securable
240
+ @Securable(roles = Rol.ADMIN)
240241 @RolesAllowed(BasicSecurityContext.ROL_ADMIN)
241242 public Response delete(@PathParam("ltid") String ltid, @Context HttpServletRequest request) {
242243 LOG.info("Deleting app with id: {}", ltid);
securis/src/main/java/net/curisit/securis/services/OrganizationResource.java
....@@ -24,18 +24,19 @@
2424 import javax.ws.rs.core.Response;
2525 import javax.ws.rs.core.Response.Status;
2626
27
+import org.apache.logging.log4j.LogManager;
28
+import org.apache.logging.log4j.Logger;
29
+
2730 import net.curisit.integrity.commons.Utils;
2831 import net.curisit.securis.DefaultExceptionHandler;
2932 import net.curisit.securis.SeCurisException;
3033 import net.curisit.securis.db.Organization;
3134 import net.curisit.securis.db.User;
35
+import net.curisit.securis.db.User.Rol;
3236 import net.curisit.securis.ioc.EnsureTransaction;
3337 import net.curisit.securis.security.BasicSecurityContext;
3438 import net.curisit.securis.security.Securable;
3539 import net.curisit.securis.utils.TokenHelper;
36
-
37
-import org.apache.logging.log4j.LogManager;
38
-import org.apache.logging.log4j.Logger;
3940
4041 /**
4142 * Organization resource, this service will provide methods to create, modify
....@@ -47,225 +48,207 @@
4748 @RequestScoped
4849 public class OrganizationResource {
4950
50
- private static final Logger LOG = LogManager.getLogger(OrganizationResource.class);
51
+ private static final Logger LOG = LogManager.getLogger(OrganizationResource.class);
5152
52
- @Context
53
- EntityManager em;
53
+ @Context
54
+ EntityManager em;
5455
55
- @Context
56
- BasicSecurityContext bsc;
56
+ @Context
57
+ BasicSecurityContext bsc;
5758
58
- public OrganizationResource() {
59
- }
59
+ public OrganizationResource() {
60
+ }
6061
61
- /**
62
- *
63
- * @return the server version in format majorVersion.minorVersion
64
- */
65
- @GET
66
- @Path("/")
67
- @Produces({
68
- MediaType.APPLICATION_JSON
69
- })
70
- @Securable
71
- public Response index() {
72
- LOG.info("Getting organizations list ");
62
+ /**
63
+ *
64
+ * @return the server version in format majorVersion.minorVersion
65
+ */
66
+ @GET
67
+ @Path("/")
68
+ @Produces({ MediaType.APPLICATION_JSON })
69
+ @Securable
70
+ public Response index() {
71
+ LOG.info("Getting organizations list ");
7372
74
- // EntityManager em = emProvider.get();
75
- em.clear();
76
- TypedQuery<Organization> q;
77
- if (bsc.isUserInRole(BasicSecurityContext.ROL_ADMIN)) {
78
- LOG.info("GEtting all orgs for user: " + bsc.getUserPrincipal());
79
- q = em.createNamedQuery("list-organizations", Organization.class);
80
- } else {
81
- q = em.createNamedQuery("list-organizations", Organization.class);
82
- }
73
+ // EntityManager em = emProvider.get();
74
+ em.clear();
75
+ TypedQuery<Organization> q;
76
+ if (bsc.isUserInRole(BasicSecurityContext.ROL_ADMIN)) {
77
+ LOG.info("GEtting all orgs for user: " + bsc.getUserPrincipal());
78
+ q = em.createNamedQuery("list-organizations", Organization.class);
79
+ } else {
80
+ q = em.createNamedQuery("list-organizations", Organization.class);
81
+ }
8382
84
- List<Organization> list = q.getResultList();
83
+ List<Organization> list = q.getResultList();
8584
86
- return Response.ok(list).build();
87
- }
85
+ return Response.ok(list).build();
86
+ }
8887
89
- /**
90
- *
91
- * @return the server version in format majorVersion.minorVersion
92
- */
93
- @GET
94
- @Path("/{orgid}")
95
- @Produces({
96
- MediaType.APPLICATION_JSON
97
- })
98
- @Securable
99
- public Response get(@PathParam("orgid") String orgid, @HeaderParam(TokenHelper.TOKEN_HEADER_PÀRAM) String token) {
100
- LOG.info("Getting organization data for id: {}: ", orgid);
101
- if (orgid == null || "".equals(orgid)) {
102
- LOG.error("Organization ID is mandatory");
103
- return Response.status(Status.NOT_FOUND).build();
104
- }
88
+ /**
89
+ *
90
+ * @return the server version in format majorVersion.minorVersion
91
+ */
92
+ @GET
93
+ @Path("/{orgid}")
94
+ @Produces({ MediaType.APPLICATION_JSON })
95
+ @Securable
96
+ public Response get(@PathParam("orgid") String orgid, @HeaderParam(TokenHelper.TOKEN_HEADER_PÀRAM) String token) {
97
+ LOG.info("Getting organization data for id: {}: ", orgid);
98
+ if (orgid == null || "".equals(orgid)) {
99
+ LOG.error("Organization ID is mandatory");
100
+ return Response.status(Status.NOT_FOUND).build();
101
+ }
105102
106
- // EntityManager em = emProvider.get();
107
- em.clear();
108
- Organization org = em.find(Organization.class, Integer.parseInt(orgid));
109
- if (org == null) {
110
- LOG.error("Organization with id {} not found in DB", orgid);
111
- return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Organization not found, id: " + orgid)
112
- .build();
113
- }
114
- return Response.ok(org).build();
115
- }
103
+ // EntityManager em = emProvider.get();
104
+ em.clear();
105
+ Organization org = em.find(Organization.class, Integer.parseInt(orgid));
106
+ if (org == null) {
107
+ LOG.error("Organization with id {} not found in DB", orgid);
108
+ return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Organization not found, id: " + orgid).build();
109
+ }
110
+ return Response.ok(org).build();
111
+ }
116112
117
- private boolean isCyclicalRelationship(int currentId, Organization parent) {
118
- while (parent != null) {
119
- if (parent.getId() == currentId) {
120
- return true;
121
- }
122
- parent = parent.getParentOrganization();
123
- }
124
- return false;
125
- }
113
+ private boolean isCyclicalRelationship(int currentId, Organization parent) {
114
+ while (parent != null) {
115
+ if (parent.getId() == currentId) {
116
+ return true;
117
+ }
118
+ parent = parent.getParentOrganization();
119
+ }
120
+ return false;
121
+ }
126122
127
- @POST
128
- @Path("/")
129
- @Consumes(MediaType.APPLICATION_JSON)
130
- @Produces({
131
- MediaType.APPLICATION_JSON
132
- })
133
- @EnsureTransaction
134
- @Securable
135
- @RolesAllowed(BasicSecurityContext.ROL_ADMIN)
136
- public Response create(Organization org) {
137
- LOG.info("Creating new organization");
138
- // EntityManager em = emProvider.get();
123
+ @POST
124
+ @Path("/")
125
+ @Consumes(MediaType.APPLICATION_JSON)
126
+ @Produces({ MediaType.APPLICATION_JSON })
127
+ @EnsureTransaction
128
+ @Securable(roles = Rol.ADMIN)
129
+ @RolesAllowed(BasicSecurityContext.ROL_ADMIN)
130
+ public Response create(Organization org) {
131
+ LOG.info("Creating new organization");
132
+ // EntityManager em = emProvider.get();
139133
140
- try {
141
- this.setParentOrg(org, org.getParentOrgId(), em);
142
- } catch (SeCurisException e) {
143
- return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, e.getMessage()).build();
144
- }
134
+ try {
135
+ this.setParentOrg(org, org.getParentOrgId(), em);
136
+ } catch (SeCurisException e) {
137
+ return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, e.getMessage()).build();
138
+ }
145139
146
- Set<User> users = null;
147
- Set<String> usersIds = org.getUsersIds();
148
- if (usersIds != null && !usersIds.isEmpty()) {
149
- users = new HashSet<>();
150
- for (String username : usersIds) {
151
- User user = em.find(User.class, username);
152
- if (user == null) {
153
- LOG.error("Organization user with id {} not found in DB", username);
154
- return Response.status(Status.NOT_FOUND)
155
- .header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Organization's user not found with ID: " + username).build();
156
- }
157
- users.add(user);
158
- }
159
- }
140
+ Set<User> users = null;
141
+ Set<String> usersIds = org.getUsersIds();
142
+ if (usersIds != null && !usersIds.isEmpty()) {
143
+ users = new HashSet<>();
144
+ for (String username : usersIds) {
145
+ User user = em.find(User.class, username);
146
+ if (user == null) {
147
+ LOG.error("Organization user with id {} not found in DB", username);
148
+ return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Organization's user not found with ID: " + username).build();
149
+ }
150
+ users.add(user);
151
+ }
152
+ }
160153
161
- org.setUsers(users);
162
- org.setCreationTimestamp(new Date());
163
- em.persist(org);
164
- return Response.ok(org).build();
165
- }
154
+ org.setUsers(users);
155
+ org.setCreationTimestamp(new Date());
156
+ em.persist(org);
157
+ return Response.ok(org).build();
158
+ }
166159
167
- private void setParentOrg(Organization org, Integer parentOrgId, EntityManager em) throws SeCurisException {
168
- Organization parentOrg = null;
169
- if (parentOrgId != null) {
170
- parentOrg = em.find(Organization.class, parentOrgId);
171
- if (parentOrg == null) {
172
- LOG.error("Organization parent with id {} not found in DB", org.getParentOrgId());
173
- throw new SecurityException("Organization's parent not found with ID: " + org.getParentOrgId());
174
- }
175
- }
160
+ private void setParentOrg(Organization org, Integer parentOrgId, EntityManager em) throws SeCurisException {
161
+ Organization parentOrg = null;
162
+ if (parentOrgId != null) {
163
+ parentOrg = em.find(Organization.class, parentOrgId);
164
+ if (parentOrg == null) {
165
+ LOG.error("Organization parent with id {} not found in DB", org.getParentOrgId());
166
+ throw new SecurityException("Organization's parent not found with ID: " + org.getParentOrgId());
167
+ }
168
+ }
176169
177
- org.setParentOrganization(parentOrg);
178
- }
170
+ org.setParentOrganization(parentOrg);
171
+ }
179172
180
- private void setOrgUsers(Organization org, Set<String> usersIds, EntityManager em) throws SeCurisException {
181
- Set<User> users = null;
182
- if (usersIds != null && !usersIds.isEmpty()) {
183
- users = new HashSet<>();
184
- for (String username : usersIds) {
185
- User user = em.find(User.class, username);
186
- if (user == null) {
187
- LOG.error("Organization user with id '{}' not found in DB", username);
188
- throw new SecurityException("Organization's user not found with ID: " + username);
189
- }
190
- users.add(user);
191
- }
192
- }
173
+ private void setOrgUsers(Organization org, Set<String> usersIds, EntityManager em) throws SeCurisException {
174
+ Set<User> users = null;
175
+ if (usersIds != null && !usersIds.isEmpty()) {
176
+ users = new HashSet<>();
177
+ for (String username : usersIds) {
178
+ User user = em.find(User.class, username);
179
+ if (user == null) {
180
+ LOG.error("Organization user with id '{}' not found in DB", username);
181
+ throw new SecurityException("Organization's user not found with ID: " + username);
182
+ }
183
+ users.add(user);
184
+ }
185
+ }
193186
194
- org.setUsers(users);
195
- }
187
+ org.setUsers(users);
188
+ }
196189
197
- @PUT
198
- @POST
199
- @Path("/{orgid}")
200
- @Consumes(MediaType.APPLICATION_JSON)
201
- @Produces({
202
- MediaType.APPLICATION_JSON
203
- })
204
- @EnsureTransaction
205
- @Securable
206
- @RolesAllowed(BasicSecurityContext.ROL_ADMIN)
207
- public Response modify(Organization org, @PathParam("orgid") String orgid, @HeaderParam(TokenHelper.TOKEN_HEADER_PÀRAM) String token) {
208
- LOG.info("Modifying organization with id: {}", orgid);
209
- // EntityManager em = emProvider.get();
210
- Organization currentOrg = em.find(Organization.class, Integer.parseInt(orgid));
211
- if (currentOrg == null) {
212
- LOG.error("Organization with id {} not found in DB", orgid);
213
- return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Organization not found with ID: " + orgid)
214
- .build();
215
- }
216
- try {
217
- this.setParentOrg(currentOrg, org.getParentOrgId(), em);
218
- } catch (SeCurisException e) {
219
- return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, e.getMessage()).build();
220
- }
221
- if (org.getParentOrganization() != null && (isCyclicalRelationship(currentOrg.getId(), org.getParentOrganization()))) {
222
- LOG.error("Organization parent generate a cyclical relationship, parent id {}, current id: {}", org.getParentOrgId(), currentOrg.getId());
223
- return Response
224
- .status(Status.FORBIDDEN)
225
- .header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER,
226
- "Cyclical relationships are not allowed, please change the parent organization, current Parent: "
227
- + org.getParentOrganization().getName()).build();
228
- }
190
+ @PUT
191
+ @POST
192
+ @Path("/{orgid}")
193
+ @Consumes(MediaType.APPLICATION_JSON)
194
+ @Produces({ MediaType.APPLICATION_JSON })
195
+ @EnsureTransaction
196
+ @Securable(roles = Rol.ADMIN)
197
+ @RolesAllowed(BasicSecurityContext.ROL_ADMIN)
198
+ public Response modify(Organization org, @PathParam("orgid") String orgid, @HeaderParam(TokenHelper.TOKEN_HEADER_PÀRAM) String token) {
199
+ LOG.info("Modifying organization with id: {}", orgid);
200
+ // EntityManager em = emProvider.get();
201
+ Organization currentOrg = em.find(Organization.class, Integer.parseInt(orgid));
202
+ if (currentOrg == null) {
203
+ LOG.error("Organization with id {} not found in DB", orgid);
204
+ return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Organization not found with ID: " + orgid).build();
205
+ }
206
+ try {
207
+ this.setParentOrg(currentOrg, org.getParentOrgId(), em);
208
+ } catch (SeCurisException e) {
209
+ return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, e.getMessage()).build();
210
+ }
211
+ if (org.getParentOrganization() != null && (isCyclicalRelationship(currentOrg.getId(), org.getParentOrganization()))) {
212
+ LOG.error("Organization parent generate a cyclical relationship, parent id {}, current id: {}", org.getParentOrgId(), currentOrg.getId());
213
+ return Response.status(Status.FORBIDDEN).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER,
214
+ "Cyclical relationships are not allowed, please change the parent organization, current Parent: " + org.getParentOrganization().getName()).build();
215
+ }
229216
230
- try {
231
- setOrgUsers(currentOrg, org.getUsersIds(), em);
232
- } catch (SeCurisException e) {
233
- return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, e.getMessage()).build();
234
- }
217
+ try {
218
+ setOrgUsers(currentOrg, org.getUsersIds(), em);
219
+ } catch (SeCurisException e) {
220
+ return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, e.getMessage()).build();
221
+ }
235222
236
- currentOrg.setCode(org.getCode());
237
- currentOrg.setName(org.getName());
238
- currentOrg.setDescription(org.getDescription());
239
- em.persist(currentOrg);
223
+ currentOrg.setCode(org.getCode());
224
+ currentOrg.setName(org.getName());
225
+ currentOrg.setDescription(org.getDescription());
226
+ em.persist(currentOrg);
240227
241
- return Response.ok(currentOrg).build();
242
- }
228
+ return Response.ok(currentOrg).build();
229
+ }
243230
244
- @DELETE
245
- @Path("/{orgid}")
246
- @EnsureTransaction
247
- @Produces({
248
- MediaType.APPLICATION_JSON
249
- })
250
- @Securable
251
- @RolesAllowed(BasicSecurityContext.ROL_ADMIN)
252
- public Response delete(@PathParam("orgid") String orgid, @Context HttpServletRequest request) {
253
- LOG.info("Deleting organization with id: {}", orgid);
254
- // EntityManager em = emProvider.get();
255
- Organization org = em.find(Organization.class, Integer.parseInt(orgid));
256
- if (org == null) {
257
- LOG.error("Organization with id {} can not be deleted, It was not found in DB", orgid);
258
- return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Organization was not found, ID: " + orgid)
259
- .build();
260
- }
261
- if (org.getChildOrganizations() != null && !org.getChildOrganizations().isEmpty()) {
262
- LOG.error("Organization has children and can not be deleted, ID: " + orgid);
263
- return Response.status(Status.FORBIDDEN)
264
- .header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Organization has children and can not be deleted, ID: " + orgid).build();
265
- }
231
+ @DELETE
232
+ @Path("/{orgid}")
233
+ @EnsureTransaction
234
+ @Produces({ MediaType.APPLICATION_JSON })
235
+ @Securable(roles = Rol.ADMIN)
236
+ @RolesAllowed(BasicSecurityContext.ROL_ADMIN)
237
+ public Response delete(@PathParam("orgid") String orgid, @Context HttpServletRequest request) {
238
+ LOG.info("Deleting organization with id: {}", orgid);
239
+ // EntityManager em = emProvider.get();
240
+ Organization org = em.find(Organization.class, Integer.parseInt(orgid));
241
+ if (org == null) {
242
+ LOG.error("Organization with id {} can not be deleted, It was not found in DB", orgid);
243
+ return Response.status(Status.NOT_FOUND).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Organization was not found, ID: " + orgid).build();
244
+ }
245
+ if (org.getChildOrganizations() != null && !org.getChildOrganizations().isEmpty()) {
246
+ LOG.error("Organization has children and can not be deleted, ID: " + orgid);
247
+ return Response.status(Status.FORBIDDEN).header(DefaultExceptionHandler.ERROR_MESSAGE_HEADER, "Organization has children and can not be deleted, ID: " + orgid).build();
248
+ }
266249
267
- em.remove(org);
268
- return Response.ok(Utils.createMap("success", true, "id", orgid)).build();
269
- }
250
+ em.remove(org);
251
+ return Response.ok(Utils.createMap("success", true, "id", orgid)).build();
252
+ }
270253
271254 }
securis/src/main/java/net/curisit/securis/services/PackResource.java
....@@ -38,6 +38,7 @@
3838 import net.curisit.securis.db.PackMetadata;
3939 import net.curisit.securis.db.PackStatus;
4040 import net.curisit.securis.db.User;
41
+import net.curisit.securis.db.User.Rol;
4142 import net.curisit.securis.ioc.EnsureTransaction;
4243 import net.curisit.securis.security.BasicSecurityContext;
4344 import net.curisit.securis.security.Securable;
....@@ -90,12 +91,15 @@
9091 LOG.info("Getting all packs for user: " + bsc.getUserPrincipal());
9192 q = em.createNamedQuery("list-packs", Pack.class);
9293 } else {
93
- if (bsc.getOrganizationsIds() == null || bsc.getOrganizationsIds().isEmpty() || //
94
- bsc.getApplicationsIds() == null || bsc.getApplicationsIds().isEmpty()) {
94
+ if (bsc.getApplicationsIds() == null || bsc.getApplicationsIds().isEmpty()) {
9595 return Response.ok().build();
9696 }
97
- q = em.createNamedQuery("list-packs-by-orgs-apps", Pack.class);
98
- q.setParameter("list_ids_org", bsc.getOrganizationsIds());
97
+ if (bsc.getOrganizationsIds() == null || bsc.getOrganizationsIds().isEmpty()) {
98
+ q = em.createNamedQuery("list-packs-by-apps", Pack.class);
99
+ } else {
100
+ q = em.createNamedQuery("list-packs-by-orgs-apps", Pack.class);
101
+ q.setParameter("list_ids_org", bsc.getOrganizationsIds());
102
+ }
99103 q.setParameter("list_ids_app", bsc.getApplicationsIds());
100104 LOG.info("Getting packs from orgs: {} and apps: {}", bsc.getOrganizationsIds(), bsc.getApplicationsIds());
101105 }
....@@ -140,7 +144,7 @@
140144
141145 @POST
142146 @Path("/")
143
- @Securable
147
+ @Securable(roles = Rol.ADMIN | Rol.ADVANCE)
144148 @RolesAllowed(BasicSecurityContext.ROL_ADMIN)
145149 @Consumes(MediaType.APPLICATION_JSON)
146150 @Produces({ MediaType.APPLICATION_JSON })
....@@ -207,7 +211,7 @@
207211 */
208212 @GET
209213 @Path("/{packId}/next_license_code")
210
- @Securable
214
+ @Securable(roles = Rol.ADMIN | Rol.ADVANCE)
211215 @Produces({ MediaType.TEXT_PLAIN })
212216 public Response getCodeSuffix(@PathParam("packId") Integer packId, @Context BasicSecurityContext bsc) throws SeCurisServiceException {
213217 // EntityManager em = emProvider.get();
....@@ -249,7 +253,7 @@
249253 @POST
250254 @Path("/{packId}")
251255 @EnsureTransaction
252
- @Securable
256
+ @Securable(roles = Rol.ADMIN | Rol.ADVANCE)
253257 @RolesAllowed(BasicSecurityContext.ROL_ADMIN)
254258 @Consumes(MediaType.APPLICATION_JSON)
255259 @Produces({ MediaType.APPLICATION_JSON })
....@@ -314,7 +318,7 @@
314318 @POST
315319 @Path("/{packId}/activate")
316320 @EnsureTransaction
317
- @Securable
321
+ @Securable(roles = Rol.ADMIN | Rol.ADVANCE)
318322 @RolesAllowed(BasicSecurityContext.ROL_ADMIN)
319323 @Consumes(MediaType.APPLICATION_JSON)
320324 @Produces({ MediaType.APPLICATION_JSON })
....@@ -338,7 +342,7 @@
338342 @POST
339343 @Path("/{packId}/putonhold")
340344 @EnsureTransaction
341
- @Securable
345
+ @Securable(roles = Rol.ADMIN | Rol.ADVANCE)
342346 @RolesAllowed(BasicSecurityContext.ROL_ADMIN)
343347 @Consumes(MediaType.APPLICATION_JSON)
344348 @Produces({ MediaType.APPLICATION_JSON })
....@@ -362,7 +366,7 @@
362366 @POST
363367 @Path("/{packId}/cancel")
364368 @EnsureTransaction
365
- @Securable
369
+ @Securable(roles = Rol.ADMIN | Rol.ADVANCE)
366370 @RolesAllowed(BasicSecurityContext.ROL_ADMIN)
367371 @Consumes(MediaType.APPLICATION_JSON)
368372 @Produces({ MediaType.APPLICATION_JSON })
....@@ -403,7 +407,7 @@
403407
404408 @DELETE
405409 @Path("/{packId}")
406
- @Securable
410
+ @Securable(roles = Rol.ADMIN | Rol.ADVANCE)
407411 @RolesAllowed(BasicSecurityContext.ROL_ADMIN)
408412 @EnsureTransaction
409413 @Produces({ MediaType.APPLICATION_JSON })
securis/src/main/java/net/curisit/securis/services/UserResource.java
....@@ -37,6 +37,7 @@
3737 import net.curisit.securis.db.Application;
3838 import net.curisit.securis.db.Organization;
3939 import net.curisit.securis.db.User;
40
+import net.curisit.securis.db.User.Rol;
4041 import net.curisit.securis.ioc.EnsureTransaction;
4142 import net.curisit.securis.security.BasicSecurityContext;
4243 import net.curisit.securis.security.Securable;
....@@ -120,7 +121,7 @@
120121 @Consumes(MediaType.APPLICATION_JSON)
121122 @Produces({ MediaType.APPLICATION_JSON })
122123 @EnsureTransaction
123
- @Securable
124
+ @Securable(roles = Rol.ADMIN)
124125 @RolesAllowed(BasicSecurityContext.ROL_ADMIN)
125126 public Response create(User user, @HeaderParam(TokenHelper.TOKEN_HEADER_PÀRAM) String token) {
126127 LOG.info("Creating new user");
....@@ -196,7 +197,7 @@
196197 @EnsureTransaction
197198 @Consumes(MediaType.APPLICATION_JSON)
198199 @Produces({ MediaType.APPLICATION_JSON })
199
- @Securable
200
+ @Securable(roles = Rol.ADMIN)
200201 @RolesAllowed(BasicSecurityContext.ROL_ADMIN)
201202 public Response modify(User user, @PathParam("uid") String uid, @HeaderParam(TokenHelper.TOKEN_HEADER_PÀRAM) String token) {
202203 LOG.info("Modifying user with id: {}", uid);
....@@ -241,7 +242,7 @@
241242 @Path("/{uid}")
242243 @EnsureTransaction
243244 @Produces({ MediaType.APPLICATION_JSON })
244
- @Securable
245
+ @Securable(roles = Rol.ADMIN)
245246 @RolesAllowed(BasicSecurityContext.ROL_ADMIN)
246247 public Response delete(@PathParam("uid") String uid, @Context HttpServletRequest request) {
247248 LOG.info("Deleting app with id: {}", uid);
securis/src/main/webapp/bs-config.js
....@@ -0,0 +1,33 @@
1
+
2
+var gz_urls = /\.gz$/
3
+
4
+middleware = function(req, res, next) {
5
+ if ('GET' != req.method && 'HEAD' != req.method) {
6
+ return next();
7
+ }
8
+ if (gz_urls.test(req.url)) {
9
+ console.log('GZIP detected for url: ' + req.url);
10
+ res.setHeader('Content-Encoding', 'gzip');
11
+ }
12
+ return next();
13
+}
14
+
15
+
16
+console.log(middleware);
17
+
18
+module.exports = function(bs) {
19
+ return {
20
+ "server": {
21
+ "baseDir": "",
22
+ "routes": {
23
+ "/node_modules": "node_modules",
24
+ "/assets": "assets"
25
+ }
26
+ },
27
+ middleware: [
28
+ middleware
29
+ ]
30
+
31
+
32
+ }
33
+}
securis/src/main/webapp/bs-config.json
deleted file mode 100644
....@@ -1,9 +0,0 @@
1
-{
2
- "server": {
3
- "baseDir": "",
4
- "routes": {
5
- "/node_modules": "node_modules",
6
- "/assets": "assets"
7
- }
8
- }
9
-}
securis/src/main/webapp/index.html
....@@ -19,13 +19,12 @@
1919 -->
2020
2121 <script src="jspm_packages/system.js"></script>
22
-
2322
23
+ <!-- <script src="main-bundle.js.gz"></script> -->
2424 <script src="jspm.browser.js"></script>
25
- <script src="jspm.config.js"></script>
26
- <!-- <script src="systemjs.config.js"></script> -->
25
+ <script src="jspm.config.js"></script>
2726 <script>
28
- System.import('main').catch(function(err){ console.error(err); });
27
+ System.import('src/main.js').catch(function(err){ console.error(err); });
2928 </script>
3029
3130 <!-- Load the Covalent platform stylesheet -->
....@@ -43,7 +42,7 @@
4342 <app-home>
4443 <div style="padding: 20%;text-align:center;">
4544 <img src="assets/securis_logo.svg" width="100">
46
- <div style="font-size: 0.8em;color: darkgrey;">SeCuris Loading2...</div>
45
+ <div style="font-size: 0.8em;color: darkgrey;">SeCuris Loading...</div>
4746 </div>
4847 </app-home>
4948 </body>
securis/src/main/webapp/jspm.browser.js
....@@ -1,7 +1,6 @@
11 SystemJS.config({
2
- paths: {
3
- "github:": "./jspm_packages/github/",
4
- "npm:": "./jspm_packages/npm/",
5
- "securis/": "./src/"
6
- }
2
+ "paths": {
3
+ "github:": "jspm_packages/github/",
4
+ "npm:": "jspm_packages/npm/"
5
+ }
76 });
securis/src/main/webapp/jspm.config.js
....@@ -2,8 +2,7 @@
22 nodeConfig: {
33 "paths": {
44 "github:": "jspm_packages/github/",
5
- "npm:": "jspm_packages/npm/",
6
- "app/": "src/app/"
5
+ "npm:": "jspm_packages/npm/"
76 }
87 },
98 devConfig: {
....@@ -27,23 +26,19 @@
2726 }
2827 }
2928 },
29
+ transpiler: false,
3030 packages: {
31
- 'environments': {
32
- defaultExtension: 'js'
31
+ "environments": {
32
+ "defaultExtension": "js"
3333 },
34
- 'app': {
35
- defaultExtension: 'js'
36
- },
37
- 'main': {
38
- main: 'main.js',
39
- defaultExtension: 'js'
34
+ "src": {
35
+ "defaultExtension": "js"
4036 }
4137 },
4238 map: {
4339 "@angular/animations/browser": "npm:@angular/animations@4.0.2/bundles/animations-browser.umd.min.js",
4440 "@angular/platform-browser/animations": "npm:@angular/platform-browser@4.0.2/bundles/platform-browser-animations.umd.min.js",
45
- 'main': 'src',
46
- 'app': 'src/app'
41
+ "app": "src/app"
4742 }
4843 });
4944
....@@ -334,4 +329,5 @@
334329 }
335330 }
336331 }
332
+
337333 });
securis/src/main/webapp/package.json
....@@ -6,7 +6,7 @@
66 "build": "tsc -p src/",
77 "build:watch": "tsc -p src/ -w",
88 "build:e2e": "tsc -p e2e/",
9
- "serve": "lite-server -c=bs-config.json",
9
+ "serve": "lite-server -c=bs-config.js",
1010 "serve:e2e": "lite-server -c=bs-config.e2e.json",
1111 "prestart": "npm run build",
1212 "start": "concurrently \"npm run build:watch\" \"npm run serve\"",
securis/src/main/webapp/src/app/forms/user.form.component.ts
....@@ -23,6 +23,12 @@
2323 organizations_ids: [ 1, 2, 5, 6, 7, 8 ]
2424 }
2525
26
+const ROL = {
27
+ ADVANCE: 1,
28
+ ADMIN: 2,
29
+ BASIC: 4
30
+}
31
+
2632 @Component({
2733 selector: 'user-form',
2834 templateUrl: 'src/app/forms/user.form.html'
....@@ -32,7 +38,9 @@
3238 allApplications: IComboOption[];
3339 orgNames: string[] = [];
3440 appNames: string[] = [];
35
- allRoles: any[] = [{"id":4, "code": "basic","label":"Basic"}, {"id":1, "code": "advance", "label":"Advance"}, {"id":2, "code": "admin","label":"Admin"}];
41
+ allRoles: any[] = [{"id":ROL.BASIC, "code": "basic","label":"Basic"},
42
+ {"id":ROL.ADVANCE, "code": "advance", "label":"Advance"},
43
+ {"id":ROL.ADMIN, "code": "admin","label":"Admin"}];
3644 user_orgs: string[] = [];
3745 user_apps: string[] = [];
3846 user_roles: any = {};
....@@ -59,8 +67,9 @@
5967 var selectedApp = this.allApplications.find(app => app.label === appName);
6068 this.data.applications_ids.push(selectedApp.id);
6169 });
62
- this.user_roles.advance && this.data.roles.push(1);
63
- this.user_roles.admin && this.data.roles.push(2);
70
+ this.user_roles.basic && this.data.roles.push(ROL.BASIC);
71
+ this.user_roles.advance && this.data.roles.push(ROL.ADVANCE);
72
+ this.user_roles.admin && this.data.roles.push(ROL.ADMIN);
6473 super.save('username');
6574 }
6675
securis/src/main/webapp/src/app/forms/user.form.html
....@@ -72,6 +72,9 @@
7272 [items]="orgNames" [(ngModel)]="user_orgs" name="user_orgs" requireMatch>
7373 </td-chips>
7474 <div layout="column" layout-fill flex="25">
75
+ <md-checkbox [(ngModel)]="user_roles.basic" name="basic_role" [mdTooltip]="$L.get('Role {}', 'basic')">
76
+ <span i18n>Basic</span>
77
+ </md-checkbox>
7578 <md-checkbox [(ngModel)]="user_roles.advance" name="advance_role" [mdTooltip]="$L.get('Role {}', 'advance')">
7679 <span i18n>Advance</span>
7780 </md-checkbox>
securis/src/main/webapp/src/main.ts
....@@ -9,5 +9,5 @@
99 if (environment.production) {
1010 enableProdMode();
1111 }
12
-
12
+// console.log('This is a test.')
1313 platformBrowserDynamic().bootstrapModule(AppModule);