/** * 验证是否有访问权限 * @param entity entity名称 * @param access 访问权限: read, create, update, destroy * @return */ public boolean hasPermission(Object entity, Object access) { if (Strings.isNullOrEmpty(permissions)) return false; Map ps = JsonParserFactory.getJsonParser().parseMap(permissions); String entityName; if (entity instanceof String) { entityName = (String) entity; } else { entityName = (String) entity; } String permission; if (access instanceof Permission) { permission = ((Permission) access).name(); } else { permission = (String) access; } if (ps.containsKey(entityName)) { List<String> methodNames = (List<String>) ps.get(entityName); return methodNames.stream().filter(m -> m.equals(permission)).count() > 0; } return false; }
public Json2MapReader(String json) { JsonParser parser = JsonParserFactory.getJsonParser(); map = parser.parseMap(json); // For creating test files: // try { // FileWriter writer = new FileWriter(new SimpleDateFormat("yyyy-MM-dd_HH_mm_ss.SSS").format(new Date()) + "-json.txt"); // writer.append(json); // writer.close(); // } catch (IOException e) { // System.out.println(e.getMessage()); // } }
private void processJson(ConfigurableEnvironment environment, String json) { try { JsonParser parser = JsonParserFactory.getJsonParser(); Map<String, Object> map = parser.parseMap(json); if (!map.isEmpty()) { addJsonPropertySource(environment, new MapPropertySource("spring.application.json", flatten(map))); } } catch (Exception ex) { logger.warn("Cannot parse JSON for spring.application.json: " + json, ex); } }
@Bean @Profile("cloud") public PubSub pubSubCloud(Environment environment) throws Exception { String vcapServicesEnv = environment.getProperty("VCAP_SERVICES"); JsonParser parser = JsonParserFactory.getJsonParser(); Map<String, Object> services = parser.parseMap(vcapServicesEnv); List<Map<String, Object>> googlePubsub = (List<Map<String, Object>>) services.get("google-pubsub"); Map<String, Object> credentials = (Map<String, Object>) googlePubsub.get(0).get("credentials"); String privateKeyData = (String) credentials.get("PrivateKeyData"); GoogleCredential googleCredential = GoogleCredential.fromStream(new ByteArrayInputStream(Base64.decodeBase64(privateKeyData))); return PubSubOptions.newBuilder().setAuthCredentials(AuthCredentials.createFor(googleCredential.getServiceAccountId(), googleCredential.getServiceAccountPrivateKey())) .setProjectId(pubSubBinderConfigurationProperties.getProjectName()).build().getService(); }
@JsonIgnore public Map getPermissionsMap() { return Strings.isNullOrEmpty(permissions) ? new HashMap() : JsonParserFactory.getJsonParser().parseMap(permissions); }
public void setCredentialsJson(String credentialsJson) { JsonParser parser = JsonParserFactory.getJsonParser(); this.credentialsJson = parser.parseMap(credentialsJson); }
private Map<String, Object> getJsonMapFromEnvironment() { JsonParser jsonParser = JsonParserFactory.getJsonParser(); Map<String, Object> jsonMap; jsonMap = jsonParser.parseMap(getVCapVariable()); return (Map<String, Object>) ((List<Map<String, Object>>) jsonMap.get( "p-cassandra")).get(0).get("credentials"); }