@SuppressWarnings("rawtypes") @Test public void testGoodCreate() throws URISyntaxException { when(uriInfo.getRequestUri()).thenReturn(new URI("http: EntityBody app = getNewApp(); Response resp = resource.post(app, uriInfo); assertEquals(STATUS_CREATED, resp.getStatus()); assertTrue("Client id set", app.get(CLIENT_ID).toString().length() == 10); assertTrue("Client secret set", app.get(CLIENT_SECRET).toString().length() == 48); Map reg = (Map) app.get(REGISTRATION); assertEquals("Reg is pending", "PENDING", reg.get(STATUS)); assertTrue("request date set", reg.containsKey(REQUEST_DATE)); assertFalse("approval date not set", reg.containsKey(APPROVAL_DATE)); }
@POST @Override @RightsAllowed({ Right.DEV_APP_CRUD }) public Response post(EntityBody newApp, @Context final UriInfo uriInfo) { if (newApp.containsKey(CLIENT_SECRET) || newApp.containsKey(CLIENT_ID) || newApp.containsKey("id")) { EntityBody body = new EntityBody(); body.put(MESSAGE, "Auto-generated attribute (id|client_secret|client_id) specified in POST. " + "Remove attribute and try again."); return Response.status(Status.BAD_REQUEST).entity(body).build(); } if (missingRequiredUrls(newApp)) { EntityBody body = new EntityBody(); body.put(MESSAGE, "Applications that are not marked as installed must have a application url and redirect url"); return Response.status(Status.BAD_REQUEST).entity(body).build(); } newApp.put(AUTHORIZED_ED_ORGS, new ArrayList<String>()); String clientId = TokenGenerator.generateToken(CLIENT_ID_LENGTH); while (isDuplicateToken(clientId)) { clientId = TokenGenerator.generateToken(CLIENT_ID_LENGTH); } newApp.put(CLIENT_ID, clientId); SLIPrincipal principal = (SLIPrincipal) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); newApp.put(CREATED_BY, principal.getExternalId()); if (principal.getSandboxTenant() != null) { newApp.put(AUTHOR_SANDBOX_TENANT, principal.getSandboxTenant()); } if (principal.getFirstName() != null) { newApp.put(AUTHOR_FIRST_NAME, principal.getFirstName()); } if (principal.getLastName() != null) { newApp.put(AUTHOR_LAST_NAME, principal.getLastName()); } Map<String, Object> registration = new HashMap<String, Object>(); registration.put(STATUS, STATUS_PENDING); if (autoRegister) { registration.put(APPROVAL_DATE, System.currentTimeMillis()); registration.put(STATUS, STATUS_APPROVED); } registration.put(REQUEST_DATE, System.currentTimeMillis()); newApp.put(REGISTRATION, registration); String clientSecret = TokenGenerator.generateToken(CLIENT_SECRET_LENGTH); newApp.put(CLIENT_SECRET, clientSecret); for (String fieldName : PERMANENT_FIELDS) { newApp.remove(fieldName); } return super.post(newApp, uriInfo); }
ApplicationResource extends UnversionedResource { @POST @Override @RightsAllowed({ Right.DEV_APP_CRUD }) public Response post(EntityBody newApp, @Context final UriInfo uriInfo) { if (newApp.containsKey(CLIENT_SECRET) || newApp.containsKey(CLIENT_ID) || newApp.containsKey("id")) { EntityBody body = new EntityBody(); body.put(MESSAGE, "Auto-generated attribute (id|client_secret|client_id) specified in POST. " + "Remove attribute and try again."); return Response.status(Status.BAD_REQUEST).entity(body).build(); } if (missingRequiredUrls(newApp)) { EntityBody body = new EntityBody(); body.put(MESSAGE, "Applications that are not marked as installed must have a application url and redirect url"); return Response.status(Status.BAD_REQUEST).entity(body).build(); } newApp.put(AUTHORIZED_ED_ORGS, new ArrayList<String>()); String clientId = TokenGenerator.generateToken(CLIENT_ID_LENGTH); while (isDuplicateToken(clientId)) { clientId = TokenGenerator.generateToken(CLIENT_ID_LENGTH); } newApp.put(CLIENT_ID, clientId); SLIPrincipal principal = (SLIPrincipal) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); newApp.put(CREATED_BY, principal.getExternalId()); if (principal.getSandboxTenant() != null) { newApp.put(AUTHOR_SANDBOX_TENANT, principal.getSandboxTenant()); } if (principal.getFirstName() != null) { newApp.put(AUTHOR_FIRST_NAME, principal.getFirstName()); } if (principal.getLastName() != null) { newApp.put(AUTHOR_LAST_NAME, principal.getLastName()); } Map<String, Object> registration = new HashMap<String, Object>(); registration.put(STATUS, STATUS_PENDING); if (autoRegister) { registration.put(APPROVAL_DATE, System.currentTimeMillis()); registration.put(STATUS, STATUS_APPROVED); } registration.put(REQUEST_DATE, System.currentTimeMillis()); newApp.put(REGISTRATION, registration); String clientSecret = TokenGenerator.generateToken(CLIENT_SECRET_LENGTH); newApp.put(CLIENT_SECRET, clientSecret); for (String fieldName : PERMANENT_FIELDS) { newApp.remove(fieldName); } return super.post(newApp, uriInfo); } }
ApplicationResource extends UnversionedResource { @POST @Override @RightsAllowed({ Right.DEV_APP_CRUD }) public Response post(EntityBody newApp, @Context final UriInfo uriInfo) { if (newApp.containsKey(CLIENT_SECRET) || newApp.containsKey(CLIENT_ID) || newApp.containsKey("id")) { EntityBody body = new EntityBody(); body.put(MESSAGE, "Auto-generated attribute (id|client_secret|client_id) specified in POST. " + "Remove attribute and try again."); return Response.status(Status.BAD_REQUEST).entity(body).build(); } if (missingRequiredUrls(newApp)) { EntityBody body = new EntityBody(); body.put(MESSAGE, "Applications that are not marked as installed must have a application url and redirect url"); return Response.status(Status.BAD_REQUEST).entity(body).build(); } newApp.put(AUTHORIZED_ED_ORGS, new ArrayList<String>()); String clientId = TokenGenerator.generateToken(CLIENT_ID_LENGTH); while (isDuplicateToken(clientId)) { clientId = TokenGenerator.generateToken(CLIENT_ID_LENGTH); } newApp.put(CLIENT_ID, clientId); SLIPrincipal principal = (SLIPrincipal) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); newApp.put(CREATED_BY, principal.getExternalId()); if (principal.getSandboxTenant() != null) { newApp.put(AUTHOR_SANDBOX_TENANT, principal.getSandboxTenant()); } if (principal.getFirstName() != null) { newApp.put(AUTHOR_FIRST_NAME, principal.getFirstName()); } if (principal.getLastName() != null) { newApp.put(AUTHOR_LAST_NAME, principal.getLastName()); } Map<String, Object> registration = new HashMap<String, Object>(); registration.put(STATUS, STATUS_PENDING); if (autoRegister) { registration.put(APPROVAL_DATE, System.currentTimeMillis()); registration.put(STATUS, STATUS_APPROVED); } registration.put(REQUEST_DATE, System.currentTimeMillis()); newApp.put(REGISTRATION, registration); String clientSecret = TokenGenerator.generateToken(CLIENT_SECRET_LENGTH); newApp.put(CLIENT_SECRET, clientSecret); for (String fieldName : PERMANENT_FIELDS) { newApp.remove(fieldName); } return super.post(newApp, uriInfo); } @Autowired  ApplicationResource(EntityDefinitionStore entityDefs); }
ApplicationResource extends UnversionedResource { @POST @Override @RightsAllowed({ Right.DEV_APP_CRUD }) public Response post(EntityBody newApp, @Context final UriInfo uriInfo) { if (newApp.containsKey(CLIENT_SECRET) || newApp.containsKey(CLIENT_ID) || newApp.containsKey("id")) { EntityBody body = new EntityBody(); body.put(MESSAGE, "Auto-generated attribute (id|client_secret|client_id) specified in POST. " + "Remove attribute and try again."); return Response.status(Status.BAD_REQUEST).entity(body).build(); } if (missingRequiredUrls(newApp)) { EntityBody body = new EntityBody(); body.put(MESSAGE, "Applications that are not marked as installed must have a application url and redirect url"); return Response.status(Status.BAD_REQUEST).entity(body).build(); } newApp.put(AUTHORIZED_ED_ORGS, new ArrayList<String>()); String clientId = TokenGenerator.generateToken(CLIENT_ID_LENGTH); while (isDuplicateToken(clientId)) { clientId = TokenGenerator.generateToken(CLIENT_ID_LENGTH); } newApp.put(CLIENT_ID, clientId); SLIPrincipal principal = (SLIPrincipal) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); newApp.put(CREATED_BY, principal.getExternalId()); if (principal.getSandboxTenant() != null) { newApp.put(AUTHOR_SANDBOX_TENANT, principal.getSandboxTenant()); } if (principal.getFirstName() != null) { newApp.put(AUTHOR_FIRST_NAME, principal.getFirstName()); } if (principal.getLastName() != null) { newApp.put(AUTHOR_LAST_NAME, principal.getLastName()); } Map<String, Object> registration = new HashMap<String, Object>(); registration.put(STATUS, STATUS_PENDING); if (autoRegister) { registration.put(APPROVAL_DATE, System.currentTimeMillis()); registration.put(STATUS, STATUS_APPROVED); } registration.put(REQUEST_DATE, System.currentTimeMillis()); newApp.put(REGISTRATION, registration); String clientSecret = TokenGenerator.generateToken(CLIENT_SECRET_LENGTH); newApp.put(CLIENT_SECRET, clientSecret); for (String fieldName : PERMANENT_FIELDS) { newApp.remove(fieldName); } return super.post(newApp, uriInfo); } @Autowired  ApplicationResource(EntityDefinitionStore entityDefs); void setAutoRegister(boolean register); @PostConstruct void init(); @POST @Override @RightsAllowed({ Right.DEV_APP_CRUD }) Response post(EntityBody newApp, @Context final UriInfo uriInfo); @SuppressWarnings("rawtypes") @GET @RightsAllowed({ Right.APP_AUTHORIZE, Right.ADMIN_ACCESS }) @Override Response getAll(@Context final UriInfo uriInfo); @SuppressWarnings("rawtypes") @GET @Override @Path("{" + UUID + "}") @RightsAllowed({ Right.APP_AUTHORIZE, Right.ADMIN_ACCESS }) Response getWithId(@PathParam(UUID) String uuid, @Context final UriInfo uriInfo); @DELETE @Override @Path("{" + UUID + "}") @RightsAllowed({ Right.DEV_APP_CRUD }) Response delete(@PathParam(UUID) String uuid, @Context final UriInfo uriInfo); @SuppressWarnings("unchecked") @PUT @Path("{" + UUID + "}") @RightsAllowed({ Right.DEV_APP_CRUD, Right.SLC_APP_APPROVE}) @Override Response put(@PathParam(UUID) String uuid, EntityBody app, @Context final UriInfo uriInfo); boolean isSandboxEnabled(); void setSandboxEnabled(boolean sandboxEnabled); }
ApplicationResource extends UnversionedResource { @POST @Override @RightsAllowed({ Right.DEV_APP_CRUD }) public Response post(EntityBody newApp, @Context final UriInfo uriInfo) { if (newApp.containsKey(CLIENT_SECRET) || newApp.containsKey(CLIENT_ID) || newApp.containsKey("id")) { EntityBody body = new EntityBody(); body.put(MESSAGE, "Auto-generated attribute (id|client_secret|client_id) specified in POST. " + "Remove attribute and try again."); return Response.status(Status.BAD_REQUEST).entity(body).build(); } if (missingRequiredUrls(newApp)) { EntityBody body = new EntityBody(); body.put(MESSAGE, "Applications that are not marked as installed must have a application url and redirect url"); return Response.status(Status.BAD_REQUEST).entity(body).build(); } newApp.put(AUTHORIZED_ED_ORGS, new ArrayList<String>()); String clientId = TokenGenerator.generateToken(CLIENT_ID_LENGTH); while (isDuplicateToken(clientId)) { clientId = TokenGenerator.generateToken(CLIENT_ID_LENGTH); } newApp.put(CLIENT_ID, clientId); SLIPrincipal principal = (SLIPrincipal) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); newApp.put(CREATED_BY, principal.getExternalId()); if (principal.getSandboxTenant() != null) { newApp.put(AUTHOR_SANDBOX_TENANT, principal.getSandboxTenant()); } if (principal.getFirstName() != null) { newApp.put(AUTHOR_FIRST_NAME, principal.getFirstName()); } if (principal.getLastName() != null) { newApp.put(AUTHOR_LAST_NAME, principal.getLastName()); } Map<String, Object> registration = new HashMap<String, Object>(); registration.put(STATUS, STATUS_PENDING); if (autoRegister) { registration.put(APPROVAL_DATE, System.currentTimeMillis()); registration.put(STATUS, STATUS_APPROVED); } registration.put(REQUEST_DATE, System.currentTimeMillis()); newApp.put(REGISTRATION, registration); String clientSecret = TokenGenerator.generateToken(CLIENT_SECRET_LENGTH); newApp.put(CLIENT_SECRET, clientSecret); for (String fieldName : PERMANENT_FIELDS) { newApp.remove(fieldName); } return super.post(newApp, uriInfo); } @Autowired  ApplicationResource(EntityDefinitionStore entityDefs); void setAutoRegister(boolean register); @PostConstruct void init(); @POST @Override @RightsAllowed({ Right.DEV_APP_CRUD }) Response post(EntityBody newApp, @Context final UriInfo uriInfo); @SuppressWarnings("rawtypes") @GET @RightsAllowed({ Right.APP_AUTHORIZE, Right.ADMIN_ACCESS }) @Override Response getAll(@Context final UriInfo uriInfo); @SuppressWarnings("rawtypes") @GET @Override @Path("{" + UUID + "}") @RightsAllowed({ Right.APP_AUTHORIZE, Right.ADMIN_ACCESS }) Response getWithId(@PathParam(UUID) String uuid, @Context final UriInfo uriInfo); @DELETE @Override @Path("{" + UUID + "}") @RightsAllowed({ Right.DEV_APP_CRUD }) Response delete(@PathParam(UUID) String uuid, @Context final UriInfo uriInfo); @SuppressWarnings("unchecked") @PUT @Path("{" + UUID + "}") @RightsAllowed({ Right.DEV_APP_CRUD, Right.SLC_APP_APPROVE}) @Override Response put(@PathParam(UUID) String uuid, EntityBody app, @Context final UriInfo uriInfo); boolean isSandboxEnabled(); void setSandboxEnabled(boolean sandboxEnabled); static final String AUTHORIZED_ED_ORGS; static final String APPLICATION; static final String MESSAGE; static final String STATUS_PENDING; static final String STATUS_APPROVED; static final String REGISTRATION; static final String CLIENT_ID; static final String CLIENT_SECRET; static final String APPROVAL_DATE; static final String REQUEST_DATE; static final String STATUS; static final String RESOURCE_NAME; static final String UUID; static final String LOCATION; }