securis/src/main/java/net/curisit/securis/db/Pack.java
.. .. @@ -44,7 +44,7 @@ 44 44 @NamedQuery(name = "pack-by-code", query = "SELECT pa FROM Pack pa where pa.code = :code"), // 45 45 @NamedQuery(name = "list-packs-by-lic-type", query = "SELECT pa FROM Pack pa where pa.licenseType.id = :lt_id"), // 46 46 @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 ") })48 48 public class Pack implements Serializable { 49 49 50 50 private static final long serialVersionUID = 1L; securis/src/main/java/net/curisit/securis/db/User.java
.. .. @@ -294,7 +294,8 @@ 294 294 public static final int ADVANCE = 0x01; 295 295 public static final int ADMIN = 0x02; 296 296 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 client298 299 } 299 300 300 301 } securis/src/main/java/net/curisit/securis/services/ApiResource.java
.. .. @@ -35,6 +35,7 @@ 35 35 import net.curisit.securis.db.LicenseStatus; 36 36 import net.curisit.securis.db.Pack; 37 37 import net.curisit.securis.db.User; 38 +import net.curisit.securis.db.User.Rol;38 39 import net.curisit.securis.ioc.EnsureTransaction; 39 40 import net.curisit.securis.security.BasicSecurityContext; 40 41 import net.curisit.securis.security.Securable; .. .. @@ -111,7 +112,7 @@ 111 112 @POST 112 113 @Path("/request") 113 114 @Consumes(MediaType.APPLICATION_JSON) 114 - @Securable115 + @Securable(roles = Rol.API_CLIENT)115 116 @Produces({ MediaType.APPLICATION_JSON }) 116 117 @EnsureTransaction 117 118 public Response createFromRequest(RequestBean request, @HeaderParam(LicenseManager.HEADER_LICENSE_NAME_OR_REFERENCE) String nameOrReference, .. .. @@ -135,7 +136,7 @@ 135 136 @POST 136 137 @Path("/request") 137 138 @Consumes(MediaType.MULTIPART_FORM_DATA) 138 - @Securable139 + @Securable(roles = Rol.API_CLIENT)139 140 @Produces({ MediaType.APPLICATION_JSON }) 140 141 @EnsureTransaction 141 142 @SuppressWarnings("unchecked") .. .. @@ -168,7 +169,7 @@ 168 169 @POST 169 170 @Path("/renew") 170 171 @Consumes(MediaType.APPLICATION_JSON) 171 - @Securable172 + @Securable(roles = Rol.API_CLIENT)172 173 @Produces({ MediaType.APPLICATION_JSON }) 173 174 @EnsureTransaction 174 175 public Response renewFromPreviousLicense(LicenseBean previousLic, @Context BasicSecurityContext bsc) throws IOException, SeCurisServiceException, SeCurisException { .. .. @@ -208,7 +209,7 @@ 208 209 @POST 209 210 @Path("/validate") 210 211 @Consumes(MediaType.APPLICATION_JSON) 211 - @Securable212 + @Securable(roles = Rol.API_CLIENT)212 213 @Produces({ MediaType.APPLICATION_JSON }) 213 214 @EnsureTransaction 214 215 public Response validate(LicenseBean currentLic, @Context BasicSecurityContext bsc) throws IOException, SeCurisServiceException, SeCurisException { .. .. @@ -242,7 +243,7 @@ 242 243 @POST 243 244 @Path("/renew") 244 245 @Consumes(MediaType.MULTIPART_FORM_DATA) 245 - @Securable246 + @Securable(roles = Rol.API_CLIENT)246 247 @Produces({ MediaType.APPLICATION_JSON }) 247 248 @EnsureTransaction 248 249 @SuppressWarnings("unchecked") securis/src/main/java/net/curisit/securis/services/ApplicationResource.java
.. .. @@ -32,6 +32,7 @@ 32 32 import net.curisit.securis.DefaultExceptionHandler; 33 33 import net.curisit.securis.db.Application; 34 34 import net.curisit.securis.db.ApplicationMetadata; 35 +import net.curisit.securis.db.User.Rol;35 36 import net.curisit.securis.ioc.EnsureTransaction; 36 37 import net.curisit.securis.security.BasicSecurityContext; 37 38 import net.curisit.securis.security.Securable; .. .. @@ -120,7 +121,7 @@ 120 121 @Consumes(MediaType.APPLICATION_JSON) 121 122 @Produces({ MediaType.APPLICATION_JSON }) 122 123 @EnsureTransaction 123 - @Securable124 + @Securable(roles = Rol.ADMIN)124 125 @RolesAllowed(BasicSecurityContext.ROL_ADMIN) 125 126 public Response create(Application app, @HeaderParam(TokenHelper.TOKEN_HEADER_PÀRAM) String token) { 126 127 LOG.info("Creating new application"); .. .. @@ -146,7 +147,7 @@ 146 147 @EnsureTransaction 147 148 @Consumes(MediaType.APPLICATION_JSON) 148 149 @Produces({ MediaType.APPLICATION_JSON }) 149 - @Securable150 + @Securable(roles = Rol.ADMIN)150 151 @RolesAllowed(BasicSecurityContext.ROL_ADMIN) 151 152 public Response modify(Application app, @PathParam("appid") String appid, @HeaderParam(TokenHelper.TOKEN_HEADER_PÀRAM) String token) { 152 153 LOG.info("Modifying application with id: {}", appid); .. .. @@ -209,7 +210,7 @@ 209 210 @Path("/{appid}") 210 211 @EnsureTransaction 211 212 @Produces({ MediaType.APPLICATION_JSON }) 212 - @Securable213 + @Securable(roles = Rol.ADMIN)213 214 @RolesAllowed(BasicSecurityContext.ROL_ADMIN) 214 215 public Response delete(@PathParam("appid") String appid, @Context HttpServletRequest request) { 215 216 LOG.info("Deleting app with id: {}", appid); securis/src/main/java/net/curisit/securis/services/LicenseResource.java
.. .. @@ -49,6 +49,7 @@ 49 49 import net.curisit.securis.db.Pack; 50 50 import net.curisit.securis.db.PackStatus; 51 51 import net.curisit.securis.db.User; 52 +import net.curisit.securis.db.User.Rol;52 53 import net.curisit.securis.ioc.EnsureTransaction; 53 54 import net.curisit.securis.security.BasicSecurityContext; 54 55 import net.curisit.securis.security.Securable; .. .. @@ -175,7 +176,7 @@ 175 176 @PUT 176 177 @POST 177 178 @Path("/{licId}/activate") 178 - @Securable179 + @Securable(roles = Rol.ADMIN | Rol.ADVANCE)179 180 @EnsureTransaction 180 181 @Consumes(MediaType.APPLICATION_JSON) 181 182 @Produces({ MediaType.APPLICATION_JSON }) .. .. @@ -220,7 +221,7 @@ 220 221 @PUT 221 222 @POST 222 223 @Path("/{licId}/send") 223 - @Securable224 + @Securable(roles = Rol.ADMIN | Rol.ADVANCE)224 225 @EnsureTransaction 225 226 @Consumes(MediaType.APPLICATION_JSON) 226 227 @Produces({ MediaType.APPLICATION_JSON }) .. .. @@ -274,7 +275,7 @@ 274 275 @PUT 275 276 @POST 276 277 @Path("/{licId}/cancel") 277 - @Securable278 + @Securable(roles = Rol.ADMIN | Rol.ADVANCE)278 279 @EnsureTransaction 279 280 @Consumes(MediaType.APPLICATION_JSON) 280 281 @Produces({ MediaType.APPLICATION_JSON }) .. .. @@ -317,7 +318,7 @@ 317 318 @POST 318 319 @Path("/") 319 320 @Consumes(MediaType.APPLICATION_JSON) 320 - @Securable321 + @Securable(roles = Rol.ADMIN | Rol.ADVANCE)321 322 @Produces({ MediaType.APPLICATION_JSON }) 322 323 @EnsureTransaction 323 324 public Response create(License lic, @Context BasicSecurityContext bsc) throws SeCurisServiceException { .. .. @@ -456,7 +457,7 @@ 456 457 @PUT 457 458 @POST 458 459 @Path("/{licId}") 459 - @Securable460 + @Securable(roles = Rol.ADMIN | Rol.ADVANCE)460 461 @EnsureTransaction 461 462 @Consumes(MediaType.APPLICATION_JSON) 462 463 @Produces({ MediaType.APPLICATION_JSON }) .. .. @@ -506,7 +507,7 @@ 506 507 @DELETE 507 508 @Path("/{licId}") 508 509 @EnsureTransaction 509 - @Securable510 + @Securable(roles = Rol.ADMIN | Rol.ADVANCE)510 511 @Produces({ MediaType.APPLICATION_JSON }) 511 512 public Response delete(@PathParam("licId") Integer licId, @Context BasicSecurityContext bsc) throws SeCurisServiceException { 512 513 LOG.info("Deleting license with id: {}", licId); .. .. @@ -536,7 +537,7 @@ 536 537 @POST 537 538 @Path("/{licId}/block") 538 539 @EnsureTransaction 539 - @Securable540 + @Securable(roles = Rol.ADMIN | Rol.ADVANCE)540 541 @Produces({ MediaType.APPLICATION_JSON }) 541 542 public Response block(@PathParam("licId") Integer licId, @Context BasicSecurityContext bsc) throws SeCurisServiceException { 542 543 LOG.info("Blocking license with id: {}", licId); .. .. @@ -567,7 +568,7 @@ 567 568 @POST 568 569 @Path("/{licId}/unblock") 569 570 @EnsureTransaction 570 - @Securable571 + @Securable(roles = Rol.ADMIN | Rol.ADVANCE)571 572 @Produces({ MediaType.APPLICATION_JSON }) 572 573 public Response unblock(@PathParam("licId") Integer licId, @Context BasicSecurityContext bsc) throws SeCurisServiceException { 573 574 LOG.info("Unblocking license with id: {}", licId); securis/src/main/java/net/curisit/securis/services/LicenseTypeResource.java
.. .. @@ -34,6 +34,7 @@ 34 34 import net.curisit.securis.db.Application; 35 35 import net.curisit.securis.db.LicenseType; 36 36 import net.curisit.securis.db.LicenseTypeMetadata; 37 +import net.curisit.securis.db.User.Rol;37 38 import net.curisit.securis.ioc.EnsureTransaction; 38 39 import net.curisit.securis.security.BasicSecurityContext; 39 40 import net.curisit.securis.security.Securable; .. .. @@ -115,7 +116,7 @@ 115 116 @Consumes(MediaType.APPLICATION_JSON) 116 117 @Produces({ MediaType.APPLICATION_JSON }) 117 118 @EnsureTransaction 118 - @Securable119 + @Securable(roles = Rol.ADMIN)119 120 @RolesAllowed(BasicSecurityContext.ROL_ADMIN) 120 121 public Response create(LicenseType lt, @HeaderParam(TokenHelper.TOKEN_HEADER_PÀRAM) String token) { 121 122 LOG.info("Creating new license type"); .. .. @@ -163,7 +164,7 @@ 163 164 @EnsureTransaction 164 165 @Consumes(MediaType.APPLICATION_JSON) 165 166 @Produces({ MediaType.APPLICATION_JSON }) 166 - @Securable167 + @Securable(roles = Rol.ADMIN)167 168 @RolesAllowed(BasicSecurityContext.ROL_ADMIN) 168 169 public Response modify(LicenseType lt, @PathParam("ltid") String ltid, @HeaderParam(TokenHelper.TOKEN_HEADER_PÀRAM) String token) { 169 170 LOG.info("Modifying license type with id: {}", ltid); .. .. @@ -236,7 +237,7 @@ 236 237 @Path("/{ltid}") 237 238 @EnsureTransaction 238 239 @Produces({ MediaType.APPLICATION_JSON }) 239 - @Securable240 + @Securable(roles = Rol.ADMIN)240 241 @RolesAllowed(BasicSecurityContext.ROL_ADMIN) 241 242 public Response delete(@PathParam("ltid") String ltid, @Context HttpServletRequest request) { 242 243 LOG.info("Deleting app with id: {}", ltid); securis/src/main/java/net/curisit/securis/services/OrganizationResource.java
.. .. @@ -24,18 +24,19 @@ 24 24 import javax.ws.rs.core.Response; 25 25 import javax.ws.rs.core.Response.Status; 26 26 27 +import org.apache.logging.log4j.LogManager;28 +import org.apache.logging.log4j.Logger;29 +27 30 import net.curisit.integrity.commons.Utils; 28 31 import net.curisit.securis.DefaultExceptionHandler; 29 32 import net.curisit.securis.SeCurisException; 30 33 import net.curisit.securis.db.Organization; 31 34 import net.curisit.securis.db.User; 35 +import net.curisit.securis.db.User.Rol;32 36 import net.curisit.securis.ioc.EnsureTransaction; 33 37 import net.curisit.securis.security.BasicSecurityContext; 34 38 import net.curisit.securis.security.Securable; 35 39 import net.curisit.securis.utils.TokenHelper; 36 -37 -import org.apache.logging.log4j.LogManager;38 -import org.apache.logging.log4j.Logger;39 40 40 41 /** 41 42 * Organization resource, this service will provide methods to create, modify .. .. @@ -47,225 +48,207 @@ 47 48 @RequestScoped 48 49 public class OrganizationResource { 49 50 50 - private static final Logger LOG = LogManager.getLogger(OrganizationResource.class);51 + private static final Logger LOG = LogManager.getLogger(OrganizationResource.class);51 52 52 - @Context53 - EntityManager em;53 + @Context54 + EntityManager em;54 55 55 - @Context56 - BasicSecurityContext bsc;56 + @Context57 + BasicSecurityContext bsc;57 58 58 - public OrganizationResource() {59 - }59 + public OrganizationResource() {60 + }60 61 61 - /**62 - *63 - * @return the server version in format majorVersion.minorVersion64 - */65 - @GET66 - @Path("/")67 - @Produces({68 - MediaType.APPLICATION_JSON69 - })70 - @Securable71 - public Response index() {72 - LOG.info("Getting organizations list ");62 + /**63 + *64 + * @return the server version in format majorVersion.minorVersion65 + */66 + @GET67 + @Path("/")68 + @Produces({ MediaType.APPLICATION_JSON })69 + @Securable70 + public Response index() {71 + LOG.info("Getting organizations list ");73 72 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 + }83 82 84 - List<Organization> list = q.getResultList();83 + List<Organization> list = q.getResultList();85 84 86 - return Response.ok(list).build();87 - }85 + return Response.ok(list).build();86 + }88 87 89 - /**90 - *91 - * @return the server version in format majorVersion.minorVersion92 - */93 - @GET94 - @Path("/{orgid}")95 - @Produces({96 - MediaType.APPLICATION_JSON97 - })98 - @Securable99 - 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.minorVersion91 + */92 + @GET93 + @Path("/{orgid}")94 + @Produces({ MediaType.APPLICATION_JSON })95 + @Securable96 + 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 + }105 102 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 + }116 112 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 + }126 122 127 - @POST128 - @Path("/")129 - @Consumes(MediaType.APPLICATION_JSON)130 - @Produces({131 - MediaType.APPLICATION_JSON132 - })133 - @EnsureTransaction134 - @Securable135 - @RolesAllowed(BasicSecurityContext.ROL_ADMIN)136 - public Response create(Organization org) {137 - LOG.info("Creating new organization");138 - // EntityManager em = emProvider.get();123 + @POST124 + @Path("/")125 + @Consumes(MediaType.APPLICATION_JSON)126 + @Produces({ MediaType.APPLICATION_JSON })127 + @EnsureTransaction128 + @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();139 133 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 + }145 139 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 + }160 153 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 + }166 159 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 + }176 169 177 - org.setParentOrganization(parentOrg);178 - }170 + org.setParentOrganization(parentOrg);171 + }179 172 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 + }193 186 194 - org.setUsers(users);195 - }187 + org.setUsers(users);188 + }196 189 197 - @PUT198 - @POST199 - @Path("/{orgid}")200 - @Consumes(MediaType.APPLICATION_JSON)201 - @Produces({202 - MediaType.APPLICATION_JSON203 - })204 - @EnsureTransaction205 - @Securable206 - @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 Response224 - .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 + @PUT191 + @POST192 + @Path("/{orgid}")193 + @Consumes(MediaType.APPLICATION_JSON)194 + @Produces({ MediaType.APPLICATION_JSON })195 + @EnsureTransaction196 + @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 + }229 216 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 + }235 222 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);240 227 241 - return Response.ok(currentOrg).build();242 - }228 + return Response.ok(currentOrg).build();229 + }243 230 244 - @DELETE245 - @Path("/{orgid}")246 - @EnsureTransaction247 - @Produces({248 - MediaType.APPLICATION_JSON249 - })250 - @Securable251 - @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 + @DELETE232 + @Path("/{orgid}")233 + @EnsureTransaction234 + @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 + }266 249 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 + }270 253 271 254 } securis/src/main/java/net/curisit/securis/services/PackResource.java
.. .. @@ -38,6 +38,7 @@ 38 38 import net.curisit.securis.db.PackMetadata; 39 39 import net.curisit.securis.db.PackStatus; 40 40 import net.curisit.securis.db.User; 41 +import net.curisit.securis.db.User.Rol;41 42 import net.curisit.securis.ioc.EnsureTransaction; 42 43 import net.curisit.securis.security.BasicSecurityContext; 43 44 import net.curisit.securis.security.Securable; .. .. @@ -90,12 +91,15 @@ 90 91 LOG.info("Getting all packs for user: " + bsc.getUserPrincipal()); 91 92 q = em.createNamedQuery("list-packs", Pack.class); 92 93 } else { 93 - if (bsc.getOrganizationsIds() == null || bsc.getOrganizationsIds().isEmpty() || //94 - bsc.getApplicationsIds() == null || bsc.getApplicationsIds().isEmpty()) {94 + if (bsc.getApplicationsIds() == null || bsc.getApplicationsIds().isEmpty()) {95 95 return Response.ok().build(); 96 96 } 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 + }99 103 q.setParameter("list_ids_app", bsc.getApplicationsIds()); 100 104 LOG.info("Getting packs from orgs: {} and apps: {}", bsc.getOrganizationsIds(), bsc.getApplicationsIds()); 101 105 } .. .. @@ -140,7 +144,7 @@ 140 144 141 145 @POST 142 146 @Path("/") 143 - @Securable147 + @Securable(roles = Rol.ADMIN | Rol.ADVANCE)144 148 @RolesAllowed(BasicSecurityContext.ROL_ADMIN) 145 149 @Consumes(MediaType.APPLICATION_JSON) 146 150 @Produces({ MediaType.APPLICATION_JSON }) .. .. @@ -207,7 +211,7 @@ 207 211 */ 208 212 @GET 209 213 @Path("/{packId}/next_license_code") 210 - @Securable214 + @Securable(roles = Rol.ADMIN | Rol.ADVANCE)211 215 @Produces({ MediaType.TEXT_PLAIN }) 212 216 public Response getCodeSuffix(@PathParam("packId") Integer packId, @Context BasicSecurityContext bsc) throws SeCurisServiceException { 213 217 // EntityManager em = emProvider.get(); .. .. @@ -249,7 +253,7 @@ 249 253 @POST 250 254 @Path("/{packId}") 251 255 @EnsureTransaction 252 - @Securable256 + @Securable(roles = Rol.ADMIN | Rol.ADVANCE)253 257 @RolesAllowed(BasicSecurityContext.ROL_ADMIN) 254 258 @Consumes(MediaType.APPLICATION_JSON) 255 259 @Produces({ MediaType.APPLICATION_JSON }) .. .. @@ -314,7 +318,7 @@ 314 318 @POST 315 319 @Path("/{packId}/activate") 316 320 @EnsureTransaction 317 - @Securable321 + @Securable(roles = Rol.ADMIN | Rol.ADVANCE)318 322 @RolesAllowed(BasicSecurityContext.ROL_ADMIN) 319 323 @Consumes(MediaType.APPLICATION_JSON) 320 324 @Produces({ MediaType.APPLICATION_JSON }) .. .. @@ -338,7 +342,7 @@ 338 342 @POST 339 343 @Path("/{packId}/putonhold") 340 344 @EnsureTransaction 341 - @Securable345 + @Securable(roles = Rol.ADMIN | Rol.ADVANCE)342 346 @RolesAllowed(BasicSecurityContext.ROL_ADMIN) 343 347 @Consumes(MediaType.APPLICATION_JSON) 344 348 @Produces({ MediaType.APPLICATION_JSON }) .. .. @@ -362,7 +366,7 @@ 362 366 @POST 363 367 @Path("/{packId}/cancel") 364 368 @EnsureTransaction 365 - @Securable369 + @Securable(roles = Rol.ADMIN | Rol.ADVANCE)366 370 @RolesAllowed(BasicSecurityContext.ROL_ADMIN) 367 371 @Consumes(MediaType.APPLICATION_JSON) 368 372 @Produces({ MediaType.APPLICATION_JSON }) .. .. @@ -403,7 +407,7 @@ 403 407 404 408 @DELETE 405 409 @Path("/{packId}") 406 - @Securable410 + @Securable(roles = Rol.ADMIN | Rol.ADVANCE)407 411 @RolesAllowed(BasicSecurityContext.ROL_ADMIN) 408 412 @EnsureTransaction 409 413 @Produces({ MediaType.APPLICATION_JSON }) securis/src/main/java/net/curisit/securis/services/UserResource.java
.. .. @@ -37,6 +37,7 @@ 37 37 import net.curisit.securis.db.Application; 38 38 import net.curisit.securis.db.Organization; 39 39 import net.curisit.securis.db.User; 40 +import net.curisit.securis.db.User.Rol;40 41 import net.curisit.securis.ioc.EnsureTransaction; 41 42 import net.curisit.securis.security.BasicSecurityContext; 42 43 import net.curisit.securis.security.Securable; .. .. @@ -120,7 +121,7 @@ 120 121 @Consumes(MediaType.APPLICATION_JSON) 121 122 @Produces({ MediaType.APPLICATION_JSON }) 122 123 @EnsureTransaction 123 - @Securable124 + @Securable(roles = Rol.ADMIN)124 125 @RolesAllowed(BasicSecurityContext.ROL_ADMIN) 125 126 public Response create(User user, @HeaderParam(TokenHelper.TOKEN_HEADER_PÀRAM) String token) { 126 127 LOG.info("Creating new user"); .. .. @@ -196,7 +197,7 @@ 196 197 @EnsureTransaction 197 198 @Consumes(MediaType.APPLICATION_JSON) 198 199 @Produces({ MediaType.APPLICATION_JSON }) 199 - @Securable200 + @Securable(roles = Rol.ADMIN)200 201 @RolesAllowed(BasicSecurityContext.ROL_ADMIN) 201 202 public Response modify(User user, @PathParam("uid") String uid, @HeaderParam(TokenHelper.TOKEN_HEADER_PÀRAM) String token) { 202 203 LOG.info("Modifying user with id: {}", uid); .. .. @@ -241,7 +242,7 @@ 241 242 @Path("/{uid}") 242 243 @EnsureTransaction 243 244 @Produces({ MediaType.APPLICATION_JSON }) 244 - @Securable245 + @Securable(roles = Rol.ADMIN)245 246 @RolesAllowed(BasicSecurityContext.ROL_ADMIN) 246 247 public Response delete(@PathParam("uid") String uid, @Context HttpServletRequest request) { 247 248 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 + middleware29 + ]30 +31 +32 + }33 +}securis/src/main/webapp/bs-config.jsondeleted 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 @@ 19 19 --> 20 20 21 21 <script src="jspm_packages/system.js"></script> 22 -23 22 23 + <!-- <script src="main-bundle.js.gz"></script> -->24 24 <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>27 26 <script> 28 - System.import('main').catch(function(err){ console.error(err); });27 + System.import('src/main.js').catch(function(err){ console.error(err); });29 28 </script> 30 29 31 30 <!-- Load the Covalent platform stylesheet --> .. .. @@ -43,7 +42,7 @@ 43 42 <app-home> 44 43 <div style="padding: 20%;text-align:center;"> 45 44 <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>47 46 </div> 48 47 </app-home> 49 48 </body> securis/src/main/webapp/jspm.browser.js
.. .. @@ -1,7 +1,6 @@ 1 1 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 + }7 6 }); securis/src/main/webapp/jspm.config.js
.. .. @@ -2,8 +2,7 @@ 2 2 nodeConfig: { 3 3 "paths": { 4 4 "github:": "jspm_packages/github/", 5 - "npm:": "jspm_packages/npm/",6 - "app/": "src/app/"5 + "npm:": "jspm_packages/npm/"7 6 } 8 7 }, 9 8 devConfig: { .. .. @@ -27,23 +26,19 @@ 27 26 } 28 27 } 29 28 }, 29 + transpiler: false,30 30 packages: { 31 - 'environments': {32 - defaultExtension: 'js'31 + "environments": {32 + "defaultExtension": "js"33 33 }, 34 - 'app': {35 - defaultExtension: 'js'36 - },37 - 'main': {38 - main: 'main.js',39 - defaultExtension: 'js'34 + "src": {35 + "defaultExtension": "js"40 36 } 41 37 }, 42 38 map: { 43 39 "@angular/animations/browser": "npm:@angular/animations@4.0.2/bundles/animations-browser.umd.min.js", 44 40 "@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"47 42 } 48 43 }); 49 44 .. .. @@ -334,4 +329,5 @@ 334 329 } 335 330 } 336 331 } 332 +337 333 }); securis/src/main/webapp/package.json
.. .. @@ -6,7 +6,7 @@ 6 6 "build": "tsc -p src/", 7 7 "build:watch": "tsc -p src/ -w", 8 8 "build:e2e": "tsc -p e2e/", 9 - "serve": "lite-server -c=bs-config.json",9 + "serve": "lite-server -c=bs-config.js",10 10 "serve:e2e": "lite-server -c=bs-config.e2e.json", 11 11 "prestart": "npm run build", 12 12 "start": "concurrently \"npm run build:watch\" \"npm run serve\"", securis/src/main/webapp/src/app/forms/user.form.component.ts
.. .. @@ -23,6 +23,12 @@ 23 23 organizations_ids: [ 1, 2, 5, 6, 7, 8 ] 24 24 } 25 25 26 +const ROL = {27 + ADVANCE: 1,28 + ADMIN: 2,29 + BASIC: 430 +}31 +26 32 @Component({ 27 33 selector: 'user-form', 28 34 templateUrl: 'src/app/forms/user.form.html' .. .. @@ -32,7 +38,9 @@ 32 38 allApplications: IComboOption[]; 33 39 orgNames: string[] = []; 34 40 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"}];36 44 user_orgs: string[] = []; 37 45 user_apps: string[] = []; 38 46 user_roles: any = {}; .. .. @@ -59,8 +67,9 @@ 59 67 var selectedApp = this.allApplications.find(app => app.label === appName); 60 68 this.data.applications_ids.push(selectedApp.id); 61 69 }); 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);64 73 super.save('username'); 65 74 } 66 75 securis/src/main/webapp/src/app/forms/user.form.html
.. .. @@ -72,6 +72,9 @@ 72 72 [items]="orgNames" [(ngModel)]="user_orgs" name="user_orgs" requireMatch> 73 73 </td-chips> 74 74 <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>75 78 <md-checkbox [(ngModel)]="user_roles.advance" name="advance_role" [mdTooltip]="$L.get('Role {}', 'advance')"> 76 79 <span i18n>Advance</span> 77 80 </md-checkbox> securis/src/main/webapp/src/main.ts
.. .. @@ -9,5 +9,5 @@ 9 9 if (environment.production) { 10 10 enableProdMode(); 11 11 } 12 -12 +// console.log('This is a test.')13 13 platformBrowserDynamic().bootstrapModule(AppModule);