private String getSecretKeyDigest(SecretKey key) throws NinjaException { MessageDigest sha1; try { sha1 = MessageDigest.getInstance(KEY_DIGEST_TYPE); } catch (NoSuchAlgorithmException ex) { throw new NinjaException(ex.getMessage(), ex); } return Base64.encode(sha1.digest(key.getEncoded())); } }
public void start() { if (state != State.NOT_STARTED) { throw new NinjaException("Can't start operation, previous state is was not " + State.NOT_STARTED); } debug("Operation: started"); startTime = System.currentTimeMillis(); state = State.STARTED; }
public void producerFinish() { if (state != State.STARTED) { throw new NinjaException("Can't set state " + State.PRODUCER_FINISHED + " for operation, previous state is was not " + State.STARTED); } debug("Operation: producer finished"); state = State.PRODUCER_FINISHED; }
public void finish() { if (state == State.NOT_STARTED) { throw new NinjaException("Can't finish operation, previous state was " + State.NOT_STARTED); } debug("Operation: finished"); finishTime = System.currentTimeMillis(); state = State.FINISHED; }
private InputStream openInputStream() throws IOException { File input = options.getInput(); InputStream is; if (input != null) { if (!input.exists()) { throw new NinjaException("Import file '" + input.getPath() + "' doesn't exist"); } is = new FileInputStream(input); } else { is = System.in; } return is; }
public static Writer createWriter(File output, Charset charset, boolean zip) throws IOException { OutputStream os; if (output != null) { if (output.exists()) { throw new NinjaException("Export file '" + output.getPath() + "' already exists"); } output.createNewFile(); os = new FileOutputStream(output); } else { os = System.out; } if (zip) { ZipOutputStream zos = new ZipOutputStream(os); String entryName = output.getName().replaceAll("\\.", "-") + ".xml"; ZipEntry entry = new ZipEntry(entryName); zos.putNextEntry(entry); os = zos; } return new OutputStreamWriter(os, charset); }
private void registerExtensionSchemas(SchemaRegistryImpl schemaRegistry) { try { List<String> schemas = getSchemaList(); for (String name : schemas) { String xsd = fetchSchema(name); ByteArrayInputStream bis = new ByteArrayInputStream(xsd.getBytes()); schemaRegistry.registerPrismSchema(bis, "rest " + name); } } catch (Exception ex) { throw new NinjaException("Couldn't register extension schema", ex); } }
public RestService(String url, String username, String password) { this.url = url; template = new RestTemplate(); List<ClientHttpRequestInterceptor> interceptors = new ArrayList<>(); if (username != null) { interceptors.add(new BasicAuthenticationInterceptor(username, password)); } interceptors.add(new LoggingInterceptor()); template.setRequestFactory( new InterceptingClientHttpRequestFactory(template.getRequestFactory(), interceptors)); prismContext = ProxyCreator.getProxy(PrismContext.class, () -> { try { PrismContextFactory factory = new MidPointPrismContextFactory() { @Override protected void registerExtensionSchemas(SchemaRegistryImpl schemaRegistry) throws SchemaException, FileNotFoundException { super.registerExtensionSchemas(schemaRegistry); RestService.this.registerExtensionSchemas(schemaRegistry); } }; return factory.createPrismContext(); } catch (SchemaException | FileNotFoundException ex) { throw new NinjaException("Couldn't load prism context", ex); } }); }
@Override public <T extends Objectable> EventResult postMarshall(PrismObject<T> object, Element objectElement, OperationResult objectResult) { try { if (filter != null) { boolean match = ObjectQuery.match(object, filter, matchingRuleRegistry); if (!match) { operation.incrementSkipped(); return EventResult.skipObject("Object doesn't match filter"); } } if (!matchSelectedType(object.getCompileTimeClass())) { operation.incrementSkipped(); return EventResult.skipObject("Type doesn't match"); } queue.put(object); } catch (Exception ex) { throw new NinjaException("Couldn't import object, reason: " + ex.getMessage(), ex); } return stopAfterFound ? EventResult.skipObject() : EventResult.cont(); }
throw new NinjaException("Couldn't import object, reason: " + ex.getMessage(), ex);
@Override public void execute() throws Exception { RepositoryService repository = context.getRepository(); FileReference fileReference = options.getFilter(); if (fileReference != null && options.getFilter() == null) { throw new NinjaException("Type must be defined"); } List<ObjectTypes> types = NinjaUtils.getTypes(options.getType()); int total = 0; OperationResult result = new OperationResult(OPERATION_COUNT); for (ObjectTypes type : types) { ObjectQuery query = NinjaUtils.createObjectQuery(options.getFilter(), context, type.getClassDefinition()); int count = repository.countObjects(type.getClassDefinition(), query, new ArrayList<>(), result); if (count == 0 && options.getType() == null) { continue; } log.info("{}:\t{}", type.name(), count); total += count; } log.info("===\nTotal:\t{}", total); } }