repo_name
stringlengths
7
104
file_path
stringlengths
13
198
context
stringlengths
67
7.15k
import_statement
stringlengths
16
4.43k
code
stringlengths
40
6.98k
prompt
stringlengths
227
8.27k
next_line
stringlengths
8
795
blazegraph/tinkerpop3
src/test/java/com/blazegraph/gremlin/structure/TestBulkLoad.java
// Path: src/main/java/com/blazegraph/gremlin/listener/BlazeGraphEdit.java // public class BlazeGraphEdit { // // /** // * Edit action - add or remove. // * // * @author mikepersonick // */ // public static enum Action { // // /** // * Graph atom added. // */ // Add, // // /** // * Graph atom removed. // */ // Remove; // // } // // /** // * Edit action. // */ // private final Action action; // // /** // * Atomic unit of graph information edited. // */ // private final BlazeGraphAtom atom; // // /** // * The commit time of the edit action. // */ // private final long timestamp; // // /** // * Construct an edit with an unknown commit time (listener API). // */ // public BlazeGraphEdit(final Action action, final BlazeGraphAtom atom) { // this(action, atom, 0l); // } // // /** // * Construct an edit with an known commit time (history API). // */ // public BlazeGraphEdit(final Action action, final BlazeGraphAtom atom, // final long timestamp) { // this.action = action; // this.atom = atom; // this.timestamp = timestamp; // } // // /** // * Return the edit action. // */ // public Action getAction() { // return action; // } // // /** // * Return the atomic unit of graph information edited. // */ // public BlazeGraphAtom getAtom() { // return atom; // } // // /** // * Return the commit time of the edit action or 0l if this is an // * uncommitted edit. // */ // public long getTimestamp() { // return timestamp; // } // // @Override // public String toString() { // return "BlazeGraphEdit [action=" + action + ", atom=" + atom // + (timestamp > 0 ? ", timestamp=" + timestamp : "") + "]"; // } // // } // // Path: src/main/java/com/blazegraph/gremlin/listener/BlazeGraphEdit.java // public static enum Action { // // /** // * Graph atom added. // */ // Add, // // /** // * Graph atom removed. // */ // Remove; // // }
import java.util.LinkedList; import java.util.List; import org.apache.tinkerpop.gremlin.structure.T; import org.apache.tinkerpop.gremlin.structure.VertexProperty.Cardinality; import com.blazegraph.gremlin.listener.BlazeGraphEdit; import com.blazegraph.gremlin.listener.BlazeGraphEdit.Action;
/** Copyright (C) SYSTAP, LLC DBA Blazegraph 2006-2016. All rights reserved. Contact: SYSTAP, LLC DBA Blazegraph 2501 Calvert ST NW #106 Washington, DC 20008 [email protected] This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ package com.blazegraph.gremlin.structure; /** * Bulk load API tests. * * @author mikepersonick */ public class TestBulkLoad extends TestBlazeGraph { public void testBulkLoad1() { final List<BlazeGraphEdit> edits = new LinkedList<>(); graph.addListener((edit,rdfEdit) -> edits.add(edit)); final BlazeVertex a = graph.addVertex(T.id, "a"); graph.bulkLoad(() -> { /* * In incremental update mode Cardinality.single would clean old * values when a new value is set. If bulk load is working we * should see three values and no removes. Breaks the semantics * of Cardinality.single which is why bulk load should be used with * care. */ a.property(Cardinality.single, "key", "v1"); a.property(Cardinality.single, "key", "v2"); a.property(Cardinality.single, "key", "v3"); }); graph.commit(); // bulk load should be off again assertFalse(graph.isBulkLoad()); // three properties assertEquals(3, a.properties().count()); // zero removes
// Path: src/main/java/com/blazegraph/gremlin/listener/BlazeGraphEdit.java // public class BlazeGraphEdit { // // /** // * Edit action - add or remove. // * // * @author mikepersonick // */ // public static enum Action { // // /** // * Graph atom added. // */ // Add, // // /** // * Graph atom removed. // */ // Remove; // // } // // /** // * Edit action. // */ // private final Action action; // // /** // * Atomic unit of graph information edited. // */ // private final BlazeGraphAtom atom; // // /** // * The commit time of the edit action. // */ // private final long timestamp; // // /** // * Construct an edit with an unknown commit time (listener API). // */ // public BlazeGraphEdit(final Action action, final BlazeGraphAtom atom) { // this(action, atom, 0l); // } // // /** // * Construct an edit with an known commit time (history API). // */ // public BlazeGraphEdit(final Action action, final BlazeGraphAtom atom, // final long timestamp) { // this.action = action; // this.atom = atom; // this.timestamp = timestamp; // } // // /** // * Return the edit action. // */ // public Action getAction() { // return action; // } // // /** // * Return the atomic unit of graph information edited. // */ // public BlazeGraphAtom getAtom() { // return atom; // } // // /** // * Return the commit time of the edit action or 0l if this is an // * uncommitted edit. // */ // public long getTimestamp() { // return timestamp; // } // // @Override // public String toString() { // return "BlazeGraphEdit [action=" + action + ", atom=" + atom // + (timestamp > 0 ? ", timestamp=" + timestamp : "") + "]"; // } // // } // // Path: src/main/java/com/blazegraph/gremlin/listener/BlazeGraphEdit.java // public static enum Action { // // /** // * Graph atom added. // */ // Add, // // /** // * Graph atom removed. // */ // Remove; // // } // Path: src/test/java/com/blazegraph/gremlin/structure/TestBulkLoad.java import java.util.LinkedList; import java.util.List; import org.apache.tinkerpop.gremlin.structure.T; import org.apache.tinkerpop.gremlin.structure.VertexProperty.Cardinality; import com.blazegraph.gremlin.listener.BlazeGraphEdit; import com.blazegraph.gremlin.listener.BlazeGraphEdit.Action; /** Copyright (C) SYSTAP, LLC DBA Blazegraph 2006-2016. All rights reserved. Contact: SYSTAP, LLC DBA Blazegraph 2501 Calvert ST NW #106 Washington, DC 20008 [email protected] This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ package com.blazegraph.gremlin.structure; /** * Bulk load API tests. * * @author mikepersonick */ public class TestBulkLoad extends TestBlazeGraph { public void testBulkLoad1() { final List<BlazeGraphEdit> edits = new LinkedList<>(); graph.addListener((edit,rdfEdit) -> edits.add(edit)); final BlazeVertex a = graph.addVertex(T.id, "a"); graph.bulkLoad(() -> { /* * In incremental update mode Cardinality.single would clean old * values when a new value is set. If bulk load is working we * should see three values and no removes. Breaks the semantics * of Cardinality.single which is why bulk load should be used with * care. */ a.property(Cardinality.single, "key", "v1"); a.property(Cardinality.single, "key", "v2"); a.property(Cardinality.single, "key", "v3"); }); graph.commit(); // bulk load should be off again assertFalse(graph.isBulkLoad()); // three properties assertEquals(3, a.properties().count()); // zero removes
assertEquals(0, edits.stream().filter(e -> e.getAction() == Action.Remove).count());
blazegraph/tinkerpop3
src/main/java/com/blazegraph/gremlin/structure/EmptyBlazeVertexProperty.java
// Path: src/main/java/com/blazegraph/gremlin/util/CloseableIterator.java // public interface CloseableIterator<E> extends Iterator<E>, AutoCloseable { // // /** // * You MUST close this iterator or auto-close with a try-with-resources. // */ // @Override // void close(); // // /** // * Perform some action on each remaining element and then close the itertor. // */ // @Override // default void forEachRemaining(Consumer<? super E> action) { // try { // Iterator.super.forEachRemaining(action); // } finally { // close(); // } // } // // /** // * You MUST close this stream or auto-close in a try-with-resources. // */ // default Stream<E> stream() { // return Streams.of(this).onClose(() -> close()); // } // // /** // * Collect the elements into a list. This will close the iterator. // */ // default List<E> collect() { // try (Stream<E> s = stream()) { // return s.collect(toList()); // } // } // // /** // * Count the elements. This will close the iterator. // */ // default long count() { // try (Stream<E> s = stream()) { // return s.count(); // } // } // // /** // * Count the distinct elements. This will close the iterator. // */ // default long countDistinct() { // try (Stream<E> s = stream()) { // return s.distinct().count(); // } // } // // /** // * Construct an instance from a stream using stream.close() as the close // * behavior for the iterator. // */ // public static <T> CloseableIterator<T> of(final Stream<T> stream) { // return of(stream.iterator(), () -> stream.close()); // } // // /** // * Construct an instance from the supplied iterator and the supplied // * onClose behavior. // */ // public static <T> // CloseableIterator<T> of(final Iterator<T> it, final Runnable onClose) { // return new CloseableIterator<T>() { // // @Override // public boolean hasNext() { // return it.hasNext(); // } // // @Override // public T next() { // return it.next(); // } // // @Override // public void remove() { // it.remove(); // } // // @Override // public void close() { // onClose.run(); // } // // @Override // public void forEachRemaining(Consumer<? super T> action) { // it.forEachRemaining(action); // } // // }; // } // // /** // * Empty instance. // */ // public static <T> CloseableIterator<T> emptyIterator() { // final Iterator<T> it = Collections.<T>emptyIterator(); // return of(it, () -> {}); // } // // }
import com.blazegraph.gremlin.util.CloseableIterator; import java.util.NoSuchElementException; import org.apache.tinkerpop.gremlin.structure.Property; import org.apache.tinkerpop.gremlin.structure.util.StringFactory; import org.apache.tinkerpop.gremlin.structure.util.empty.EmptyVertexProperty; import org.openrdf.model.URI; import com.bigdata.rdf.model.BigdataBNode;
public <U> BlazeProperty<U> property(String key, U value) { return EmptyBlazeProperty.<U>instance(); } @Override public String key() { throw Property.Exceptions.propertyDoesNotExist(); } @Override public V value() throws NoSuchElementException { throw Property.Exceptions.propertyDoesNotExist(); } @Override public boolean isPresent() { return false; } @Override public void remove() { } @Override public String toString() { return StringFactory.propertyString(this); } @Override
// Path: src/main/java/com/blazegraph/gremlin/util/CloseableIterator.java // public interface CloseableIterator<E> extends Iterator<E>, AutoCloseable { // // /** // * You MUST close this iterator or auto-close with a try-with-resources. // */ // @Override // void close(); // // /** // * Perform some action on each remaining element and then close the itertor. // */ // @Override // default void forEachRemaining(Consumer<? super E> action) { // try { // Iterator.super.forEachRemaining(action); // } finally { // close(); // } // } // // /** // * You MUST close this stream or auto-close in a try-with-resources. // */ // default Stream<E> stream() { // return Streams.of(this).onClose(() -> close()); // } // // /** // * Collect the elements into a list. This will close the iterator. // */ // default List<E> collect() { // try (Stream<E> s = stream()) { // return s.collect(toList()); // } // } // // /** // * Count the elements. This will close the iterator. // */ // default long count() { // try (Stream<E> s = stream()) { // return s.count(); // } // } // // /** // * Count the distinct elements. This will close the iterator. // */ // default long countDistinct() { // try (Stream<E> s = stream()) { // return s.distinct().count(); // } // } // // /** // * Construct an instance from a stream using stream.close() as the close // * behavior for the iterator. // */ // public static <T> CloseableIterator<T> of(final Stream<T> stream) { // return of(stream.iterator(), () -> stream.close()); // } // // /** // * Construct an instance from the supplied iterator and the supplied // * onClose behavior. // */ // public static <T> // CloseableIterator<T> of(final Iterator<T> it, final Runnable onClose) { // return new CloseableIterator<T>() { // // @Override // public boolean hasNext() { // return it.hasNext(); // } // // @Override // public T next() { // return it.next(); // } // // @Override // public void remove() { // it.remove(); // } // // @Override // public void close() { // onClose.run(); // } // // @Override // public void forEachRemaining(Consumer<? super T> action) { // it.forEachRemaining(action); // } // // }; // } // // /** // * Empty instance. // */ // public static <T> CloseableIterator<T> emptyIterator() { // final Iterator<T> it = Collections.<T>emptyIterator(); // return of(it, () -> {}); // } // // } // Path: src/main/java/com/blazegraph/gremlin/structure/EmptyBlazeVertexProperty.java import com.blazegraph.gremlin.util.CloseableIterator; import java.util.NoSuchElementException; import org.apache.tinkerpop.gremlin.structure.Property; import org.apache.tinkerpop.gremlin.structure.util.StringFactory; import org.apache.tinkerpop.gremlin.structure.util.empty.EmptyVertexProperty; import org.openrdf.model.URI; import com.bigdata.rdf.model.BigdataBNode; public <U> BlazeProperty<U> property(String key, U value) { return EmptyBlazeProperty.<U>instance(); } @Override public String key() { throw Property.Exceptions.propertyDoesNotExist(); } @Override public V value() throws NoSuchElementException { throw Property.Exceptions.propertyDoesNotExist(); } @Override public boolean isPresent() { return false; } @Override public void remove() { } @Override public String toString() { return StringFactory.propertyString(this); } @Override
public <U> CloseableIterator<Property<U>> properties(String... propertyKeys) {
blazegraph/tinkerpop3
src/main/java/com/blazegraph/gremlin/structure/SparqlGenerator.java
// Path: src/main/java/com/blazegraph/gremlin/structure/BlazeGraph.java // public static enum Match { // // /** // * Match any terms in the search string (OR). // */ // ANY, // // /** // * Match all terms in the search string (AND). // */ // ALL, // // /** // * Match the search string exactly using a regex filter. Most expensive // * option - use ALL instead if possible. // */ // EXACT; // // }
import org.apache.tinkerpop.gremlin.structure.Direction; import org.apache.tinkerpop.gremlin.structure.VertexProperty.Cardinality; import org.openrdf.model.Literal; import org.openrdf.model.Resource; import org.openrdf.model.URI; import org.openrdf.model.Value; import com.bigdata.rdf.model.BigdataBNode; import com.bigdata.rdf.model.BigdataStatement; import com.bigdata.rdf.sparql.ast.QueryHints; import com.bigdata.rdf.store.BDS; import com.blazegraph.gremlin.structure.BlazeGraph.Match; import static java.util.Arrays.asList; import static java.util.stream.Collectors.joining; import java.util.Arrays; import java.util.List; import java.util.UUID; import java.util.function.Function;
*/ String removeVertex(final BlazeVertex v) { final URI id = v.rdfId(); final StringBuilder vc = buildValuesClause( new StringBuilder(), "?id", asList(id)); final String queryStr = REMOVE_VERTEX.replace(Templates.VALUES, vc.toString()); return queryStr; } /** * @see {@link Templates#REMOVE_REIFIED_ELEMENT} */ String removeReifiedElement(final BlazeReifiedElement e) { final BigdataBNode sid = e.rdfId(); final BigdataStatement stmt = sid.getStatement(); final Resource s = stmt.getSubject(); final URI p = stmt.getPredicate(); final Value o = stmt.getObject(); final StringBuilder vc = buildValuesClause(new StringBuilder(), new String[] { "?s", "?p", "?o" }, new Value[] { s, p, o }); final String queryStr = REMOVE_REIFIED_ELEMENT.replace(Templates.VALUES, vc.toString()); return queryStr; } /** * @see {@link Templates#TEXT_SEARCH} */
// Path: src/main/java/com/blazegraph/gremlin/structure/BlazeGraph.java // public static enum Match { // // /** // * Match any terms in the search string (OR). // */ // ANY, // // /** // * Match all terms in the search string (AND). // */ // ALL, // // /** // * Match the search string exactly using a regex filter. Most expensive // * option - use ALL instead if possible. // */ // EXACT; // // } // Path: src/main/java/com/blazegraph/gremlin/structure/SparqlGenerator.java import org.apache.tinkerpop.gremlin.structure.Direction; import org.apache.tinkerpop.gremlin.structure.VertexProperty.Cardinality; import org.openrdf.model.Literal; import org.openrdf.model.Resource; import org.openrdf.model.URI; import org.openrdf.model.Value; import com.bigdata.rdf.model.BigdataBNode; import com.bigdata.rdf.model.BigdataStatement; import com.bigdata.rdf.sparql.ast.QueryHints; import com.bigdata.rdf.store.BDS; import com.blazegraph.gremlin.structure.BlazeGraph.Match; import static java.util.Arrays.asList; import static java.util.stream.Collectors.joining; import java.util.Arrays; import java.util.List; import java.util.UUID; import java.util.function.Function; */ String removeVertex(final BlazeVertex v) { final URI id = v.rdfId(); final StringBuilder vc = buildValuesClause( new StringBuilder(), "?id", asList(id)); final String queryStr = REMOVE_VERTEX.replace(Templates.VALUES, vc.toString()); return queryStr; } /** * @see {@link Templates#REMOVE_REIFIED_ELEMENT} */ String removeReifiedElement(final BlazeReifiedElement e) { final BigdataBNode sid = e.rdfId(); final BigdataStatement stmt = sid.getStatement(); final Resource s = stmt.getSubject(); final URI p = stmt.getPredicate(); final Value o = stmt.getObject(); final StringBuilder vc = buildValuesClause(new StringBuilder(), new String[] { "?s", "?p", "?o" }, new Value[] { s, p, o }); final String queryStr = REMOVE_REIFIED_ELEMENT.replace(Templates.VALUES, vc.toString()); return queryStr; } /** * @see {@link Templates#TEXT_SEARCH} */
String search(final String search, final Match match) {
blazegraph/tinkerpop3
src/main/java/com/blazegraph/gremlin/structure/BlazeVertexProperty.java
// Path: src/main/java/com/blazegraph/gremlin/util/CloseableIterator.java // public interface CloseableIterator<E> extends Iterator<E>, AutoCloseable { // // /** // * You MUST close this iterator or auto-close with a try-with-resources. // */ // @Override // void close(); // // /** // * Perform some action on each remaining element and then close the itertor. // */ // @Override // default void forEachRemaining(Consumer<? super E> action) { // try { // Iterator.super.forEachRemaining(action); // } finally { // close(); // } // } // // /** // * You MUST close this stream or auto-close in a try-with-resources. // */ // default Stream<E> stream() { // return Streams.of(this).onClose(() -> close()); // } // // /** // * Collect the elements into a list. This will close the iterator. // */ // default List<E> collect() { // try (Stream<E> s = stream()) { // return s.collect(toList()); // } // } // // /** // * Count the elements. This will close the iterator. // */ // default long count() { // try (Stream<E> s = stream()) { // return s.count(); // } // } // // /** // * Count the distinct elements. This will close the iterator. // */ // default long countDistinct() { // try (Stream<E> s = stream()) { // return s.distinct().count(); // } // } // // /** // * Construct an instance from a stream using stream.close() as the close // * behavior for the iterator. // */ // public static <T> CloseableIterator<T> of(final Stream<T> stream) { // return of(stream.iterator(), () -> stream.close()); // } // // /** // * Construct an instance from the supplied iterator and the supplied // * onClose behavior. // */ // public static <T> // CloseableIterator<T> of(final Iterator<T> it, final Runnable onClose) { // return new CloseableIterator<T>() { // // @Override // public boolean hasNext() { // return it.hasNext(); // } // // @Override // public T next() { // return it.next(); // } // // @Override // public void remove() { // it.remove(); // } // // @Override // public void close() { // onClose.run(); // } // // @Override // public void forEachRemaining(Consumer<? super T> action) { // it.forEachRemaining(action); // } // // }; // } // // /** // * Empty instance. // */ // public static <T> CloseableIterator<T> emptyIterator() { // final Iterator<T> it = Collections.<T>emptyIterator(); // return of(it, () -> {}); // } // // }
import org.openrdf.model.URI; import com.bigdata.rdf.model.BigdataBNode; import com.blazegraph.gremlin.util.CloseableIterator; import java.util.NoSuchElementException; import org.apache.tinkerpop.gremlin.structure.Element; import org.apache.tinkerpop.gremlin.structure.Property; import org.apache.tinkerpop.gremlin.structure.VertexProperty; import org.apache.tinkerpop.gremlin.structure.util.ElementHelper; import org.apache.tinkerpop.gremlin.structure.util.StringFactory; import org.openrdf.model.Literal;
/** * @see Property#isPresent() */ @Override public boolean isPresent() { return prop.isPresent(); } /** * @see Property#remove() * @see BlazeGraph#remove(BlazeReifiedElement) */ @Override public void remove() { graph().remove(this); } /** * Strengthen return type to {@link BlazeProperty}. */ @Override public <U> BlazeProperty<U> property(final String key, final U val) { return BlazeReifiedElement.super.property(key, val); } /** * Strength return type to {@link CloseableIterator}. You MUST close this * iterator when finished. */ @Override
// Path: src/main/java/com/blazegraph/gremlin/util/CloseableIterator.java // public interface CloseableIterator<E> extends Iterator<E>, AutoCloseable { // // /** // * You MUST close this iterator or auto-close with a try-with-resources. // */ // @Override // void close(); // // /** // * Perform some action on each remaining element and then close the itertor. // */ // @Override // default void forEachRemaining(Consumer<? super E> action) { // try { // Iterator.super.forEachRemaining(action); // } finally { // close(); // } // } // // /** // * You MUST close this stream or auto-close in a try-with-resources. // */ // default Stream<E> stream() { // return Streams.of(this).onClose(() -> close()); // } // // /** // * Collect the elements into a list. This will close the iterator. // */ // default List<E> collect() { // try (Stream<E> s = stream()) { // return s.collect(toList()); // } // } // // /** // * Count the elements. This will close the iterator. // */ // default long count() { // try (Stream<E> s = stream()) { // return s.count(); // } // } // // /** // * Count the distinct elements. This will close the iterator. // */ // default long countDistinct() { // try (Stream<E> s = stream()) { // return s.distinct().count(); // } // } // // /** // * Construct an instance from a stream using stream.close() as the close // * behavior for the iterator. // */ // public static <T> CloseableIterator<T> of(final Stream<T> stream) { // return of(stream.iterator(), () -> stream.close()); // } // // /** // * Construct an instance from the supplied iterator and the supplied // * onClose behavior. // */ // public static <T> // CloseableIterator<T> of(final Iterator<T> it, final Runnable onClose) { // return new CloseableIterator<T>() { // // @Override // public boolean hasNext() { // return it.hasNext(); // } // // @Override // public T next() { // return it.next(); // } // // @Override // public void remove() { // it.remove(); // } // // @Override // public void close() { // onClose.run(); // } // // @Override // public void forEachRemaining(Consumer<? super T> action) { // it.forEachRemaining(action); // } // // }; // } // // /** // * Empty instance. // */ // public static <T> CloseableIterator<T> emptyIterator() { // final Iterator<T> it = Collections.<T>emptyIterator(); // return of(it, () -> {}); // } // // } // Path: src/main/java/com/blazegraph/gremlin/structure/BlazeVertexProperty.java import org.openrdf.model.URI; import com.bigdata.rdf.model.BigdataBNode; import com.blazegraph.gremlin.util.CloseableIterator; import java.util.NoSuchElementException; import org.apache.tinkerpop.gremlin.structure.Element; import org.apache.tinkerpop.gremlin.structure.Property; import org.apache.tinkerpop.gremlin.structure.VertexProperty; import org.apache.tinkerpop.gremlin.structure.util.ElementHelper; import org.apache.tinkerpop.gremlin.structure.util.StringFactory; import org.openrdf.model.Literal; /** * @see Property#isPresent() */ @Override public boolean isPresent() { return prop.isPresent(); } /** * @see Property#remove() * @see BlazeGraph#remove(BlazeReifiedElement) */ @Override public void remove() { graph().remove(this); } /** * Strengthen return type to {@link BlazeProperty}. */ @Override public <U> BlazeProperty<U> property(final String key, final U val) { return BlazeReifiedElement.super.property(key, val); } /** * Strength return type to {@link CloseableIterator}. You MUST close this * iterator when finished. */ @Override
public <U> CloseableIterator<Property<U>> properties(final String... keys) {
blazegraph/tinkerpop3
src/main/java/com/blazegraph/gremlin/structure/BlazeReifiedElement.java
// Path: src/main/java/com/blazegraph/gremlin/util/CloseableIterator.java // public interface CloseableIterator<E> extends Iterator<E>, AutoCloseable { // // /** // * You MUST close this iterator or auto-close with a try-with-resources. // */ // @Override // void close(); // // /** // * Perform some action on each remaining element and then close the itertor. // */ // @Override // default void forEachRemaining(Consumer<? super E> action) { // try { // Iterator.super.forEachRemaining(action); // } finally { // close(); // } // } // // /** // * You MUST close this stream or auto-close in a try-with-resources. // */ // default Stream<E> stream() { // return Streams.of(this).onClose(() -> close()); // } // // /** // * Collect the elements into a list. This will close the iterator. // */ // default List<E> collect() { // try (Stream<E> s = stream()) { // return s.collect(toList()); // } // } // // /** // * Count the elements. This will close the iterator. // */ // default long count() { // try (Stream<E> s = stream()) { // return s.count(); // } // } // // /** // * Count the distinct elements. This will close the iterator. // */ // default long countDistinct() { // try (Stream<E> s = stream()) { // return s.distinct().count(); // } // } // // /** // * Construct an instance from a stream using stream.close() as the close // * behavior for the iterator. // */ // public static <T> CloseableIterator<T> of(final Stream<T> stream) { // return of(stream.iterator(), () -> stream.close()); // } // // /** // * Construct an instance from the supplied iterator and the supplied // * onClose behavior. // */ // public static <T> // CloseableIterator<T> of(final Iterator<T> it, final Runnable onClose) { // return new CloseableIterator<T>() { // // @Override // public boolean hasNext() { // return it.hasNext(); // } // // @Override // public T next() { // return it.next(); // } // // @Override // public void remove() { // it.remove(); // } // // @Override // public void close() { // onClose.run(); // } // // @Override // public void forEachRemaining(Consumer<? super T> action) { // it.forEachRemaining(action); // } // // }; // } // // /** // * Empty instance. // */ // public static <T> CloseableIterator<T> emptyIterator() { // final Iterator<T> it = Collections.<T>emptyIterator(); // return of(it, () -> {}); // } // // }
import org.apache.tinkerpop.gremlin.structure.Property; import org.apache.tinkerpop.gremlin.structure.util.ElementHelper; import com.bigdata.rdf.model.BigdataBNode; import com.blazegraph.gremlin.util.CloseableIterator;
/** Copyright (C) SYSTAP, LLC DBA Blazegraph 2006-2016. All rights reserved. Contact: SYSTAP, LLC DBA Blazegraph 2501 Calvert ST NW #106 Washington, DC 20008 [email protected] This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ package com.blazegraph.gremlin.structure; /** * Common interface for {@link BlazeEdge} and {@link BlazeVertexProperty}, * both of which use a sid (reified statement) as their RDF id for attaching * labels (BlazeEdge) and properties (both). * * @author mikepersonick */ public interface BlazeReifiedElement extends BlazeElement { /** * Strengthen return type. * * @see BlazeElement#rdfId() */ @Override BigdataBNode rdfId(); /** * Safer default implementation that closes the iterator from properties(). */ @Override default <V> BlazeProperty<V> property(final String key) {
// Path: src/main/java/com/blazegraph/gremlin/util/CloseableIterator.java // public interface CloseableIterator<E> extends Iterator<E>, AutoCloseable { // // /** // * You MUST close this iterator or auto-close with a try-with-resources. // */ // @Override // void close(); // // /** // * Perform some action on each remaining element and then close the itertor. // */ // @Override // default void forEachRemaining(Consumer<? super E> action) { // try { // Iterator.super.forEachRemaining(action); // } finally { // close(); // } // } // // /** // * You MUST close this stream or auto-close in a try-with-resources. // */ // default Stream<E> stream() { // return Streams.of(this).onClose(() -> close()); // } // // /** // * Collect the elements into a list. This will close the iterator. // */ // default List<E> collect() { // try (Stream<E> s = stream()) { // return s.collect(toList()); // } // } // // /** // * Count the elements. This will close the iterator. // */ // default long count() { // try (Stream<E> s = stream()) { // return s.count(); // } // } // // /** // * Count the distinct elements. This will close the iterator. // */ // default long countDistinct() { // try (Stream<E> s = stream()) { // return s.distinct().count(); // } // } // // /** // * Construct an instance from a stream using stream.close() as the close // * behavior for the iterator. // */ // public static <T> CloseableIterator<T> of(final Stream<T> stream) { // return of(stream.iterator(), () -> stream.close()); // } // // /** // * Construct an instance from the supplied iterator and the supplied // * onClose behavior. // */ // public static <T> // CloseableIterator<T> of(final Iterator<T> it, final Runnable onClose) { // return new CloseableIterator<T>() { // // @Override // public boolean hasNext() { // return it.hasNext(); // } // // @Override // public T next() { // return it.next(); // } // // @Override // public void remove() { // it.remove(); // } // // @Override // public void close() { // onClose.run(); // } // // @Override // public void forEachRemaining(Consumer<? super T> action) { // it.forEachRemaining(action); // } // // }; // } // // /** // * Empty instance. // */ // public static <T> CloseableIterator<T> emptyIterator() { // final Iterator<T> it = Collections.<T>emptyIterator(); // return of(it, () -> {}); // } // // } // Path: src/main/java/com/blazegraph/gremlin/structure/BlazeReifiedElement.java import org.apache.tinkerpop.gremlin.structure.Property; import org.apache.tinkerpop.gremlin.structure.util.ElementHelper; import com.bigdata.rdf.model.BigdataBNode; import com.blazegraph.gremlin.util.CloseableIterator; /** Copyright (C) SYSTAP, LLC DBA Blazegraph 2006-2016. All rights reserved. Contact: SYSTAP, LLC DBA Blazegraph 2501 Calvert ST NW #106 Washington, DC 20008 [email protected] This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ package com.blazegraph.gremlin.structure; /** * Common interface for {@link BlazeEdge} and {@link BlazeVertexProperty}, * both of which use a sid (reified statement) as their RDF id for attaching * labels (BlazeEdge) and properties (both). * * @author mikepersonick */ public interface BlazeReifiedElement extends BlazeElement { /** * Strengthen return type. * * @see BlazeElement#rdfId() */ @Override BigdataBNode rdfId(); /** * Safer default implementation that closes the iterator from properties(). */ @Override default <V> BlazeProperty<V> property(final String key) {
try (CloseableIterator<? extends Property<V>> it = this.<V>properties(key)) {
blazegraph/tinkerpop3
src/main/java/com/blazegraph/gremlin/structure/BlazeElement.java
// Path: src/main/java/com/blazegraph/gremlin/util/CloseableIterator.java // public interface CloseableIterator<E> extends Iterator<E>, AutoCloseable { // // /** // * You MUST close this iterator or auto-close with a try-with-resources. // */ // @Override // void close(); // // /** // * Perform some action on each remaining element and then close the itertor. // */ // @Override // default void forEachRemaining(Consumer<? super E> action) { // try { // Iterator.super.forEachRemaining(action); // } finally { // close(); // } // } // // /** // * You MUST close this stream or auto-close in a try-with-resources. // */ // default Stream<E> stream() { // return Streams.of(this).onClose(() -> close()); // } // // /** // * Collect the elements into a list. This will close the iterator. // */ // default List<E> collect() { // try (Stream<E> s = stream()) { // return s.collect(toList()); // } // } // // /** // * Count the elements. This will close the iterator. // */ // default long count() { // try (Stream<E> s = stream()) { // return s.count(); // } // } // // /** // * Count the distinct elements. This will close the iterator. // */ // default long countDistinct() { // try (Stream<E> s = stream()) { // return s.distinct().count(); // } // } // // /** // * Construct an instance from a stream using stream.close() as the close // * behavior for the iterator. // */ // public static <T> CloseableIterator<T> of(final Stream<T> stream) { // return of(stream.iterator(), () -> stream.close()); // } // // /** // * Construct an instance from the supplied iterator and the supplied // * onClose behavior. // */ // public static <T> // CloseableIterator<T> of(final Iterator<T> it, final Runnable onClose) { // return new CloseableIterator<T>() { // // @Override // public boolean hasNext() { // return it.hasNext(); // } // // @Override // public T next() { // return it.next(); // } // // @Override // public void remove() { // it.remove(); // } // // @Override // public void close() { // onClose.run(); // } // // @Override // public void forEachRemaining(Consumer<? super T> action) { // it.forEachRemaining(action); // } // // }; // } // // /** // * Empty instance. // */ // public static <T> CloseableIterator<T> emptyIterator() { // final Iterator<T> it = Collections.<T>emptyIterator(); // return of(it, () -> {}); // } // // }
import com.bigdata.rdf.model.BigdataResource; import com.blazegraph.gremlin.util.CloseableIterator; import java.util.Collections; import java.util.HashSet; import java.util.Set; import org.apache.tinkerpop.gremlin.structure.Element; import org.apache.tinkerpop.gremlin.structure.Property; import org.openrdf.model.Literal; import org.openrdf.model.URI;
/** Copyright (C) SYSTAP, LLC DBA Blazegraph 2006-2016. All rights reserved. Contact: SYSTAP, LLC DBA Blazegraph 2501 Calvert ST NW #106 Washington, DC 20008 [email protected] This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ package com.blazegraph.gremlin.structure; /** * Extends the Tinkerpop3 interface to strengthen return types from Iterator * to {@link CloseableIterator} and to expose RDF values for id and label. * * @author mikepersonick */ public interface BlazeElement extends Element { /** * Strengthen return type to {@link BlazeGraph}. */ @Override BlazeGraph graph(); /** * Return RDF value for element id (URI for Vertex, BNode for Edge and * VertexProperty). */ BigdataResource rdfId(); /** * Return RDF literal for element label. */ URI rdfLabel(); /** * Strengthen return type to {@link CloseableIterator}. You MUST close this * iterator when finished. */ @Override
// Path: src/main/java/com/blazegraph/gremlin/util/CloseableIterator.java // public interface CloseableIterator<E> extends Iterator<E>, AutoCloseable { // // /** // * You MUST close this iterator or auto-close with a try-with-resources. // */ // @Override // void close(); // // /** // * Perform some action on each remaining element and then close the itertor. // */ // @Override // default void forEachRemaining(Consumer<? super E> action) { // try { // Iterator.super.forEachRemaining(action); // } finally { // close(); // } // } // // /** // * You MUST close this stream or auto-close in a try-with-resources. // */ // default Stream<E> stream() { // return Streams.of(this).onClose(() -> close()); // } // // /** // * Collect the elements into a list. This will close the iterator. // */ // default List<E> collect() { // try (Stream<E> s = stream()) { // return s.collect(toList()); // } // } // // /** // * Count the elements. This will close the iterator. // */ // default long count() { // try (Stream<E> s = stream()) { // return s.count(); // } // } // // /** // * Count the distinct elements. This will close the iterator. // */ // default long countDistinct() { // try (Stream<E> s = stream()) { // return s.distinct().count(); // } // } // // /** // * Construct an instance from a stream using stream.close() as the close // * behavior for the iterator. // */ // public static <T> CloseableIterator<T> of(final Stream<T> stream) { // return of(stream.iterator(), () -> stream.close()); // } // // /** // * Construct an instance from the supplied iterator and the supplied // * onClose behavior. // */ // public static <T> // CloseableIterator<T> of(final Iterator<T> it, final Runnable onClose) { // return new CloseableIterator<T>() { // // @Override // public boolean hasNext() { // return it.hasNext(); // } // // @Override // public T next() { // return it.next(); // } // // @Override // public void remove() { // it.remove(); // } // // @Override // public void close() { // onClose.run(); // } // // @Override // public void forEachRemaining(Consumer<? super T> action) { // it.forEachRemaining(action); // } // // }; // } // // /** // * Empty instance. // */ // public static <T> CloseableIterator<T> emptyIterator() { // final Iterator<T> it = Collections.<T>emptyIterator(); // return of(it, () -> {}); // } // // } // Path: src/main/java/com/blazegraph/gremlin/structure/BlazeElement.java import com.bigdata.rdf.model.BigdataResource; import com.blazegraph.gremlin.util.CloseableIterator; import java.util.Collections; import java.util.HashSet; import java.util.Set; import org.apache.tinkerpop.gremlin.structure.Element; import org.apache.tinkerpop.gremlin.structure.Property; import org.openrdf.model.Literal; import org.openrdf.model.URI; /** Copyright (C) SYSTAP, LLC DBA Blazegraph 2006-2016. All rights reserved. Contact: SYSTAP, LLC DBA Blazegraph 2501 Calvert ST NW #106 Washington, DC 20008 [email protected] This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ package com.blazegraph.gremlin.structure; /** * Extends the Tinkerpop3 interface to strengthen return types from Iterator * to {@link CloseableIterator} and to expose RDF values for id and label. * * @author mikepersonick */ public interface BlazeElement extends Element { /** * Strengthen return type to {@link BlazeGraph}. */ @Override BlazeGraph graph(); /** * Return RDF value for element id (URI for Vertex, BNode for Edge and * VertexProperty). */ BigdataResource rdfId(); /** * Return RDF literal for element label. */ URI rdfLabel(); /** * Strengthen return type to {@link CloseableIterator}. You MUST close this * iterator when finished. */ @Override
<V> CloseableIterator<? extends Property<V>> properties(String... keys);
olivierlemasle/java-certificate-authority
ca-api/src/main/java/io/github/olivierlemasle/caweb/resources/CertificateAuthoritiesResource.java
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificateBuilder createSelfSignedCertificate( // final DistinguishedName subject) { // return new RootCertificateBuilderImpl(subject); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // } // // Path: ca-api/src/main/java/io/github/olivierlemasle/caweb/api/CertificateAuthority.java // public class CertificateAuthority { // private RootCertificate caCertificate; // // public CertificateAuthority() { // // Jackson // } // // public CertificateAuthority(final RootCertificate caCertificate) { // this.caCertificate = caCertificate; // } // // @JsonIgnore // public RootCertificate getCaCertificate() { // return caCertificate; // } // // @JsonProperty // public DistinguishedName getSubject() { // return dn(caCertificate.getX509Certificate().getSubjectX500Principal()); // } // // }
import static io.github.olivierlemasle.ca.CA.createSelfSignedCertificate; import java.util.ArrayList; import java.util.List; import javax.ws.rs.GET; import javax.ws.rs.NotFoundException; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import com.codahale.metrics.annotation.Timed; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate; import io.github.olivierlemasle.caweb.api.CertificateAuthority;
package io.github.olivierlemasle.caweb.resources; @Path("/certificateAuthorities") @Produces(MediaType.APPLICATION_JSON) public class CertificateAuthoritiesResource { public CertificateAuthoritiesResource() { } @GET @Timed
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificateBuilder createSelfSignedCertificate( // final DistinguishedName subject) { // return new RootCertificateBuilderImpl(subject); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // } // // Path: ca-api/src/main/java/io/github/olivierlemasle/caweb/api/CertificateAuthority.java // public class CertificateAuthority { // private RootCertificate caCertificate; // // public CertificateAuthority() { // // Jackson // } // // public CertificateAuthority(final RootCertificate caCertificate) { // this.caCertificate = caCertificate; // } // // @JsonIgnore // public RootCertificate getCaCertificate() { // return caCertificate; // } // // @JsonProperty // public DistinguishedName getSubject() { // return dn(caCertificate.getX509Certificate().getSubjectX500Principal()); // } // // } // Path: ca-api/src/main/java/io/github/olivierlemasle/caweb/resources/CertificateAuthoritiesResource.java import static io.github.olivierlemasle.ca.CA.createSelfSignedCertificate; import java.util.ArrayList; import java.util.List; import javax.ws.rs.GET; import javax.ws.rs.NotFoundException; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import com.codahale.metrics.annotation.Timed; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate; import io.github.olivierlemasle.caweb.api.CertificateAuthority; package io.github.olivierlemasle.caweb.resources; @Path("/certificateAuthorities") @Produces(MediaType.APPLICATION_JSON) public class CertificateAuthoritiesResource { public CertificateAuthoritiesResource() { } @GET @Timed
public List<CertificateAuthority> get() {
olivierlemasle/java-certificate-authority
ca-api/src/main/java/io/github/olivierlemasle/caweb/resources/CertificateAuthoritiesResource.java
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificateBuilder createSelfSignedCertificate( // final DistinguishedName subject) { // return new RootCertificateBuilderImpl(subject); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // } // // Path: ca-api/src/main/java/io/github/olivierlemasle/caweb/api/CertificateAuthority.java // public class CertificateAuthority { // private RootCertificate caCertificate; // // public CertificateAuthority() { // // Jackson // } // // public CertificateAuthority(final RootCertificate caCertificate) { // this.caCertificate = caCertificate; // } // // @JsonIgnore // public RootCertificate getCaCertificate() { // return caCertificate; // } // // @JsonProperty // public DistinguishedName getSubject() { // return dn(caCertificate.getX509Certificate().getSubjectX500Principal()); // } // // }
import static io.github.olivierlemasle.ca.CA.createSelfSignedCertificate; import java.util.ArrayList; import java.util.List; import javax.ws.rs.GET; import javax.ws.rs.NotFoundException; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import com.codahale.metrics.annotation.Timed; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate; import io.github.olivierlemasle.caweb.api.CertificateAuthority;
package io.github.olivierlemasle.caweb.resources; @Path("/certificateAuthorities") @Produces(MediaType.APPLICATION_JSON) public class CertificateAuthoritiesResource { public CertificateAuthoritiesResource() { } @GET @Timed public List<CertificateAuthority> get() { return new ArrayList<>(); } @GET @Path("/{dn}") @Timed public CertificateAuthority get(@PathParam("dn") final String dn) { throw new NotFoundException(); } @POST @Timed
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificateBuilder createSelfSignedCertificate( // final DistinguishedName subject) { // return new RootCertificateBuilderImpl(subject); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // } // // Path: ca-api/src/main/java/io/github/olivierlemasle/caweb/api/CertificateAuthority.java // public class CertificateAuthority { // private RootCertificate caCertificate; // // public CertificateAuthority() { // // Jackson // } // // public CertificateAuthority(final RootCertificate caCertificate) { // this.caCertificate = caCertificate; // } // // @JsonIgnore // public RootCertificate getCaCertificate() { // return caCertificate; // } // // @JsonProperty // public DistinguishedName getSubject() { // return dn(caCertificate.getX509Certificate().getSubjectX500Principal()); // } // // } // Path: ca-api/src/main/java/io/github/olivierlemasle/caweb/resources/CertificateAuthoritiesResource.java import static io.github.olivierlemasle.ca.CA.createSelfSignedCertificate; import java.util.ArrayList; import java.util.List; import javax.ws.rs.GET; import javax.ws.rs.NotFoundException; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import com.codahale.metrics.annotation.Timed; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate; import io.github.olivierlemasle.caweb.api.CertificateAuthority; package io.github.olivierlemasle.caweb.resources; @Path("/certificateAuthorities") @Produces(MediaType.APPLICATION_JSON) public class CertificateAuthoritiesResource { public CertificateAuthoritiesResource() { } @GET @Timed public List<CertificateAuthority> get() { return new ArrayList<>(); } @GET @Path("/{dn}") @Timed public CertificateAuthority get(@PathParam("dn") final String dn) { throw new NotFoundException(); } @POST @Timed
public CertificateAuthority create(final DistinguishedName dn) {
olivierlemasle/java-certificate-authority
ca-api/src/main/java/io/github/olivierlemasle/caweb/resources/CertificateAuthoritiesResource.java
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificateBuilder createSelfSignedCertificate( // final DistinguishedName subject) { // return new RootCertificateBuilderImpl(subject); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // } // // Path: ca-api/src/main/java/io/github/olivierlemasle/caweb/api/CertificateAuthority.java // public class CertificateAuthority { // private RootCertificate caCertificate; // // public CertificateAuthority() { // // Jackson // } // // public CertificateAuthority(final RootCertificate caCertificate) { // this.caCertificate = caCertificate; // } // // @JsonIgnore // public RootCertificate getCaCertificate() { // return caCertificate; // } // // @JsonProperty // public DistinguishedName getSubject() { // return dn(caCertificate.getX509Certificate().getSubjectX500Principal()); // } // // }
import static io.github.olivierlemasle.ca.CA.createSelfSignedCertificate; import java.util.ArrayList; import java.util.List; import javax.ws.rs.GET; import javax.ws.rs.NotFoundException; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import com.codahale.metrics.annotation.Timed; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate; import io.github.olivierlemasle.caweb.api.CertificateAuthority;
package io.github.olivierlemasle.caweb.resources; @Path("/certificateAuthorities") @Produces(MediaType.APPLICATION_JSON) public class CertificateAuthoritiesResource { public CertificateAuthoritiesResource() { } @GET @Timed public List<CertificateAuthority> get() { return new ArrayList<>(); } @GET @Path("/{dn}") @Timed public CertificateAuthority get(@PathParam("dn") final String dn) { throw new NotFoundException(); } @POST @Timed public CertificateAuthority create(final DistinguishedName dn) {
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificateBuilder createSelfSignedCertificate( // final DistinguishedName subject) { // return new RootCertificateBuilderImpl(subject); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // } // // Path: ca-api/src/main/java/io/github/olivierlemasle/caweb/api/CertificateAuthority.java // public class CertificateAuthority { // private RootCertificate caCertificate; // // public CertificateAuthority() { // // Jackson // } // // public CertificateAuthority(final RootCertificate caCertificate) { // this.caCertificate = caCertificate; // } // // @JsonIgnore // public RootCertificate getCaCertificate() { // return caCertificate; // } // // @JsonProperty // public DistinguishedName getSubject() { // return dn(caCertificate.getX509Certificate().getSubjectX500Principal()); // } // // } // Path: ca-api/src/main/java/io/github/olivierlemasle/caweb/resources/CertificateAuthoritiesResource.java import static io.github.olivierlemasle.ca.CA.createSelfSignedCertificate; import java.util.ArrayList; import java.util.List; import javax.ws.rs.GET; import javax.ws.rs.NotFoundException; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import com.codahale.metrics.annotation.Timed; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate; import io.github.olivierlemasle.caweb.api.CertificateAuthority; package io.github.olivierlemasle.caweb.resources; @Path("/certificateAuthorities") @Produces(MediaType.APPLICATION_JSON) public class CertificateAuthoritiesResource { public CertificateAuthoritiesResource() { } @GET @Timed public List<CertificateAuthority> get() { return new ArrayList<>(); } @GET @Path("/{dn}") @Timed public CertificateAuthority get(@PathParam("dn") final String dn) { throw new NotFoundException(); } @POST @Timed public CertificateAuthority create(final DistinguishedName dn) {
final RootCertificate caCertificate = createSelfSignedCertificate(dn)
olivierlemasle/java-certificate-authority
ca-api/src/main/java/io/github/olivierlemasle/caweb/resources/CertificateAuthoritiesResource.java
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificateBuilder createSelfSignedCertificate( // final DistinguishedName subject) { // return new RootCertificateBuilderImpl(subject); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // } // // Path: ca-api/src/main/java/io/github/olivierlemasle/caweb/api/CertificateAuthority.java // public class CertificateAuthority { // private RootCertificate caCertificate; // // public CertificateAuthority() { // // Jackson // } // // public CertificateAuthority(final RootCertificate caCertificate) { // this.caCertificate = caCertificate; // } // // @JsonIgnore // public RootCertificate getCaCertificate() { // return caCertificate; // } // // @JsonProperty // public DistinguishedName getSubject() { // return dn(caCertificate.getX509Certificate().getSubjectX500Principal()); // } // // }
import static io.github.olivierlemasle.ca.CA.createSelfSignedCertificate; import java.util.ArrayList; import java.util.List; import javax.ws.rs.GET; import javax.ws.rs.NotFoundException; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import com.codahale.metrics.annotation.Timed; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate; import io.github.olivierlemasle.caweb.api.CertificateAuthority;
package io.github.olivierlemasle.caweb.resources; @Path("/certificateAuthorities") @Produces(MediaType.APPLICATION_JSON) public class CertificateAuthoritiesResource { public CertificateAuthoritiesResource() { } @GET @Timed public List<CertificateAuthority> get() { return new ArrayList<>(); } @GET @Path("/{dn}") @Timed public CertificateAuthority get(@PathParam("dn") final String dn) { throw new NotFoundException(); } @POST @Timed public CertificateAuthority create(final DistinguishedName dn) {
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificateBuilder createSelfSignedCertificate( // final DistinguishedName subject) { // return new RootCertificateBuilderImpl(subject); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // } // // Path: ca-api/src/main/java/io/github/olivierlemasle/caweb/api/CertificateAuthority.java // public class CertificateAuthority { // private RootCertificate caCertificate; // // public CertificateAuthority() { // // Jackson // } // // public CertificateAuthority(final RootCertificate caCertificate) { // this.caCertificate = caCertificate; // } // // @JsonIgnore // public RootCertificate getCaCertificate() { // return caCertificate; // } // // @JsonProperty // public DistinguishedName getSubject() { // return dn(caCertificate.getX509Certificate().getSubjectX500Principal()); // } // // } // Path: ca-api/src/main/java/io/github/olivierlemasle/caweb/resources/CertificateAuthoritiesResource.java import static io.github.olivierlemasle.ca.CA.createSelfSignedCertificate; import java.util.ArrayList; import java.util.List; import javax.ws.rs.GET; import javax.ws.rs.NotFoundException; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import com.codahale.metrics.annotation.Timed; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate; import io.github.olivierlemasle.caweb.api.CertificateAuthority; package io.github.olivierlemasle.caweb.resources; @Path("/certificateAuthorities") @Produces(MediaType.APPLICATION_JSON) public class CertificateAuthoritiesResource { public CertificateAuthoritiesResource() { } @GET @Timed public List<CertificateAuthority> get() { return new ArrayList<>(); } @GET @Path("/{dn}") @Timed public CertificateAuthority get(@PathParam("dn") final String dn) { throw new NotFoundException(); } @POST @Timed public CertificateAuthority create(final DistinguishedName dn) {
final RootCertificate caCertificate = createSelfSignedCertificate(dn)
olivierlemasle/java-certificate-authority
java-ca-lib/src/test/java/io/github/olivierlemasle/tests/it/WindowsIT.java
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificateBuilder createSelfSignedCertificate( // final DistinguishedName subject) { // return new RootCertificateBuilderImpl(subject); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static CsrLoader loadCsr(final File csrFile) { // return new CsrLoaderImpl(csrFile); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CSR.java // public interface CSR { // // public DistinguishedName getSubject(); // // public PublicKey getPublicKey(); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/Certificate.java // public interface Certificate { // // public X509Certificate getX509Certificate(); // // public String print(); // // public void save(File file); // // public void save(String fileName); // // public CertificateWithPrivateKey attachPrivateKey(PrivateKey privateKey); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // }
import static io.github.olivierlemasle.ca.CA.createSelfSignedCertificate; import static io.github.olivierlemasle.ca.CA.dn; import static io.github.olivierlemasle.ca.CA.loadCsr; import static org.junit.Assert.assertTrue; import static org.junit.Assume.assumeTrue; import java.io.File; import java.io.IOException; import java.lang.ProcessBuilder.Redirect; import java.security.KeyManagementException; import java.security.KeyStore; import java.security.KeyStoreException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.security.cert.CertificateEncodingException; import java.security.cert.CertificateException; import java.security.cert.X509Certificate; import java.util.UUID; import javax.net.ssl.SSLContext; import org.apache.http.HttpEntity; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.ssl.SSLContexts; import org.apache.http.util.EntityUtils; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import io.github.olivierlemasle.ca.CSR; import io.github.olivierlemasle.ca.Certificate; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate;
package io.github.olivierlemasle.tests.it; public class WindowsIT { @BeforeClass @AfterClass public static void clean() { final File caCertPath = new File("ca.cer"); caCertPath.delete(); final File reqPath = new File("cert.req"); reqPath.delete(); final File certPath = new File("cert.cer"); certPath.delete(); } @Before public void checkPlatform() { assumeTrue(TestUtils.isWindows()); assumeTrue(TestUtils.isWindowsAdministrator()); } @Test public void completeTest() throws IOException, InterruptedException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException, CertificateException { // Create a self-signed root certificate System.out.println("Generate ..");
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificateBuilder createSelfSignedCertificate( // final DistinguishedName subject) { // return new RootCertificateBuilderImpl(subject); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static CsrLoader loadCsr(final File csrFile) { // return new CsrLoaderImpl(csrFile); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CSR.java // public interface CSR { // // public DistinguishedName getSubject(); // // public PublicKey getPublicKey(); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/Certificate.java // public interface Certificate { // // public X509Certificate getX509Certificate(); // // public String print(); // // public void save(File file); // // public void save(String fileName); // // public CertificateWithPrivateKey attachPrivateKey(PrivateKey privateKey); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // } // Path: java-ca-lib/src/test/java/io/github/olivierlemasle/tests/it/WindowsIT.java import static io.github.olivierlemasle.ca.CA.createSelfSignedCertificate; import static io.github.olivierlemasle.ca.CA.dn; import static io.github.olivierlemasle.ca.CA.loadCsr; import static org.junit.Assert.assertTrue; import static org.junit.Assume.assumeTrue; import java.io.File; import java.io.IOException; import java.lang.ProcessBuilder.Redirect; import java.security.KeyManagementException; import java.security.KeyStore; import java.security.KeyStoreException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.security.cert.CertificateEncodingException; import java.security.cert.CertificateException; import java.security.cert.X509Certificate; import java.util.UUID; import javax.net.ssl.SSLContext; import org.apache.http.HttpEntity; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.ssl.SSLContexts; import org.apache.http.util.EntityUtils; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import io.github.olivierlemasle.ca.CSR; import io.github.olivierlemasle.ca.Certificate; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate; package io.github.olivierlemasle.tests.it; public class WindowsIT { @BeforeClass @AfterClass public static void clean() { final File caCertPath = new File("ca.cer"); caCertPath.delete(); final File reqPath = new File("cert.req"); reqPath.delete(); final File certPath = new File("cert.cer"); certPath.delete(); } @Before public void checkPlatform() { assumeTrue(TestUtils.isWindows()); assumeTrue(TestUtils.isWindowsAdministrator()); } @Test public void completeTest() throws IOException, InterruptedException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException, CertificateException { // Create a self-signed root certificate System.out.println("Generate ..");
final DistinguishedName rootDn = dn("CN=CA-Test");
olivierlemasle/java-certificate-authority
java-ca-lib/src/test/java/io/github/olivierlemasle/tests/it/WindowsIT.java
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificateBuilder createSelfSignedCertificate( // final DistinguishedName subject) { // return new RootCertificateBuilderImpl(subject); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static CsrLoader loadCsr(final File csrFile) { // return new CsrLoaderImpl(csrFile); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CSR.java // public interface CSR { // // public DistinguishedName getSubject(); // // public PublicKey getPublicKey(); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/Certificate.java // public interface Certificate { // // public X509Certificate getX509Certificate(); // // public String print(); // // public void save(File file); // // public void save(String fileName); // // public CertificateWithPrivateKey attachPrivateKey(PrivateKey privateKey); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // }
import static io.github.olivierlemasle.ca.CA.createSelfSignedCertificate; import static io.github.olivierlemasle.ca.CA.dn; import static io.github.olivierlemasle.ca.CA.loadCsr; import static org.junit.Assert.assertTrue; import static org.junit.Assume.assumeTrue; import java.io.File; import java.io.IOException; import java.lang.ProcessBuilder.Redirect; import java.security.KeyManagementException; import java.security.KeyStore; import java.security.KeyStoreException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.security.cert.CertificateEncodingException; import java.security.cert.CertificateException; import java.security.cert.X509Certificate; import java.util.UUID; import javax.net.ssl.SSLContext; import org.apache.http.HttpEntity; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.ssl.SSLContexts; import org.apache.http.util.EntityUtils; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import io.github.olivierlemasle.ca.CSR; import io.github.olivierlemasle.ca.Certificate; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate;
package io.github.olivierlemasle.tests.it; public class WindowsIT { @BeforeClass @AfterClass public static void clean() { final File caCertPath = new File("ca.cer"); caCertPath.delete(); final File reqPath = new File("cert.req"); reqPath.delete(); final File certPath = new File("cert.cer"); certPath.delete(); } @Before public void checkPlatform() { assumeTrue(TestUtils.isWindows()); assumeTrue(TestUtils.isWindowsAdministrator()); } @Test public void completeTest() throws IOException, InterruptedException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException, CertificateException { // Create a self-signed root certificate System.out.println("Generate ..");
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificateBuilder createSelfSignedCertificate( // final DistinguishedName subject) { // return new RootCertificateBuilderImpl(subject); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static CsrLoader loadCsr(final File csrFile) { // return new CsrLoaderImpl(csrFile); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CSR.java // public interface CSR { // // public DistinguishedName getSubject(); // // public PublicKey getPublicKey(); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/Certificate.java // public interface Certificate { // // public X509Certificate getX509Certificate(); // // public String print(); // // public void save(File file); // // public void save(String fileName); // // public CertificateWithPrivateKey attachPrivateKey(PrivateKey privateKey); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // } // Path: java-ca-lib/src/test/java/io/github/olivierlemasle/tests/it/WindowsIT.java import static io.github.olivierlemasle.ca.CA.createSelfSignedCertificate; import static io.github.olivierlemasle.ca.CA.dn; import static io.github.olivierlemasle.ca.CA.loadCsr; import static org.junit.Assert.assertTrue; import static org.junit.Assume.assumeTrue; import java.io.File; import java.io.IOException; import java.lang.ProcessBuilder.Redirect; import java.security.KeyManagementException; import java.security.KeyStore; import java.security.KeyStoreException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.security.cert.CertificateEncodingException; import java.security.cert.CertificateException; import java.security.cert.X509Certificate; import java.util.UUID; import javax.net.ssl.SSLContext; import org.apache.http.HttpEntity; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.ssl.SSLContexts; import org.apache.http.util.EntityUtils; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import io.github.olivierlemasle.ca.CSR; import io.github.olivierlemasle.ca.Certificate; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate; package io.github.olivierlemasle.tests.it; public class WindowsIT { @BeforeClass @AfterClass public static void clean() { final File caCertPath = new File("ca.cer"); caCertPath.delete(); final File reqPath = new File("cert.req"); reqPath.delete(); final File certPath = new File("cert.cer"); certPath.delete(); } @Before public void checkPlatform() { assumeTrue(TestUtils.isWindows()); assumeTrue(TestUtils.isWindowsAdministrator()); } @Test public void completeTest() throws IOException, InterruptedException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException, CertificateException { // Create a self-signed root certificate System.out.println("Generate ..");
final DistinguishedName rootDn = dn("CN=CA-Test");
olivierlemasle/java-certificate-authority
java-ca-lib/src/test/java/io/github/olivierlemasle/tests/it/WindowsIT.java
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificateBuilder createSelfSignedCertificate( // final DistinguishedName subject) { // return new RootCertificateBuilderImpl(subject); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static CsrLoader loadCsr(final File csrFile) { // return new CsrLoaderImpl(csrFile); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CSR.java // public interface CSR { // // public DistinguishedName getSubject(); // // public PublicKey getPublicKey(); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/Certificate.java // public interface Certificate { // // public X509Certificate getX509Certificate(); // // public String print(); // // public void save(File file); // // public void save(String fileName); // // public CertificateWithPrivateKey attachPrivateKey(PrivateKey privateKey); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // }
import static io.github.olivierlemasle.ca.CA.createSelfSignedCertificate; import static io.github.olivierlemasle.ca.CA.dn; import static io.github.olivierlemasle.ca.CA.loadCsr; import static org.junit.Assert.assertTrue; import static org.junit.Assume.assumeTrue; import java.io.File; import java.io.IOException; import java.lang.ProcessBuilder.Redirect; import java.security.KeyManagementException; import java.security.KeyStore; import java.security.KeyStoreException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.security.cert.CertificateEncodingException; import java.security.cert.CertificateException; import java.security.cert.X509Certificate; import java.util.UUID; import javax.net.ssl.SSLContext; import org.apache.http.HttpEntity; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.ssl.SSLContexts; import org.apache.http.util.EntityUtils; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import io.github.olivierlemasle.ca.CSR; import io.github.olivierlemasle.ca.Certificate; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate;
package io.github.olivierlemasle.tests.it; public class WindowsIT { @BeforeClass @AfterClass public static void clean() { final File caCertPath = new File("ca.cer"); caCertPath.delete(); final File reqPath = new File("cert.req"); reqPath.delete(); final File certPath = new File("cert.cer"); certPath.delete(); } @Before public void checkPlatform() { assumeTrue(TestUtils.isWindows()); assumeTrue(TestUtils.isWindowsAdministrator()); } @Test public void completeTest() throws IOException, InterruptedException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException, CertificateException { // Create a self-signed root certificate System.out.println("Generate .."); final DistinguishedName rootDn = dn("CN=CA-Test");
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificateBuilder createSelfSignedCertificate( // final DistinguishedName subject) { // return new RootCertificateBuilderImpl(subject); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static CsrLoader loadCsr(final File csrFile) { // return new CsrLoaderImpl(csrFile); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CSR.java // public interface CSR { // // public DistinguishedName getSubject(); // // public PublicKey getPublicKey(); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/Certificate.java // public interface Certificate { // // public X509Certificate getX509Certificate(); // // public String print(); // // public void save(File file); // // public void save(String fileName); // // public CertificateWithPrivateKey attachPrivateKey(PrivateKey privateKey); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // } // Path: java-ca-lib/src/test/java/io/github/olivierlemasle/tests/it/WindowsIT.java import static io.github.olivierlemasle.ca.CA.createSelfSignedCertificate; import static io.github.olivierlemasle.ca.CA.dn; import static io.github.olivierlemasle.ca.CA.loadCsr; import static org.junit.Assert.assertTrue; import static org.junit.Assume.assumeTrue; import java.io.File; import java.io.IOException; import java.lang.ProcessBuilder.Redirect; import java.security.KeyManagementException; import java.security.KeyStore; import java.security.KeyStoreException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.security.cert.CertificateEncodingException; import java.security.cert.CertificateException; import java.security.cert.X509Certificate; import java.util.UUID; import javax.net.ssl.SSLContext; import org.apache.http.HttpEntity; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.ssl.SSLContexts; import org.apache.http.util.EntityUtils; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import io.github.olivierlemasle.ca.CSR; import io.github.olivierlemasle.ca.Certificate; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate; package io.github.olivierlemasle.tests.it; public class WindowsIT { @BeforeClass @AfterClass public static void clean() { final File caCertPath = new File("ca.cer"); caCertPath.delete(); final File reqPath = new File("cert.req"); reqPath.delete(); final File certPath = new File("cert.cer"); certPath.delete(); } @Before public void checkPlatform() { assumeTrue(TestUtils.isWindows()); assumeTrue(TestUtils.isWindowsAdministrator()); } @Test public void completeTest() throws IOException, InterruptedException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException, CertificateException { // Create a self-signed root certificate System.out.println("Generate .."); final DistinguishedName rootDn = dn("CN=CA-Test");
final RootCertificate root = createSelfSignedCertificate(rootDn).build();
olivierlemasle/java-certificate-authority
java-ca-lib/src/test/java/io/github/olivierlemasle/tests/it/WindowsIT.java
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificateBuilder createSelfSignedCertificate( // final DistinguishedName subject) { // return new RootCertificateBuilderImpl(subject); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static CsrLoader loadCsr(final File csrFile) { // return new CsrLoaderImpl(csrFile); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CSR.java // public interface CSR { // // public DistinguishedName getSubject(); // // public PublicKey getPublicKey(); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/Certificate.java // public interface Certificate { // // public X509Certificate getX509Certificate(); // // public String print(); // // public void save(File file); // // public void save(String fileName); // // public CertificateWithPrivateKey attachPrivateKey(PrivateKey privateKey); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // }
import static io.github.olivierlemasle.ca.CA.createSelfSignedCertificate; import static io.github.olivierlemasle.ca.CA.dn; import static io.github.olivierlemasle.ca.CA.loadCsr; import static org.junit.Assert.assertTrue; import static org.junit.Assume.assumeTrue; import java.io.File; import java.io.IOException; import java.lang.ProcessBuilder.Redirect; import java.security.KeyManagementException; import java.security.KeyStore; import java.security.KeyStoreException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.security.cert.CertificateEncodingException; import java.security.cert.CertificateException; import java.security.cert.X509Certificate; import java.util.UUID; import javax.net.ssl.SSLContext; import org.apache.http.HttpEntity; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.ssl.SSLContexts; import org.apache.http.util.EntityUtils; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import io.github.olivierlemasle.ca.CSR; import io.github.olivierlemasle.ca.Certificate; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate;
package io.github.olivierlemasle.tests.it; public class WindowsIT { @BeforeClass @AfterClass public static void clean() { final File caCertPath = new File("ca.cer"); caCertPath.delete(); final File reqPath = new File("cert.req"); reqPath.delete(); final File certPath = new File("cert.cer"); certPath.delete(); } @Before public void checkPlatform() { assumeTrue(TestUtils.isWindows()); assumeTrue(TestUtils.isWindowsAdministrator()); } @Test public void completeTest() throws IOException, InterruptedException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException, CertificateException { // Create a self-signed root certificate System.out.println("Generate .."); final DistinguishedName rootDn = dn("CN=CA-Test");
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificateBuilder createSelfSignedCertificate( // final DistinguishedName subject) { // return new RootCertificateBuilderImpl(subject); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static CsrLoader loadCsr(final File csrFile) { // return new CsrLoaderImpl(csrFile); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CSR.java // public interface CSR { // // public DistinguishedName getSubject(); // // public PublicKey getPublicKey(); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/Certificate.java // public interface Certificate { // // public X509Certificate getX509Certificate(); // // public String print(); // // public void save(File file); // // public void save(String fileName); // // public CertificateWithPrivateKey attachPrivateKey(PrivateKey privateKey); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // } // Path: java-ca-lib/src/test/java/io/github/olivierlemasle/tests/it/WindowsIT.java import static io.github.olivierlemasle.ca.CA.createSelfSignedCertificate; import static io.github.olivierlemasle.ca.CA.dn; import static io.github.olivierlemasle.ca.CA.loadCsr; import static org.junit.Assert.assertTrue; import static org.junit.Assume.assumeTrue; import java.io.File; import java.io.IOException; import java.lang.ProcessBuilder.Redirect; import java.security.KeyManagementException; import java.security.KeyStore; import java.security.KeyStoreException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.security.cert.CertificateEncodingException; import java.security.cert.CertificateException; import java.security.cert.X509Certificate; import java.util.UUID; import javax.net.ssl.SSLContext; import org.apache.http.HttpEntity; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.ssl.SSLContexts; import org.apache.http.util.EntityUtils; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import io.github.olivierlemasle.ca.CSR; import io.github.olivierlemasle.ca.Certificate; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate; package io.github.olivierlemasle.tests.it; public class WindowsIT { @BeforeClass @AfterClass public static void clean() { final File caCertPath = new File("ca.cer"); caCertPath.delete(); final File reqPath = new File("cert.req"); reqPath.delete(); final File certPath = new File("cert.cer"); certPath.delete(); } @Before public void checkPlatform() { assumeTrue(TestUtils.isWindows()); assumeTrue(TestUtils.isWindowsAdministrator()); } @Test public void completeTest() throws IOException, InterruptedException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException, CertificateException { // Create a self-signed root certificate System.out.println("Generate .."); final DistinguishedName rootDn = dn("CN=CA-Test");
final RootCertificate root = createSelfSignedCertificate(rootDn).build();
olivierlemasle/java-certificate-authority
java-ca-lib/src/test/java/io/github/olivierlemasle/tests/it/WindowsIT.java
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificateBuilder createSelfSignedCertificate( // final DistinguishedName subject) { // return new RootCertificateBuilderImpl(subject); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static CsrLoader loadCsr(final File csrFile) { // return new CsrLoaderImpl(csrFile); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CSR.java // public interface CSR { // // public DistinguishedName getSubject(); // // public PublicKey getPublicKey(); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/Certificate.java // public interface Certificate { // // public X509Certificate getX509Certificate(); // // public String print(); // // public void save(File file); // // public void save(String fileName); // // public CertificateWithPrivateKey attachPrivateKey(PrivateKey privateKey); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // }
import static io.github.olivierlemasle.ca.CA.createSelfSignedCertificate; import static io.github.olivierlemasle.ca.CA.dn; import static io.github.olivierlemasle.ca.CA.loadCsr; import static org.junit.Assert.assertTrue; import static org.junit.Assume.assumeTrue; import java.io.File; import java.io.IOException; import java.lang.ProcessBuilder.Redirect; import java.security.KeyManagementException; import java.security.KeyStore; import java.security.KeyStoreException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.security.cert.CertificateEncodingException; import java.security.cert.CertificateException; import java.security.cert.X509Certificate; import java.util.UUID; import javax.net.ssl.SSLContext; import org.apache.http.HttpEntity; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.ssl.SSLContexts; import org.apache.http.util.EntityUtils; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import io.github.olivierlemasle.ca.CSR; import io.github.olivierlemasle.ca.Certificate; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate;
package io.github.olivierlemasle.tests.it; public class WindowsIT { @BeforeClass @AfterClass public static void clean() { final File caCertPath = new File("ca.cer"); caCertPath.delete(); final File reqPath = new File("cert.req"); reqPath.delete(); final File certPath = new File("cert.cer"); certPath.delete(); } @Before public void checkPlatform() { assumeTrue(TestUtils.isWindows()); assumeTrue(TestUtils.isWindowsAdministrator()); } @Test public void completeTest() throws IOException, InterruptedException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException, CertificateException { // Create a self-signed root certificate System.out.println("Generate .."); final DistinguishedName rootDn = dn("CN=CA-Test"); final RootCertificate root = createSelfSignedCertificate(rootDn).build(); // Export the root certificate root.save("ca.cer"); System.out.println("CA ready. CA certificate saved to \"ca.cer\"."); // Generate CSR using Windows utilities System.out.println("Generate CSR with \"cert.req\"..."); generateCsr(); // Load the generated CSR, sign it and export the resulting certificate System.out.println("Sign CSR...");
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificateBuilder createSelfSignedCertificate( // final DistinguishedName subject) { // return new RootCertificateBuilderImpl(subject); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static CsrLoader loadCsr(final File csrFile) { // return new CsrLoaderImpl(csrFile); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CSR.java // public interface CSR { // // public DistinguishedName getSubject(); // // public PublicKey getPublicKey(); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/Certificate.java // public interface Certificate { // // public X509Certificate getX509Certificate(); // // public String print(); // // public void save(File file); // // public void save(String fileName); // // public CertificateWithPrivateKey attachPrivateKey(PrivateKey privateKey); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // } // Path: java-ca-lib/src/test/java/io/github/olivierlemasle/tests/it/WindowsIT.java import static io.github.olivierlemasle.ca.CA.createSelfSignedCertificate; import static io.github.olivierlemasle.ca.CA.dn; import static io.github.olivierlemasle.ca.CA.loadCsr; import static org.junit.Assert.assertTrue; import static org.junit.Assume.assumeTrue; import java.io.File; import java.io.IOException; import java.lang.ProcessBuilder.Redirect; import java.security.KeyManagementException; import java.security.KeyStore; import java.security.KeyStoreException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.security.cert.CertificateEncodingException; import java.security.cert.CertificateException; import java.security.cert.X509Certificate; import java.util.UUID; import javax.net.ssl.SSLContext; import org.apache.http.HttpEntity; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.ssl.SSLContexts; import org.apache.http.util.EntityUtils; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import io.github.olivierlemasle.ca.CSR; import io.github.olivierlemasle.ca.Certificate; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate; package io.github.olivierlemasle.tests.it; public class WindowsIT { @BeforeClass @AfterClass public static void clean() { final File caCertPath = new File("ca.cer"); caCertPath.delete(); final File reqPath = new File("cert.req"); reqPath.delete(); final File certPath = new File("cert.cer"); certPath.delete(); } @Before public void checkPlatform() { assumeTrue(TestUtils.isWindows()); assumeTrue(TestUtils.isWindowsAdministrator()); } @Test public void completeTest() throws IOException, InterruptedException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException, CertificateException { // Create a self-signed root certificate System.out.println("Generate .."); final DistinguishedName rootDn = dn("CN=CA-Test"); final RootCertificate root = createSelfSignedCertificate(rootDn).build(); // Export the root certificate root.save("ca.cer"); System.out.println("CA ready. CA certificate saved to \"ca.cer\"."); // Generate CSR using Windows utilities System.out.println("Generate CSR with \"cert.req\"..."); generateCsr(); // Load the generated CSR, sign it and export the resulting certificate System.out.println("Sign CSR...");
final CSR csr = loadCsr("cert.req").getCsr();
olivierlemasle/java-certificate-authority
java-ca-lib/src/test/java/io/github/olivierlemasle/tests/it/WindowsIT.java
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificateBuilder createSelfSignedCertificate( // final DistinguishedName subject) { // return new RootCertificateBuilderImpl(subject); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static CsrLoader loadCsr(final File csrFile) { // return new CsrLoaderImpl(csrFile); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CSR.java // public interface CSR { // // public DistinguishedName getSubject(); // // public PublicKey getPublicKey(); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/Certificate.java // public interface Certificate { // // public X509Certificate getX509Certificate(); // // public String print(); // // public void save(File file); // // public void save(String fileName); // // public CertificateWithPrivateKey attachPrivateKey(PrivateKey privateKey); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // }
import static io.github.olivierlemasle.ca.CA.createSelfSignedCertificate; import static io.github.olivierlemasle.ca.CA.dn; import static io.github.olivierlemasle.ca.CA.loadCsr; import static org.junit.Assert.assertTrue; import static org.junit.Assume.assumeTrue; import java.io.File; import java.io.IOException; import java.lang.ProcessBuilder.Redirect; import java.security.KeyManagementException; import java.security.KeyStore; import java.security.KeyStoreException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.security.cert.CertificateEncodingException; import java.security.cert.CertificateException; import java.security.cert.X509Certificate; import java.util.UUID; import javax.net.ssl.SSLContext; import org.apache.http.HttpEntity; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.ssl.SSLContexts; import org.apache.http.util.EntityUtils; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import io.github.olivierlemasle.ca.CSR; import io.github.olivierlemasle.ca.Certificate; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate;
package io.github.olivierlemasle.tests.it; public class WindowsIT { @BeforeClass @AfterClass public static void clean() { final File caCertPath = new File("ca.cer"); caCertPath.delete(); final File reqPath = new File("cert.req"); reqPath.delete(); final File certPath = new File("cert.cer"); certPath.delete(); } @Before public void checkPlatform() { assumeTrue(TestUtils.isWindows()); assumeTrue(TestUtils.isWindowsAdministrator()); } @Test public void completeTest() throws IOException, InterruptedException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException, CertificateException { // Create a self-signed root certificate System.out.println("Generate .."); final DistinguishedName rootDn = dn("CN=CA-Test"); final RootCertificate root = createSelfSignedCertificate(rootDn).build(); // Export the root certificate root.save("ca.cer"); System.out.println("CA ready. CA certificate saved to \"ca.cer\"."); // Generate CSR using Windows utilities System.out.println("Generate CSR with \"cert.req\"..."); generateCsr(); // Load the generated CSR, sign it and export the resulting certificate System.out.println("Sign CSR...");
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificateBuilder createSelfSignedCertificate( // final DistinguishedName subject) { // return new RootCertificateBuilderImpl(subject); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static CsrLoader loadCsr(final File csrFile) { // return new CsrLoaderImpl(csrFile); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CSR.java // public interface CSR { // // public DistinguishedName getSubject(); // // public PublicKey getPublicKey(); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/Certificate.java // public interface Certificate { // // public X509Certificate getX509Certificate(); // // public String print(); // // public void save(File file); // // public void save(String fileName); // // public CertificateWithPrivateKey attachPrivateKey(PrivateKey privateKey); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // } // Path: java-ca-lib/src/test/java/io/github/olivierlemasle/tests/it/WindowsIT.java import static io.github.olivierlemasle.ca.CA.createSelfSignedCertificate; import static io.github.olivierlemasle.ca.CA.dn; import static io.github.olivierlemasle.ca.CA.loadCsr; import static org.junit.Assert.assertTrue; import static org.junit.Assume.assumeTrue; import java.io.File; import java.io.IOException; import java.lang.ProcessBuilder.Redirect; import java.security.KeyManagementException; import java.security.KeyStore; import java.security.KeyStoreException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.security.cert.CertificateEncodingException; import java.security.cert.CertificateException; import java.security.cert.X509Certificate; import java.util.UUID; import javax.net.ssl.SSLContext; import org.apache.http.HttpEntity; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.ssl.SSLContexts; import org.apache.http.util.EntityUtils; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import io.github.olivierlemasle.ca.CSR; import io.github.olivierlemasle.ca.Certificate; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate; package io.github.olivierlemasle.tests.it; public class WindowsIT { @BeforeClass @AfterClass public static void clean() { final File caCertPath = new File("ca.cer"); caCertPath.delete(); final File reqPath = new File("cert.req"); reqPath.delete(); final File certPath = new File("cert.cer"); certPath.delete(); } @Before public void checkPlatform() { assumeTrue(TestUtils.isWindows()); assumeTrue(TestUtils.isWindowsAdministrator()); } @Test public void completeTest() throws IOException, InterruptedException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException, CertificateException { // Create a self-signed root certificate System.out.println("Generate .."); final DistinguishedName rootDn = dn("CN=CA-Test"); final RootCertificate root = createSelfSignedCertificate(rootDn).build(); // Export the root certificate root.save("ca.cer"); System.out.println("CA ready. CA certificate saved to \"ca.cer\"."); // Generate CSR using Windows utilities System.out.println("Generate CSR with \"cert.req\"..."); generateCsr(); // Load the generated CSR, sign it and export the resulting certificate System.out.println("Sign CSR...");
final CSR csr = loadCsr("cert.req").getCsr();
olivierlemasle/java-certificate-authority
java-ca-lib/src/test/java/io/github/olivierlemasle/tests/it/WindowsIT.java
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificateBuilder createSelfSignedCertificate( // final DistinguishedName subject) { // return new RootCertificateBuilderImpl(subject); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static CsrLoader loadCsr(final File csrFile) { // return new CsrLoaderImpl(csrFile); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CSR.java // public interface CSR { // // public DistinguishedName getSubject(); // // public PublicKey getPublicKey(); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/Certificate.java // public interface Certificate { // // public X509Certificate getX509Certificate(); // // public String print(); // // public void save(File file); // // public void save(String fileName); // // public CertificateWithPrivateKey attachPrivateKey(PrivateKey privateKey); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // }
import static io.github.olivierlemasle.ca.CA.createSelfSignedCertificate; import static io.github.olivierlemasle.ca.CA.dn; import static io.github.olivierlemasle.ca.CA.loadCsr; import static org.junit.Assert.assertTrue; import static org.junit.Assume.assumeTrue; import java.io.File; import java.io.IOException; import java.lang.ProcessBuilder.Redirect; import java.security.KeyManagementException; import java.security.KeyStore; import java.security.KeyStoreException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.security.cert.CertificateEncodingException; import java.security.cert.CertificateException; import java.security.cert.X509Certificate; import java.util.UUID; import javax.net.ssl.SSLContext; import org.apache.http.HttpEntity; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.ssl.SSLContexts; import org.apache.http.util.EntityUtils; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import io.github.olivierlemasle.ca.CSR; import io.github.olivierlemasle.ca.Certificate; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate;
package io.github.olivierlemasle.tests.it; public class WindowsIT { @BeforeClass @AfterClass public static void clean() { final File caCertPath = new File("ca.cer"); caCertPath.delete(); final File reqPath = new File("cert.req"); reqPath.delete(); final File certPath = new File("cert.cer"); certPath.delete(); } @Before public void checkPlatform() { assumeTrue(TestUtils.isWindows()); assumeTrue(TestUtils.isWindowsAdministrator()); } @Test public void completeTest() throws IOException, InterruptedException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException, CertificateException { // Create a self-signed root certificate System.out.println("Generate .."); final DistinguishedName rootDn = dn("CN=CA-Test"); final RootCertificate root = createSelfSignedCertificate(rootDn).build(); // Export the root certificate root.save("ca.cer"); System.out.println("CA ready. CA certificate saved to \"ca.cer\"."); // Generate CSR using Windows utilities System.out.println("Generate CSR with \"cert.req\"..."); generateCsr(); // Load the generated CSR, sign it and export the resulting certificate System.out.println("Sign CSR..."); final CSR csr = loadCsr("cert.req").getCsr();
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificateBuilder createSelfSignedCertificate( // final DistinguishedName subject) { // return new RootCertificateBuilderImpl(subject); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static CsrLoader loadCsr(final File csrFile) { // return new CsrLoaderImpl(csrFile); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CSR.java // public interface CSR { // // public DistinguishedName getSubject(); // // public PublicKey getPublicKey(); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/Certificate.java // public interface Certificate { // // public X509Certificate getX509Certificate(); // // public String print(); // // public void save(File file); // // public void save(String fileName); // // public CertificateWithPrivateKey attachPrivateKey(PrivateKey privateKey); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // } // Path: java-ca-lib/src/test/java/io/github/olivierlemasle/tests/it/WindowsIT.java import static io.github.olivierlemasle.ca.CA.createSelfSignedCertificate; import static io.github.olivierlemasle.ca.CA.dn; import static io.github.olivierlemasle.ca.CA.loadCsr; import static org.junit.Assert.assertTrue; import static org.junit.Assume.assumeTrue; import java.io.File; import java.io.IOException; import java.lang.ProcessBuilder.Redirect; import java.security.KeyManagementException; import java.security.KeyStore; import java.security.KeyStoreException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.security.cert.CertificateEncodingException; import java.security.cert.CertificateException; import java.security.cert.X509Certificate; import java.util.UUID; import javax.net.ssl.SSLContext; import org.apache.http.HttpEntity; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.ssl.SSLContexts; import org.apache.http.util.EntityUtils; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import io.github.olivierlemasle.ca.CSR; import io.github.olivierlemasle.ca.Certificate; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate; package io.github.olivierlemasle.tests.it; public class WindowsIT { @BeforeClass @AfterClass public static void clean() { final File caCertPath = new File("ca.cer"); caCertPath.delete(); final File reqPath = new File("cert.req"); reqPath.delete(); final File certPath = new File("cert.cer"); certPath.delete(); } @Before public void checkPlatform() { assumeTrue(TestUtils.isWindows()); assumeTrue(TestUtils.isWindowsAdministrator()); } @Test public void completeTest() throws IOException, InterruptedException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException, CertificateException { // Create a self-signed root certificate System.out.println("Generate .."); final DistinguishedName rootDn = dn("CN=CA-Test"); final RootCertificate root = createSelfSignedCertificate(rootDn).build(); // Export the root certificate root.save("ca.cer"); System.out.println("CA ready. CA certificate saved to \"ca.cer\"."); // Generate CSR using Windows utilities System.out.println("Generate CSR with \"cert.req\"..."); generateCsr(); // Load the generated CSR, sign it and export the resulting certificate System.out.println("Sign CSR..."); final CSR csr = loadCsr("cert.req").getCsr();
final Certificate cert = root.signCsr(csr)
olivierlemasle/java-certificate-authority
java-ca-lib/src/main/java/io/github/olivierlemasle/ca/SignerImpl.java
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static BigInteger generateRandomSerialNumber() { // return SerialNumberGenerator.instance.generateRandomSerialNumber(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/Signer.java // public static interface SignerWithSerial extends Signer { // public Certificate sign(); // // public SignerWithSerial setNotBefore(final ZonedDateTime notBefore); // // public SignerWithSerial setNotAfter(final ZonedDateTime notAfter); // // public SignerWithSerial validDuringYears(final int years); // // public SignerWithSerial addExtension(final CertExtension extension); // // public SignerWithSerial addExtension(ASN1ObjectIdentifier oid, boolean isCritical, // ASN1Encodable value); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/ext/CertExtension.java // public class CertExtension { // private final ASN1ObjectIdentifier oid; // private final boolean isCritical; // private final ASN1Encodable value; // // public CertExtension(final ASN1ObjectIdentifier oid, final boolean isCritical, // final ASN1Encodable value) { // this.oid = oid; // this.isCritical = isCritical; // this.value = value; // } // // public ASN1ObjectIdentifier getOid() { // return oid; // } // // public boolean isCritical() { // return isCritical; // } // // public ASN1Encodable getValue() { // return value; // } // // @Override // public String toString() { // return "Extension [" + oid + "=" + value + "]"; // } // // }
import static io.github.olivierlemasle.ca.CA.generateRandomSerialNumber; import java.math.BigInteger; import java.security.InvalidKeyException; import java.security.KeyPair; import java.security.NoSuchAlgorithmException; import java.security.NoSuchProviderException; import java.security.PublicKey; import java.security.SignatureException; import java.security.cert.CertificateException; import java.security.cert.X509Certificate; import java.time.ZonedDateTime; import java.util.ArrayList; import java.util.Date; import java.util.List; import org.bouncycastle.asn1.ASN1Encodable; import org.bouncycastle.asn1.ASN1ObjectIdentifier; import org.bouncycastle.asn1.x509.Extension; import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo; import org.bouncycastle.cert.CertIOException; import org.bouncycastle.cert.X509CertificateHolder; import org.bouncycastle.cert.X509v3CertificateBuilder; import org.bouncycastle.cert.jcajce.JcaX509CertificateConverter; import org.bouncycastle.cert.jcajce.JcaX509ExtensionUtils; import org.bouncycastle.operator.ContentSigner; import org.bouncycastle.operator.OperatorCreationException; import org.bouncycastle.operator.jcajce.JcaContentSignerBuilder; import io.github.olivierlemasle.ca.Signer.SignerWithSerial; import io.github.olivierlemasle.ca.ext.CertExtension;
package io.github.olivierlemasle.ca; class SignerImpl implements Signer, SignerWithSerial { private static final String SIGNATURE_ALGORITHM = "SHA256withRSA"; private final KeyPair signerKeyPair; private final DistinguishedName signerDn; private final PublicKey publicKey; private final DistinguishedName dn;
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static BigInteger generateRandomSerialNumber() { // return SerialNumberGenerator.instance.generateRandomSerialNumber(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/Signer.java // public static interface SignerWithSerial extends Signer { // public Certificate sign(); // // public SignerWithSerial setNotBefore(final ZonedDateTime notBefore); // // public SignerWithSerial setNotAfter(final ZonedDateTime notAfter); // // public SignerWithSerial validDuringYears(final int years); // // public SignerWithSerial addExtension(final CertExtension extension); // // public SignerWithSerial addExtension(ASN1ObjectIdentifier oid, boolean isCritical, // ASN1Encodable value); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/ext/CertExtension.java // public class CertExtension { // private final ASN1ObjectIdentifier oid; // private final boolean isCritical; // private final ASN1Encodable value; // // public CertExtension(final ASN1ObjectIdentifier oid, final boolean isCritical, // final ASN1Encodable value) { // this.oid = oid; // this.isCritical = isCritical; // this.value = value; // } // // public ASN1ObjectIdentifier getOid() { // return oid; // } // // public boolean isCritical() { // return isCritical; // } // // public ASN1Encodable getValue() { // return value; // } // // @Override // public String toString() { // return "Extension [" + oid + "=" + value + "]"; // } // // } // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/SignerImpl.java import static io.github.olivierlemasle.ca.CA.generateRandomSerialNumber; import java.math.BigInteger; import java.security.InvalidKeyException; import java.security.KeyPair; import java.security.NoSuchAlgorithmException; import java.security.NoSuchProviderException; import java.security.PublicKey; import java.security.SignatureException; import java.security.cert.CertificateException; import java.security.cert.X509Certificate; import java.time.ZonedDateTime; import java.util.ArrayList; import java.util.Date; import java.util.List; import org.bouncycastle.asn1.ASN1Encodable; import org.bouncycastle.asn1.ASN1ObjectIdentifier; import org.bouncycastle.asn1.x509.Extension; import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo; import org.bouncycastle.cert.CertIOException; import org.bouncycastle.cert.X509CertificateHolder; import org.bouncycastle.cert.X509v3CertificateBuilder; import org.bouncycastle.cert.jcajce.JcaX509CertificateConverter; import org.bouncycastle.cert.jcajce.JcaX509ExtensionUtils; import org.bouncycastle.operator.ContentSigner; import org.bouncycastle.operator.OperatorCreationException; import org.bouncycastle.operator.jcajce.JcaContentSignerBuilder; import io.github.olivierlemasle.ca.Signer.SignerWithSerial; import io.github.olivierlemasle.ca.ext.CertExtension; package io.github.olivierlemasle.ca; class SignerImpl implements Signer, SignerWithSerial { private static final String SIGNATURE_ALGORITHM = "SHA256withRSA"; private final KeyPair signerKeyPair; private final DistinguishedName signerDn; private final PublicKey publicKey; private final DistinguishedName dn;
private final List<CertExtension> extensions = new ArrayList<>();
olivierlemasle/java-certificate-authority
java-ca-lib/src/main/java/io/github/olivierlemasle/ca/SignerImpl.java
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static BigInteger generateRandomSerialNumber() { // return SerialNumberGenerator.instance.generateRandomSerialNumber(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/Signer.java // public static interface SignerWithSerial extends Signer { // public Certificate sign(); // // public SignerWithSerial setNotBefore(final ZonedDateTime notBefore); // // public SignerWithSerial setNotAfter(final ZonedDateTime notAfter); // // public SignerWithSerial validDuringYears(final int years); // // public SignerWithSerial addExtension(final CertExtension extension); // // public SignerWithSerial addExtension(ASN1ObjectIdentifier oid, boolean isCritical, // ASN1Encodable value); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/ext/CertExtension.java // public class CertExtension { // private final ASN1ObjectIdentifier oid; // private final boolean isCritical; // private final ASN1Encodable value; // // public CertExtension(final ASN1ObjectIdentifier oid, final boolean isCritical, // final ASN1Encodable value) { // this.oid = oid; // this.isCritical = isCritical; // this.value = value; // } // // public ASN1ObjectIdentifier getOid() { // return oid; // } // // public boolean isCritical() { // return isCritical; // } // // public ASN1Encodable getValue() { // return value; // } // // @Override // public String toString() { // return "Extension [" + oid + "=" + value + "]"; // } // // }
import static io.github.olivierlemasle.ca.CA.generateRandomSerialNumber; import java.math.BigInteger; import java.security.InvalidKeyException; import java.security.KeyPair; import java.security.NoSuchAlgorithmException; import java.security.NoSuchProviderException; import java.security.PublicKey; import java.security.SignatureException; import java.security.cert.CertificateException; import java.security.cert.X509Certificate; import java.time.ZonedDateTime; import java.util.ArrayList; import java.util.Date; import java.util.List; import org.bouncycastle.asn1.ASN1Encodable; import org.bouncycastle.asn1.ASN1ObjectIdentifier; import org.bouncycastle.asn1.x509.Extension; import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo; import org.bouncycastle.cert.CertIOException; import org.bouncycastle.cert.X509CertificateHolder; import org.bouncycastle.cert.X509v3CertificateBuilder; import org.bouncycastle.cert.jcajce.JcaX509CertificateConverter; import org.bouncycastle.cert.jcajce.JcaX509ExtensionUtils; import org.bouncycastle.operator.ContentSigner; import org.bouncycastle.operator.OperatorCreationException; import org.bouncycastle.operator.jcajce.JcaContentSignerBuilder; import io.github.olivierlemasle.ca.Signer.SignerWithSerial; import io.github.olivierlemasle.ca.ext.CertExtension;
package io.github.olivierlemasle.ca; class SignerImpl implements Signer, SignerWithSerial { private static final String SIGNATURE_ALGORITHM = "SHA256withRSA"; private final KeyPair signerKeyPair; private final DistinguishedName signerDn; private final PublicKey publicKey; private final DistinguishedName dn; private final List<CertExtension> extensions = new ArrayList<>(); private BigInteger serialNumber; private ZonedDateTime notBefore = ZonedDateTime.now(); private ZonedDateTime notAfter = notBefore.plusYears(1); SignerImpl(final KeyPair signerKeyPair, final DistinguishedName signerDn, final PublicKey publicKey, final DistinguishedName dn) { this.signerKeyPair = signerKeyPair; this.signerDn = signerDn; this.publicKey = publicKey; this.dn = dn; } @Override public SignerWithSerial setSerialNumber(final BigInteger serialNumber) { this.serialNumber = serialNumber; return this; } @Override public SignerWithSerial setRandomSerialNumber() {
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static BigInteger generateRandomSerialNumber() { // return SerialNumberGenerator.instance.generateRandomSerialNumber(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/Signer.java // public static interface SignerWithSerial extends Signer { // public Certificate sign(); // // public SignerWithSerial setNotBefore(final ZonedDateTime notBefore); // // public SignerWithSerial setNotAfter(final ZonedDateTime notAfter); // // public SignerWithSerial validDuringYears(final int years); // // public SignerWithSerial addExtension(final CertExtension extension); // // public SignerWithSerial addExtension(ASN1ObjectIdentifier oid, boolean isCritical, // ASN1Encodable value); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/ext/CertExtension.java // public class CertExtension { // private final ASN1ObjectIdentifier oid; // private final boolean isCritical; // private final ASN1Encodable value; // // public CertExtension(final ASN1ObjectIdentifier oid, final boolean isCritical, // final ASN1Encodable value) { // this.oid = oid; // this.isCritical = isCritical; // this.value = value; // } // // public ASN1ObjectIdentifier getOid() { // return oid; // } // // public boolean isCritical() { // return isCritical; // } // // public ASN1Encodable getValue() { // return value; // } // // @Override // public String toString() { // return "Extension [" + oid + "=" + value + "]"; // } // // } // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/SignerImpl.java import static io.github.olivierlemasle.ca.CA.generateRandomSerialNumber; import java.math.BigInteger; import java.security.InvalidKeyException; import java.security.KeyPair; import java.security.NoSuchAlgorithmException; import java.security.NoSuchProviderException; import java.security.PublicKey; import java.security.SignatureException; import java.security.cert.CertificateException; import java.security.cert.X509Certificate; import java.time.ZonedDateTime; import java.util.ArrayList; import java.util.Date; import java.util.List; import org.bouncycastle.asn1.ASN1Encodable; import org.bouncycastle.asn1.ASN1ObjectIdentifier; import org.bouncycastle.asn1.x509.Extension; import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo; import org.bouncycastle.cert.CertIOException; import org.bouncycastle.cert.X509CertificateHolder; import org.bouncycastle.cert.X509v3CertificateBuilder; import org.bouncycastle.cert.jcajce.JcaX509CertificateConverter; import org.bouncycastle.cert.jcajce.JcaX509ExtensionUtils; import org.bouncycastle.operator.ContentSigner; import org.bouncycastle.operator.OperatorCreationException; import org.bouncycastle.operator.jcajce.JcaContentSignerBuilder; import io.github.olivierlemasle.ca.Signer.SignerWithSerial; import io.github.olivierlemasle.ca.ext.CertExtension; package io.github.olivierlemasle.ca; class SignerImpl implements Signer, SignerWithSerial { private static final String SIGNATURE_ALGORITHM = "SHA256withRSA"; private final KeyPair signerKeyPair; private final DistinguishedName signerDn; private final PublicKey publicKey; private final DistinguishedName dn; private final List<CertExtension> extensions = new ArrayList<>(); private BigInteger serialNumber; private ZonedDateTime notBefore = ZonedDateTime.now(); private ZonedDateTime notAfter = notBefore.plusYears(1); SignerImpl(final KeyPair signerKeyPair, final DistinguishedName signerDn, final PublicKey publicKey, final DistinguishedName dn) { this.signerKeyPair = signerKeyPair; this.signerDn = signerDn; this.publicKey = publicKey; this.dn = dn; } @Override public SignerWithSerial setSerialNumber(final BigInteger serialNumber) { this.serialNumber = serialNumber; return this; } @Override public SignerWithSerial setRandomSerialNumber() {
this.serialNumber = generateRandomSerialNumber();
olivierlemasle/java-certificate-authority
ca-api/src/main/java/io/github/olivierlemasle/caweb/CaConfiguration.java
// Path: ca-api/src/main/java/io/github/olivierlemasle/caweb/api/User.java // public class User { // @NotEmpty // private String name; // // @NotEmpty // @Email // private String email; // // @NotEmpty // private List<String> roles; // // public User() { // // Jackson // } // // public User(final String name, final String email, final List<String> roles) { // this.name = name; // this.email = email; // this.roles = roles; // } // // @JsonProperty // public String getName() { // return name; // } // // @JsonProperty // public String getEmail() { // return email; // } // // @JsonProperty // public List<String> getRoles() { // return roles; // } // }
import java.util.List; import javax.validation.Valid; import org.hibernate.validator.constraints.NotEmpty; import com.fasterxml.jackson.annotation.JsonProperty; import io.dropwizard.Configuration; import io.github.olivierlemasle.caweb.api.User;
package io.github.olivierlemasle.caweb; public class CaConfiguration extends Configuration { @NotEmpty @Valid
// Path: ca-api/src/main/java/io/github/olivierlemasle/caweb/api/User.java // public class User { // @NotEmpty // private String name; // // @NotEmpty // @Email // private String email; // // @NotEmpty // private List<String> roles; // // public User() { // // Jackson // } // // public User(final String name, final String email, final List<String> roles) { // this.name = name; // this.email = email; // this.roles = roles; // } // // @JsonProperty // public String getName() { // return name; // } // // @JsonProperty // public String getEmail() { // return email; // } // // @JsonProperty // public List<String> getRoles() { // return roles; // } // } // Path: ca-api/src/main/java/io/github/olivierlemasle/caweb/CaConfiguration.java import java.util.List; import javax.validation.Valid; import org.hibernate.validator.constraints.NotEmpty; import com.fasterxml.jackson.annotation.JsonProperty; import io.dropwizard.Configuration; import io.github.olivierlemasle.caweb.api.User; package io.github.olivierlemasle.caweb; public class CaConfiguration extends Configuration { @NotEmpty @Valid
private List<User> users;
olivierlemasle/java-certificate-authority
java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificateImpl.java
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // }
import static io.github.olivierlemasle.ca.CA.dn; import java.io.IOException; import java.security.KeyPair; import java.security.PrivateKey; import java.security.cert.CertificateEncodingException; import java.security.cert.X509Certificate; import org.bouncycastle.cert.X509CertificateHolder;
package io.github.olivierlemasle.ca; class RootCertificateImpl extends CertificateWithPrivateKeyImpl implements RootCertificate { static final String KEYSTORE_TYPE = "PKCS12"; private final X509CertificateHolder caCertificateHolder; RootCertificateImpl(final X509Certificate caCertificate, final PrivateKey caPrivateKey) { super(caCertificate, caPrivateKey); try { this.caCertificateHolder = new X509CertificateHolder(caCertificate.getEncoded()); } catch (CertificateEncodingException | IOException e) { throw new CaException(e); } } @Override public Signer signCsr(final CSR request) { final KeyPair pair = new KeyPair(getX509Certificate().getPublicKey(), getPrivateKey());
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificateImpl.java import static io.github.olivierlemasle.ca.CA.dn; import java.io.IOException; import java.security.KeyPair; import java.security.PrivateKey; import java.security.cert.CertificateEncodingException; import java.security.cert.X509Certificate; import org.bouncycastle.cert.X509CertificateHolder; package io.github.olivierlemasle.ca; class RootCertificateImpl extends CertificateWithPrivateKeyImpl implements RootCertificate { static final String KEYSTORE_TYPE = "PKCS12"; private final X509CertificateHolder caCertificateHolder; RootCertificateImpl(final X509Certificate caCertificate, final PrivateKey caPrivateKey) { super(caCertificate, caPrivateKey); try { this.caCertificateHolder = new X509CertificateHolder(caCertificate.getEncoded()); } catch (CertificateEncodingException | IOException e) { throw new CaException(e); } } @Override public Signer signCsr(final CSR request) { final KeyPair pair = new KeyPair(getX509Certificate().getPublicKey(), getPrivateKey());
final DistinguishedName signerSubject = dn(caCertificateHolder.getSubject());
olivierlemasle/java-certificate-authority
java-ca-lib/src/main/java/io/github/olivierlemasle/ca/Signer.java
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/ext/CertExtension.java // public class CertExtension { // private final ASN1ObjectIdentifier oid; // private final boolean isCritical; // private final ASN1Encodable value; // // public CertExtension(final ASN1ObjectIdentifier oid, final boolean isCritical, // final ASN1Encodable value) { // this.oid = oid; // this.isCritical = isCritical; // this.value = value; // } // // public ASN1ObjectIdentifier getOid() { // return oid; // } // // public boolean isCritical() { // return isCritical; // } // // public ASN1Encodable getValue() { // return value; // } // // @Override // public String toString() { // return "Extension [" + oid + "=" + value + "]"; // } // // }
import java.math.BigInteger; import java.time.ZonedDateTime; import org.bouncycastle.asn1.ASN1Encodable; import org.bouncycastle.asn1.ASN1ObjectIdentifier; import io.github.olivierlemasle.ca.ext.CertExtension;
package io.github.olivierlemasle.ca; public interface Signer { public SignerWithSerial setSerialNumber(final BigInteger serialNumber); public SignerWithSerial setRandomSerialNumber(); public static interface SignerWithSerial extends Signer { public Certificate sign(); public SignerWithSerial setNotBefore(final ZonedDateTime notBefore); public SignerWithSerial setNotAfter(final ZonedDateTime notAfter); public SignerWithSerial validDuringYears(final int years);
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/ext/CertExtension.java // public class CertExtension { // private final ASN1ObjectIdentifier oid; // private final boolean isCritical; // private final ASN1Encodable value; // // public CertExtension(final ASN1ObjectIdentifier oid, final boolean isCritical, // final ASN1Encodable value) { // this.oid = oid; // this.isCritical = isCritical; // this.value = value; // } // // public ASN1ObjectIdentifier getOid() { // return oid; // } // // public boolean isCritical() { // return isCritical; // } // // public ASN1Encodable getValue() { // return value; // } // // @Override // public String toString() { // return "Extension [" + oid + "=" + value + "]"; // } // // } // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/Signer.java import java.math.BigInteger; import java.time.ZonedDateTime; import org.bouncycastle.asn1.ASN1Encodable; import org.bouncycastle.asn1.ASN1ObjectIdentifier; import io.github.olivierlemasle.ca.ext.CertExtension; package io.github.olivierlemasle.ca; public interface Signer { public SignerWithSerial setSerialNumber(final BigInteger serialNumber); public SignerWithSerial setRandomSerialNumber(); public static interface SignerWithSerial extends Signer { public Certificate sign(); public SignerWithSerial setNotBefore(final ZonedDateTime notBefore); public SignerWithSerial setNotAfter(final ZonedDateTime notAfter); public SignerWithSerial validDuringYears(final int years);
public SignerWithSerial addExtension(final CertExtension extension);
olivierlemasle/java-certificate-authority
ca-api/src/main/java/io/github/olivierlemasle/caweb/json/DnDeserializer.java
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DnBuilder.java // public interface DnBuilder { // // public DnBuilder setCn(String cn); // // public DnBuilder setCommonName(String cn); // // public DnBuilder setL(String l); // // public DnBuilder setLocalityName(String l); // // public DnBuilder setSt(String st); // // public DnBuilder setStateOrProvinceName(String st); // // public DnBuilder setO(String o); // // public DnBuilder setOrganizationName(String o); // // public DnBuilder setOu(String ou); // // public DnBuilder setOrganizationalUnitName(String ou); // // public DnBuilder setC(String c); // // public DnBuilder setCountryName(String c); // // public DnBuilder setStreet(String street); // // public DistinguishedName build(); // // }
import static io.github.olivierlemasle.ca.CA.dn; import java.io.IOException; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonToken; import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.deser.std.StdDeserializer; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.DnBuilder;
package io.github.olivierlemasle.caweb.json; class DnDeserializer extends StdDeserializer<DistinguishedName> { private static final long serialVersionUID = 9192735092617403295L; public DnDeserializer() { super(DistinguishedName.class); } @Override public DistinguishedName deserialize(final JsonParser p, final DeserializationContext ctxt) throws IOException { if (p.getCurrentToken() == JsonToken.START_OBJECT) {
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DnBuilder.java // public interface DnBuilder { // // public DnBuilder setCn(String cn); // // public DnBuilder setCommonName(String cn); // // public DnBuilder setL(String l); // // public DnBuilder setLocalityName(String l); // // public DnBuilder setSt(String st); // // public DnBuilder setStateOrProvinceName(String st); // // public DnBuilder setO(String o); // // public DnBuilder setOrganizationName(String o); // // public DnBuilder setOu(String ou); // // public DnBuilder setOrganizationalUnitName(String ou); // // public DnBuilder setC(String c); // // public DnBuilder setCountryName(String c); // // public DnBuilder setStreet(String street); // // public DistinguishedName build(); // // } // Path: ca-api/src/main/java/io/github/olivierlemasle/caweb/json/DnDeserializer.java import static io.github.olivierlemasle.ca.CA.dn; import java.io.IOException; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonToken; import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.deser.std.StdDeserializer; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.DnBuilder; package io.github.olivierlemasle.caweb.json; class DnDeserializer extends StdDeserializer<DistinguishedName> { private static final long serialVersionUID = 9192735092617403295L; public DnDeserializer() { super(DistinguishedName.class); } @Override public DistinguishedName deserialize(final JsonParser p, final DeserializationContext ctxt) throws IOException { if (p.getCurrentToken() == JsonToken.START_OBJECT) {
DnBuilder dnBuilder = dn();
olivierlemasle/java-certificate-authority
ca-api/src/main/java/io/github/olivierlemasle/caweb/json/DnDeserializer.java
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DnBuilder.java // public interface DnBuilder { // // public DnBuilder setCn(String cn); // // public DnBuilder setCommonName(String cn); // // public DnBuilder setL(String l); // // public DnBuilder setLocalityName(String l); // // public DnBuilder setSt(String st); // // public DnBuilder setStateOrProvinceName(String st); // // public DnBuilder setO(String o); // // public DnBuilder setOrganizationName(String o); // // public DnBuilder setOu(String ou); // // public DnBuilder setOrganizationalUnitName(String ou); // // public DnBuilder setC(String c); // // public DnBuilder setCountryName(String c); // // public DnBuilder setStreet(String street); // // public DistinguishedName build(); // // }
import static io.github.olivierlemasle.ca.CA.dn; import java.io.IOException; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonToken; import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.deser.std.StdDeserializer; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.DnBuilder;
package io.github.olivierlemasle.caweb.json; class DnDeserializer extends StdDeserializer<DistinguishedName> { private static final long serialVersionUID = 9192735092617403295L; public DnDeserializer() { super(DistinguishedName.class); } @Override public DistinguishedName deserialize(final JsonParser p, final DeserializationContext ctxt) throws IOException { if (p.getCurrentToken() == JsonToken.START_OBJECT) {
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DnBuilder.java // public interface DnBuilder { // // public DnBuilder setCn(String cn); // // public DnBuilder setCommonName(String cn); // // public DnBuilder setL(String l); // // public DnBuilder setLocalityName(String l); // // public DnBuilder setSt(String st); // // public DnBuilder setStateOrProvinceName(String st); // // public DnBuilder setO(String o); // // public DnBuilder setOrganizationName(String o); // // public DnBuilder setOu(String ou); // // public DnBuilder setOrganizationalUnitName(String ou); // // public DnBuilder setC(String c); // // public DnBuilder setCountryName(String c); // // public DnBuilder setStreet(String street); // // public DistinguishedName build(); // // } // Path: ca-api/src/main/java/io/github/olivierlemasle/caweb/json/DnDeserializer.java import static io.github.olivierlemasle.ca.CA.dn; import java.io.IOException; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonToken; import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.deser.std.StdDeserializer; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.DnBuilder; package io.github.olivierlemasle.caweb.json; class DnDeserializer extends StdDeserializer<DistinguishedName> { private static final long serialVersionUID = 9192735092617403295L; public DnDeserializer() { super(DistinguishedName.class); } @Override public DistinguishedName deserialize(final JsonParser p, final DeserializationContext ctxt) throws IOException { if (p.getCurrentToken() == JsonToken.START_OBJECT) {
DnBuilder dnBuilder = dn();
olivierlemasle/java-certificate-authority
ca-api/src/main/java/io/github/olivierlemasle/caweb/resources/UsersResource.java
// Path: ca-api/src/main/java/io/github/olivierlemasle/caweb/api/User.java // public class User { // @NotEmpty // private String name; // // @NotEmpty // @Email // private String email; // // @NotEmpty // private List<String> roles; // // public User() { // // Jackson // } // // public User(final String name, final String email, final List<String> roles) { // this.name = name; // this.email = email; // this.roles = roles; // } // // @JsonProperty // public String getName() { // return name; // } // // @JsonProperty // public String getEmail() { // return email; // } // // @JsonProperty // public List<String> getRoles() { // return roles; // } // }
import java.util.List; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import com.codahale.metrics.annotation.Timed; import io.github.olivierlemasle.caweb.api.User;
package io.github.olivierlemasle.caweb.resources; @Path("/users") @Produces(MediaType.APPLICATION_JSON) public class UsersResource {
// Path: ca-api/src/main/java/io/github/olivierlemasle/caweb/api/User.java // public class User { // @NotEmpty // private String name; // // @NotEmpty // @Email // private String email; // // @NotEmpty // private List<String> roles; // // public User() { // // Jackson // } // // public User(final String name, final String email, final List<String> roles) { // this.name = name; // this.email = email; // this.roles = roles; // } // // @JsonProperty // public String getName() { // return name; // } // // @JsonProperty // public String getEmail() { // return email; // } // // @JsonProperty // public List<String> getRoles() { // return roles; // } // } // Path: ca-api/src/main/java/io/github/olivierlemasle/caweb/resources/UsersResource.java import java.util.List; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import com.codahale.metrics.annotation.Timed; import io.github.olivierlemasle.caweb.api.User; package io.github.olivierlemasle.caweb.resources; @Path("/users") @Produces(MediaType.APPLICATION_JSON) public class UsersResource {
private final List<User> users;
olivierlemasle/java-certificate-authority
java-ca-lib/src/test/java/io/github/olivierlemasle/tests/SignTest.java
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static CsrBuilder createCsr() { // return new CsrBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificateBuilder createSelfSignedCertificate( // final DistinguishedName subject) { // return new RootCertificateBuilderImpl(subject); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CSR.java // public interface CSR { // // public DistinguishedName getSubject(); // // public PublicKey getPublicKey(); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // }
import static io.github.olivierlemasle.ca.CA.createCsr; import static io.github.olivierlemasle.ca.CA.createSelfSignedCertificate; import static io.github.olivierlemasle.ca.CA.dn; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; import java.security.cert.CertificateExpiredException; import java.security.cert.CertificateNotYetValidException; import java.security.cert.X509Certificate; import org.junit.Test; import io.github.olivierlemasle.ca.CSR; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate;
package io.github.olivierlemasle.tests; public class SignTest { @Test public void sign() {
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static CsrBuilder createCsr() { // return new CsrBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificateBuilder createSelfSignedCertificate( // final DistinguishedName subject) { // return new RootCertificateBuilderImpl(subject); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CSR.java // public interface CSR { // // public DistinguishedName getSubject(); // // public PublicKey getPublicKey(); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // } // Path: java-ca-lib/src/test/java/io/github/olivierlemasle/tests/SignTest.java import static io.github.olivierlemasle.ca.CA.createCsr; import static io.github.olivierlemasle.ca.CA.createSelfSignedCertificate; import static io.github.olivierlemasle.ca.CA.dn; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; import java.security.cert.CertificateExpiredException; import java.security.cert.CertificateNotYetValidException; import java.security.cert.X509Certificate; import org.junit.Test; import io.github.olivierlemasle.ca.CSR; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate; package io.github.olivierlemasle.tests; public class SignTest { @Test public void sign() {
final DistinguishedName caName = dn("CN=CA-Test");
olivierlemasle/java-certificate-authority
java-ca-lib/src/test/java/io/github/olivierlemasle/tests/SignTest.java
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static CsrBuilder createCsr() { // return new CsrBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificateBuilder createSelfSignedCertificate( // final DistinguishedName subject) { // return new RootCertificateBuilderImpl(subject); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CSR.java // public interface CSR { // // public DistinguishedName getSubject(); // // public PublicKey getPublicKey(); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // }
import static io.github.olivierlemasle.ca.CA.createCsr; import static io.github.olivierlemasle.ca.CA.createSelfSignedCertificate; import static io.github.olivierlemasle.ca.CA.dn; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; import java.security.cert.CertificateExpiredException; import java.security.cert.CertificateNotYetValidException; import java.security.cert.X509Certificate; import org.junit.Test; import io.github.olivierlemasle.ca.CSR; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate;
package io.github.olivierlemasle.tests; public class SignTest { @Test public void sign() {
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static CsrBuilder createCsr() { // return new CsrBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificateBuilder createSelfSignedCertificate( // final DistinguishedName subject) { // return new RootCertificateBuilderImpl(subject); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CSR.java // public interface CSR { // // public DistinguishedName getSubject(); // // public PublicKey getPublicKey(); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // } // Path: java-ca-lib/src/test/java/io/github/olivierlemasle/tests/SignTest.java import static io.github.olivierlemasle.ca.CA.createCsr; import static io.github.olivierlemasle.ca.CA.createSelfSignedCertificate; import static io.github.olivierlemasle.ca.CA.dn; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; import java.security.cert.CertificateExpiredException; import java.security.cert.CertificateNotYetValidException; import java.security.cert.X509Certificate; import org.junit.Test; import io.github.olivierlemasle.ca.CSR; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate; package io.github.olivierlemasle.tests; public class SignTest { @Test public void sign() {
final DistinguishedName caName = dn("CN=CA-Test");
olivierlemasle/java-certificate-authority
java-ca-lib/src/test/java/io/github/olivierlemasle/tests/SignTest.java
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static CsrBuilder createCsr() { // return new CsrBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificateBuilder createSelfSignedCertificate( // final DistinguishedName subject) { // return new RootCertificateBuilderImpl(subject); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CSR.java // public interface CSR { // // public DistinguishedName getSubject(); // // public PublicKey getPublicKey(); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // }
import static io.github.olivierlemasle.ca.CA.createCsr; import static io.github.olivierlemasle.ca.CA.createSelfSignedCertificate; import static io.github.olivierlemasle.ca.CA.dn; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; import java.security.cert.CertificateExpiredException; import java.security.cert.CertificateNotYetValidException; import java.security.cert.X509Certificate; import org.junit.Test; import io.github.olivierlemasle.ca.CSR; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate;
package io.github.olivierlemasle.tests; public class SignTest { @Test public void sign() { final DistinguishedName caName = dn("CN=CA-Test");
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static CsrBuilder createCsr() { // return new CsrBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificateBuilder createSelfSignedCertificate( // final DistinguishedName subject) { // return new RootCertificateBuilderImpl(subject); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CSR.java // public interface CSR { // // public DistinguishedName getSubject(); // // public PublicKey getPublicKey(); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // } // Path: java-ca-lib/src/test/java/io/github/olivierlemasle/tests/SignTest.java import static io.github.olivierlemasle.ca.CA.createCsr; import static io.github.olivierlemasle.ca.CA.createSelfSignedCertificate; import static io.github.olivierlemasle.ca.CA.dn; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; import java.security.cert.CertificateExpiredException; import java.security.cert.CertificateNotYetValidException; import java.security.cert.X509Certificate; import org.junit.Test; import io.github.olivierlemasle.ca.CSR; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate; package io.github.olivierlemasle.tests; public class SignTest { @Test public void sign() { final DistinguishedName caName = dn("CN=CA-Test");
final RootCertificate ca = createSelfSignedCertificate(caName).build();
olivierlemasle/java-certificate-authority
java-ca-lib/src/test/java/io/github/olivierlemasle/tests/SignTest.java
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static CsrBuilder createCsr() { // return new CsrBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificateBuilder createSelfSignedCertificate( // final DistinguishedName subject) { // return new RootCertificateBuilderImpl(subject); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CSR.java // public interface CSR { // // public DistinguishedName getSubject(); // // public PublicKey getPublicKey(); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // }
import static io.github.olivierlemasle.ca.CA.createCsr; import static io.github.olivierlemasle.ca.CA.createSelfSignedCertificate; import static io.github.olivierlemasle.ca.CA.dn; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; import java.security.cert.CertificateExpiredException; import java.security.cert.CertificateNotYetValidException; import java.security.cert.X509Certificate; import org.junit.Test; import io.github.olivierlemasle.ca.CSR; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate;
package io.github.olivierlemasle.tests; public class SignTest { @Test public void sign() { final DistinguishedName caName = dn("CN=CA-Test");
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static CsrBuilder createCsr() { // return new CsrBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificateBuilder createSelfSignedCertificate( // final DistinguishedName subject) { // return new RootCertificateBuilderImpl(subject); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CSR.java // public interface CSR { // // public DistinguishedName getSubject(); // // public PublicKey getPublicKey(); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // } // Path: java-ca-lib/src/test/java/io/github/olivierlemasle/tests/SignTest.java import static io.github.olivierlemasle.ca.CA.createCsr; import static io.github.olivierlemasle.ca.CA.createSelfSignedCertificate; import static io.github.olivierlemasle.ca.CA.dn; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; import java.security.cert.CertificateExpiredException; import java.security.cert.CertificateNotYetValidException; import java.security.cert.X509Certificate; import org.junit.Test; import io.github.olivierlemasle.ca.CSR; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate; package io.github.olivierlemasle.tests; public class SignTest { @Test public void sign() { final DistinguishedName caName = dn("CN=CA-Test");
final RootCertificate ca = createSelfSignedCertificate(caName).build();
olivierlemasle/java-certificate-authority
java-ca-lib/src/test/java/io/github/olivierlemasle/tests/SignTest.java
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static CsrBuilder createCsr() { // return new CsrBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificateBuilder createSelfSignedCertificate( // final DistinguishedName subject) { // return new RootCertificateBuilderImpl(subject); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CSR.java // public interface CSR { // // public DistinguishedName getSubject(); // // public PublicKey getPublicKey(); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // }
import static io.github.olivierlemasle.ca.CA.createCsr; import static io.github.olivierlemasle.ca.CA.createSelfSignedCertificate; import static io.github.olivierlemasle.ca.CA.dn; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; import java.security.cert.CertificateExpiredException; import java.security.cert.CertificateNotYetValidException; import java.security.cert.X509Certificate; import org.junit.Test; import io.github.olivierlemasle.ca.CSR; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate;
package io.github.olivierlemasle.tests; public class SignTest { @Test public void sign() { final DistinguishedName caName = dn("CN=CA-Test"); final RootCertificate ca = createSelfSignedCertificate(caName).build();
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static CsrBuilder createCsr() { // return new CsrBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificateBuilder createSelfSignedCertificate( // final DistinguishedName subject) { // return new RootCertificateBuilderImpl(subject); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CSR.java // public interface CSR { // // public DistinguishedName getSubject(); // // public PublicKey getPublicKey(); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // } // Path: java-ca-lib/src/test/java/io/github/olivierlemasle/tests/SignTest.java import static io.github.olivierlemasle.ca.CA.createCsr; import static io.github.olivierlemasle.ca.CA.createSelfSignedCertificate; import static io.github.olivierlemasle.ca.CA.dn; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; import java.security.cert.CertificateExpiredException; import java.security.cert.CertificateNotYetValidException; import java.security.cert.X509Certificate; import org.junit.Test; import io.github.olivierlemasle.ca.CSR; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate; package io.github.olivierlemasle.tests; public class SignTest { @Test public void sign() { final DistinguishedName caName = dn("CN=CA-Test"); final RootCertificate ca = createSelfSignedCertificate(caName).build();
final CSR csr = createCsr().generateRequest(dn("CN=test"));
olivierlemasle/java-certificate-authority
java-ca-lib/src/test/java/io/github/olivierlemasle/tests/SignTest.java
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static CsrBuilder createCsr() { // return new CsrBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificateBuilder createSelfSignedCertificate( // final DistinguishedName subject) { // return new RootCertificateBuilderImpl(subject); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CSR.java // public interface CSR { // // public DistinguishedName getSubject(); // // public PublicKey getPublicKey(); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // }
import static io.github.olivierlemasle.ca.CA.createCsr; import static io.github.olivierlemasle.ca.CA.createSelfSignedCertificate; import static io.github.olivierlemasle.ca.CA.dn; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; import java.security.cert.CertificateExpiredException; import java.security.cert.CertificateNotYetValidException; import java.security.cert.X509Certificate; import org.junit.Test; import io.github.olivierlemasle.ca.CSR; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate;
package io.github.olivierlemasle.tests; public class SignTest { @Test public void sign() { final DistinguishedName caName = dn("CN=CA-Test"); final RootCertificate ca = createSelfSignedCertificate(caName).build();
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static CsrBuilder createCsr() { // return new CsrBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificateBuilder createSelfSignedCertificate( // final DistinguishedName subject) { // return new RootCertificateBuilderImpl(subject); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CSR.java // public interface CSR { // // public DistinguishedName getSubject(); // // public PublicKey getPublicKey(); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // } // Path: java-ca-lib/src/test/java/io/github/olivierlemasle/tests/SignTest.java import static io.github.olivierlemasle.ca.CA.createCsr; import static io.github.olivierlemasle.ca.CA.createSelfSignedCertificate; import static io.github.olivierlemasle.ca.CA.dn; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; import java.security.cert.CertificateExpiredException; import java.security.cert.CertificateNotYetValidException; import java.security.cert.X509Certificate; import org.junit.Test; import io.github.olivierlemasle.ca.CSR; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate; package io.github.olivierlemasle.tests; public class SignTest { @Test public void sign() { final DistinguishedName caName = dn("CN=CA-Test"); final RootCertificate ca = createSelfSignedCertificate(caName).build();
final CSR csr = createCsr().generateRequest(dn("CN=test"));
olivierlemasle/java-certificate-authority
ca-api/src/main/java/io/github/olivierlemasle/caweb/json/CertJsonModule.java
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // }
import java.security.cert.X509Certificate; import com.fasterxml.jackson.databind.module.SimpleModule; import io.github.olivierlemasle.ca.DistinguishedName;
package io.github.olivierlemasle.caweb.json; public class CertJsonModule extends SimpleModule { private static final long serialVersionUID = 5830481586565293705L; public CertJsonModule() {
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // Path: ca-api/src/main/java/io/github/olivierlemasle/caweb/json/CertJsonModule.java import java.security.cert.X509Certificate; import com.fasterxml.jackson.databind.module.SimpleModule; import io.github.olivierlemasle.ca.DistinguishedName; package io.github.olivierlemasle.caweb.json; public class CertJsonModule extends SimpleModule { private static final long serialVersionUID = 5830481586565293705L; public CertJsonModule() {
addSerializer(DistinguishedName.class, new DnSerializer());
olivierlemasle/java-certificate-authority
java-ca-lib/src/test/java/io/github/olivierlemasle/tests/DistinguishedNameTest.java
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // }
import static io.github.olivierlemasle.ca.CA.dn; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import javax.security.auth.x500.X500Principal; import org.bouncycastle.asn1.x500.X500Name; import org.junit.Test; import io.github.olivierlemasle.ca.DistinguishedName;
package io.github.olivierlemasle.tests; public class DistinguishedNameTest { @Test public void testImplementations() {
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // Path: java-ca-lib/src/test/java/io/github/olivierlemasle/tests/DistinguishedNameTest.java import static io.github.olivierlemasle.ca.CA.dn; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import javax.security.auth.x500.X500Principal; import org.bouncycastle.asn1.x500.X500Name; import org.junit.Test; import io.github.olivierlemasle.ca.DistinguishedName; package io.github.olivierlemasle.tests; public class DistinguishedNameTest { @Test public void testImplementations() {
final DistinguishedName dn = dn("CN=test");
olivierlemasle/java-certificate-authority
java-ca-lib/src/test/java/io/github/olivierlemasle/tests/DistinguishedNameTest.java
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // }
import static io.github.olivierlemasle.ca.CA.dn; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import javax.security.auth.x500.X500Principal; import org.bouncycastle.asn1.x500.X500Name; import org.junit.Test; import io.github.olivierlemasle.ca.DistinguishedName;
package io.github.olivierlemasle.tests; public class DistinguishedNameTest { @Test public void testImplementations() {
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // Path: java-ca-lib/src/test/java/io/github/olivierlemasle/tests/DistinguishedNameTest.java import static io.github.olivierlemasle.ca.CA.dn; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import javax.security.auth.x500.X500Principal; import org.bouncycastle.asn1.x500.X500Name; import org.junit.Test; import io.github.olivierlemasle.ca.DistinguishedName; package io.github.olivierlemasle.tests; public class DistinguishedNameTest { @Test public void testImplementations() {
final DistinguishedName dn = dn("CN=test");
olivierlemasle/java-certificate-authority
ca-api/src/main/java/io/github/olivierlemasle/caweb/cli/CreateSelfSignedCertificate.java
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificateBuilder createSelfSignedCertificate( // final DistinguishedName subject) { // return new RootCertificateBuilderImpl(subject); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // }
import static io.github.olivierlemasle.ca.CA.createSelfSignedCertificate; import static io.github.olivierlemasle.ca.CA.dn; import io.dropwizard.cli.Command; import io.dropwizard.setup.Bootstrap; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate; import net.sourceforge.argparse4j.inf.Namespace; import net.sourceforge.argparse4j.inf.Subparser;
public void configure(final Subparser parser) { parser.addArgument("-s", "--subject") .dest("subject") .type(String.class) .required(true) .help("The subject CN"); parser.addArgument("-o", "--out") .dest("out") .type(String.class) .required(true) .help("The name of the keystore to be created"); parser.addArgument("-p", "--password") .dest("password") .type(String.class) .required(true) .help("The password of the keystore to be created"); parser.addArgument("-c", "--cert") .dest("cert") .type(String.class) .required(true) .help("The certificate file to be created"); } @Override public void run(final Bootstrap<?> bootstrap, final Namespace namespace) throws Exception { final String subject = namespace.getString("subject"); final String out = namespace.getString("out"); final String password = namespace.getString("password"); final String cert = namespace.getString("cert");
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificateBuilder createSelfSignedCertificate( // final DistinguishedName subject) { // return new RootCertificateBuilderImpl(subject); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // } // Path: ca-api/src/main/java/io/github/olivierlemasle/caweb/cli/CreateSelfSignedCertificate.java import static io.github.olivierlemasle.ca.CA.createSelfSignedCertificate; import static io.github.olivierlemasle.ca.CA.dn; import io.dropwizard.cli.Command; import io.dropwizard.setup.Bootstrap; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate; import net.sourceforge.argparse4j.inf.Namespace; import net.sourceforge.argparse4j.inf.Subparser; public void configure(final Subparser parser) { parser.addArgument("-s", "--subject") .dest("subject") .type(String.class) .required(true) .help("The subject CN"); parser.addArgument("-o", "--out") .dest("out") .type(String.class) .required(true) .help("The name of the keystore to be created"); parser.addArgument("-p", "--password") .dest("password") .type(String.class) .required(true) .help("The password of the keystore to be created"); parser.addArgument("-c", "--cert") .dest("cert") .type(String.class) .required(true) .help("The certificate file to be created"); } @Override public void run(final Bootstrap<?> bootstrap, final Namespace namespace) throws Exception { final String subject = namespace.getString("subject"); final String out = namespace.getString("out"); final String password = namespace.getString("password"); final String cert = namespace.getString("cert");
final DistinguishedName dn = dn().setCn(subject).build();
olivierlemasle/java-certificate-authority
ca-api/src/main/java/io/github/olivierlemasle/caweb/cli/CreateSelfSignedCertificate.java
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificateBuilder createSelfSignedCertificate( // final DistinguishedName subject) { // return new RootCertificateBuilderImpl(subject); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // }
import static io.github.olivierlemasle.ca.CA.createSelfSignedCertificate; import static io.github.olivierlemasle.ca.CA.dn; import io.dropwizard.cli.Command; import io.dropwizard.setup.Bootstrap; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate; import net.sourceforge.argparse4j.inf.Namespace; import net.sourceforge.argparse4j.inf.Subparser;
public void configure(final Subparser parser) { parser.addArgument("-s", "--subject") .dest("subject") .type(String.class) .required(true) .help("The subject CN"); parser.addArgument("-o", "--out") .dest("out") .type(String.class) .required(true) .help("The name of the keystore to be created"); parser.addArgument("-p", "--password") .dest("password") .type(String.class) .required(true) .help("The password of the keystore to be created"); parser.addArgument("-c", "--cert") .dest("cert") .type(String.class) .required(true) .help("The certificate file to be created"); } @Override public void run(final Bootstrap<?> bootstrap, final Namespace namespace) throws Exception { final String subject = namespace.getString("subject"); final String out = namespace.getString("out"); final String password = namespace.getString("password"); final String cert = namespace.getString("cert");
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificateBuilder createSelfSignedCertificate( // final DistinguishedName subject) { // return new RootCertificateBuilderImpl(subject); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // } // Path: ca-api/src/main/java/io/github/olivierlemasle/caweb/cli/CreateSelfSignedCertificate.java import static io.github.olivierlemasle.ca.CA.createSelfSignedCertificate; import static io.github.olivierlemasle.ca.CA.dn; import io.dropwizard.cli.Command; import io.dropwizard.setup.Bootstrap; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate; import net.sourceforge.argparse4j.inf.Namespace; import net.sourceforge.argparse4j.inf.Subparser; public void configure(final Subparser parser) { parser.addArgument("-s", "--subject") .dest("subject") .type(String.class) .required(true) .help("The subject CN"); parser.addArgument("-o", "--out") .dest("out") .type(String.class) .required(true) .help("The name of the keystore to be created"); parser.addArgument("-p", "--password") .dest("password") .type(String.class) .required(true) .help("The password of the keystore to be created"); parser.addArgument("-c", "--cert") .dest("cert") .type(String.class) .required(true) .help("The certificate file to be created"); } @Override public void run(final Bootstrap<?> bootstrap, final Namespace namespace) throws Exception { final String subject = namespace.getString("subject"); final String out = namespace.getString("out"); final String password = namespace.getString("password"); final String cert = namespace.getString("cert");
final DistinguishedName dn = dn().setCn(subject).build();
olivierlemasle/java-certificate-authority
ca-api/src/main/java/io/github/olivierlemasle/caweb/cli/CreateSelfSignedCertificate.java
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificateBuilder createSelfSignedCertificate( // final DistinguishedName subject) { // return new RootCertificateBuilderImpl(subject); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // }
import static io.github.olivierlemasle.ca.CA.createSelfSignedCertificate; import static io.github.olivierlemasle.ca.CA.dn; import io.dropwizard.cli.Command; import io.dropwizard.setup.Bootstrap; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate; import net.sourceforge.argparse4j.inf.Namespace; import net.sourceforge.argparse4j.inf.Subparser;
parser.addArgument("-s", "--subject") .dest("subject") .type(String.class) .required(true) .help("The subject CN"); parser.addArgument("-o", "--out") .dest("out") .type(String.class) .required(true) .help("The name of the keystore to be created"); parser.addArgument("-p", "--password") .dest("password") .type(String.class) .required(true) .help("The password of the keystore to be created"); parser.addArgument("-c", "--cert") .dest("cert") .type(String.class) .required(true) .help("The certificate file to be created"); } @Override public void run(final Bootstrap<?> bootstrap, final Namespace namespace) throws Exception { final String subject = namespace.getString("subject"); final String out = namespace.getString("out"); final String password = namespace.getString("password"); final String cert = namespace.getString("cert"); final DistinguishedName dn = dn().setCn(subject).build();
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificateBuilder createSelfSignedCertificate( // final DistinguishedName subject) { // return new RootCertificateBuilderImpl(subject); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // } // Path: ca-api/src/main/java/io/github/olivierlemasle/caweb/cli/CreateSelfSignedCertificate.java import static io.github.olivierlemasle.ca.CA.createSelfSignedCertificate; import static io.github.olivierlemasle.ca.CA.dn; import io.dropwizard.cli.Command; import io.dropwizard.setup.Bootstrap; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate; import net.sourceforge.argparse4j.inf.Namespace; import net.sourceforge.argparse4j.inf.Subparser; parser.addArgument("-s", "--subject") .dest("subject") .type(String.class) .required(true) .help("The subject CN"); parser.addArgument("-o", "--out") .dest("out") .type(String.class) .required(true) .help("The name of the keystore to be created"); parser.addArgument("-p", "--password") .dest("password") .type(String.class) .required(true) .help("The password of the keystore to be created"); parser.addArgument("-c", "--cert") .dest("cert") .type(String.class) .required(true) .help("The certificate file to be created"); } @Override public void run(final Bootstrap<?> bootstrap, final Namespace namespace) throws Exception { final String subject = namespace.getString("subject"); final String out = namespace.getString("out"); final String password = namespace.getString("password"); final String cert = namespace.getString("cert"); final DistinguishedName dn = dn().setCn(subject).build();
final RootCertificate root = createSelfSignedCertificate(dn).build();
olivierlemasle/java-certificate-authority
ca-api/src/main/java/io/github/olivierlemasle/caweb/cli/CreateSelfSignedCertificate.java
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificateBuilder createSelfSignedCertificate( // final DistinguishedName subject) { // return new RootCertificateBuilderImpl(subject); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // }
import static io.github.olivierlemasle.ca.CA.createSelfSignedCertificate; import static io.github.olivierlemasle.ca.CA.dn; import io.dropwizard.cli.Command; import io.dropwizard.setup.Bootstrap; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate; import net.sourceforge.argparse4j.inf.Namespace; import net.sourceforge.argparse4j.inf.Subparser;
parser.addArgument("-s", "--subject") .dest("subject") .type(String.class) .required(true) .help("The subject CN"); parser.addArgument("-o", "--out") .dest("out") .type(String.class) .required(true) .help("The name of the keystore to be created"); parser.addArgument("-p", "--password") .dest("password") .type(String.class) .required(true) .help("The password of the keystore to be created"); parser.addArgument("-c", "--cert") .dest("cert") .type(String.class) .required(true) .help("The certificate file to be created"); } @Override public void run(final Bootstrap<?> bootstrap, final Namespace namespace) throws Exception { final String subject = namespace.getString("subject"); final String out = namespace.getString("out"); final String password = namespace.getString("password"); final String cert = namespace.getString("cert"); final DistinguishedName dn = dn().setCn(subject).build();
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificateBuilder createSelfSignedCertificate( // final DistinguishedName subject) { // return new RootCertificateBuilderImpl(subject); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // } // Path: ca-api/src/main/java/io/github/olivierlemasle/caweb/cli/CreateSelfSignedCertificate.java import static io.github.olivierlemasle.ca.CA.createSelfSignedCertificate; import static io.github.olivierlemasle.ca.CA.dn; import io.dropwizard.cli.Command; import io.dropwizard.setup.Bootstrap; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate; import net.sourceforge.argparse4j.inf.Namespace; import net.sourceforge.argparse4j.inf.Subparser; parser.addArgument("-s", "--subject") .dest("subject") .type(String.class) .required(true) .help("The subject CN"); parser.addArgument("-o", "--out") .dest("out") .type(String.class) .required(true) .help("The name of the keystore to be created"); parser.addArgument("-p", "--password") .dest("password") .type(String.class) .required(true) .help("The password of the keystore to be created"); parser.addArgument("-c", "--cert") .dest("cert") .type(String.class) .required(true) .help("The certificate file to be created"); } @Override public void run(final Bootstrap<?> bootstrap, final Namespace namespace) throws Exception { final String subject = namespace.getString("subject"); final String out = namespace.getString("out"); final String password = namespace.getString("password"); final String cert = namespace.getString("cert"); final DistinguishedName dn = dn().setCn(subject).build();
final RootCertificate root = createSelfSignedCertificate(dn).build();
olivierlemasle/java-certificate-authority
java-ca-lib/src/test/java/io/github/olivierlemasle/tests/it/OpenSslIT.java
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificateBuilder createSelfSignedCertificate( // final DistinguishedName subject) { // return new RootCertificateBuilderImpl(subject); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static CsrLoader loadCsr(final File csrFile) { // return new CsrLoaderImpl(csrFile); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CSR.java // public interface CSR { // // public DistinguishedName getSubject(); // // public PublicKey getPublicKey(); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/Certificate.java // public interface Certificate { // // public X509Certificate getX509Certificate(); // // public String print(); // // public void save(File file); // // public void save(String fileName); // // public CertificateWithPrivateKey attachPrivateKey(PrivateKey privateKey); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // }
import static io.github.olivierlemasle.ca.CA.createSelfSignedCertificate; import static io.github.olivierlemasle.ca.CA.dn; import static io.github.olivierlemasle.ca.CA.loadCsr; import static org.junit.Assert.assertTrue; import static org.junit.Assume.assumeFalse; import static org.junit.Assume.assumeTrue; import java.io.File; import java.io.IOException; import java.lang.ProcessBuilder.Redirect; import java.security.KeyManagementException; import java.security.KeyStore; import java.security.KeyStoreException; import java.security.NoSuchAlgorithmException; import java.security.cert.CertificateException; import javax.net.ssl.SSLContext; import org.apache.http.HttpEntity; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.ssl.SSLContexts; import org.apache.http.util.EntityUtils; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import io.github.olivierlemasle.ca.CSR; import io.github.olivierlemasle.ca.Certificate; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate;
package io.github.olivierlemasle.tests.it; public class OpenSslIT { @BeforeClass @AfterClass public static void clean() { final File caCertPath = new File("ca.cer"); caCertPath.delete(); final File reqPath = new File("CSR.csr"); reqPath.delete(); final File keyPath = new File("private.key"); keyPath.delete(); final File certPath = new File("cert.cer"); certPath.delete(); } @Before public void checkPlatform() { assumeFalse(TestUtils.isWindows()); assumeTrue(TestUtils.opensslExists()); } @Test public void completeTest() throws IOException, InterruptedException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException, CertificateException { // Create a self-signed root certificate System.out.println("Generate ..");
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificateBuilder createSelfSignedCertificate( // final DistinguishedName subject) { // return new RootCertificateBuilderImpl(subject); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static CsrLoader loadCsr(final File csrFile) { // return new CsrLoaderImpl(csrFile); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CSR.java // public interface CSR { // // public DistinguishedName getSubject(); // // public PublicKey getPublicKey(); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/Certificate.java // public interface Certificate { // // public X509Certificate getX509Certificate(); // // public String print(); // // public void save(File file); // // public void save(String fileName); // // public CertificateWithPrivateKey attachPrivateKey(PrivateKey privateKey); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // } // Path: java-ca-lib/src/test/java/io/github/olivierlemasle/tests/it/OpenSslIT.java import static io.github.olivierlemasle.ca.CA.createSelfSignedCertificate; import static io.github.olivierlemasle.ca.CA.dn; import static io.github.olivierlemasle.ca.CA.loadCsr; import static org.junit.Assert.assertTrue; import static org.junit.Assume.assumeFalse; import static org.junit.Assume.assumeTrue; import java.io.File; import java.io.IOException; import java.lang.ProcessBuilder.Redirect; import java.security.KeyManagementException; import java.security.KeyStore; import java.security.KeyStoreException; import java.security.NoSuchAlgorithmException; import java.security.cert.CertificateException; import javax.net.ssl.SSLContext; import org.apache.http.HttpEntity; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.ssl.SSLContexts; import org.apache.http.util.EntityUtils; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import io.github.olivierlemasle.ca.CSR; import io.github.olivierlemasle.ca.Certificate; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate; package io.github.olivierlemasle.tests.it; public class OpenSslIT { @BeforeClass @AfterClass public static void clean() { final File caCertPath = new File("ca.cer"); caCertPath.delete(); final File reqPath = new File("CSR.csr"); reqPath.delete(); final File keyPath = new File("private.key"); keyPath.delete(); final File certPath = new File("cert.cer"); certPath.delete(); } @Before public void checkPlatform() { assumeFalse(TestUtils.isWindows()); assumeTrue(TestUtils.opensslExists()); } @Test public void completeTest() throws IOException, InterruptedException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException, CertificateException { // Create a self-signed root certificate System.out.println("Generate ..");
final DistinguishedName rootDn = dn("CN=CA-Test");
olivierlemasle/java-certificate-authority
java-ca-lib/src/test/java/io/github/olivierlemasle/tests/it/OpenSslIT.java
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificateBuilder createSelfSignedCertificate( // final DistinguishedName subject) { // return new RootCertificateBuilderImpl(subject); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static CsrLoader loadCsr(final File csrFile) { // return new CsrLoaderImpl(csrFile); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CSR.java // public interface CSR { // // public DistinguishedName getSubject(); // // public PublicKey getPublicKey(); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/Certificate.java // public interface Certificate { // // public X509Certificate getX509Certificate(); // // public String print(); // // public void save(File file); // // public void save(String fileName); // // public CertificateWithPrivateKey attachPrivateKey(PrivateKey privateKey); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // }
import static io.github.olivierlemasle.ca.CA.createSelfSignedCertificate; import static io.github.olivierlemasle.ca.CA.dn; import static io.github.olivierlemasle.ca.CA.loadCsr; import static org.junit.Assert.assertTrue; import static org.junit.Assume.assumeFalse; import static org.junit.Assume.assumeTrue; import java.io.File; import java.io.IOException; import java.lang.ProcessBuilder.Redirect; import java.security.KeyManagementException; import java.security.KeyStore; import java.security.KeyStoreException; import java.security.NoSuchAlgorithmException; import java.security.cert.CertificateException; import javax.net.ssl.SSLContext; import org.apache.http.HttpEntity; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.ssl.SSLContexts; import org.apache.http.util.EntityUtils; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import io.github.olivierlemasle.ca.CSR; import io.github.olivierlemasle.ca.Certificate; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate;
package io.github.olivierlemasle.tests.it; public class OpenSslIT { @BeforeClass @AfterClass public static void clean() { final File caCertPath = new File("ca.cer"); caCertPath.delete(); final File reqPath = new File("CSR.csr"); reqPath.delete(); final File keyPath = new File("private.key"); keyPath.delete(); final File certPath = new File("cert.cer"); certPath.delete(); } @Before public void checkPlatform() { assumeFalse(TestUtils.isWindows()); assumeTrue(TestUtils.opensslExists()); } @Test public void completeTest() throws IOException, InterruptedException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException, CertificateException { // Create a self-signed root certificate System.out.println("Generate ..");
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificateBuilder createSelfSignedCertificate( // final DistinguishedName subject) { // return new RootCertificateBuilderImpl(subject); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static CsrLoader loadCsr(final File csrFile) { // return new CsrLoaderImpl(csrFile); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CSR.java // public interface CSR { // // public DistinguishedName getSubject(); // // public PublicKey getPublicKey(); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/Certificate.java // public interface Certificate { // // public X509Certificate getX509Certificate(); // // public String print(); // // public void save(File file); // // public void save(String fileName); // // public CertificateWithPrivateKey attachPrivateKey(PrivateKey privateKey); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // } // Path: java-ca-lib/src/test/java/io/github/olivierlemasle/tests/it/OpenSslIT.java import static io.github.olivierlemasle.ca.CA.createSelfSignedCertificate; import static io.github.olivierlemasle.ca.CA.dn; import static io.github.olivierlemasle.ca.CA.loadCsr; import static org.junit.Assert.assertTrue; import static org.junit.Assume.assumeFalse; import static org.junit.Assume.assumeTrue; import java.io.File; import java.io.IOException; import java.lang.ProcessBuilder.Redirect; import java.security.KeyManagementException; import java.security.KeyStore; import java.security.KeyStoreException; import java.security.NoSuchAlgorithmException; import java.security.cert.CertificateException; import javax.net.ssl.SSLContext; import org.apache.http.HttpEntity; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.ssl.SSLContexts; import org.apache.http.util.EntityUtils; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import io.github.olivierlemasle.ca.CSR; import io.github.olivierlemasle.ca.Certificate; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate; package io.github.olivierlemasle.tests.it; public class OpenSslIT { @BeforeClass @AfterClass public static void clean() { final File caCertPath = new File("ca.cer"); caCertPath.delete(); final File reqPath = new File("CSR.csr"); reqPath.delete(); final File keyPath = new File("private.key"); keyPath.delete(); final File certPath = new File("cert.cer"); certPath.delete(); } @Before public void checkPlatform() { assumeFalse(TestUtils.isWindows()); assumeTrue(TestUtils.opensslExists()); } @Test public void completeTest() throws IOException, InterruptedException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException, CertificateException { // Create a self-signed root certificate System.out.println("Generate ..");
final DistinguishedName rootDn = dn("CN=CA-Test");
olivierlemasle/java-certificate-authority
java-ca-lib/src/test/java/io/github/olivierlemasle/tests/it/OpenSslIT.java
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificateBuilder createSelfSignedCertificate( // final DistinguishedName subject) { // return new RootCertificateBuilderImpl(subject); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static CsrLoader loadCsr(final File csrFile) { // return new CsrLoaderImpl(csrFile); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CSR.java // public interface CSR { // // public DistinguishedName getSubject(); // // public PublicKey getPublicKey(); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/Certificate.java // public interface Certificate { // // public X509Certificate getX509Certificate(); // // public String print(); // // public void save(File file); // // public void save(String fileName); // // public CertificateWithPrivateKey attachPrivateKey(PrivateKey privateKey); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // }
import static io.github.olivierlemasle.ca.CA.createSelfSignedCertificate; import static io.github.olivierlemasle.ca.CA.dn; import static io.github.olivierlemasle.ca.CA.loadCsr; import static org.junit.Assert.assertTrue; import static org.junit.Assume.assumeFalse; import static org.junit.Assume.assumeTrue; import java.io.File; import java.io.IOException; import java.lang.ProcessBuilder.Redirect; import java.security.KeyManagementException; import java.security.KeyStore; import java.security.KeyStoreException; import java.security.NoSuchAlgorithmException; import java.security.cert.CertificateException; import javax.net.ssl.SSLContext; import org.apache.http.HttpEntity; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.ssl.SSLContexts; import org.apache.http.util.EntityUtils; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import io.github.olivierlemasle.ca.CSR; import io.github.olivierlemasle.ca.Certificate; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate;
package io.github.olivierlemasle.tests.it; public class OpenSslIT { @BeforeClass @AfterClass public static void clean() { final File caCertPath = new File("ca.cer"); caCertPath.delete(); final File reqPath = new File("CSR.csr"); reqPath.delete(); final File keyPath = new File("private.key"); keyPath.delete(); final File certPath = new File("cert.cer"); certPath.delete(); } @Before public void checkPlatform() { assumeFalse(TestUtils.isWindows()); assumeTrue(TestUtils.opensslExists()); } @Test public void completeTest() throws IOException, InterruptedException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException, CertificateException { // Create a self-signed root certificate System.out.println("Generate .."); final DistinguishedName rootDn = dn("CN=CA-Test");
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificateBuilder createSelfSignedCertificate( // final DistinguishedName subject) { // return new RootCertificateBuilderImpl(subject); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static CsrLoader loadCsr(final File csrFile) { // return new CsrLoaderImpl(csrFile); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CSR.java // public interface CSR { // // public DistinguishedName getSubject(); // // public PublicKey getPublicKey(); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/Certificate.java // public interface Certificate { // // public X509Certificate getX509Certificate(); // // public String print(); // // public void save(File file); // // public void save(String fileName); // // public CertificateWithPrivateKey attachPrivateKey(PrivateKey privateKey); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // } // Path: java-ca-lib/src/test/java/io/github/olivierlemasle/tests/it/OpenSslIT.java import static io.github.olivierlemasle.ca.CA.createSelfSignedCertificate; import static io.github.olivierlemasle.ca.CA.dn; import static io.github.olivierlemasle.ca.CA.loadCsr; import static org.junit.Assert.assertTrue; import static org.junit.Assume.assumeFalse; import static org.junit.Assume.assumeTrue; import java.io.File; import java.io.IOException; import java.lang.ProcessBuilder.Redirect; import java.security.KeyManagementException; import java.security.KeyStore; import java.security.KeyStoreException; import java.security.NoSuchAlgorithmException; import java.security.cert.CertificateException; import javax.net.ssl.SSLContext; import org.apache.http.HttpEntity; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.ssl.SSLContexts; import org.apache.http.util.EntityUtils; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import io.github.olivierlemasle.ca.CSR; import io.github.olivierlemasle.ca.Certificate; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate; package io.github.olivierlemasle.tests.it; public class OpenSslIT { @BeforeClass @AfterClass public static void clean() { final File caCertPath = new File("ca.cer"); caCertPath.delete(); final File reqPath = new File("CSR.csr"); reqPath.delete(); final File keyPath = new File("private.key"); keyPath.delete(); final File certPath = new File("cert.cer"); certPath.delete(); } @Before public void checkPlatform() { assumeFalse(TestUtils.isWindows()); assumeTrue(TestUtils.opensslExists()); } @Test public void completeTest() throws IOException, InterruptedException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException, CertificateException { // Create a self-signed root certificate System.out.println("Generate .."); final DistinguishedName rootDn = dn("CN=CA-Test");
final RootCertificate root = createSelfSignedCertificate(rootDn).build();
olivierlemasle/java-certificate-authority
java-ca-lib/src/test/java/io/github/olivierlemasle/tests/it/OpenSslIT.java
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificateBuilder createSelfSignedCertificate( // final DistinguishedName subject) { // return new RootCertificateBuilderImpl(subject); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static CsrLoader loadCsr(final File csrFile) { // return new CsrLoaderImpl(csrFile); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CSR.java // public interface CSR { // // public DistinguishedName getSubject(); // // public PublicKey getPublicKey(); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/Certificate.java // public interface Certificate { // // public X509Certificate getX509Certificate(); // // public String print(); // // public void save(File file); // // public void save(String fileName); // // public CertificateWithPrivateKey attachPrivateKey(PrivateKey privateKey); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // }
import static io.github.olivierlemasle.ca.CA.createSelfSignedCertificate; import static io.github.olivierlemasle.ca.CA.dn; import static io.github.olivierlemasle.ca.CA.loadCsr; import static org.junit.Assert.assertTrue; import static org.junit.Assume.assumeFalse; import static org.junit.Assume.assumeTrue; import java.io.File; import java.io.IOException; import java.lang.ProcessBuilder.Redirect; import java.security.KeyManagementException; import java.security.KeyStore; import java.security.KeyStoreException; import java.security.NoSuchAlgorithmException; import java.security.cert.CertificateException; import javax.net.ssl.SSLContext; import org.apache.http.HttpEntity; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.ssl.SSLContexts; import org.apache.http.util.EntityUtils; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import io.github.olivierlemasle.ca.CSR; import io.github.olivierlemasle.ca.Certificate; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate;
package io.github.olivierlemasle.tests.it; public class OpenSslIT { @BeforeClass @AfterClass public static void clean() { final File caCertPath = new File("ca.cer"); caCertPath.delete(); final File reqPath = new File("CSR.csr"); reqPath.delete(); final File keyPath = new File("private.key"); keyPath.delete(); final File certPath = new File("cert.cer"); certPath.delete(); } @Before public void checkPlatform() { assumeFalse(TestUtils.isWindows()); assumeTrue(TestUtils.opensslExists()); } @Test public void completeTest() throws IOException, InterruptedException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException, CertificateException { // Create a self-signed root certificate System.out.println("Generate .."); final DistinguishedName rootDn = dn("CN=CA-Test");
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificateBuilder createSelfSignedCertificate( // final DistinguishedName subject) { // return new RootCertificateBuilderImpl(subject); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static CsrLoader loadCsr(final File csrFile) { // return new CsrLoaderImpl(csrFile); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CSR.java // public interface CSR { // // public DistinguishedName getSubject(); // // public PublicKey getPublicKey(); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/Certificate.java // public interface Certificate { // // public X509Certificate getX509Certificate(); // // public String print(); // // public void save(File file); // // public void save(String fileName); // // public CertificateWithPrivateKey attachPrivateKey(PrivateKey privateKey); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // } // Path: java-ca-lib/src/test/java/io/github/olivierlemasle/tests/it/OpenSslIT.java import static io.github.olivierlemasle.ca.CA.createSelfSignedCertificate; import static io.github.olivierlemasle.ca.CA.dn; import static io.github.olivierlemasle.ca.CA.loadCsr; import static org.junit.Assert.assertTrue; import static org.junit.Assume.assumeFalse; import static org.junit.Assume.assumeTrue; import java.io.File; import java.io.IOException; import java.lang.ProcessBuilder.Redirect; import java.security.KeyManagementException; import java.security.KeyStore; import java.security.KeyStoreException; import java.security.NoSuchAlgorithmException; import java.security.cert.CertificateException; import javax.net.ssl.SSLContext; import org.apache.http.HttpEntity; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.ssl.SSLContexts; import org.apache.http.util.EntityUtils; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import io.github.olivierlemasle.ca.CSR; import io.github.olivierlemasle.ca.Certificate; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate; package io.github.olivierlemasle.tests.it; public class OpenSslIT { @BeforeClass @AfterClass public static void clean() { final File caCertPath = new File("ca.cer"); caCertPath.delete(); final File reqPath = new File("CSR.csr"); reqPath.delete(); final File keyPath = new File("private.key"); keyPath.delete(); final File certPath = new File("cert.cer"); certPath.delete(); } @Before public void checkPlatform() { assumeFalse(TestUtils.isWindows()); assumeTrue(TestUtils.opensslExists()); } @Test public void completeTest() throws IOException, InterruptedException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException, CertificateException { // Create a self-signed root certificate System.out.println("Generate .."); final DistinguishedName rootDn = dn("CN=CA-Test");
final RootCertificate root = createSelfSignedCertificate(rootDn).build();
olivierlemasle/java-certificate-authority
java-ca-lib/src/test/java/io/github/olivierlemasle/tests/it/OpenSslIT.java
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificateBuilder createSelfSignedCertificate( // final DistinguishedName subject) { // return new RootCertificateBuilderImpl(subject); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static CsrLoader loadCsr(final File csrFile) { // return new CsrLoaderImpl(csrFile); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CSR.java // public interface CSR { // // public DistinguishedName getSubject(); // // public PublicKey getPublicKey(); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/Certificate.java // public interface Certificate { // // public X509Certificate getX509Certificate(); // // public String print(); // // public void save(File file); // // public void save(String fileName); // // public CertificateWithPrivateKey attachPrivateKey(PrivateKey privateKey); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // }
import static io.github.olivierlemasle.ca.CA.createSelfSignedCertificate; import static io.github.olivierlemasle.ca.CA.dn; import static io.github.olivierlemasle.ca.CA.loadCsr; import static org.junit.Assert.assertTrue; import static org.junit.Assume.assumeFalse; import static org.junit.Assume.assumeTrue; import java.io.File; import java.io.IOException; import java.lang.ProcessBuilder.Redirect; import java.security.KeyManagementException; import java.security.KeyStore; import java.security.KeyStoreException; import java.security.NoSuchAlgorithmException; import java.security.cert.CertificateException; import javax.net.ssl.SSLContext; import org.apache.http.HttpEntity; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.ssl.SSLContexts; import org.apache.http.util.EntityUtils; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import io.github.olivierlemasle.ca.CSR; import io.github.olivierlemasle.ca.Certificate; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate;
package io.github.olivierlemasle.tests.it; public class OpenSslIT { @BeforeClass @AfterClass public static void clean() { final File caCertPath = new File("ca.cer"); caCertPath.delete(); final File reqPath = new File("CSR.csr"); reqPath.delete(); final File keyPath = new File("private.key"); keyPath.delete(); final File certPath = new File("cert.cer"); certPath.delete(); } @Before public void checkPlatform() { assumeFalse(TestUtils.isWindows()); assumeTrue(TestUtils.opensslExists()); } @Test public void completeTest() throws IOException, InterruptedException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException, CertificateException { // Create a self-signed root certificate System.out.println("Generate .."); final DistinguishedName rootDn = dn("CN=CA-Test"); final RootCertificate root = createSelfSignedCertificate(rootDn).build(); // Export the CA certificate root.save("ca.cer"); System.out.println("CA ready. CA certificate saved to \"ca.cer\"."); // Generate CSR using OpenSSL System.out.println("Generate CSR with \"CSR.csr\"..."); generateCsr(); // Load the generated CSR, sign it and export the resulting certificate System.out.println("Sign CSR...");
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificateBuilder createSelfSignedCertificate( // final DistinguishedName subject) { // return new RootCertificateBuilderImpl(subject); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static CsrLoader loadCsr(final File csrFile) { // return new CsrLoaderImpl(csrFile); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CSR.java // public interface CSR { // // public DistinguishedName getSubject(); // // public PublicKey getPublicKey(); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/Certificate.java // public interface Certificate { // // public X509Certificate getX509Certificate(); // // public String print(); // // public void save(File file); // // public void save(String fileName); // // public CertificateWithPrivateKey attachPrivateKey(PrivateKey privateKey); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // } // Path: java-ca-lib/src/test/java/io/github/olivierlemasle/tests/it/OpenSslIT.java import static io.github.olivierlemasle.ca.CA.createSelfSignedCertificate; import static io.github.olivierlemasle.ca.CA.dn; import static io.github.olivierlemasle.ca.CA.loadCsr; import static org.junit.Assert.assertTrue; import static org.junit.Assume.assumeFalse; import static org.junit.Assume.assumeTrue; import java.io.File; import java.io.IOException; import java.lang.ProcessBuilder.Redirect; import java.security.KeyManagementException; import java.security.KeyStore; import java.security.KeyStoreException; import java.security.NoSuchAlgorithmException; import java.security.cert.CertificateException; import javax.net.ssl.SSLContext; import org.apache.http.HttpEntity; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.ssl.SSLContexts; import org.apache.http.util.EntityUtils; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import io.github.olivierlemasle.ca.CSR; import io.github.olivierlemasle.ca.Certificate; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate; package io.github.olivierlemasle.tests.it; public class OpenSslIT { @BeforeClass @AfterClass public static void clean() { final File caCertPath = new File("ca.cer"); caCertPath.delete(); final File reqPath = new File("CSR.csr"); reqPath.delete(); final File keyPath = new File("private.key"); keyPath.delete(); final File certPath = new File("cert.cer"); certPath.delete(); } @Before public void checkPlatform() { assumeFalse(TestUtils.isWindows()); assumeTrue(TestUtils.opensslExists()); } @Test public void completeTest() throws IOException, InterruptedException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException, CertificateException { // Create a self-signed root certificate System.out.println("Generate .."); final DistinguishedName rootDn = dn("CN=CA-Test"); final RootCertificate root = createSelfSignedCertificate(rootDn).build(); // Export the CA certificate root.save("ca.cer"); System.out.println("CA ready. CA certificate saved to \"ca.cer\"."); // Generate CSR using OpenSSL System.out.println("Generate CSR with \"CSR.csr\"..."); generateCsr(); // Load the generated CSR, sign it and export the resulting certificate System.out.println("Sign CSR...");
final CSR csr = loadCsr("CSR.csr").getCsr();
olivierlemasle/java-certificate-authority
java-ca-lib/src/test/java/io/github/olivierlemasle/tests/it/OpenSslIT.java
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificateBuilder createSelfSignedCertificate( // final DistinguishedName subject) { // return new RootCertificateBuilderImpl(subject); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static CsrLoader loadCsr(final File csrFile) { // return new CsrLoaderImpl(csrFile); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CSR.java // public interface CSR { // // public DistinguishedName getSubject(); // // public PublicKey getPublicKey(); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/Certificate.java // public interface Certificate { // // public X509Certificate getX509Certificate(); // // public String print(); // // public void save(File file); // // public void save(String fileName); // // public CertificateWithPrivateKey attachPrivateKey(PrivateKey privateKey); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // }
import static io.github.olivierlemasle.ca.CA.createSelfSignedCertificate; import static io.github.olivierlemasle.ca.CA.dn; import static io.github.olivierlemasle.ca.CA.loadCsr; import static org.junit.Assert.assertTrue; import static org.junit.Assume.assumeFalse; import static org.junit.Assume.assumeTrue; import java.io.File; import java.io.IOException; import java.lang.ProcessBuilder.Redirect; import java.security.KeyManagementException; import java.security.KeyStore; import java.security.KeyStoreException; import java.security.NoSuchAlgorithmException; import java.security.cert.CertificateException; import javax.net.ssl.SSLContext; import org.apache.http.HttpEntity; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.ssl.SSLContexts; import org.apache.http.util.EntityUtils; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import io.github.olivierlemasle.ca.CSR; import io.github.olivierlemasle.ca.Certificate; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate;
package io.github.olivierlemasle.tests.it; public class OpenSslIT { @BeforeClass @AfterClass public static void clean() { final File caCertPath = new File("ca.cer"); caCertPath.delete(); final File reqPath = new File("CSR.csr"); reqPath.delete(); final File keyPath = new File("private.key"); keyPath.delete(); final File certPath = new File("cert.cer"); certPath.delete(); } @Before public void checkPlatform() { assumeFalse(TestUtils.isWindows()); assumeTrue(TestUtils.opensslExists()); } @Test public void completeTest() throws IOException, InterruptedException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException, CertificateException { // Create a self-signed root certificate System.out.println("Generate .."); final DistinguishedName rootDn = dn("CN=CA-Test"); final RootCertificate root = createSelfSignedCertificate(rootDn).build(); // Export the CA certificate root.save("ca.cer"); System.out.println("CA ready. CA certificate saved to \"ca.cer\"."); // Generate CSR using OpenSSL System.out.println("Generate CSR with \"CSR.csr\"..."); generateCsr(); // Load the generated CSR, sign it and export the resulting certificate System.out.println("Sign CSR...");
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificateBuilder createSelfSignedCertificate( // final DistinguishedName subject) { // return new RootCertificateBuilderImpl(subject); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static CsrLoader loadCsr(final File csrFile) { // return new CsrLoaderImpl(csrFile); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CSR.java // public interface CSR { // // public DistinguishedName getSubject(); // // public PublicKey getPublicKey(); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/Certificate.java // public interface Certificate { // // public X509Certificate getX509Certificate(); // // public String print(); // // public void save(File file); // // public void save(String fileName); // // public CertificateWithPrivateKey attachPrivateKey(PrivateKey privateKey); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // } // Path: java-ca-lib/src/test/java/io/github/olivierlemasle/tests/it/OpenSslIT.java import static io.github.olivierlemasle.ca.CA.createSelfSignedCertificate; import static io.github.olivierlemasle.ca.CA.dn; import static io.github.olivierlemasle.ca.CA.loadCsr; import static org.junit.Assert.assertTrue; import static org.junit.Assume.assumeFalse; import static org.junit.Assume.assumeTrue; import java.io.File; import java.io.IOException; import java.lang.ProcessBuilder.Redirect; import java.security.KeyManagementException; import java.security.KeyStore; import java.security.KeyStoreException; import java.security.NoSuchAlgorithmException; import java.security.cert.CertificateException; import javax.net.ssl.SSLContext; import org.apache.http.HttpEntity; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.ssl.SSLContexts; import org.apache.http.util.EntityUtils; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import io.github.olivierlemasle.ca.CSR; import io.github.olivierlemasle.ca.Certificate; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate; package io.github.olivierlemasle.tests.it; public class OpenSslIT { @BeforeClass @AfterClass public static void clean() { final File caCertPath = new File("ca.cer"); caCertPath.delete(); final File reqPath = new File("CSR.csr"); reqPath.delete(); final File keyPath = new File("private.key"); keyPath.delete(); final File certPath = new File("cert.cer"); certPath.delete(); } @Before public void checkPlatform() { assumeFalse(TestUtils.isWindows()); assumeTrue(TestUtils.opensslExists()); } @Test public void completeTest() throws IOException, InterruptedException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException, CertificateException { // Create a self-signed root certificate System.out.println("Generate .."); final DistinguishedName rootDn = dn("CN=CA-Test"); final RootCertificate root = createSelfSignedCertificate(rootDn).build(); // Export the CA certificate root.save("ca.cer"); System.out.println("CA ready. CA certificate saved to \"ca.cer\"."); // Generate CSR using OpenSSL System.out.println("Generate CSR with \"CSR.csr\"..."); generateCsr(); // Load the generated CSR, sign it and export the resulting certificate System.out.println("Sign CSR...");
final CSR csr = loadCsr("CSR.csr").getCsr();
olivierlemasle/java-certificate-authority
java-ca-lib/src/test/java/io/github/olivierlemasle/tests/it/OpenSslIT.java
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificateBuilder createSelfSignedCertificate( // final DistinguishedName subject) { // return new RootCertificateBuilderImpl(subject); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static CsrLoader loadCsr(final File csrFile) { // return new CsrLoaderImpl(csrFile); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CSR.java // public interface CSR { // // public DistinguishedName getSubject(); // // public PublicKey getPublicKey(); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/Certificate.java // public interface Certificate { // // public X509Certificate getX509Certificate(); // // public String print(); // // public void save(File file); // // public void save(String fileName); // // public CertificateWithPrivateKey attachPrivateKey(PrivateKey privateKey); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // }
import static io.github.olivierlemasle.ca.CA.createSelfSignedCertificate; import static io.github.olivierlemasle.ca.CA.dn; import static io.github.olivierlemasle.ca.CA.loadCsr; import static org.junit.Assert.assertTrue; import static org.junit.Assume.assumeFalse; import static org.junit.Assume.assumeTrue; import java.io.File; import java.io.IOException; import java.lang.ProcessBuilder.Redirect; import java.security.KeyManagementException; import java.security.KeyStore; import java.security.KeyStoreException; import java.security.NoSuchAlgorithmException; import java.security.cert.CertificateException; import javax.net.ssl.SSLContext; import org.apache.http.HttpEntity; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.ssl.SSLContexts; import org.apache.http.util.EntityUtils; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import io.github.olivierlemasle.ca.CSR; import io.github.olivierlemasle.ca.Certificate; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate;
final File keyPath = new File("private.key"); keyPath.delete(); final File certPath = new File("cert.cer"); certPath.delete(); } @Before public void checkPlatform() { assumeFalse(TestUtils.isWindows()); assumeTrue(TestUtils.opensslExists()); } @Test public void completeTest() throws IOException, InterruptedException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException, CertificateException { // Create a self-signed root certificate System.out.println("Generate .."); final DistinguishedName rootDn = dn("CN=CA-Test"); final RootCertificate root = createSelfSignedCertificate(rootDn).build(); // Export the CA certificate root.save("ca.cer"); System.out.println("CA ready. CA certificate saved to \"ca.cer\"."); // Generate CSR using OpenSSL System.out.println("Generate CSR with \"CSR.csr\"..."); generateCsr(); // Load the generated CSR, sign it and export the resulting certificate System.out.println("Sign CSR..."); final CSR csr = loadCsr("CSR.csr").getCsr();
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificateBuilder createSelfSignedCertificate( // final DistinguishedName subject) { // return new RootCertificateBuilderImpl(subject); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static CsrLoader loadCsr(final File csrFile) { // return new CsrLoaderImpl(csrFile); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CSR.java // public interface CSR { // // public DistinguishedName getSubject(); // // public PublicKey getPublicKey(); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/Certificate.java // public interface Certificate { // // public X509Certificate getX509Certificate(); // // public String print(); // // public void save(File file); // // public void save(String fileName); // // public CertificateWithPrivateKey attachPrivateKey(PrivateKey privateKey); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // } // Path: java-ca-lib/src/test/java/io/github/olivierlemasle/tests/it/OpenSslIT.java import static io.github.olivierlemasle.ca.CA.createSelfSignedCertificate; import static io.github.olivierlemasle.ca.CA.dn; import static io.github.olivierlemasle.ca.CA.loadCsr; import static org.junit.Assert.assertTrue; import static org.junit.Assume.assumeFalse; import static org.junit.Assume.assumeTrue; import java.io.File; import java.io.IOException; import java.lang.ProcessBuilder.Redirect; import java.security.KeyManagementException; import java.security.KeyStore; import java.security.KeyStoreException; import java.security.NoSuchAlgorithmException; import java.security.cert.CertificateException; import javax.net.ssl.SSLContext; import org.apache.http.HttpEntity; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.ssl.SSLContexts; import org.apache.http.util.EntityUtils; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import io.github.olivierlemasle.ca.CSR; import io.github.olivierlemasle.ca.Certificate; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate; final File keyPath = new File("private.key"); keyPath.delete(); final File certPath = new File("cert.cer"); certPath.delete(); } @Before public void checkPlatform() { assumeFalse(TestUtils.isWindows()); assumeTrue(TestUtils.opensslExists()); } @Test public void completeTest() throws IOException, InterruptedException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException, CertificateException { // Create a self-signed root certificate System.out.println("Generate .."); final DistinguishedName rootDn = dn("CN=CA-Test"); final RootCertificate root = createSelfSignedCertificate(rootDn).build(); // Export the CA certificate root.save("ca.cer"); System.out.println("CA ready. CA certificate saved to \"ca.cer\"."); // Generate CSR using OpenSSL System.out.println("Generate CSR with \"CSR.csr\"..."); generateCsr(); // Load the generated CSR, sign it and export the resulting certificate System.out.println("Sign CSR..."); final CSR csr = loadCsr("CSR.csr").getCsr();
final Certificate cert = root.signCsr(csr)
olivierlemasle/java-certificate-authority
java-ca-lib/src/test/java/io/github/olivierlemasle/tests/KeystoreExportTest.java
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static CsrBuilder createCsr() { // return new CsrBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificateBuilder createSelfSignedCertificate( // final DistinguishedName subject) { // return new RootCertificateBuilderImpl(subject); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static BigInteger generateRandomSerialNumber() { // return SerialNumberGenerator.instance.generateRandomSerialNumber(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificate loadRootCertificate(final String keystorePath, // final char[] password, final String alias) { // return RootCertificateLoader.loadRootCertificate(keystorePath, password, alias); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CSR.java // public interface CSR { // // public DistinguishedName getSubject(); // // public PublicKey getPublicKey(); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CaException.java // public class CaException extends RuntimeException { // private static final long serialVersionUID = -9188923051885159431L; // // public CaException(final String message, final Throwable cause) { // super(message, cause); // } // // public CaException(final String message) { // super(message); // } // // public CaException(final Throwable cause) { // super(cause); // } // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // }
import static io.github.olivierlemasle.ca.CA.createCsr; import static io.github.olivierlemasle.ca.CA.createSelfSignedCertificate; import static io.github.olivierlemasle.ca.CA.dn; import static io.github.olivierlemasle.ca.CA.generateRandomSerialNumber; import static io.github.olivierlemasle.ca.CA.loadRootCertificate; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; import java.io.IOException; import java.math.BigInteger; import java.nio.file.Files; import java.nio.file.Paths; import java.security.cert.X509Certificate; import java.time.ZonedDateTime; import org.junit.After; import org.junit.BeforeClass; import org.junit.Test; import io.github.olivierlemasle.ca.CSR; import io.github.olivierlemasle.ca.CaException; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate;
package io.github.olivierlemasle.tests; public class KeystoreExportTest { private static RootCertificate ca; private static ZonedDateTime time = ZonedDateTime.now();
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static CsrBuilder createCsr() { // return new CsrBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificateBuilder createSelfSignedCertificate( // final DistinguishedName subject) { // return new RootCertificateBuilderImpl(subject); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static BigInteger generateRandomSerialNumber() { // return SerialNumberGenerator.instance.generateRandomSerialNumber(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificate loadRootCertificate(final String keystorePath, // final char[] password, final String alias) { // return RootCertificateLoader.loadRootCertificate(keystorePath, password, alias); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CSR.java // public interface CSR { // // public DistinguishedName getSubject(); // // public PublicKey getPublicKey(); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CaException.java // public class CaException extends RuntimeException { // private static final long serialVersionUID = -9188923051885159431L; // // public CaException(final String message, final Throwable cause) { // super(message, cause); // } // // public CaException(final String message) { // super(message); // } // // public CaException(final Throwable cause) { // super(cause); // } // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // } // Path: java-ca-lib/src/test/java/io/github/olivierlemasle/tests/KeystoreExportTest.java import static io.github.olivierlemasle.ca.CA.createCsr; import static io.github.olivierlemasle.ca.CA.createSelfSignedCertificate; import static io.github.olivierlemasle.ca.CA.dn; import static io.github.olivierlemasle.ca.CA.generateRandomSerialNumber; import static io.github.olivierlemasle.ca.CA.loadRootCertificate; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; import java.io.IOException; import java.math.BigInteger; import java.nio.file.Files; import java.nio.file.Paths; import java.security.cert.X509Certificate; import java.time.ZonedDateTime; import org.junit.After; import org.junit.BeforeClass; import org.junit.Test; import io.github.olivierlemasle.ca.CSR; import io.github.olivierlemasle.ca.CaException; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate; package io.github.olivierlemasle.tests; public class KeystoreExportTest { private static RootCertificate ca; private static ZonedDateTime time = ZonedDateTime.now();
private static CSR csr;
olivierlemasle/java-certificate-authority
java-ca-lib/src/test/java/io/github/olivierlemasle/tests/KeystoreExportTest.java
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static CsrBuilder createCsr() { // return new CsrBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificateBuilder createSelfSignedCertificate( // final DistinguishedName subject) { // return new RootCertificateBuilderImpl(subject); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static BigInteger generateRandomSerialNumber() { // return SerialNumberGenerator.instance.generateRandomSerialNumber(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificate loadRootCertificate(final String keystorePath, // final char[] password, final String alias) { // return RootCertificateLoader.loadRootCertificate(keystorePath, password, alias); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CSR.java // public interface CSR { // // public DistinguishedName getSubject(); // // public PublicKey getPublicKey(); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CaException.java // public class CaException extends RuntimeException { // private static final long serialVersionUID = -9188923051885159431L; // // public CaException(final String message, final Throwable cause) { // super(message, cause); // } // // public CaException(final String message) { // super(message); // } // // public CaException(final Throwable cause) { // super(cause); // } // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // }
import static io.github.olivierlemasle.ca.CA.createCsr; import static io.github.olivierlemasle.ca.CA.createSelfSignedCertificate; import static io.github.olivierlemasle.ca.CA.dn; import static io.github.olivierlemasle.ca.CA.generateRandomSerialNumber; import static io.github.olivierlemasle.ca.CA.loadRootCertificate; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; import java.io.IOException; import java.math.BigInteger; import java.nio.file.Files; import java.nio.file.Paths; import java.security.cert.X509Certificate; import java.time.ZonedDateTime; import org.junit.After; import org.junit.BeforeClass; import org.junit.Test; import io.github.olivierlemasle.ca.CSR; import io.github.olivierlemasle.ca.CaException; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate;
package io.github.olivierlemasle.tests; public class KeystoreExportTest { private static RootCertificate ca; private static ZonedDateTime time = ZonedDateTime.now(); private static CSR csr; private static BigInteger serialNumber; private static X509Certificate cert; @BeforeClass public static void setup() {
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static CsrBuilder createCsr() { // return new CsrBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificateBuilder createSelfSignedCertificate( // final DistinguishedName subject) { // return new RootCertificateBuilderImpl(subject); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static BigInteger generateRandomSerialNumber() { // return SerialNumberGenerator.instance.generateRandomSerialNumber(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificate loadRootCertificate(final String keystorePath, // final char[] password, final String alias) { // return RootCertificateLoader.loadRootCertificate(keystorePath, password, alias); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CSR.java // public interface CSR { // // public DistinguishedName getSubject(); // // public PublicKey getPublicKey(); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CaException.java // public class CaException extends RuntimeException { // private static final long serialVersionUID = -9188923051885159431L; // // public CaException(final String message, final Throwable cause) { // super(message, cause); // } // // public CaException(final String message) { // super(message); // } // // public CaException(final Throwable cause) { // super(cause); // } // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // } // Path: java-ca-lib/src/test/java/io/github/olivierlemasle/tests/KeystoreExportTest.java import static io.github.olivierlemasle.ca.CA.createCsr; import static io.github.olivierlemasle.ca.CA.createSelfSignedCertificate; import static io.github.olivierlemasle.ca.CA.dn; import static io.github.olivierlemasle.ca.CA.generateRandomSerialNumber; import static io.github.olivierlemasle.ca.CA.loadRootCertificate; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; import java.io.IOException; import java.math.BigInteger; import java.nio.file.Files; import java.nio.file.Paths; import java.security.cert.X509Certificate; import java.time.ZonedDateTime; import org.junit.After; import org.junit.BeforeClass; import org.junit.Test; import io.github.olivierlemasle.ca.CSR; import io.github.olivierlemasle.ca.CaException; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate; package io.github.olivierlemasle.tests; public class KeystoreExportTest { private static RootCertificate ca; private static ZonedDateTime time = ZonedDateTime.now(); private static CSR csr; private static BigInteger serialNumber; private static X509Certificate cert; @BeforeClass public static void setup() {
final DistinguishedName caName = dn("CN=CA-Test");
olivierlemasle/java-certificate-authority
java-ca-lib/src/test/java/io/github/olivierlemasle/tests/KeystoreExportTest.java
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static CsrBuilder createCsr() { // return new CsrBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificateBuilder createSelfSignedCertificate( // final DistinguishedName subject) { // return new RootCertificateBuilderImpl(subject); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static BigInteger generateRandomSerialNumber() { // return SerialNumberGenerator.instance.generateRandomSerialNumber(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificate loadRootCertificate(final String keystorePath, // final char[] password, final String alias) { // return RootCertificateLoader.loadRootCertificate(keystorePath, password, alias); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CSR.java // public interface CSR { // // public DistinguishedName getSubject(); // // public PublicKey getPublicKey(); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CaException.java // public class CaException extends RuntimeException { // private static final long serialVersionUID = -9188923051885159431L; // // public CaException(final String message, final Throwable cause) { // super(message, cause); // } // // public CaException(final String message) { // super(message); // } // // public CaException(final Throwable cause) { // super(cause); // } // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // }
import static io.github.olivierlemasle.ca.CA.createCsr; import static io.github.olivierlemasle.ca.CA.createSelfSignedCertificate; import static io.github.olivierlemasle.ca.CA.dn; import static io.github.olivierlemasle.ca.CA.generateRandomSerialNumber; import static io.github.olivierlemasle.ca.CA.loadRootCertificate; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; import java.io.IOException; import java.math.BigInteger; import java.nio.file.Files; import java.nio.file.Paths; import java.security.cert.X509Certificate; import java.time.ZonedDateTime; import org.junit.After; import org.junit.BeforeClass; import org.junit.Test; import io.github.olivierlemasle.ca.CSR; import io.github.olivierlemasle.ca.CaException; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate;
package io.github.olivierlemasle.tests; public class KeystoreExportTest { private static RootCertificate ca; private static ZonedDateTime time = ZonedDateTime.now(); private static CSR csr; private static BigInteger serialNumber; private static X509Certificate cert; @BeforeClass public static void setup() {
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static CsrBuilder createCsr() { // return new CsrBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificateBuilder createSelfSignedCertificate( // final DistinguishedName subject) { // return new RootCertificateBuilderImpl(subject); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static BigInteger generateRandomSerialNumber() { // return SerialNumberGenerator.instance.generateRandomSerialNumber(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificate loadRootCertificate(final String keystorePath, // final char[] password, final String alias) { // return RootCertificateLoader.loadRootCertificate(keystorePath, password, alias); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CSR.java // public interface CSR { // // public DistinguishedName getSubject(); // // public PublicKey getPublicKey(); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CaException.java // public class CaException extends RuntimeException { // private static final long serialVersionUID = -9188923051885159431L; // // public CaException(final String message, final Throwable cause) { // super(message, cause); // } // // public CaException(final String message) { // super(message); // } // // public CaException(final Throwable cause) { // super(cause); // } // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // } // Path: java-ca-lib/src/test/java/io/github/olivierlemasle/tests/KeystoreExportTest.java import static io.github.olivierlemasle.ca.CA.createCsr; import static io.github.olivierlemasle.ca.CA.createSelfSignedCertificate; import static io.github.olivierlemasle.ca.CA.dn; import static io.github.olivierlemasle.ca.CA.generateRandomSerialNumber; import static io.github.olivierlemasle.ca.CA.loadRootCertificate; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; import java.io.IOException; import java.math.BigInteger; import java.nio.file.Files; import java.nio.file.Paths; import java.security.cert.X509Certificate; import java.time.ZonedDateTime; import org.junit.After; import org.junit.BeforeClass; import org.junit.Test; import io.github.olivierlemasle.ca.CSR; import io.github.olivierlemasle.ca.CaException; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate; package io.github.olivierlemasle.tests; public class KeystoreExportTest { private static RootCertificate ca; private static ZonedDateTime time = ZonedDateTime.now(); private static CSR csr; private static BigInteger serialNumber; private static X509Certificate cert; @BeforeClass public static void setup() {
final DistinguishedName caName = dn("CN=CA-Test");
olivierlemasle/java-certificate-authority
java-ca-lib/src/test/java/io/github/olivierlemasle/tests/KeystoreExportTest.java
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static CsrBuilder createCsr() { // return new CsrBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificateBuilder createSelfSignedCertificate( // final DistinguishedName subject) { // return new RootCertificateBuilderImpl(subject); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static BigInteger generateRandomSerialNumber() { // return SerialNumberGenerator.instance.generateRandomSerialNumber(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificate loadRootCertificate(final String keystorePath, // final char[] password, final String alias) { // return RootCertificateLoader.loadRootCertificate(keystorePath, password, alias); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CSR.java // public interface CSR { // // public DistinguishedName getSubject(); // // public PublicKey getPublicKey(); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CaException.java // public class CaException extends RuntimeException { // private static final long serialVersionUID = -9188923051885159431L; // // public CaException(final String message, final Throwable cause) { // super(message, cause); // } // // public CaException(final String message) { // super(message); // } // // public CaException(final Throwable cause) { // super(cause); // } // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // }
import static io.github.olivierlemasle.ca.CA.createCsr; import static io.github.olivierlemasle.ca.CA.createSelfSignedCertificate; import static io.github.olivierlemasle.ca.CA.dn; import static io.github.olivierlemasle.ca.CA.generateRandomSerialNumber; import static io.github.olivierlemasle.ca.CA.loadRootCertificate; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; import java.io.IOException; import java.math.BigInteger; import java.nio.file.Files; import java.nio.file.Paths; import java.security.cert.X509Certificate; import java.time.ZonedDateTime; import org.junit.After; import org.junit.BeforeClass; import org.junit.Test; import io.github.olivierlemasle.ca.CSR; import io.github.olivierlemasle.ca.CaException; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate;
package io.github.olivierlemasle.tests; public class KeystoreExportTest { private static RootCertificate ca; private static ZonedDateTime time = ZonedDateTime.now(); private static CSR csr; private static BigInteger serialNumber; private static X509Certificate cert; @BeforeClass public static void setup() { final DistinguishedName caName = dn("CN=CA-Test");
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static CsrBuilder createCsr() { // return new CsrBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificateBuilder createSelfSignedCertificate( // final DistinguishedName subject) { // return new RootCertificateBuilderImpl(subject); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static BigInteger generateRandomSerialNumber() { // return SerialNumberGenerator.instance.generateRandomSerialNumber(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificate loadRootCertificate(final String keystorePath, // final char[] password, final String alias) { // return RootCertificateLoader.loadRootCertificate(keystorePath, password, alias); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CSR.java // public interface CSR { // // public DistinguishedName getSubject(); // // public PublicKey getPublicKey(); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CaException.java // public class CaException extends RuntimeException { // private static final long serialVersionUID = -9188923051885159431L; // // public CaException(final String message, final Throwable cause) { // super(message, cause); // } // // public CaException(final String message) { // super(message); // } // // public CaException(final Throwable cause) { // super(cause); // } // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // } // Path: java-ca-lib/src/test/java/io/github/olivierlemasle/tests/KeystoreExportTest.java import static io.github.olivierlemasle.ca.CA.createCsr; import static io.github.olivierlemasle.ca.CA.createSelfSignedCertificate; import static io.github.olivierlemasle.ca.CA.dn; import static io.github.olivierlemasle.ca.CA.generateRandomSerialNumber; import static io.github.olivierlemasle.ca.CA.loadRootCertificate; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; import java.io.IOException; import java.math.BigInteger; import java.nio.file.Files; import java.nio.file.Paths; import java.security.cert.X509Certificate; import java.time.ZonedDateTime; import org.junit.After; import org.junit.BeforeClass; import org.junit.Test; import io.github.olivierlemasle.ca.CSR; import io.github.olivierlemasle.ca.CaException; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate; package io.github.olivierlemasle.tests; public class KeystoreExportTest { private static RootCertificate ca; private static ZonedDateTime time = ZonedDateTime.now(); private static CSR csr; private static BigInteger serialNumber; private static X509Certificate cert; @BeforeClass public static void setup() { final DistinguishedName caName = dn("CN=CA-Test");
ca = createSelfSignedCertificate(caName).build();
olivierlemasle/java-certificate-authority
java-ca-lib/src/test/java/io/github/olivierlemasle/tests/KeystoreExportTest.java
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static CsrBuilder createCsr() { // return new CsrBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificateBuilder createSelfSignedCertificate( // final DistinguishedName subject) { // return new RootCertificateBuilderImpl(subject); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static BigInteger generateRandomSerialNumber() { // return SerialNumberGenerator.instance.generateRandomSerialNumber(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificate loadRootCertificate(final String keystorePath, // final char[] password, final String alias) { // return RootCertificateLoader.loadRootCertificate(keystorePath, password, alias); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CSR.java // public interface CSR { // // public DistinguishedName getSubject(); // // public PublicKey getPublicKey(); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CaException.java // public class CaException extends RuntimeException { // private static final long serialVersionUID = -9188923051885159431L; // // public CaException(final String message, final Throwable cause) { // super(message, cause); // } // // public CaException(final String message) { // super(message); // } // // public CaException(final Throwable cause) { // super(cause); // } // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // }
import static io.github.olivierlemasle.ca.CA.createCsr; import static io.github.olivierlemasle.ca.CA.createSelfSignedCertificate; import static io.github.olivierlemasle.ca.CA.dn; import static io.github.olivierlemasle.ca.CA.generateRandomSerialNumber; import static io.github.olivierlemasle.ca.CA.loadRootCertificate; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; import java.io.IOException; import java.math.BigInteger; import java.nio.file.Files; import java.nio.file.Paths; import java.security.cert.X509Certificate; import java.time.ZonedDateTime; import org.junit.After; import org.junit.BeforeClass; import org.junit.Test; import io.github.olivierlemasle.ca.CSR; import io.github.olivierlemasle.ca.CaException; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate;
package io.github.olivierlemasle.tests; public class KeystoreExportTest { private static RootCertificate ca; private static ZonedDateTime time = ZonedDateTime.now(); private static CSR csr; private static BigInteger serialNumber; private static X509Certificate cert; @BeforeClass public static void setup() { final DistinguishedName caName = dn("CN=CA-Test"); ca = createSelfSignedCertificate(caName).build();
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static CsrBuilder createCsr() { // return new CsrBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificateBuilder createSelfSignedCertificate( // final DistinguishedName subject) { // return new RootCertificateBuilderImpl(subject); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static BigInteger generateRandomSerialNumber() { // return SerialNumberGenerator.instance.generateRandomSerialNumber(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificate loadRootCertificate(final String keystorePath, // final char[] password, final String alias) { // return RootCertificateLoader.loadRootCertificate(keystorePath, password, alias); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CSR.java // public interface CSR { // // public DistinguishedName getSubject(); // // public PublicKey getPublicKey(); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CaException.java // public class CaException extends RuntimeException { // private static final long serialVersionUID = -9188923051885159431L; // // public CaException(final String message, final Throwable cause) { // super(message, cause); // } // // public CaException(final String message) { // super(message); // } // // public CaException(final Throwable cause) { // super(cause); // } // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // } // Path: java-ca-lib/src/test/java/io/github/olivierlemasle/tests/KeystoreExportTest.java import static io.github.olivierlemasle.ca.CA.createCsr; import static io.github.olivierlemasle.ca.CA.createSelfSignedCertificate; import static io.github.olivierlemasle.ca.CA.dn; import static io.github.olivierlemasle.ca.CA.generateRandomSerialNumber; import static io.github.olivierlemasle.ca.CA.loadRootCertificate; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; import java.io.IOException; import java.math.BigInteger; import java.nio.file.Files; import java.nio.file.Paths; import java.security.cert.X509Certificate; import java.time.ZonedDateTime; import org.junit.After; import org.junit.BeforeClass; import org.junit.Test; import io.github.olivierlemasle.ca.CSR; import io.github.olivierlemasle.ca.CaException; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate; package io.github.olivierlemasle.tests; public class KeystoreExportTest { private static RootCertificate ca; private static ZonedDateTime time = ZonedDateTime.now(); private static CSR csr; private static BigInteger serialNumber; private static X509Certificate cert; @BeforeClass public static void setup() { final DistinguishedName caName = dn("CN=CA-Test"); ca = createSelfSignedCertificate(caName).build();
csr = createCsr().generateRequest(dn("CN=Test"));
olivierlemasle/java-certificate-authority
java-ca-lib/src/test/java/io/github/olivierlemasle/tests/KeystoreExportTest.java
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static CsrBuilder createCsr() { // return new CsrBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificateBuilder createSelfSignedCertificate( // final DistinguishedName subject) { // return new RootCertificateBuilderImpl(subject); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static BigInteger generateRandomSerialNumber() { // return SerialNumberGenerator.instance.generateRandomSerialNumber(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificate loadRootCertificate(final String keystorePath, // final char[] password, final String alias) { // return RootCertificateLoader.loadRootCertificate(keystorePath, password, alias); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CSR.java // public interface CSR { // // public DistinguishedName getSubject(); // // public PublicKey getPublicKey(); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CaException.java // public class CaException extends RuntimeException { // private static final long serialVersionUID = -9188923051885159431L; // // public CaException(final String message, final Throwable cause) { // super(message, cause); // } // // public CaException(final String message) { // super(message); // } // // public CaException(final Throwable cause) { // super(cause); // } // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // }
import static io.github.olivierlemasle.ca.CA.createCsr; import static io.github.olivierlemasle.ca.CA.createSelfSignedCertificate; import static io.github.olivierlemasle.ca.CA.dn; import static io.github.olivierlemasle.ca.CA.generateRandomSerialNumber; import static io.github.olivierlemasle.ca.CA.loadRootCertificate; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; import java.io.IOException; import java.math.BigInteger; import java.nio.file.Files; import java.nio.file.Paths; import java.security.cert.X509Certificate; import java.time.ZonedDateTime; import org.junit.After; import org.junit.BeforeClass; import org.junit.Test; import io.github.olivierlemasle.ca.CSR; import io.github.olivierlemasle.ca.CaException; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate;
package io.github.olivierlemasle.tests; public class KeystoreExportTest { private static RootCertificate ca; private static ZonedDateTime time = ZonedDateTime.now(); private static CSR csr; private static BigInteger serialNumber; private static X509Certificate cert; @BeforeClass public static void setup() { final DistinguishedName caName = dn("CN=CA-Test"); ca = createSelfSignedCertificate(caName).build(); csr = createCsr().generateRequest(dn("CN=Test"));
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static CsrBuilder createCsr() { // return new CsrBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificateBuilder createSelfSignedCertificate( // final DistinguishedName subject) { // return new RootCertificateBuilderImpl(subject); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static BigInteger generateRandomSerialNumber() { // return SerialNumberGenerator.instance.generateRandomSerialNumber(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificate loadRootCertificate(final String keystorePath, // final char[] password, final String alias) { // return RootCertificateLoader.loadRootCertificate(keystorePath, password, alias); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CSR.java // public interface CSR { // // public DistinguishedName getSubject(); // // public PublicKey getPublicKey(); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CaException.java // public class CaException extends RuntimeException { // private static final long serialVersionUID = -9188923051885159431L; // // public CaException(final String message, final Throwable cause) { // super(message, cause); // } // // public CaException(final String message) { // super(message); // } // // public CaException(final Throwable cause) { // super(cause); // } // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // } // Path: java-ca-lib/src/test/java/io/github/olivierlemasle/tests/KeystoreExportTest.java import static io.github.olivierlemasle.ca.CA.createCsr; import static io.github.olivierlemasle.ca.CA.createSelfSignedCertificate; import static io.github.olivierlemasle.ca.CA.dn; import static io.github.olivierlemasle.ca.CA.generateRandomSerialNumber; import static io.github.olivierlemasle.ca.CA.loadRootCertificate; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; import java.io.IOException; import java.math.BigInteger; import java.nio.file.Files; import java.nio.file.Paths; import java.security.cert.X509Certificate; import java.time.ZonedDateTime; import org.junit.After; import org.junit.BeforeClass; import org.junit.Test; import io.github.olivierlemasle.ca.CSR; import io.github.olivierlemasle.ca.CaException; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate; package io.github.olivierlemasle.tests; public class KeystoreExportTest { private static RootCertificate ca; private static ZonedDateTime time = ZonedDateTime.now(); private static CSR csr; private static BigInteger serialNumber; private static X509Certificate cert; @BeforeClass public static void setup() { final DistinguishedName caName = dn("CN=CA-Test"); ca = createSelfSignedCertificate(caName).build(); csr = createCsr().generateRequest(dn("CN=Test"));
serialNumber = generateRandomSerialNumber();
olivierlemasle/java-certificate-authority
java-ca-lib/src/test/java/io/github/olivierlemasle/tests/KeystoreExportTest.java
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static CsrBuilder createCsr() { // return new CsrBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificateBuilder createSelfSignedCertificate( // final DistinguishedName subject) { // return new RootCertificateBuilderImpl(subject); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static BigInteger generateRandomSerialNumber() { // return SerialNumberGenerator.instance.generateRandomSerialNumber(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificate loadRootCertificate(final String keystorePath, // final char[] password, final String alias) { // return RootCertificateLoader.loadRootCertificate(keystorePath, password, alias); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CSR.java // public interface CSR { // // public DistinguishedName getSubject(); // // public PublicKey getPublicKey(); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CaException.java // public class CaException extends RuntimeException { // private static final long serialVersionUID = -9188923051885159431L; // // public CaException(final String message, final Throwable cause) { // super(message, cause); // } // // public CaException(final String message) { // super(message); // } // // public CaException(final Throwable cause) { // super(cause); // } // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // }
import static io.github.olivierlemasle.ca.CA.createCsr; import static io.github.olivierlemasle.ca.CA.createSelfSignedCertificate; import static io.github.olivierlemasle.ca.CA.dn; import static io.github.olivierlemasle.ca.CA.generateRandomSerialNumber; import static io.github.olivierlemasle.ca.CA.loadRootCertificate; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; import java.io.IOException; import java.math.BigInteger; import java.nio.file.Files; import java.nio.file.Paths; import java.security.cert.X509Certificate; import java.time.ZonedDateTime; import org.junit.After; import org.junit.BeforeClass; import org.junit.Test; import io.github.olivierlemasle.ca.CSR; import io.github.olivierlemasle.ca.CaException; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate;
private static BigInteger serialNumber; private static X509Certificate cert; @BeforeClass public static void setup() { final DistinguishedName caName = dn("CN=CA-Test"); ca = createSelfSignedCertificate(caName).build(); csr = createCsr().generateRequest(dn("CN=Test")); serialNumber = generateRandomSerialNumber(); cert = ca.signCsr(csr) .setSerialNumber(serialNumber) .setNotBefore(time) .validDuringYears(1) .sign() .getX509Certificate(); } @After public void clean() { try { Files.delete(Paths.get("test.p12")); } catch (final IOException e) { fail("Cannot delete keystore"); } } @Test public void saveToKeystoreFileAndBack() { ca.exportPkcs12("test.p12", "password".toCharArray(), "ca");
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static CsrBuilder createCsr() { // return new CsrBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificateBuilder createSelfSignedCertificate( // final DistinguishedName subject) { // return new RootCertificateBuilderImpl(subject); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static BigInteger generateRandomSerialNumber() { // return SerialNumberGenerator.instance.generateRandomSerialNumber(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificate loadRootCertificate(final String keystorePath, // final char[] password, final String alias) { // return RootCertificateLoader.loadRootCertificate(keystorePath, password, alias); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CSR.java // public interface CSR { // // public DistinguishedName getSubject(); // // public PublicKey getPublicKey(); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CaException.java // public class CaException extends RuntimeException { // private static final long serialVersionUID = -9188923051885159431L; // // public CaException(final String message, final Throwable cause) { // super(message, cause); // } // // public CaException(final String message) { // super(message); // } // // public CaException(final Throwable cause) { // super(cause); // } // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // } // Path: java-ca-lib/src/test/java/io/github/olivierlemasle/tests/KeystoreExportTest.java import static io.github.olivierlemasle.ca.CA.createCsr; import static io.github.olivierlemasle.ca.CA.createSelfSignedCertificate; import static io.github.olivierlemasle.ca.CA.dn; import static io.github.olivierlemasle.ca.CA.generateRandomSerialNumber; import static io.github.olivierlemasle.ca.CA.loadRootCertificate; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; import java.io.IOException; import java.math.BigInteger; import java.nio.file.Files; import java.nio.file.Paths; import java.security.cert.X509Certificate; import java.time.ZonedDateTime; import org.junit.After; import org.junit.BeforeClass; import org.junit.Test; import io.github.olivierlemasle.ca.CSR; import io.github.olivierlemasle.ca.CaException; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate; private static BigInteger serialNumber; private static X509Certificate cert; @BeforeClass public static void setup() { final DistinguishedName caName = dn("CN=CA-Test"); ca = createSelfSignedCertificate(caName).build(); csr = createCsr().generateRequest(dn("CN=Test")); serialNumber = generateRandomSerialNumber(); cert = ca.signCsr(csr) .setSerialNumber(serialNumber) .setNotBefore(time) .validDuringYears(1) .sign() .getX509Certificate(); } @After public void clean() { try { Files.delete(Paths.get("test.p12")); } catch (final IOException e) { fail("Cannot delete keystore"); } } @Test public void saveToKeystoreFileAndBack() { ca.exportPkcs12("test.p12", "password".toCharArray(), "ca");
final RootCertificate ca2 = loadRootCertificate("test.p12",
olivierlemasle/java-certificate-authority
java-ca-lib/src/test/java/io/github/olivierlemasle/tests/KeystoreExportTest.java
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static CsrBuilder createCsr() { // return new CsrBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificateBuilder createSelfSignedCertificate( // final DistinguishedName subject) { // return new RootCertificateBuilderImpl(subject); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static BigInteger generateRandomSerialNumber() { // return SerialNumberGenerator.instance.generateRandomSerialNumber(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificate loadRootCertificate(final String keystorePath, // final char[] password, final String alias) { // return RootCertificateLoader.loadRootCertificate(keystorePath, password, alias); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CSR.java // public interface CSR { // // public DistinguishedName getSubject(); // // public PublicKey getPublicKey(); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CaException.java // public class CaException extends RuntimeException { // private static final long serialVersionUID = -9188923051885159431L; // // public CaException(final String message, final Throwable cause) { // super(message, cause); // } // // public CaException(final String message) { // super(message); // } // // public CaException(final Throwable cause) { // super(cause); // } // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // }
import static io.github.olivierlemasle.ca.CA.createCsr; import static io.github.olivierlemasle.ca.CA.createSelfSignedCertificate; import static io.github.olivierlemasle.ca.CA.dn; import static io.github.olivierlemasle.ca.CA.generateRandomSerialNumber; import static io.github.olivierlemasle.ca.CA.loadRootCertificate; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; import java.io.IOException; import java.math.BigInteger; import java.nio.file.Files; import java.nio.file.Paths; import java.security.cert.X509Certificate; import java.time.ZonedDateTime; import org.junit.After; import org.junit.BeforeClass; import org.junit.Test; import io.github.olivierlemasle.ca.CSR; import io.github.olivierlemasle.ca.CaException; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate;
Files.delete(Paths.get("test.p12")); } catch (final IOException e) { fail("Cannot delete keystore"); } } @Test public void saveToKeystoreFileAndBack() { ca.exportPkcs12("test.p12", "password".toCharArray(), "ca"); final RootCertificate ca2 = loadRootCertificate("test.p12", "password".toCharArray(), "ca"); assertEquals(ca.getX509Certificate(), ca2.getX509Certificate()); final X509Certificate cert2 = ca2.signCsr(csr) .setSerialNumber(serialNumber) .setNotBefore(time) .validDuringYears(1) .sign() .getX509Certificate(); assertEquals(cert, cert2); } @Test public void testInvalidKeystorePath() { ca.exportPkcs12("test.p12", "password".toCharArray(), "ca"); try { loadRootCertificate("invalid", "password".toCharArray(), "ca"); fail("CaException expected");
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static CsrBuilder createCsr() { // return new CsrBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificateBuilder createSelfSignedCertificate( // final DistinguishedName subject) { // return new RootCertificateBuilderImpl(subject); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static BigInteger generateRandomSerialNumber() { // return SerialNumberGenerator.instance.generateRandomSerialNumber(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificate loadRootCertificate(final String keystorePath, // final char[] password, final String alias) { // return RootCertificateLoader.loadRootCertificate(keystorePath, password, alias); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CSR.java // public interface CSR { // // public DistinguishedName getSubject(); // // public PublicKey getPublicKey(); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CaException.java // public class CaException extends RuntimeException { // private static final long serialVersionUID = -9188923051885159431L; // // public CaException(final String message, final Throwable cause) { // super(message, cause); // } // // public CaException(final String message) { // super(message); // } // // public CaException(final Throwable cause) { // super(cause); // } // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // } // Path: java-ca-lib/src/test/java/io/github/olivierlemasle/tests/KeystoreExportTest.java import static io.github.olivierlemasle.ca.CA.createCsr; import static io.github.olivierlemasle.ca.CA.createSelfSignedCertificate; import static io.github.olivierlemasle.ca.CA.dn; import static io.github.olivierlemasle.ca.CA.generateRandomSerialNumber; import static io.github.olivierlemasle.ca.CA.loadRootCertificate; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; import java.io.IOException; import java.math.BigInteger; import java.nio.file.Files; import java.nio.file.Paths; import java.security.cert.X509Certificate; import java.time.ZonedDateTime; import org.junit.After; import org.junit.BeforeClass; import org.junit.Test; import io.github.olivierlemasle.ca.CSR; import io.github.olivierlemasle.ca.CaException; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate; Files.delete(Paths.get("test.p12")); } catch (final IOException e) { fail("Cannot delete keystore"); } } @Test public void saveToKeystoreFileAndBack() { ca.exportPkcs12("test.p12", "password".toCharArray(), "ca"); final RootCertificate ca2 = loadRootCertificate("test.p12", "password".toCharArray(), "ca"); assertEquals(ca.getX509Certificate(), ca2.getX509Certificate()); final X509Certificate cert2 = ca2.signCsr(csr) .setSerialNumber(serialNumber) .setNotBefore(time) .validDuringYears(1) .sign() .getX509Certificate(); assertEquals(cert, cert2); } @Test public void testInvalidKeystorePath() { ca.exportPkcs12("test.p12", "password".toCharArray(), "ca"); try { loadRootCertificate("invalid", "password".toCharArray(), "ca"); fail("CaException expected");
} catch (final CaException expected) {
olivierlemasle/java-certificate-authority
ca-api/src/main/java/io/github/olivierlemasle/caweb/cli/CreateCertificate.java
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static CsrBuilder createCsr() { // return new CsrBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificate loadRootCertificate(final String keystorePath, // final char[] password, final String alias) { // return RootCertificateLoader.loadRootCertificate(keystorePath, password, alias); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/Certificate.java // public interface Certificate { // // public X509Certificate getX509Certificate(); // // public String print(); // // public void save(File file); // // public void save(String fileName); // // public CertificateWithPrivateKey attachPrivateKey(PrivateKey privateKey); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CertificateWithPrivateKey.java // public interface CertificateWithPrivateKey extends Certificate { // // public KeyStore addToKeystore(KeyStore keyStore, String alias); // // public KeyStore saveInPkcs12Keystore(String alias); // // public void exportPkcs12(final String keystorePath, final char[] keystorePassword, // final String alias); // // public void exportPkcs12(final File keystoreFile, final char[] keystorePassword, // final String alias); // // public PrivateKey getPrivateKey(); // // public String printKey(); // // public void saveKey(File file); // // public void saveKey(String fileName); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CsrWithPrivateKey.java // public interface CsrWithPrivateKey extends CSR { // // public PrivateKey getPrivateKey(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // }
import static io.github.olivierlemasle.ca.CA.createCsr; import static io.github.olivierlemasle.ca.CA.dn; import static io.github.olivierlemasle.ca.CA.loadRootCertificate; import io.dropwizard.cli.Command; import io.dropwizard.setup.Bootstrap; import io.github.olivierlemasle.ca.Certificate; import io.github.olivierlemasle.ca.CertificateWithPrivateKey; import io.github.olivierlemasle.ca.CsrWithPrivateKey; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate; import net.sourceforge.argparse4j.inf.Namespace; import net.sourceforge.argparse4j.inf.Subparser;
.dest("in") .type(String.class) .required(true) .help("The name of the root certificate keystore"); parser.addArgument("-p", "--password") .dest("password") .type(String.class) .required(true) .help("The password of the keystore"); parser.addArgument("-c", "--cert") .dest("cert") .type(String.class) .required(true) .help("The certificate file to be created"); parser.addArgument("-k", "--key") .dest("key") .type(String.class) .required(true) .help("The key file to be created"); } @Override public void run(final Bootstrap<?> bootstrap, final Namespace namespace) throws Exception { final String subject = namespace.getString("subject"); final String signer = namespace.getString("signer"); final String in = namespace.getString("in"); final String password = namespace.getString("password"); final String cert = namespace.getString("cert"); final String key = namespace.getString("key");
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static CsrBuilder createCsr() { // return new CsrBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificate loadRootCertificate(final String keystorePath, // final char[] password, final String alias) { // return RootCertificateLoader.loadRootCertificate(keystorePath, password, alias); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/Certificate.java // public interface Certificate { // // public X509Certificate getX509Certificate(); // // public String print(); // // public void save(File file); // // public void save(String fileName); // // public CertificateWithPrivateKey attachPrivateKey(PrivateKey privateKey); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CertificateWithPrivateKey.java // public interface CertificateWithPrivateKey extends Certificate { // // public KeyStore addToKeystore(KeyStore keyStore, String alias); // // public KeyStore saveInPkcs12Keystore(String alias); // // public void exportPkcs12(final String keystorePath, final char[] keystorePassword, // final String alias); // // public void exportPkcs12(final File keystoreFile, final char[] keystorePassword, // final String alias); // // public PrivateKey getPrivateKey(); // // public String printKey(); // // public void saveKey(File file); // // public void saveKey(String fileName); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CsrWithPrivateKey.java // public interface CsrWithPrivateKey extends CSR { // // public PrivateKey getPrivateKey(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // } // Path: ca-api/src/main/java/io/github/olivierlemasle/caweb/cli/CreateCertificate.java import static io.github.olivierlemasle.ca.CA.createCsr; import static io.github.olivierlemasle.ca.CA.dn; import static io.github.olivierlemasle.ca.CA.loadRootCertificate; import io.dropwizard.cli.Command; import io.dropwizard.setup.Bootstrap; import io.github.olivierlemasle.ca.Certificate; import io.github.olivierlemasle.ca.CertificateWithPrivateKey; import io.github.olivierlemasle.ca.CsrWithPrivateKey; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate; import net.sourceforge.argparse4j.inf.Namespace; import net.sourceforge.argparse4j.inf.Subparser; .dest("in") .type(String.class) .required(true) .help("The name of the root certificate keystore"); parser.addArgument("-p", "--password") .dest("password") .type(String.class) .required(true) .help("The password of the keystore"); parser.addArgument("-c", "--cert") .dest("cert") .type(String.class) .required(true) .help("The certificate file to be created"); parser.addArgument("-k", "--key") .dest("key") .type(String.class) .required(true) .help("The key file to be created"); } @Override public void run(final Bootstrap<?> bootstrap, final Namespace namespace) throws Exception { final String subject = namespace.getString("subject"); final String signer = namespace.getString("signer"); final String in = namespace.getString("in"); final String password = namespace.getString("password"); final String cert = namespace.getString("cert"); final String key = namespace.getString("key");
final RootCertificate root = loadRootCertificate(in, password.toCharArray(), signer);
olivierlemasle/java-certificate-authority
ca-api/src/main/java/io/github/olivierlemasle/caweb/cli/CreateCertificate.java
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static CsrBuilder createCsr() { // return new CsrBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificate loadRootCertificate(final String keystorePath, // final char[] password, final String alias) { // return RootCertificateLoader.loadRootCertificate(keystorePath, password, alias); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/Certificate.java // public interface Certificate { // // public X509Certificate getX509Certificate(); // // public String print(); // // public void save(File file); // // public void save(String fileName); // // public CertificateWithPrivateKey attachPrivateKey(PrivateKey privateKey); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CertificateWithPrivateKey.java // public interface CertificateWithPrivateKey extends Certificate { // // public KeyStore addToKeystore(KeyStore keyStore, String alias); // // public KeyStore saveInPkcs12Keystore(String alias); // // public void exportPkcs12(final String keystorePath, final char[] keystorePassword, // final String alias); // // public void exportPkcs12(final File keystoreFile, final char[] keystorePassword, // final String alias); // // public PrivateKey getPrivateKey(); // // public String printKey(); // // public void saveKey(File file); // // public void saveKey(String fileName); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CsrWithPrivateKey.java // public interface CsrWithPrivateKey extends CSR { // // public PrivateKey getPrivateKey(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // }
import static io.github.olivierlemasle.ca.CA.createCsr; import static io.github.olivierlemasle.ca.CA.dn; import static io.github.olivierlemasle.ca.CA.loadRootCertificate; import io.dropwizard.cli.Command; import io.dropwizard.setup.Bootstrap; import io.github.olivierlemasle.ca.Certificate; import io.github.olivierlemasle.ca.CertificateWithPrivateKey; import io.github.olivierlemasle.ca.CsrWithPrivateKey; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate; import net.sourceforge.argparse4j.inf.Namespace; import net.sourceforge.argparse4j.inf.Subparser;
.dest("in") .type(String.class) .required(true) .help("The name of the root certificate keystore"); parser.addArgument("-p", "--password") .dest("password") .type(String.class) .required(true) .help("The password of the keystore"); parser.addArgument("-c", "--cert") .dest("cert") .type(String.class) .required(true) .help("The certificate file to be created"); parser.addArgument("-k", "--key") .dest("key") .type(String.class) .required(true) .help("The key file to be created"); } @Override public void run(final Bootstrap<?> bootstrap, final Namespace namespace) throws Exception { final String subject = namespace.getString("subject"); final String signer = namespace.getString("signer"); final String in = namespace.getString("in"); final String password = namespace.getString("password"); final String cert = namespace.getString("cert"); final String key = namespace.getString("key");
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static CsrBuilder createCsr() { // return new CsrBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificate loadRootCertificate(final String keystorePath, // final char[] password, final String alias) { // return RootCertificateLoader.loadRootCertificate(keystorePath, password, alias); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/Certificate.java // public interface Certificate { // // public X509Certificate getX509Certificate(); // // public String print(); // // public void save(File file); // // public void save(String fileName); // // public CertificateWithPrivateKey attachPrivateKey(PrivateKey privateKey); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CertificateWithPrivateKey.java // public interface CertificateWithPrivateKey extends Certificate { // // public KeyStore addToKeystore(KeyStore keyStore, String alias); // // public KeyStore saveInPkcs12Keystore(String alias); // // public void exportPkcs12(final String keystorePath, final char[] keystorePassword, // final String alias); // // public void exportPkcs12(final File keystoreFile, final char[] keystorePassword, // final String alias); // // public PrivateKey getPrivateKey(); // // public String printKey(); // // public void saveKey(File file); // // public void saveKey(String fileName); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CsrWithPrivateKey.java // public interface CsrWithPrivateKey extends CSR { // // public PrivateKey getPrivateKey(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // } // Path: ca-api/src/main/java/io/github/olivierlemasle/caweb/cli/CreateCertificate.java import static io.github.olivierlemasle.ca.CA.createCsr; import static io.github.olivierlemasle.ca.CA.dn; import static io.github.olivierlemasle.ca.CA.loadRootCertificate; import io.dropwizard.cli.Command; import io.dropwizard.setup.Bootstrap; import io.github.olivierlemasle.ca.Certificate; import io.github.olivierlemasle.ca.CertificateWithPrivateKey; import io.github.olivierlemasle.ca.CsrWithPrivateKey; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate; import net.sourceforge.argparse4j.inf.Namespace; import net.sourceforge.argparse4j.inf.Subparser; .dest("in") .type(String.class) .required(true) .help("The name of the root certificate keystore"); parser.addArgument("-p", "--password") .dest("password") .type(String.class) .required(true) .help("The password of the keystore"); parser.addArgument("-c", "--cert") .dest("cert") .type(String.class) .required(true) .help("The certificate file to be created"); parser.addArgument("-k", "--key") .dest("key") .type(String.class) .required(true) .help("The key file to be created"); } @Override public void run(final Bootstrap<?> bootstrap, final Namespace namespace) throws Exception { final String subject = namespace.getString("subject"); final String signer = namespace.getString("signer"); final String in = namespace.getString("in"); final String password = namespace.getString("password"); final String cert = namespace.getString("cert"); final String key = namespace.getString("key");
final RootCertificate root = loadRootCertificate(in, password.toCharArray(), signer);
olivierlemasle/java-certificate-authority
ca-api/src/main/java/io/github/olivierlemasle/caweb/cli/CreateCertificate.java
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static CsrBuilder createCsr() { // return new CsrBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificate loadRootCertificate(final String keystorePath, // final char[] password, final String alias) { // return RootCertificateLoader.loadRootCertificate(keystorePath, password, alias); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/Certificate.java // public interface Certificate { // // public X509Certificate getX509Certificate(); // // public String print(); // // public void save(File file); // // public void save(String fileName); // // public CertificateWithPrivateKey attachPrivateKey(PrivateKey privateKey); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CertificateWithPrivateKey.java // public interface CertificateWithPrivateKey extends Certificate { // // public KeyStore addToKeystore(KeyStore keyStore, String alias); // // public KeyStore saveInPkcs12Keystore(String alias); // // public void exportPkcs12(final String keystorePath, final char[] keystorePassword, // final String alias); // // public void exportPkcs12(final File keystoreFile, final char[] keystorePassword, // final String alias); // // public PrivateKey getPrivateKey(); // // public String printKey(); // // public void saveKey(File file); // // public void saveKey(String fileName); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CsrWithPrivateKey.java // public interface CsrWithPrivateKey extends CSR { // // public PrivateKey getPrivateKey(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // }
import static io.github.olivierlemasle.ca.CA.createCsr; import static io.github.olivierlemasle.ca.CA.dn; import static io.github.olivierlemasle.ca.CA.loadRootCertificate; import io.dropwizard.cli.Command; import io.dropwizard.setup.Bootstrap; import io.github.olivierlemasle.ca.Certificate; import io.github.olivierlemasle.ca.CertificateWithPrivateKey; import io.github.olivierlemasle.ca.CsrWithPrivateKey; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate; import net.sourceforge.argparse4j.inf.Namespace; import net.sourceforge.argparse4j.inf.Subparser;
.required(true) .help("The name of the root certificate keystore"); parser.addArgument("-p", "--password") .dest("password") .type(String.class) .required(true) .help("The password of the keystore"); parser.addArgument("-c", "--cert") .dest("cert") .type(String.class) .required(true) .help("The certificate file to be created"); parser.addArgument("-k", "--key") .dest("key") .type(String.class) .required(true) .help("The key file to be created"); } @Override public void run(final Bootstrap<?> bootstrap, final Namespace namespace) throws Exception { final String subject = namespace.getString("subject"); final String signer = namespace.getString("signer"); final String in = namespace.getString("in"); final String password = namespace.getString("password"); final String cert = namespace.getString("cert"); final String key = namespace.getString("key"); final RootCertificate root = loadRootCertificate(in, password.toCharArray(), signer);
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static CsrBuilder createCsr() { // return new CsrBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificate loadRootCertificate(final String keystorePath, // final char[] password, final String alias) { // return RootCertificateLoader.loadRootCertificate(keystorePath, password, alias); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/Certificate.java // public interface Certificate { // // public X509Certificate getX509Certificate(); // // public String print(); // // public void save(File file); // // public void save(String fileName); // // public CertificateWithPrivateKey attachPrivateKey(PrivateKey privateKey); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CertificateWithPrivateKey.java // public interface CertificateWithPrivateKey extends Certificate { // // public KeyStore addToKeystore(KeyStore keyStore, String alias); // // public KeyStore saveInPkcs12Keystore(String alias); // // public void exportPkcs12(final String keystorePath, final char[] keystorePassword, // final String alias); // // public void exportPkcs12(final File keystoreFile, final char[] keystorePassword, // final String alias); // // public PrivateKey getPrivateKey(); // // public String printKey(); // // public void saveKey(File file); // // public void saveKey(String fileName); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CsrWithPrivateKey.java // public interface CsrWithPrivateKey extends CSR { // // public PrivateKey getPrivateKey(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // } // Path: ca-api/src/main/java/io/github/olivierlemasle/caweb/cli/CreateCertificate.java import static io.github.olivierlemasle.ca.CA.createCsr; import static io.github.olivierlemasle.ca.CA.dn; import static io.github.olivierlemasle.ca.CA.loadRootCertificate; import io.dropwizard.cli.Command; import io.dropwizard.setup.Bootstrap; import io.github.olivierlemasle.ca.Certificate; import io.github.olivierlemasle.ca.CertificateWithPrivateKey; import io.github.olivierlemasle.ca.CsrWithPrivateKey; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate; import net.sourceforge.argparse4j.inf.Namespace; import net.sourceforge.argparse4j.inf.Subparser; .required(true) .help("The name of the root certificate keystore"); parser.addArgument("-p", "--password") .dest("password") .type(String.class) .required(true) .help("The password of the keystore"); parser.addArgument("-c", "--cert") .dest("cert") .type(String.class) .required(true) .help("The certificate file to be created"); parser.addArgument("-k", "--key") .dest("key") .type(String.class) .required(true) .help("The key file to be created"); } @Override public void run(final Bootstrap<?> bootstrap, final Namespace namespace) throws Exception { final String subject = namespace.getString("subject"); final String signer = namespace.getString("signer"); final String in = namespace.getString("in"); final String password = namespace.getString("password"); final String cert = namespace.getString("cert"); final String key = namespace.getString("key"); final RootCertificate root = loadRootCertificate(in, password.toCharArray(), signer);
final DistinguishedName dn = dn().setCn(subject).build();
olivierlemasle/java-certificate-authority
ca-api/src/main/java/io/github/olivierlemasle/caweb/cli/CreateCertificate.java
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static CsrBuilder createCsr() { // return new CsrBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificate loadRootCertificate(final String keystorePath, // final char[] password, final String alias) { // return RootCertificateLoader.loadRootCertificate(keystorePath, password, alias); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/Certificate.java // public interface Certificate { // // public X509Certificate getX509Certificate(); // // public String print(); // // public void save(File file); // // public void save(String fileName); // // public CertificateWithPrivateKey attachPrivateKey(PrivateKey privateKey); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CertificateWithPrivateKey.java // public interface CertificateWithPrivateKey extends Certificate { // // public KeyStore addToKeystore(KeyStore keyStore, String alias); // // public KeyStore saveInPkcs12Keystore(String alias); // // public void exportPkcs12(final String keystorePath, final char[] keystorePassword, // final String alias); // // public void exportPkcs12(final File keystoreFile, final char[] keystorePassword, // final String alias); // // public PrivateKey getPrivateKey(); // // public String printKey(); // // public void saveKey(File file); // // public void saveKey(String fileName); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CsrWithPrivateKey.java // public interface CsrWithPrivateKey extends CSR { // // public PrivateKey getPrivateKey(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // }
import static io.github.olivierlemasle.ca.CA.createCsr; import static io.github.olivierlemasle.ca.CA.dn; import static io.github.olivierlemasle.ca.CA.loadRootCertificate; import io.dropwizard.cli.Command; import io.dropwizard.setup.Bootstrap; import io.github.olivierlemasle.ca.Certificate; import io.github.olivierlemasle.ca.CertificateWithPrivateKey; import io.github.olivierlemasle.ca.CsrWithPrivateKey; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate; import net.sourceforge.argparse4j.inf.Namespace; import net.sourceforge.argparse4j.inf.Subparser;
.required(true) .help("The name of the root certificate keystore"); parser.addArgument("-p", "--password") .dest("password") .type(String.class) .required(true) .help("The password of the keystore"); parser.addArgument("-c", "--cert") .dest("cert") .type(String.class) .required(true) .help("The certificate file to be created"); parser.addArgument("-k", "--key") .dest("key") .type(String.class) .required(true) .help("The key file to be created"); } @Override public void run(final Bootstrap<?> bootstrap, final Namespace namespace) throws Exception { final String subject = namespace.getString("subject"); final String signer = namespace.getString("signer"); final String in = namespace.getString("in"); final String password = namespace.getString("password"); final String cert = namespace.getString("cert"); final String key = namespace.getString("key"); final RootCertificate root = loadRootCertificate(in, password.toCharArray(), signer);
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static CsrBuilder createCsr() { // return new CsrBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificate loadRootCertificate(final String keystorePath, // final char[] password, final String alias) { // return RootCertificateLoader.loadRootCertificate(keystorePath, password, alias); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/Certificate.java // public interface Certificate { // // public X509Certificate getX509Certificate(); // // public String print(); // // public void save(File file); // // public void save(String fileName); // // public CertificateWithPrivateKey attachPrivateKey(PrivateKey privateKey); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CertificateWithPrivateKey.java // public interface CertificateWithPrivateKey extends Certificate { // // public KeyStore addToKeystore(KeyStore keyStore, String alias); // // public KeyStore saveInPkcs12Keystore(String alias); // // public void exportPkcs12(final String keystorePath, final char[] keystorePassword, // final String alias); // // public void exportPkcs12(final File keystoreFile, final char[] keystorePassword, // final String alias); // // public PrivateKey getPrivateKey(); // // public String printKey(); // // public void saveKey(File file); // // public void saveKey(String fileName); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CsrWithPrivateKey.java // public interface CsrWithPrivateKey extends CSR { // // public PrivateKey getPrivateKey(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // } // Path: ca-api/src/main/java/io/github/olivierlemasle/caweb/cli/CreateCertificate.java import static io.github.olivierlemasle.ca.CA.createCsr; import static io.github.olivierlemasle.ca.CA.dn; import static io.github.olivierlemasle.ca.CA.loadRootCertificate; import io.dropwizard.cli.Command; import io.dropwizard.setup.Bootstrap; import io.github.olivierlemasle.ca.Certificate; import io.github.olivierlemasle.ca.CertificateWithPrivateKey; import io.github.olivierlemasle.ca.CsrWithPrivateKey; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate; import net.sourceforge.argparse4j.inf.Namespace; import net.sourceforge.argparse4j.inf.Subparser; .required(true) .help("The name of the root certificate keystore"); parser.addArgument("-p", "--password") .dest("password") .type(String.class) .required(true) .help("The password of the keystore"); parser.addArgument("-c", "--cert") .dest("cert") .type(String.class) .required(true) .help("The certificate file to be created"); parser.addArgument("-k", "--key") .dest("key") .type(String.class) .required(true) .help("The key file to be created"); } @Override public void run(final Bootstrap<?> bootstrap, final Namespace namespace) throws Exception { final String subject = namespace.getString("subject"); final String signer = namespace.getString("signer"); final String in = namespace.getString("in"); final String password = namespace.getString("password"); final String cert = namespace.getString("cert"); final String key = namespace.getString("key"); final RootCertificate root = loadRootCertificate(in, password.toCharArray(), signer);
final DistinguishedName dn = dn().setCn(subject).build();
olivierlemasle/java-certificate-authority
ca-api/src/main/java/io/github/olivierlemasle/caweb/cli/CreateCertificate.java
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static CsrBuilder createCsr() { // return new CsrBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificate loadRootCertificate(final String keystorePath, // final char[] password, final String alias) { // return RootCertificateLoader.loadRootCertificate(keystorePath, password, alias); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/Certificate.java // public interface Certificate { // // public X509Certificate getX509Certificate(); // // public String print(); // // public void save(File file); // // public void save(String fileName); // // public CertificateWithPrivateKey attachPrivateKey(PrivateKey privateKey); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CertificateWithPrivateKey.java // public interface CertificateWithPrivateKey extends Certificate { // // public KeyStore addToKeystore(KeyStore keyStore, String alias); // // public KeyStore saveInPkcs12Keystore(String alias); // // public void exportPkcs12(final String keystorePath, final char[] keystorePassword, // final String alias); // // public void exportPkcs12(final File keystoreFile, final char[] keystorePassword, // final String alias); // // public PrivateKey getPrivateKey(); // // public String printKey(); // // public void saveKey(File file); // // public void saveKey(String fileName); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CsrWithPrivateKey.java // public interface CsrWithPrivateKey extends CSR { // // public PrivateKey getPrivateKey(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // }
import static io.github.olivierlemasle.ca.CA.createCsr; import static io.github.olivierlemasle.ca.CA.dn; import static io.github.olivierlemasle.ca.CA.loadRootCertificate; import io.dropwizard.cli.Command; import io.dropwizard.setup.Bootstrap; import io.github.olivierlemasle.ca.Certificate; import io.github.olivierlemasle.ca.CertificateWithPrivateKey; import io.github.olivierlemasle.ca.CsrWithPrivateKey; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate; import net.sourceforge.argparse4j.inf.Namespace; import net.sourceforge.argparse4j.inf.Subparser;
.help("The name of the root certificate keystore"); parser.addArgument("-p", "--password") .dest("password") .type(String.class) .required(true) .help("The password of the keystore"); parser.addArgument("-c", "--cert") .dest("cert") .type(String.class) .required(true) .help("The certificate file to be created"); parser.addArgument("-k", "--key") .dest("key") .type(String.class) .required(true) .help("The key file to be created"); } @Override public void run(final Bootstrap<?> bootstrap, final Namespace namespace) throws Exception { final String subject = namespace.getString("subject"); final String signer = namespace.getString("signer"); final String in = namespace.getString("in"); final String password = namespace.getString("password"); final String cert = namespace.getString("cert"); final String key = namespace.getString("key"); final RootCertificate root = loadRootCertificate(in, password.toCharArray(), signer); final DistinguishedName dn = dn().setCn(subject).build();
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static CsrBuilder createCsr() { // return new CsrBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificate loadRootCertificate(final String keystorePath, // final char[] password, final String alias) { // return RootCertificateLoader.loadRootCertificate(keystorePath, password, alias); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/Certificate.java // public interface Certificate { // // public X509Certificate getX509Certificate(); // // public String print(); // // public void save(File file); // // public void save(String fileName); // // public CertificateWithPrivateKey attachPrivateKey(PrivateKey privateKey); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CertificateWithPrivateKey.java // public interface CertificateWithPrivateKey extends Certificate { // // public KeyStore addToKeystore(KeyStore keyStore, String alias); // // public KeyStore saveInPkcs12Keystore(String alias); // // public void exportPkcs12(final String keystorePath, final char[] keystorePassword, // final String alias); // // public void exportPkcs12(final File keystoreFile, final char[] keystorePassword, // final String alias); // // public PrivateKey getPrivateKey(); // // public String printKey(); // // public void saveKey(File file); // // public void saveKey(String fileName); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CsrWithPrivateKey.java // public interface CsrWithPrivateKey extends CSR { // // public PrivateKey getPrivateKey(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // } // Path: ca-api/src/main/java/io/github/olivierlemasle/caweb/cli/CreateCertificate.java import static io.github.olivierlemasle.ca.CA.createCsr; import static io.github.olivierlemasle.ca.CA.dn; import static io.github.olivierlemasle.ca.CA.loadRootCertificate; import io.dropwizard.cli.Command; import io.dropwizard.setup.Bootstrap; import io.github.olivierlemasle.ca.Certificate; import io.github.olivierlemasle.ca.CertificateWithPrivateKey; import io.github.olivierlemasle.ca.CsrWithPrivateKey; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate; import net.sourceforge.argparse4j.inf.Namespace; import net.sourceforge.argparse4j.inf.Subparser; .help("The name of the root certificate keystore"); parser.addArgument("-p", "--password") .dest("password") .type(String.class) .required(true) .help("The password of the keystore"); parser.addArgument("-c", "--cert") .dest("cert") .type(String.class) .required(true) .help("The certificate file to be created"); parser.addArgument("-k", "--key") .dest("key") .type(String.class) .required(true) .help("The key file to be created"); } @Override public void run(final Bootstrap<?> bootstrap, final Namespace namespace) throws Exception { final String subject = namespace.getString("subject"); final String signer = namespace.getString("signer"); final String in = namespace.getString("in"); final String password = namespace.getString("password"); final String cert = namespace.getString("cert"); final String key = namespace.getString("key"); final RootCertificate root = loadRootCertificate(in, password.toCharArray(), signer); final DistinguishedName dn = dn().setCn(subject).build();
final CsrWithPrivateKey csr = createCsr().generateRequest(dn);
olivierlemasle/java-certificate-authority
ca-api/src/main/java/io/github/olivierlemasle/caweb/cli/CreateCertificate.java
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static CsrBuilder createCsr() { // return new CsrBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificate loadRootCertificate(final String keystorePath, // final char[] password, final String alias) { // return RootCertificateLoader.loadRootCertificate(keystorePath, password, alias); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/Certificate.java // public interface Certificate { // // public X509Certificate getX509Certificate(); // // public String print(); // // public void save(File file); // // public void save(String fileName); // // public CertificateWithPrivateKey attachPrivateKey(PrivateKey privateKey); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CertificateWithPrivateKey.java // public interface CertificateWithPrivateKey extends Certificate { // // public KeyStore addToKeystore(KeyStore keyStore, String alias); // // public KeyStore saveInPkcs12Keystore(String alias); // // public void exportPkcs12(final String keystorePath, final char[] keystorePassword, // final String alias); // // public void exportPkcs12(final File keystoreFile, final char[] keystorePassword, // final String alias); // // public PrivateKey getPrivateKey(); // // public String printKey(); // // public void saveKey(File file); // // public void saveKey(String fileName); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CsrWithPrivateKey.java // public interface CsrWithPrivateKey extends CSR { // // public PrivateKey getPrivateKey(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // }
import static io.github.olivierlemasle.ca.CA.createCsr; import static io.github.olivierlemasle.ca.CA.dn; import static io.github.olivierlemasle.ca.CA.loadRootCertificate; import io.dropwizard.cli.Command; import io.dropwizard.setup.Bootstrap; import io.github.olivierlemasle.ca.Certificate; import io.github.olivierlemasle.ca.CertificateWithPrivateKey; import io.github.olivierlemasle.ca.CsrWithPrivateKey; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate; import net.sourceforge.argparse4j.inf.Namespace; import net.sourceforge.argparse4j.inf.Subparser;
.help("The name of the root certificate keystore"); parser.addArgument("-p", "--password") .dest("password") .type(String.class) .required(true) .help("The password of the keystore"); parser.addArgument("-c", "--cert") .dest("cert") .type(String.class) .required(true) .help("The certificate file to be created"); parser.addArgument("-k", "--key") .dest("key") .type(String.class) .required(true) .help("The key file to be created"); } @Override public void run(final Bootstrap<?> bootstrap, final Namespace namespace) throws Exception { final String subject = namespace.getString("subject"); final String signer = namespace.getString("signer"); final String in = namespace.getString("in"); final String password = namespace.getString("password"); final String cert = namespace.getString("cert"); final String key = namespace.getString("key"); final RootCertificate root = loadRootCertificate(in, password.toCharArray(), signer); final DistinguishedName dn = dn().setCn(subject).build();
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static CsrBuilder createCsr() { // return new CsrBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificate loadRootCertificate(final String keystorePath, // final char[] password, final String alias) { // return RootCertificateLoader.loadRootCertificate(keystorePath, password, alias); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/Certificate.java // public interface Certificate { // // public X509Certificate getX509Certificate(); // // public String print(); // // public void save(File file); // // public void save(String fileName); // // public CertificateWithPrivateKey attachPrivateKey(PrivateKey privateKey); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CertificateWithPrivateKey.java // public interface CertificateWithPrivateKey extends Certificate { // // public KeyStore addToKeystore(KeyStore keyStore, String alias); // // public KeyStore saveInPkcs12Keystore(String alias); // // public void exportPkcs12(final String keystorePath, final char[] keystorePassword, // final String alias); // // public void exportPkcs12(final File keystoreFile, final char[] keystorePassword, // final String alias); // // public PrivateKey getPrivateKey(); // // public String printKey(); // // public void saveKey(File file); // // public void saveKey(String fileName); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CsrWithPrivateKey.java // public interface CsrWithPrivateKey extends CSR { // // public PrivateKey getPrivateKey(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // } // Path: ca-api/src/main/java/io/github/olivierlemasle/caweb/cli/CreateCertificate.java import static io.github.olivierlemasle.ca.CA.createCsr; import static io.github.olivierlemasle.ca.CA.dn; import static io.github.olivierlemasle.ca.CA.loadRootCertificate; import io.dropwizard.cli.Command; import io.dropwizard.setup.Bootstrap; import io.github.olivierlemasle.ca.Certificate; import io.github.olivierlemasle.ca.CertificateWithPrivateKey; import io.github.olivierlemasle.ca.CsrWithPrivateKey; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate; import net.sourceforge.argparse4j.inf.Namespace; import net.sourceforge.argparse4j.inf.Subparser; .help("The name of the root certificate keystore"); parser.addArgument("-p", "--password") .dest("password") .type(String.class) .required(true) .help("The password of the keystore"); parser.addArgument("-c", "--cert") .dest("cert") .type(String.class) .required(true) .help("The certificate file to be created"); parser.addArgument("-k", "--key") .dest("key") .type(String.class) .required(true) .help("The key file to be created"); } @Override public void run(final Bootstrap<?> bootstrap, final Namespace namespace) throws Exception { final String subject = namespace.getString("subject"); final String signer = namespace.getString("signer"); final String in = namespace.getString("in"); final String password = namespace.getString("password"); final String cert = namespace.getString("cert"); final String key = namespace.getString("key"); final RootCertificate root = loadRootCertificate(in, password.toCharArray(), signer); final DistinguishedName dn = dn().setCn(subject).build();
final CsrWithPrivateKey csr = createCsr().generateRequest(dn);
olivierlemasle/java-certificate-authority
ca-api/src/main/java/io/github/olivierlemasle/caweb/cli/CreateCertificate.java
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static CsrBuilder createCsr() { // return new CsrBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificate loadRootCertificate(final String keystorePath, // final char[] password, final String alias) { // return RootCertificateLoader.loadRootCertificate(keystorePath, password, alias); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/Certificate.java // public interface Certificate { // // public X509Certificate getX509Certificate(); // // public String print(); // // public void save(File file); // // public void save(String fileName); // // public CertificateWithPrivateKey attachPrivateKey(PrivateKey privateKey); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CertificateWithPrivateKey.java // public interface CertificateWithPrivateKey extends Certificate { // // public KeyStore addToKeystore(KeyStore keyStore, String alias); // // public KeyStore saveInPkcs12Keystore(String alias); // // public void exportPkcs12(final String keystorePath, final char[] keystorePassword, // final String alias); // // public void exportPkcs12(final File keystoreFile, final char[] keystorePassword, // final String alias); // // public PrivateKey getPrivateKey(); // // public String printKey(); // // public void saveKey(File file); // // public void saveKey(String fileName); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CsrWithPrivateKey.java // public interface CsrWithPrivateKey extends CSR { // // public PrivateKey getPrivateKey(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // }
import static io.github.olivierlemasle.ca.CA.createCsr; import static io.github.olivierlemasle.ca.CA.dn; import static io.github.olivierlemasle.ca.CA.loadRootCertificate; import io.dropwizard.cli.Command; import io.dropwizard.setup.Bootstrap; import io.github.olivierlemasle.ca.Certificate; import io.github.olivierlemasle.ca.CertificateWithPrivateKey; import io.github.olivierlemasle.ca.CsrWithPrivateKey; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate; import net.sourceforge.argparse4j.inf.Namespace; import net.sourceforge.argparse4j.inf.Subparser;
.dest("password") .type(String.class) .required(true) .help("The password of the keystore"); parser.addArgument("-c", "--cert") .dest("cert") .type(String.class) .required(true) .help("The certificate file to be created"); parser.addArgument("-k", "--key") .dest("key") .type(String.class) .required(true) .help("The key file to be created"); } @Override public void run(final Bootstrap<?> bootstrap, final Namespace namespace) throws Exception { final String subject = namespace.getString("subject"); final String signer = namespace.getString("signer"); final String in = namespace.getString("in"); final String password = namespace.getString("password"); final String cert = namespace.getString("cert"); final String key = namespace.getString("key"); final RootCertificate root = loadRootCertificate(in, password.toCharArray(), signer); final DistinguishedName dn = dn().setCn(subject).build(); final CsrWithPrivateKey csr = createCsr().generateRequest(dn);
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static CsrBuilder createCsr() { // return new CsrBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificate loadRootCertificate(final String keystorePath, // final char[] password, final String alias) { // return RootCertificateLoader.loadRootCertificate(keystorePath, password, alias); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/Certificate.java // public interface Certificate { // // public X509Certificate getX509Certificate(); // // public String print(); // // public void save(File file); // // public void save(String fileName); // // public CertificateWithPrivateKey attachPrivateKey(PrivateKey privateKey); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CertificateWithPrivateKey.java // public interface CertificateWithPrivateKey extends Certificate { // // public KeyStore addToKeystore(KeyStore keyStore, String alias); // // public KeyStore saveInPkcs12Keystore(String alias); // // public void exportPkcs12(final String keystorePath, final char[] keystorePassword, // final String alias); // // public void exportPkcs12(final File keystoreFile, final char[] keystorePassword, // final String alias); // // public PrivateKey getPrivateKey(); // // public String printKey(); // // public void saveKey(File file); // // public void saveKey(String fileName); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CsrWithPrivateKey.java // public interface CsrWithPrivateKey extends CSR { // // public PrivateKey getPrivateKey(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // } // Path: ca-api/src/main/java/io/github/olivierlemasle/caweb/cli/CreateCertificate.java import static io.github.olivierlemasle.ca.CA.createCsr; import static io.github.olivierlemasle.ca.CA.dn; import static io.github.olivierlemasle.ca.CA.loadRootCertificate; import io.dropwizard.cli.Command; import io.dropwizard.setup.Bootstrap; import io.github.olivierlemasle.ca.Certificate; import io.github.olivierlemasle.ca.CertificateWithPrivateKey; import io.github.olivierlemasle.ca.CsrWithPrivateKey; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate; import net.sourceforge.argparse4j.inf.Namespace; import net.sourceforge.argparse4j.inf.Subparser; .dest("password") .type(String.class) .required(true) .help("The password of the keystore"); parser.addArgument("-c", "--cert") .dest("cert") .type(String.class) .required(true) .help("The certificate file to be created"); parser.addArgument("-k", "--key") .dest("key") .type(String.class) .required(true) .help("The key file to be created"); } @Override public void run(final Bootstrap<?> bootstrap, final Namespace namespace) throws Exception { final String subject = namespace.getString("subject"); final String signer = namespace.getString("signer"); final String in = namespace.getString("in"); final String password = namespace.getString("password"); final String cert = namespace.getString("cert"); final String key = namespace.getString("key"); final RootCertificate root = loadRootCertificate(in, password.toCharArray(), signer); final DistinguishedName dn = dn().setCn(subject).build(); final CsrWithPrivateKey csr = createCsr().generateRequest(dn);
final Certificate signed = root.signCsr(csr)
olivierlemasle/java-certificate-authority
ca-api/src/main/java/io/github/olivierlemasle/caweb/cli/CreateCertificate.java
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static CsrBuilder createCsr() { // return new CsrBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificate loadRootCertificate(final String keystorePath, // final char[] password, final String alias) { // return RootCertificateLoader.loadRootCertificate(keystorePath, password, alias); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/Certificate.java // public interface Certificate { // // public X509Certificate getX509Certificate(); // // public String print(); // // public void save(File file); // // public void save(String fileName); // // public CertificateWithPrivateKey attachPrivateKey(PrivateKey privateKey); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CertificateWithPrivateKey.java // public interface CertificateWithPrivateKey extends Certificate { // // public KeyStore addToKeystore(KeyStore keyStore, String alias); // // public KeyStore saveInPkcs12Keystore(String alias); // // public void exportPkcs12(final String keystorePath, final char[] keystorePassword, // final String alias); // // public void exportPkcs12(final File keystoreFile, final char[] keystorePassword, // final String alias); // // public PrivateKey getPrivateKey(); // // public String printKey(); // // public void saveKey(File file); // // public void saveKey(String fileName); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CsrWithPrivateKey.java // public interface CsrWithPrivateKey extends CSR { // // public PrivateKey getPrivateKey(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // }
import static io.github.olivierlemasle.ca.CA.createCsr; import static io.github.olivierlemasle.ca.CA.dn; import static io.github.olivierlemasle.ca.CA.loadRootCertificate; import io.dropwizard.cli.Command; import io.dropwizard.setup.Bootstrap; import io.github.olivierlemasle.ca.Certificate; import io.github.olivierlemasle.ca.CertificateWithPrivateKey; import io.github.olivierlemasle.ca.CsrWithPrivateKey; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate; import net.sourceforge.argparse4j.inf.Namespace; import net.sourceforge.argparse4j.inf.Subparser;
parser.addArgument("-c", "--cert") .dest("cert") .type(String.class) .required(true) .help("The certificate file to be created"); parser.addArgument("-k", "--key") .dest("key") .type(String.class) .required(true) .help("The key file to be created"); } @Override public void run(final Bootstrap<?> bootstrap, final Namespace namespace) throws Exception { final String subject = namespace.getString("subject"); final String signer = namespace.getString("signer"); final String in = namespace.getString("in"); final String password = namespace.getString("password"); final String cert = namespace.getString("cert"); final String key = namespace.getString("key"); final RootCertificate root = loadRootCertificate(in, password.toCharArray(), signer); final DistinguishedName dn = dn().setCn(subject).build(); final CsrWithPrivateKey csr = createCsr().generateRequest(dn); final Certificate signed = root.signCsr(csr) .setRandomSerialNumber() .sign();
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static CsrBuilder createCsr() { // return new CsrBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static RootCertificate loadRootCertificate(final String keystorePath, // final char[] password, final String alias) { // return RootCertificateLoader.loadRootCertificate(keystorePath, password, alias); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/Certificate.java // public interface Certificate { // // public X509Certificate getX509Certificate(); // // public String print(); // // public void save(File file); // // public void save(String fileName); // // public CertificateWithPrivateKey attachPrivateKey(PrivateKey privateKey); // // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CertificateWithPrivateKey.java // public interface CertificateWithPrivateKey extends Certificate { // // public KeyStore addToKeystore(KeyStore keyStore, String alias); // // public KeyStore saveInPkcs12Keystore(String alias); // // public void exportPkcs12(final String keystorePath, final char[] keystorePassword, // final String alias); // // public void exportPkcs12(final File keystoreFile, final char[] keystorePassword, // final String alias); // // public PrivateKey getPrivateKey(); // // public String printKey(); // // public void saveKey(File file); // // public void saveKey(String fileName); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CsrWithPrivateKey.java // public interface CsrWithPrivateKey extends CSR { // // public PrivateKey getPrivateKey(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // } // Path: ca-api/src/main/java/io/github/olivierlemasle/caweb/cli/CreateCertificate.java import static io.github.olivierlemasle.ca.CA.createCsr; import static io.github.olivierlemasle.ca.CA.dn; import static io.github.olivierlemasle.ca.CA.loadRootCertificate; import io.dropwizard.cli.Command; import io.dropwizard.setup.Bootstrap; import io.github.olivierlemasle.ca.Certificate; import io.github.olivierlemasle.ca.CertificateWithPrivateKey; import io.github.olivierlemasle.ca.CsrWithPrivateKey; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate; import net.sourceforge.argparse4j.inf.Namespace; import net.sourceforge.argparse4j.inf.Subparser; parser.addArgument("-c", "--cert") .dest("cert") .type(String.class) .required(true) .help("The certificate file to be created"); parser.addArgument("-k", "--key") .dest("key") .type(String.class) .required(true) .help("The key file to be created"); } @Override public void run(final Bootstrap<?> bootstrap, final Namespace namespace) throws Exception { final String subject = namespace.getString("subject"); final String signer = namespace.getString("signer"); final String in = namespace.getString("in"); final String password = namespace.getString("password"); final String cert = namespace.getString("cert"); final String key = namespace.getString("key"); final RootCertificate root = loadRootCertificate(in, password.toCharArray(), signer); final DistinguishedName dn = dn().setCn(subject).build(); final CsrWithPrivateKey csr = createCsr().generateRequest(dn); final Certificate signed = root.signCsr(csr) .setRandomSerialNumber() .sign();
final CertificateWithPrivateKey result = signed.attachPrivateKey(csr.getPrivateKey());
olivierlemasle/java-certificate-authority
ca-api/src/main/java/io/github/olivierlemasle/caweb/api/CertificateAuthority.java
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // }
import static io.github.olivierlemasle.ca.CA.dn; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate;
package io.github.olivierlemasle.caweb.api; public class CertificateAuthority { private RootCertificate caCertificate; public CertificateAuthority() { // Jackson } public CertificateAuthority(final RootCertificate caCertificate) { this.caCertificate = caCertificate; } @JsonIgnore public RootCertificate getCaCertificate() { return caCertificate; } @JsonProperty
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // } // Path: ca-api/src/main/java/io/github/olivierlemasle/caweb/api/CertificateAuthority.java import static io.github.olivierlemasle.ca.CA.dn; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate; package io.github.olivierlemasle.caweb.api; public class CertificateAuthority { private RootCertificate caCertificate; public CertificateAuthority() { // Jackson } public CertificateAuthority(final RootCertificate caCertificate) { this.caCertificate = caCertificate; } @JsonIgnore public RootCertificate getCaCertificate() { return caCertificate; } @JsonProperty
public DistinguishedName getSubject() {
olivierlemasle/java-certificate-authority
ca-api/src/main/java/io/github/olivierlemasle/caweb/api/CertificateAuthority.java
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // }
import static io.github.olivierlemasle.ca.CA.dn; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate;
package io.github.olivierlemasle.caweb.api; public class CertificateAuthority { private RootCertificate caCertificate; public CertificateAuthority() { // Jackson } public CertificateAuthority(final RootCertificate caCertificate) { this.caCertificate = caCertificate; } @JsonIgnore public RootCertificate getCaCertificate() { return caCertificate; } @JsonProperty public DistinguishedName getSubject() {
// Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/CA.java // public static DnBuilder dn() { // return new DnBuilderImpl(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/DistinguishedName.java // public interface DistinguishedName { // // public X500Name getX500Name(); // // public X500Principal getX500Principal(); // // public byte[] getEncoded(); // // public String getName(); // } // // Path: java-ca-lib/src/main/java/io/github/olivierlemasle/ca/RootCertificate.java // public interface RootCertificate extends CertificateWithPrivateKey { // // public Signer signCsr(final CSR request); // // } // Path: ca-api/src/main/java/io/github/olivierlemasle/caweb/api/CertificateAuthority.java import static io.github.olivierlemasle.ca.CA.dn; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; import io.github.olivierlemasle.ca.DistinguishedName; import io.github.olivierlemasle.ca.RootCertificate; package io.github.olivierlemasle.caweb.api; public class CertificateAuthority { private RootCertificate caCertificate; public CertificateAuthority() { // Jackson } public CertificateAuthority(final RootCertificate caCertificate) { this.caCertificate = caCertificate; } @JsonIgnore public RootCertificate getCaCertificate() { return caCertificate; } @JsonProperty public DistinguishedName getSubject() {
return dn(caCertificate.getX509Certificate().getSubjectX500Principal());
captain-miao/AndroidDataBindingTutorial
app/src/main/java/com/github/captain_miao/databinding/tutorial/recycleview/ObservableVehicleListAdapter.java
// Path: app/src/main/java/com/github/captain_miao/databinding/tutorial/listener/OnViewClickListener.java // public interface OnViewClickListener extends View.OnClickListener { // // } // // Path: app/src/main/java/com/github/captain_miao/databinding/tutorial/model/ObservableVehicleInfo.java // public class ObservableVehicleInfo implements Observable { // // private boolean isSelected; // private String logoUrl; // private String brand; // private String description; // // public ObservableVehicleInfo(boolean isSelected, String logoUrl, String brand, String description) { // this.isSelected = isSelected; // this.logoUrl = logoUrl; // this.brand = brand; // this.description = description; // } // // public ObservableVehicleInfo(VehicleInfo vehicleInfo) { // this.isSelected = vehicleInfo.isSelected.get(); // this.logoUrl = vehicleInfo.logoUrl; // this.brand = vehicleInfo.brand; // this.description = vehicleInfo.description; // } // // @Bindable // public boolean getIsSelected() { // return isSelected; // } // // public void setIsSelected(boolean isSelected) { // this.isSelected = isSelected; // notifyPropertyChanged(BR.isSelected); // } // // public String getLogoUrl() { // return logoUrl; // } // // public void setLogoUrl(String logoUrl) { // this.logoUrl = logoUrl; // } // // public String getBrand() { // return brand; // } // // public void setBrand(String brand) { // this.brand = brand; // } // // public String getDescription() { // return description; // } // // public void setDescription(String description) { // this.description = description; // } // // //for data binding Observable // private transient PropertyChangeRegistry mCallbacks; // @Override // public synchronized void addOnPropertyChangedCallback(OnPropertyChangedCallback onPropertyChangedCallback) { // if (mCallbacks == null) { // mCallbacks = new PropertyChangeRegistry(); // } // mCallbacks.add(onPropertyChangedCallback); // } // // @Override // public synchronized void removeOnPropertyChangedCallback(OnPropertyChangedCallback onPropertyChangedCallback) { // if (mCallbacks != null) { // mCallbacks.remove(onPropertyChangedCallback); // } // } // // /** // * Notifies listeners that all properties of this instance have changed. // */ // public synchronized void notifyChange() { // if (mCallbacks != null) { // mCallbacks.notifyCallbacks(this, 0, null); // } // } // // /** // * Notifies listeners that a specific property has changed. The getter for the property // * that changes should be marked with {@link Bindable} to generate a field in // * <code>BR</code> to be used as <code>fieldId</code>. // * // * @param fieldId The generated BR id for the Bindable field. // */ // public void notifyPropertyChanged(int fieldId) { // if (mCallbacks != null) { // mCallbacks.notifyCallbacks(this, fieldId, null); // } // } // }
import android.databinding.DataBindingUtil; import android.databinding.ViewDataBinding; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Toast; import com.github.captain_miao.databinding.tutorial.BR; import com.github.captain_miao.databinding.tutorial.R; import com.github.captain_miao.databinding.tutorial.databinding.ObservableRecyclerItemViewBinding; import com.github.captain_miao.databinding.tutorial.listener.OnViewClickListener; import com.github.captain_miao.databinding.tutorial.model.ObservableVehicleInfo; import com.github.captain_miao.recyclerviewutils.BaseWrapperRecyclerAdapter; import java.util.List;
return new ObservableVehicleListAdapter.ViewHolder(view); } @Override public void onBindItemViewHolder(RecyclerView.ViewHolder holder, int position) { final ObservableVehicleInfo info = getItem(position); if(holder instanceof ViewHolder){ ViewDataBinding binding = ((ViewHolder) holder).getBinding(); binding.setVariable(BR.info, info); binding.setVariable(BR.itemClick, itemListener); binding.setVariable(BR.selectedClick, selectedListener); binding.executePendingBindings(); } } public static class ViewHolder extends RecyclerView.ViewHolder { private ViewDataBinding mBinding; public ViewHolder(View itemView) { super(itemView); mBinding = DataBindingUtil.bind(itemView); } public ViewDataBinding getBinding() { return mBinding; } }
// Path: app/src/main/java/com/github/captain_miao/databinding/tutorial/listener/OnViewClickListener.java // public interface OnViewClickListener extends View.OnClickListener { // // } // // Path: app/src/main/java/com/github/captain_miao/databinding/tutorial/model/ObservableVehicleInfo.java // public class ObservableVehicleInfo implements Observable { // // private boolean isSelected; // private String logoUrl; // private String brand; // private String description; // // public ObservableVehicleInfo(boolean isSelected, String logoUrl, String brand, String description) { // this.isSelected = isSelected; // this.logoUrl = logoUrl; // this.brand = brand; // this.description = description; // } // // public ObservableVehicleInfo(VehicleInfo vehicleInfo) { // this.isSelected = vehicleInfo.isSelected.get(); // this.logoUrl = vehicleInfo.logoUrl; // this.brand = vehicleInfo.brand; // this.description = vehicleInfo.description; // } // // @Bindable // public boolean getIsSelected() { // return isSelected; // } // // public void setIsSelected(boolean isSelected) { // this.isSelected = isSelected; // notifyPropertyChanged(BR.isSelected); // } // // public String getLogoUrl() { // return logoUrl; // } // // public void setLogoUrl(String logoUrl) { // this.logoUrl = logoUrl; // } // // public String getBrand() { // return brand; // } // // public void setBrand(String brand) { // this.brand = brand; // } // // public String getDescription() { // return description; // } // // public void setDescription(String description) { // this.description = description; // } // // //for data binding Observable // private transient PropertyChangeRegistry mCallbacks; // @Override // public synchronized void addOnPropertyChangedCallback(OnPropertyChangedCallback onPropertyChangedCallback) { // if (mCallbacks == null) { // mCallbacks = new PropertyChangeRegistry(); // } // mCallbacks.add(onPropertyChangedCallback); // } // // @Override // public synchronized void removeOnPropertyChangedCallback(OnPropertyChangedCallback onPropertyChangedCallback) { // if (mCallbacks != null) { // mCallbacks.remove(onPropertyChangedCallback); // } // } // // /** // * Notifies listeners that all properties of this instance have changed. // */ // public synchronized void notifyChange() { // if (mCallbacks != null) { // mCallbacks.notifyCallbacks(this, 0, null); // } // } // // /** // * Notifies listeners that a specific property has changed. The getter for the property // * that changes should be marked with {@link Bindable} to generate a field in // * <code>BR</code> to be used as <code>fieldId</code>. // * // * @param fieldId The generated BR id for the Bindable field. // */ // public void notifyPropertyChanged(int fieldId) { // if (mCallbacks != null) { // mCallbacks.notifyCallbacks(this, fieldId, null); // } // } // } // Path: app/src/main/java/com/github/captain_miao/databinding/tutorial/recycleview/ObservableVehicleListAdapter.java import android.databinding.DataBindingUtil; import android.databinding.ViewDataBinding; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Toast; import com.github.captain_miao.databinding.tutorial.BR; import com.github.captain_miao.databinding.tutorial.R; import com.github.captain_miao.databinding.tutorial.databinding.ObservableRecyclerItemViewBinding; import com.github.captain_miao.databinding.tutorial.listener.OnViewClickListener; import com.github.captain_miao.databinding.tutorial.model.ObservableVehicleInfo; import com.github.captain_miao.recyclerviewutils.BaseWrapperRecyclerAdapter; import java.util.List; return new ObservableVehicleListAdapter.ViewHolder(view); } @Override public void onBindItemViewHolder(RecyclerView.ViewHolder holder, int position) { final ObservableVehicleInfo info = getItem(position); if(holder instanceof ViewHolder){ ViewDataBinding binding = ((ViewHolder) holder).getBinding(); binding.setVariable(BR.info, info); binding.setVariable(BR.itemClick, itemListener); binding.setVariable(BR.selectedClick, selectedListener); binding.executePendingBindings(); } } public static class ViewHolder extends RecyclerView.ViewHolder { private ViewDataBinding mBinding; public ViewHolder(View itemView) { super(itemView); mBinding = DataBindingUtil.bind(itemView); } public ViewDataBinding getBinding() { return mBinding; } }
OnViewClickListener itemListener = new OnViewClickListener() {
captain-miao/AndroidDataBindingTutorial
app/src/main/java/com/github/captain_miao/databinding/tutorial/MainActivity.java
// Path: app/src/main/java/com/github/captain_miao/databinding/tutorial/helper/ActivityNavigation.java // public class ActivityNavigation { // // public static ActivityNavigation from(final Context context) { // return new ActivityNavigation(context); // } // // // private ActivityNavigation(final Context context) { // mContext = context; // mIntent = new Intent(Intent.ACTION_VIEW); // } // // public ActivityNavigation withExtras(final Bundle extras) { // if(extras == null) { // return this; // } // // mIntent.putExtras(extras); // return this; // } // // public ActivityNavigation withFlags(final int flags) { // mIntent.addFlags(flags); // return this; // } // // /** // * @param request_code should >= 0, or no result will be returned to source activity. // * // * */ // public ActivityNavigation forResult(final int request_code) { // if (! (mContext instanceof Activity)) throw new IllegalStateException("Only valid from Activity, but from " + mContext); // mRequestCode = request_code; // return this; // } // // public boolean toUri(final String uri) { // // if (TextUtils.isEmpty(uri)) // return false; // // return toUri(Uri.parse(uri)); // } // // // public boolean toUri(final Uri uri) { // final Intent intent = mIntent.setData(uri); // Log.d(TAG, uri.toString()); // if (isIntentSafe(intent)) { // if (mRequestCode >= 0) { // ((Activity) mContext).startActivityForResult(intent, mRequestCode); // } else { // mContext.startActivity(intent); // } // return true; // } else { // // 不合法的Url 也做个尝试 // try { // if (mRequestCode >= 0) { // ((Activity) mContext).startActivityForResult(intent, mRequestCode); // } else { // mContext.startActivity(intent); // } // return true; // } catch (Exception e) { // e.printStackTrace(); // return false; // } // } // } // // /** // * this method is from the official guide: // * http://developer.android.com/training/basics/intents/sending.html#StartActivity // * */ // private boolean isIntentSafe(Intent intent) { // return !mContext.getPackageManager().queryIntentActivities(intent, 0).isEmpty(); // } // // // private final Context mContext; // private final Intent mIntent; // private int mRequestCode = -1; // // private static final String TAG = "ActivityNavigation"; // } // // Path: app/src/main/java/com/github/captain_miao/databinding/tutorial/listener/OnViewClickListener.java // public interface OnViewClickListener extends View.OnClickListener { // // } // // Path: app/src/main/java/com/github/captain_miao/databinding/tutorial/model/ActInfo.java // public class ActInfo extends BaseModel{ // private static final long serialVersionUID = 1L; // // // public enum ActEnum { // ACT_A, // ACT_B, // ACT_C // } // // // private String name; // private String url; // // public ActInfo(String name, String url) { // this.name = name; // this.url = url; // } // // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // public String getUrl() { // return url; // } // // public void setUrl(String url) { // this.url = url; // } // }
import android.databinding.DataBindingUtil; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.Menu; import android.view.View; import android.widget.Button; import com.github.captain_miao.databinding.tutorial.databinding.ActivityMainBinding; import com.github.captain_miao.databinding.tutorial.helper.ActivityNavigation; import com.github.captain_miao.databinding.tutorial.listener.OnViewClickListener; import com.github.captain_miao.databinding.tutorial.model.ActInfo; import java.util.HashMap; import java.util.Map;
package com.github.captain_miao.databinding.tutorial; public class MainActivity extends AppCompatActivity implements OnViewClickListener { private static final String TAG = "MainActivity"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //ActivityMainBinding binding = ActivityMainBinding.inflate(getLayoutInflater()); //setContentView(binding.getRoot()); ActivityMainBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_main); binding.setClickListener(this); binding.setMap(mActInfoMap); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.main_menu, menu); return true; } @Override public void onClick(View v) { if(v instanceof Button) { String name = ((Button) v).getText().toString();
// Path: app/src/main/java/com/github/captain_miao/databinding/tutorial/helper/ActivityNavigation.java // public class ActivityNavigation { // // public static ActivityNavigation from(final Context context) { // return new ActivityNavigation(context); // } // // // private ActivityNavigation(final Context context) { // mContext = context; // mIntent = new Intent(Intent.ACTION_VIEW); // } // // public ActivityNavigation withExtras(final Bundle extras) { // if(extras == null) { // return this; // } // // mIntent.putExtras(extras); // return this; // } // // public ActivityNavigation withFlags(final int flags) { // mIntent.addFlags(flags); // return this; // } // // /** // * @param request_code should >= 0, or no result will be returned to source activity. // * // * */ // public ActivityNavigation forResult(final int request_code) { // if (! (mContext instanceof Activity)) throw new IllegalStateException("Only valid from Activity, but from " + mContext); // mRequestCode = request_code; // return this; // } // // public boolean toUri(final String uri) { // // if (TextUtils.isEmpty(uri)) // return false; // // return toUri(Uri.parse(uri)); // } // // // public boolean toUri(final Uri uri) { // final Intent intent = mIntent.setData(uri); // Log.d(TAG, uri.toString()); // if (isIntentSafe(intent)) { // if (mRequestCode >= 0) { // ((Activity) mContext).startActivityForResult(intent, mRequestCode); // } else { // mContext.startActivity(intent); // } // return true; // } else { // // 不合法的Url 也做个尝试 // try { // if (mRequestCode >= 0) { // ((Activity) mContext).startActivityForResult(intent, mRequestCode); // } else { // mContext.startActivity(intent); // } // return true; // } catch (Exception e) { // e.printStackTrace(); // return false; // } // } // } // // /** // * this method is from the official guide: // * http://developer.android.com/training/basics/intents/sending.html#StartActivity // * */ // private boolean isIntentSafe(Intent intent) { // return !mContext.getPackageManager().queryIntentActivities(intent, 0).isEmpty(); // } // // // private final Context mContext; // private final Intent mIntent; // private int mRequestCode = -1; // // private static final String TAG = "ActivityNavigation"; // } // // Path: app/src/main/java/com/github/captain_miao/databinding/tutorial/listener/OnViewClickListener.java // public interface OnViewClickListener extends View.OnClickListener { // // } // // Path: app/src/main/java/com/github/captain_miao/databinding/tutorial/model/ActInfo.java // public class ActInfo extends BaseModel{ // private static final long serialVersionUID = 1L; // // // public enum ActEnum { // ACT_A, // ACT_B, // ACT_C // } // // // private String name; // private String url; // // public ActInfo(String name, String url) { // this.name = name; // this.url = url; // } // // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // public String getUrl() { // return url; // } // // public void setUrl(String url) { // this.url = url; // } // } // Path: app/src/main/java/com/github/captain_miao/databinding/tutorial/MainActivity.java import android.databinding.DataBindingUtil; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.Menu; import android.view.View; import android.widget.Button; import com.github.captain_miao.databinding.tutorial.databinding.ActivityMainBinding; import com.github.captain_miao.databinding.tutorial.helper.ActivityNavigation; import com.github.captain_miao.databinding.tutorial.listener.OnViewClickListener; import com.github.captain_miao.databinding.tutorial.model.ActInfo; import java.util.HashMap; import java.util.Map; package com.github.captain_miao.databinding.tutorial; public class MainActivity extends AppCompatActivity implements OnViewClickListener { private static final String TAG = "MainActivity"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //ActivityMainBinding binding = ActivityMainBinding.inflate(getLayoutInflater()); //setContentView(binding.getRoot()); ActivityMainBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_main); binding.setClickListener(this); binding.setMap(mActInfoMap); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.main_menu, menu); return true; } @Override public void onClick(View v) { if(v instanceof Button) { String name = ((Button) v).getText().toString();
ActivityNavigation.from(this).toUri(mActInfoMap.get(name).getUrl());
captain-miao/AndroidDataBindingTutorial
app/src/main/java/com/github/captain_miao/databinding/tutorial/MainActivity.java
// Path: app/src/main/java/com/github/captain_miao/databinding/tutorial/helper/ActivityNavigation.java // public class ActivityNavigation { // // public static ActivityNavigation from(final Context context) { // return new ActivityNavigation(context); // } // // // private ActivityNavigation(final Context context) { // mContext = context; // mIntent = new Intent(Intent.ACTION_VIEW); // } // // public ActivityNavigation withExtras(final Bundle extras) { // if(extras == null) { // return this; // } // // mIntent.putExtras(extras); // return this; // } // // public ActivityNavigation withFlags(final int flags) { // mIntent.addFlags(flags); // return this; // } // // /** // * @param request_code should >= 0, or no result will be returned to source activity. // * // * */ // public ActivityNavigation forResult(final int request_code) { // if (! (mContext instanceof Activity)) throw new IllegalStateException("Only valid from Activity, but from " + mContext); // mRequestCode = request_code; // return this; // } // // public boolean toUri(final String uri) { // // if (TextUtils.isEmpty(uri)) // return false; // // return toUri(Uri.parse(uri)); // } // // // public boolean toUri(final Uri uri) { // final Intent intent = mIntent.setData(uri); // Log.d(TAG, uri.toString()); // if (isIntentSafe(intent)) { // if (mRequestCode >= 0) { // ((Activity) mContext).startActivityForResult(intent, mRequestCode); // } else { // mContext.startActivity(intent); // } // return true; // } else { // // 不合法的Url 也做个尝试 // try { // if (mRequestCode >= 0) { // ((Activity) mContext).startActivityForResult(intent, mRequestCode); // } else { // mContext.startActivity(intent); // } // return true; // } catch (Exception e) { // e.printStackTrace(); // return false; // } // } // } // // /** // * this method is from the official guide: // * http://developer.android.com/training/basics/intents/sending.html#StartActivity // * */ // private boolean isIntentSafe(Intent intent) { // return !mContext.getPackageManager().queryIntentActivities(intent, 0).isEmpty(); // } // // // private final Context mContext; // private final Intent mIntent; // private int mRequestCode = -1; // // private static final String TAG = "ActivityNavigation"; // } // // Path: app/src/main/java/com/github/captain_miao/databinding/tutorial/listener/OnViewClickListener.java // public interface OnViewClickListener extends View.OnClickListener { // // } // // Path: app/src/main/java/com/github/captain_miao/databinding/tutorial/model/ActInfo.java // public class ActInfo extends BaseModel{ // private static final long serialVersionUID = 1L; // // // public enum ActEnum { // ACT_A, // ACT_B, // ACT_C // } // // // private String name; // private String url; // // public ActInfo(String name, String url) { // this.name = name; // this.url = url; // } // // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // public String getUrl() { // return url; // } // // public void setUrl(String url) { // this.url = url; // } // }
import android.databinding.DataBindingUtil; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.Menu; import android.view.View; import android.widget.Button; import com.github.captain_miao.databinding.tutorial.databinding.ActivityMainBinding; import com.github.captain_miao.databinding.tutorial.helper.ActivityNavigation; import com.github.captain_miao.databinding.tutorial.listener.OnViewClickListener; import com.github.captain_miao.databinding.tutorial.model.ActInfo; import java.util.HashMap; import java.util.Map;
package com.github.captain_miao.databinding.tutorial; public class MainActivity extends AppCompatActivity implements OnViewClickListener { private static final String TAG = "MainActivity"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //ActivityMainBinding binding = ActivityMainBinding.inflate(getLayoutInflater()); //setContentView(binding.getRoot()); ActivityMainBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_main); binding.setClickListener(this); binding.setMap(mActInfoMap); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.main_menu, menu); return true; } @Override public void onClick(View v) { if(v instanceof Button) { String name = ((Button) v).getText().toString(); ActivityNavigation.from(this).toUri(mActInfoMap.get(name).getUrl()); } }
// Path: app/src/main/java/com/github/captain_miao/databinding/tutorial/helper/ActivityNavigation.java // public class ActivityNavigation { // // public static ActivityNavigation from(final Context context) { // return new ActivityNavigation(context); // } // // // private ActivityNavigation(final Context context) { // mContext = context; // mIntent = new Intent(Intent.ACTION_VIEW); // } // // public ActivityNavigation withExtras(final Bundle extras) { // if(extras == null) { // return this; // } // // mIntent.putExtras(extras); // return this; // } // // public ActivityNavigation withFlags(final int flags) { // mIntent.addFlags(flags); // return this; // } // // /** // * @param request_code should >= 0, or no result will be returned to source activity. // * // * */ // public ActivityNavigation forResult(final int request_code) { // if (! (mContext instanceof Activity)) throw new IllegalStateException("Only valid from Activity, but from " + mContext); // mRequestCode = request_code; // return this; // } // // public boolean toUri(final String uri) { // // if (TextUtils.isEmpty(uri)) // return false; // // return toUri(Uri.parse(uri)); // } // // // public boolean toUri(final Uri uri) { // final Intent intent = mIntent.setData(uri); // Log.d(TAG, uri.toString()); // if (isIntentSafe(intent)) { // if (mRequestCode >= 0) { // ((Activity) mContext).startActivityForResult(intent, mRequestCode); // } else { // mContext.startActivity(intent); // } // return true; // } else { // // 不合法的Url 也做个尝试 // try { // if (mRequestCode >= 0) { // ((Activity) mContext).startActivityForResult(intent, mRequestCode); // } else { // mContext.startActivity(intent); // } // return true; // } catch (Exception e) { // e.printStackTrace(); // return false; // } // } // } // // /** // * this method is from the official guide: // * http://developer.android.com/training/basics/intents/sending.html#StartActivity // * */ // private boolean isIntentSafe(Intent intent) { // return !mContext.getPackageManager().queryIntentActivities(intent, 0).isEmpty(); // } // // // private final Context mContext; // private final Intent mIntent; // private int mRequestCode = -1; // // private static final String TAG = "ActivityNavigation"; // } // // Path: app/src/main/java/com/github/captain_miao/databinding/tutorial/listener/OnViewClickListener.java // public interface OnViewClickListener extends View.OnClickListener { // // } // // Path: app/src/main/java/com/github/captain_miao/databinding/tutorial/model/ActInfo.java // public class ActInfo extends BaseModel{ // private static final long serialVersionUID = 1L; // // // public enum ActEnum { // ACT_A, // ACT_B, // ACT_C // } // // // private String name; // private String url; // // public ActInfo(String name, String url) { // this.name = name; // this.url = url; // } // // public String getName() { // return name; // } // // public void setName(String name) { // this.name = name; // } // // public String getUrl() { // return url; // } // // public void setUrl(String url) { // this.url = url; // } // } // Path: app/src/main/java/com/github/captain_miao/databinding/tutorial/MainActivity.java import android.databinding.DataBindingUtil; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.Menu; import android.view.View; import android.widget.Button; import com.github.captain_miao.databinding.tutorial.databinding.ActivityMainBinding; import com.github.captain_miao.databinding.tutorial.helper.ActivityNavigation; import com.github.captain_miao.databinding.tutorial.listener.OnViewClickListener; import com.github.captain_miao.databinding.tutorial.model.ActInfo; import java.util.HashMap; import java.util.Map; package com.github.captain_miao.databinding.tutorial; public class MainActivity extends AppCompatActivity implements OnViewClickListener { private static final String TAG = "MainActivity"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //ActivityMainBinding binding = ActivityMainBinding.inflate(getLayoutInflater()); //setContentView(binding.getRoot()); ActivityMainBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_main); binding.setClickListener(this); binding.setMap(mActInfoMap); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.main_menu, menu); return true; } @Override public void onClick(View v) { if(v instanceof Button) { String name = ((Button) v).getText().toString(); ActivityNavigation.from(this).toUri(mActInfoMap.get(name).getUrl()); } }
private Map<String, ActInfo> mActInfoMap = new HashMap<String, ActInfo>() {{
captain-miao/AndroidDataBindingTutorial
app/src/main/java/com/github/captain_miao/databinding/tutorial/app/TutorialApp.java
// Path: app/src/main/java/com/github/captain_miao/databinding/tutorial/helper/MyDataBindingComponent.java // public class MyDataBindingComponent implements android.databinding.DataBindingComponent { // @Override // public ImageViewBindingInterface getImageViewBindingInterface() { // return new ImageViewBinding4Picasso(); // } // }
import android.app.Application; import android.content.Context; import android.databinding.DataBindingUtil; import com.github.captain_miao.databinding.tutorial.helper.MyDataBindingComponent;
package com.github.captain_miao.databinding.tutorial.app; /** * @author YanLu * @since 16/9/19 */ public class TutorialApp extends Application { @Override protected void attachBaseContext(Context base) { super.attachBaseContext(base); } @Override public void onCreate() { super.onCreate();
// Path: app/src/main/java/com/github/captain_miao/databinding/tutorial/helper/MyDataBindingComponent.java // public class MyDataBindingComponent implements android.databinding.DataBindingComponent { // @Override // public ImageViewBindingInterface getImageViewBindingInterface() { // return new ImageViewBinding4Picasso(); // } // } // Path: app/src/main/java/com/github/captain_miao/databinding/tutorial/app/TutorialApp.java import android.app.Application; import android.content.Context; import android.databinding.DataBindingUtil; import com.github.captain_miao.databinding.tutorial.helper.MyDataBindingComponent; package com.github.captain_miao.databinding.tutorial.app; /** * @author YanLu * @since 16/9/19 */ public class TutorialApp extends Application { @Override protected void attachBaseContext(Context base) { super.attachBaseContext(base); } @Override public void onCreate() { super.onCreate();
DataBindingUtil.setDefaultComponent(new MyDataBindingComponent());
captain-miao/AndroidDataBindingTutorial
app/src/main/java/com/github/captain_miao/databinding/tutorial/viewpage/ViewPageActivity.java
// Path: app/src/main/java/com/github/captain_miao/databinding/tutorial/base/BasePagerAdapter.java // public abstract class BasePagerAdapter<T> extends PagerAdapter { // protected ArrayList<T> mData = new ArrayList(); // protected LayoutInflater mInflater; // protected Context mContext; // // public BasePagerAdapter(Context c) { // mContext = c; // mInflater = (LayoutInflater)c.getSystemService(Context.LAYOUT_INFLATER_SERVICE); // } // // @Override // public abstract Object instantiateItem(ViewGroup container, int position); // // @Override // public abstract void destroyItem(ViewGroup container, int position, Object object); // // @Override // public int getCount() { // return mData != null ? mData.size() : 0; // } // // public void addItem(final T item) { // mData.add(item); // notifyDataSetChanged(); // } // public void addAll(final List<T> items) { // if (items != null) { // mData.addAll(items); // } // notifyDataSetChanged(); // } // public void setData(final List<T> items) { // mData.clear(); // if (items != null) { // mData.addAll(items); // } // notifyDataSetChanged(); // } // // public void addItem(int idx, final T item) { // mData.add(idx, item); // notifyDataSetChanged(); // } // // public void clearItems() { // mData.clear(); // notifyDataSetChanged(); // } // // public T getItem(int position) { // return mData.get(position); // } // // public ArrayList<T> getData() { // return mData; // } // }
import android.content.Context; import android.os.Bundle; import android.support.v4.view.ViewPager; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.view.ViewGroup; import com.github.captain_miao.databinding.tutorial.R; import com.github.captain_miao.databinding.tutorial.base.BasePagerAdapter; import com.github.captain_miao.databinding.tutorial.databinding.ViewPageItemViewBinding; import java.util.ArrayList; import java.util.List;
package com.github.captain_miao.databinding.tutorial.viewpage; /** * new user guide */ public class ViewPageActivity extends AppCompatActivity implements ViewPager.OnPageChangeListener { private ViewPageDotView mWelcomeDotView; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_guide); ViewPager mViewPager = (ViewPager) findViewById(R.id.view_page); final GuideAdapter guideAdapter = new GuideAdapter(ViewPageActivity.this); guideAdapter.addAll(getGuideViewModels()); mViewPager.setAdapter(guideAdapter); mViewPager.addOnPageChangeListener(this); mWelcomeDotView = (ViewPageDotView) findViewById(R.id.dot_view); mWelcomeDotView.setNumOfCircles(guideAdapter.getCount(), getResources().getDimensionPixelSize(R.dimen.height_very_small)); } @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { mWelcomeDotView.onPageScrolled(position, positionOffset, positionOffsetPixels); } @Override public void onPageSelected(int position) { mWelcomeDotView.onPageSelected(position); } @Override public void onPageScrollStateChanged(int state) { mWelcomeDotView.onPageScrollStateChanged(state); }
// Path: app/src/main/java/com/github/captain_miao/databinding/tutorial/base/BasePagerAdapter.java // public abstract class BasePagerAdapter<T> extends PagerAdapter { // protected ArrayList<T> mData = new ArrayList(); // protected LayoutInflater mInflater; // protected Context mContext; // // public BasePagerAdapter(Context c) { // mContext = c; // mInflater = (LayoutInflater)c.getSystemService(Context.LAYOUT_INFLATER_SERVICE); // } // // @Override // public abstract Object instantiateItem(ViewGroup container, int position); // // @Override // public abstract void destroyItem(ViewGroup container, int position, Object object); // // @Override // public int getCount() { // return mData != null ? mData.size() : 0; // } // // public void addItem(final T item) { // mData.add(item); // notifyDataSetChanged(); // } // public void addAll(final List<T> items) { // if (items != null) { // mData.addAll(items); // } // notifyDataSetChanged(); // } // public void setData(final List<T> items) { // mData.clear(); // if (items != null) { // mData.addAll(items); // } // notifyDataSetChanged(); // } // // public void addItem(int idx, final T item) { // mData.add(idx, item); // notifyDataSetChanged(); // } // // public void clearItems() { // mData.clear(); // notifyDataSetChanged(); // } // // public T getItem(int position) { // return mData.get(position); // } // // public ArrayList<T> getData() { // return mData; // } // } // Path: app/src/main/java/com/github/captain_miao/databinding/tutorial/viewpage/ViewPageActivity.java import android.content.Context; import android.os.Bundle; import android.support.v4.view.ViewPager; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.view.ViewGroup; import com.github.captain_miao.databinding.tutorial.R; import com.github.captain_miao.databinding.tutorial.base.BasePagerAdapter; import com.github.captain_miao.databinding.tutorial.databinding.ViewPageItemViewBinding; import java.util.ArrayList; import java.util.List; package com.github.captain_miao.databinding.tutorial.viewpage; /** * new user guide */ public class ViewPageActivity extends AppCompatActivity implements ViewPager.OnPageChangeListener { private ViewPageDotView mWelcomeDotView; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_guide); ViewPager mViewPager = (ViewPager) findViewById(R.id.view_page); final GuideAdapter guideAdapter = new GuideAdapter(ViewPageActivity.this); guideAdapter.addAll(getGuideViewModels()); mViewPager.setAdapter(guideAdapter); mViewPager.addOnPageChangeListener(this); mWelcomeDotView = (ViewPageDotView) findViewById(R.id.dot_view); mWelcomeDotView.setNumOfCircles(guideAdapter.getCount(), getResources().getDimensionPixelSize(R.dimen.height_very_small)); } @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { mWelcomeDotView.onPageScrolled(position, positionOffset, positionOffsetPixels); } @Override public void onPageSelected(int position) { mWelcomeDotView.onPageSelected(position); } @Override public void onPageScrollStateChanged(int state) { mWelcomeDotView.onPageScrollStateChanged(state); }
private class GuideAdapter extends BasePagerAdapter<GuideViewModel> {
chrisichris/yetiscript
srcc/yjs/lang/compiler/TypeAttr.java
// Path: srclib/yeti/lang/Tag.java // public final class Tag implements Comparable, Serializable { // public final String name; // public final Object value; // // public Tag(Object aValue, String aName) { // name = aName; // value = aValue; // } // // public int hashCode() { // return name.hashCode() - (value == null ? 0 : value.hashCode() * 17); // } // // public boolean equals(Object other) { // Tag o; // return other instanceof Tag && name == (o = (Tag) other).name && // (value == o.value || value != null && value.equals(o.value)); // } // // public int compareTo(Object other) { // Tag o = (Tag) other; // return name == o.name ? ((Comparable) value).compareTo(o.value) // : name.compareTo(o.name); // } // // public String toString() { // return name + ' ' + Core.show(value); // } // }
import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.IdentityHashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import yeti.lang.Tag; import yeti.renamed.asm3.AnnotationVisitor; import yeti.renamed.asm3.Attribute; import yeti.renamed.asm3.ByteVector; import yeti.renamed.asm3.ClassReader; import yeti.renamed.asm3.ClassVisitor; import yeti.renamed.asm3.ClassWriter; import yeti.renamed.asm3.FieldVisitor; import yeti.renamed.asm3.Label; import yeti.renamed.asm3.MethodVisitor; import yeti.renamed.asm3.Opcodes;
String name; boolean deprecated; boolean fromClass; boolean hasSource; long lastModified; private YType[] free; boolean isModule; JSCode jsCode; final JSSym jsModuleVar = new JSSym(); ModuleType(YType type, Map typeDefs, boolean directFields, int depth) { this.typeDefs = typeDefs; this.directFields = directFields; this.type = copy(depth, type); } YType copy(int depth, YType t) { if (t == null) t = type; if (depth == -1) return t; if (free == null) { List freeVars = new ArrayList(); YetiType.getAllTypeVar(freeVars, null, t, false); free = (YType[]) freeVars.toArray(new YType[freeVars.size()]); } return YetiType.copyType(t, YetiType.createFreeVars(free, depth), new IdentityHashMap()); }
// Path: srclib/yeti/lang/Tag.java // public final class Tag implements Comparable, Serializable { // public final String name; // public final Object value; // // public Tag(Object aValue, String aName) { // name = aName; // value = aValue; // } // // public int hashCode() { // return name.hashCode() - (value == null ? 0 : value.hashCode() * 17); // } // // public boolean equals(Object other) { // Tag o; // return other instanceof Tag && name == (o = (Tag) other).name && // (value == o.value || value != null && value.equals(o.value)); // } // // public int compareTo(Object other) { // Tag o = (Tag) other; // return name == o.name ? ((Comparable) value).compareTo(o.value) // : name.compareTo(o.name); // } // // public String toString() { // return name + ' ' + Core.show(value); // } // } // Path: srcc/yjs/lang/compiler/TypeAttr.java import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.IdentityHashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import yeti.lang.Tag; import yeti.renamed.asm3.AnnotationVisitor; import yeti.renamed.asm3.Attribute; import yeti.renamed.asm3.ByteVector; import yeti.renamed.asm3.ClassReader; import yeti.renamed.asm3.ClassVisitor; import yeti.renamed.asm3.ClassWriter; import yeti.renamed.asm3.FieldVisitor; import yeti.renamed.asm3.Label; import yeti.renamed.asm3.MethodVisitor; import yeti.renamed.asm3.Opcodes; String name; boolean deprecated; boolean fromClass; boolean hasSource; long lastModified; private YType[] free; boolean isModule; JSCode jsCode; final JSSym jsModuleVar = new JSSym(); ModuleType(YType type, Map typeDefs, boolean directFields, int depth) { this.typeDefs = typeDefs; this.directFields = directFields; this.type = copy(depth, type); } YType copy(int depth, YType t) { if (t == null) t = type; if (depth == -1) return t; if (free == null) { List freeVars = new ArrayList(); YetiType.getAllTypeVar(freeVars, null, t, false); free = (YType[]) freeVars.toArray(new YType[freeVars.size()]); } return YetiType.copyType(t, YetiType.createFreeVars(free, depth), new IdentityHashMap()); }
Tag yetiType() {
chrisichris/yetiscript
srcc/yjs/lang/compiler/YJSMain.java
// Path: srcc/yjs/lang/compiler/NanoHTTPD.java // public enum Status implements IStatus { // SWITCH_PROTOCOL(101, "Switching Protocols"), OK(200, "OK"), CREATED(201, "Created"), ACCEPTED(202, "Accepted"), NO_CONTENT(204, "No Content"), PARTIAL_CONTENT(206, "Partial Content"), REDIRECT(301, // "Moved Permanently"), NOT_MODIFIED(304, "Not Modified"), BAD_REQUEST(400, "Bad Request"), UNAUTHORIZED(401, // "Unauthorized"), FORBIDDEN(403, "Forbidden"), NOT_FOUND(404, "Not Found"), METHOD_NOT_ALLOWED(405, "Method Not Allowed"), RANGE_NOT_SATISFIABLE(416, // "Requested Range Not Satisfiable"), INTERNAL_ERROR(500, "Internal Server Error"); // private final int requestStatus; // private final String description; // // Status(int requestStatus, String description) { // this.requestStatus = requestStatus; // this.description = description; // } // // @Override // public int getRequestStatus() { // return this.requestStatus; // } // // @Override // public String getDescription() { // return "" + this.requestStatus + " " + description; // } // }
import java.awt.Event; import java.io.BufferedReader; import java.io.File; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.lang.ProcessBuilder.Redirect; import java.nio.file.FileSystems; import java.nio.file.Path; import java.nio.file.StandardWatchEventKinds; import java.nio.file.WatchEvent; import java.nio.file.WatchEvent.Kind; import java.nio.file.WatchKey; import java.nio.file.WatchService; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Timer; import java.util.TimerTask; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicLong; import yjs.lang.compiler.*; import yjs.lang.compiler.NanoHTTPD.Response.Status; import javax.script.ScriptEngine; import javax.script.ScriptEngineManager; import javax.script.ScriptException; import javax.script.SimpleScriptContext;
} } public NanoHTTPD createServer(int port){ YJSServer server = new YJSServer(port); return server; } private class YJSServer extends NanoHTTPD{ private final ConcurrentHashMap<String, ReplSession> sessions = new ConcurrentHashMap<>(); private final Timer timer = new Timer(true); private final int port; public YJSServer(int port) { super(port); this.port = port; timer.scheduleAtFixedRate(new TimerTask() { public void run() { long cur = System.currentTimeMillis() - 5 * 60 * 1000; for(ReplSession entr: sessions.values()){ if(entr.lastUsedTime.get() < cur){ sessions.remove(entr.id); } } } }, 0, 5 * 60* 1000); //every 5 min }
// Path: srcc/yjs/lang/compiler/NanoHTTPD.java // public enum Status implements IStatus { // SWITCH_PROTOCOL(101, "Switching Protocols"), OK(200, "OK"), CREATED(201, "Created"), ACCEPTED(202, "Accepted"), NO_CONTENT(204, "No Content"), PARTIAL_CONTENT(206, "Partial Content"), REDIRECT(301, // "Moved Permanently"), NOT_MODIFIED(304, "Not Modified"), BAD_REQUEST(400, "Bad Request"), UNAUTHORIZED(401, // "Unauthorized"), FORBIDDEN(403, "Forbidden"), NOT_FOUND(404, "Not Found"), METHOD_NOT_ALLOWED(405, "Method Not Allowed"), RANGE_NOT_SATISFIABLE(416, // "Requested Range Not Satisfiable"), INTERNAL_ERROR(500, "Internal Server Error"); // private final int requestStatus; // private final String description; // // Status(int requestStatus, String description) { // this.requestStatus = requestStatus; // this.description = description; // } // // @Override // public int getRequestStatus() { // return this.requestStatus; // } // // @Override // public String getDescription() { // return "" + this.requestStatus + " " + description; // } // } // Path: srcc/yjs/lang/compiler/YJSMain.java import java.awt.Event; import java.io.BufferedReader; import java.io.File; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.lang.ProcessBuilder.Redirect; import java.nio.file.FileSystems; import java.nio.file.Path; import java.nio.file.StandardWatchEventKinds; import java.nio.file.WatchEvent; import java.nio.file.WatchEvent.Kind; import java.nio.file.WatchKey; import java.nio.file.WatchService; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Timer; import java.util.TimerTask; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicLong; import yjs.lang.compiler.*; import yjs.lang.compiler.NanoHTTPD.Response.Status; import javax.script.ScriptEngine; import javax.script.ScriptEngineManager; import javax.script.ScriptException; import javax.script.SimpleScriptContext; } } public NanoHTTPD createServer(int port){ YJSServer server = new YJSServer(port); return server; } private class YJSServer extends NanoHTTPD{ private final ConcurrentHashMap<String, ReplSession> sessions = new ConcurrentHashMap<>(); private final Timer timer = new Timer(true); private final int port; public YJSServer(int port) { super(port); this.port = port; timer.scheduleAtFixedRate(new TimerTask() { public void run() { long cur = System.currentTimeMillis() - 5 * 60 * 1000; for(ReplSession entr: sessions.values()){ if(entr.lastUsedTime.get() < cur){ sessions.remove(entr.id); } } } }, 0, 5 * 60* 1000); //every 5 min }
private Response cors(IHTTPSession session, Status status, String mimeType, String txt) {
Mapyst/Mapyst
route_lib/src/com/mapyst/route/Direction.java
// Path: route_lib/src/com/mapyst/campus/Campus.java // public class Campus { // public String name; // public String acronym; // public String description; // public String directory_url; // public String phone; // public LatLngPoint location; //center of campus // // public Building[] buildings; // public Location_Type[] location_types; // // // TODO: This is never initialized // public static FileHandlerInterface fileHandler; // // public Floor getFloor(int buildingIndex, int floorIndex) { // return buildings[buildingIndex].floors[floorIndex]; // } // // public String getFloorFile (int buildingIndex, int floorIndex, String fileExtension) { // return buildingIndex + "-" + floorIndex + "." + fileExtension; // } // // public String getFloorFile (Building building, int floorIndex, String fileExtension) { // int buildingIndex = findBuilding(building); // return buildingIndex + "-" + floorIndex + "." + fileExtension; // } // // public String getBuildingFile (int buildingIndex, String fileExtension) { // return buildingIndex + "." + fileExtension; // } // // public String getBuildingFile (Building building, String fileExtension) { // int buildingIndex = findBuilding(building); // return buildingIndex + "." + fileExtension; // } // // private int findBuilding(Building building) { // for (int i = 0; i < buildings.length; i++) { // if (buildings[i] == building) // return i; // } // return -1; // } // // public int parseFloorFromText(int buildingIndex, String floorText) { // if (buildingIndex >= 0 && buildingIndex < buildings.length) { // for (int i = 0; i < buildings[buildingIndex].floors.length; i++) { // if (floorText.equals(getFloor(buildingIndex, i).name.toLowerCase())) // return i; // } // } // return -1; // } // // public Building[] getOutsideBuildings() { // ArrayList<Building> outsideBuildings = new ArrayList<Building>(); // for (int i = 0; i < buildings.length; i++) { // if (buildingIsOutside(i)) { // outsideBuildings.add(buildings[i]); // } // } // return outsideBuildings.toArray(new Building[outsideBuildings.size()]); // } // // public boolean buildingIsOutside(int building) { // return buildings[building].type == Building.OUTSIDE; // } // // public int findLocationType(String type) { // for (int i = 0; i < location_types.length; i++) { // if (location_types[i].name.toLowerCase().equals(type.toLowerCase())) // return i; // } // return -1; // } // // public Location[] getDirectionEndLocations() { // ArrayList<Location> locations = new ArrayList<Location>(); // for (Location_Type type : location_types) { // for (int j = 0; j < type.locations.length; j++) { // Location location = type.locations[j]; // if (location.is_direction_end) { // locations.add(location); // } // } // } // // return locations.toArray(new Location[locations.size()]); // } // // public Location getCampusLocation(String text) { // for (Location_Type type : location_types) { // for (int j = 0; j < type.locations.length; j++) { // for (int k = 0; k < type.locations[j].names.length; k++) { // if (text.equals(type.locations[j].names[k])) // return type.locations[j]; // } // } // } // return null; // } // // public static Campus load(int campusId) { // fileHandler.setCampusId(campusId); // // Gson gson = new Gson(); // String json = ""; // // json = fileHandler.readCampusFile(); // // return gson.fromJson(json, Campus.class); // } // }
import com.mapyst.campus.Campus;
/* * Copyright (C) 2013 Mapyst * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.mapyst.route; //a Direction represents one section of a Route //the Route is broken up so that the route can be displayed and understood public class Direction { private String text; private WaypointID start, end; private int startIcon, endIcon; private int type, time; private LatLngPoint[] points; //types of directions public static final int SAME_FLOOR = 0; public static final int STAIRS = 1; public static final int ELEVATOR = 2; public static final int RAMP = 3; public Direction() { startIcon = -1; endIcon = -1; } public Direction (String text, Waypoint2D start, Waypoint2D end, Route route, int type) { this.text = text; this.start = start.getId(); this.end = end.getId(); this.type = type; startIcon = -1; endIcon = -1; setPoints(route.getPoints(start, end)); time = route.getTime(start, end); }
// Path: route_lib/src/com/mapyst/campus/Campus.java // public class Campus { // public String name; // public String acronym; // public String description; // public String directory_url; // public String phone; // public LatLngPoint location; //center of campus // // public Building[] buildings; // public Location_Type[] location_types; // // // TODO: This is never initialized // public static FileHandlerInterface fileHandler; // // public Floor getFloor(int buildingIndex, int floorIndex) { // return buildings[buildingIndex].floors[floorIndex]; // } // // public String getFloorFile (int buildingIndex, int floorIndex, String fileExtension) { // return buildingIndex + "-" + floorIndex + "." + fileExtension; // } // // public String getFloorFile (Building building, int floorIndex, String fileExtension) { // int buildingIndex = findBuilding(building); // return buildingIndex + "-" + floorIndex + "." + fileExtension; // } // // public String getBuildingFile (int buildingIndex, String fileExtension) { // return buildingIndex + "." + fileExtension; // } // // public String getBuildingFile (Building building, String fileExtension) { // int buildingIndex = findBuilding(building); // return buildingIndex + "." + fileExtension; // } // // private int findBuilding(Building building) { // for (int i = 0; i < buildings.length; i++) { // if (buildings[i] == building) // return i; // } // return -1; // } // // public int parseFloorFromText(int buildingIndex, String floorText) { // if (buildingIndex >= 0 && buildingIndex < buildings.length) { // for (int i = 0; i < buildings[buildingIndex].floors.length; i++) { // if (floorText.equals(getFloor(buildingIndex, i).name.toLowerCase())) // return i; // } // } // return -1; // } // // public Building[] getOutsideBuildings() { // ArrayList<Building> outsideBuildings = new ArrayList<Building>(); // for (int i = 0; i < buildings.length; i++) { // if (buildingIsOutside(i)) { // outsideBuildings.add(buildings[i]); // } // } // return outsideBuildings.toArray(new Building[outsideBuildings.size()]); // } // // public boolean buildingIsOutside(int building) { // return buildings[building].type == Building.OUTSIDE; // } // // public int findLocationType(String type) { // for (int i = 0; i < location_types.length; i++) { // if (location_types[i].name.toLowerCase().equals(type.toLowerCase())) // return i; // } // return -1; // } // // public Location[] getDirectionEndLocations() { // ArrayList<Location> locations = new ArrayList<Location>(); // for (Location_Type type : location_types) { // for (int j = 0; j < type.locations.length; j++) { // Location location = type.locations[j]; // if (location.is_direction_end) { // locations.add(location); // } // } // } // // return locations.toArray(new Location[locations.size()]); // } // // public Location getCampusLocation(String text) { // for (Location_Type type : location_types) { // for (int j = 0; j < type.locations.length; j++) { // for (int k = 0; k < type.locations[j].names.length; k++) { // if (text.equals(type.locations[j].names[k])) // return type.locations[j]; // } // } // } // return null; // } // // public static Campus load(int campusId) { // fileHandler.setCampusId(campusId); // // Gson gson = new Gson(); // String json = ""; // // json = fileHandler.readCampusFile(); // // return gson.fromJson(json, Campus.class); // } // } // Path: route_lib/src/com/mapyst/route/Direction.java import com.mapyst.campus.Campus; /* * Copyright (C) 2013 Mapyst * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.mapyst.route; //a Direction represents one section of a Route //the Route is broken up so that the route can be displayed and understood public class Direction { private String text; private WaypointID start, end; private int startIcon, endIcon; private int type, time; private LatLngPoint[] points; //types of directions public static final int SAME_FLOOR = 0; public static final int STAIRS = 1; public static final int ELEVATOR = 2; public static final int RAMP = 3; public Direction() { startIcon = -1; endIcon = -1; } public Direction (String text, Waypoint2D start, Waypoint2D end, Route route, int type) { this.text = text; this.start = start.getId(); this.end = end.getId(); this.type = type; startIcon = -1; endIcon = -1; setPoints(route.getPoints(start, end)); time = route.getTime(start, end); }
public boolean isOutside(Campus campus) {
Mapyst/Mapyst
route_lib/src/com/mapyst/route/DistanceCalculator.java
// Path: route_lib/src/com/mapyst/campus/Building.java // public class Building { // public String[] names; //all the names by which the building can be referred to (including acronyms besides the acronym field) // public String acronym; // public int type; //type of building (see constants below) // public Floor[] floors; // public LatLngPoint location; //center of the building // // public static final int ACADEMIC = 0; // public static final int RESIDENCE = 1; // public static final int ATHLETIC = 2; // public static final int OTHER = 3; // public static final int OUTSIDE = 4; // }
import com.mapyst.campus.Building;
/* * Copyright (C) 2013 Mapyst * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.mapyst.route; //calculates distances between points and buildings public class DistanceCalculator { public static double distance(LatLngPoint p1, LatLngPoint p2) { return Math.sqrt(Math.pow(p1.lng - p2.lng, 2) + Math.pow(p1.lat - p2.lat, 2)); }
// Path: route_lib/src/com/mapyst/campus/Building.java // public class Building { // public String[] names; //all the names by which the building can be referred to (including acronyms besides the acronym field) // public String acronym; // public int type; //type of building (see constants below) // public Floor[] floors; // public LatLngPoint location; //center of the building // // public static final int ACADEMIC = 0; // public static final int RESIDENCE = 1; // public static final int ATHLETIC = 2; // public static final int OTHER = 3; // public static final int OUTSIDE = 4; // } // Path: route_lib/src/com/mapyst/route/DistanceCalculator.java import com.mapyst.campus.Building; /* * Copyright (C) 2013 Mapyst * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.mapyst.route; //calculates distances between points and buildings public class DistanceCalculator { public static double distance(LatLngPoint p1, LatLngPoint p2) { return Math.sqrt(Math.pow(p1.lng - p2.lng, 2) + Math.pow(p1.lat - p2.lat, 2)); }
public static double buildingDistance(Building b1, Building b2) {
Mapyst/Mapyst
route_lib/src/com/mapyst/campus/Building.java
// Path: route_lib/src/com/mapyst/route/LatLngPoint.java // public class LatLngPoint { // //latitude can be thought of as y // //longitude can be thought of as x // public int lat, lng; //multiplied by a million // // public LatLngPoint() { // lat = 0; // lng = 0; // } // // //note: use Google's GeoPoint convention lat then lng // public LatLngPoint(int lat, int lng) { // this.lng = lng; // this.lat = lat; // } // // public String toString() { // return "lat: " + lat + "; lng: " + lng; // } // // public LatLngPoint copy() { // return new LatLngPoint(this.lat, this.lng); // } // }
import com.mapyst.route.LatLngPoint;
/* * Copyright (C) 2013 Mapyst * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.mapyst.campus; public class Building { public String[] names; //all the names by which the building can be referred to (including acronyms besides the acronym field) public String acronym; public int type; //type of building (see constants below) public Floor[] floors;
// Path: route_lib/src/com/mapyst/route/LatLngPoint.java // public class LatLngPoint { // //latitude can be thought of as y // //longitude can be thought of as x // public int lat, lng; //multiplied by a million // // public LatLngPoint() { // lat = 0; // lng = 0; // } // // //note: use Google's GeoPoint convention lat then lng // public LatLngPoint(int lat, int lng) { // this.lng = lng; // this.lat = lat; // } // // public String toString() { // return "lat: " + lat + "; lng: " + lng; // } // // public LatLngPoint copy() { // return new LatLngPoint(this.lat, this.lng); // } // } // Path: route_lib/src/com/mapyst/campus/Building.java import com.mapyst.route.LatLngPoint; /* * Copyright (C) 2013 Mapyst * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.mapyst.campus; public class Building { public String[] names; //all the names by which the building can be referred to (including acronyms besides the acronym field) public String acronym; public int type; //type of building (see constants below) public Floor[] floors;
public LatLngPoint location; //center of the building
Mapyst/Mapyst
route_lib/src/com/mapyst/route/RouteFinder.java
// Path: route_lib/src/com/mapyst/campus/Building.java // public class Building { // public String[] names; //all the names by which the building can be referred to (including acronyms besides the acronym field) // public String acronym; // public int type; //type of building (see constants below) // public Floor[] floors; // public LatLngPoint location; //center of the building // // public static final int ACADEMIC = 0; // public static final int RESIDENCE = 1; // public static final int ATHLETIC = 2; // public static final int OTHER = 3; // public static final int OUTSIDE = 4; // } // // Path: route_lib/src/com/mapyst/campus/Campus.java // public class Campus { // public String name; // public String acronym; // public String description; // public String directory_url; // public String phone; // public LatLngPoint location; //center of campus // // public Building[] buildings; // public Location_Type[] location_types; // // // TODO: This is never initialized // public static FileHandlerInterface fileHandler; // // public Floor getFloor(int buildingIndex, int floorIndex) { // return buildings[buildingIndex].floors[floorIndex]; // } // // public String getFloorFile (int buildingIndex, int floorIndex, String fileExtension) { // return buildingIndex + "-" + floorIndex + "." + fileExtension; // } // // public String getFloorFile (Building building, int floorIndex, String fileExtension) { // int buildingIndex = findBuilding(building); // return buildingIndex + "-" + floorIndex + "." + fileExtension; // } // // public String getBuildingFile (int buildingIndex, String fileExtension) { // return buildingIndex + "." + fileExtension; // } // // public String getBuildingFile (Building building, String fileExtension) { // int buildingIndex = findBuilding(building); // return buildingIndex + "." + fileExtension; // } // // private int findBuilding(Building building) { // for (int i = 0; i < buildings.length; i++) { // if (buildings[i] == building) // return i; // } // return -1; // } // // public int parseFloorFromText(int buildingIndex, String floorText) { // if (buildingIndex >= 0 && buildingIndex < buildings.length) { // for (int i = 0; i < buildings[buildingIndex].floors.length; i++) { // if (floorText.equals(getFloor(buildingIndex, i).name.toLowerCase())) // return i; // } // } // return -1; // } // // public Building[] getOutsideBuildings() { // ArrayList<Building> outsideBuildings = new ArrayList<Building>(); // for (int i = 0; i < buildings.length; i++) { // if (buildingIsOutside(i)) { // outsideBuildings.add(buildings[i]); // } // } // return outsideBuildings.toArray(new Building[outsideBuildings.size()]); // } // // public boolean buildingIsOutside(int building) { // return buildings[building].type == Building.OUTSIDE; // } // // public int findLocationType(String type) { // for (int i = 0; i < location_types.length; i++) { // if (location_types[i].name.toLowerCase().equals(type.toLowerCase())) // return i; // } // return -1; // } // // public Location[] getDirectionEndLocations() { // ArrayList<Location> locations = new ArrayList<Location>(); // for (Location_Type type : location_types) { // for (int j = 0; j < type.locations.length; j++) { // Location location = type.locations[j]; // if (location.is_direction_end) { // locations.add(location); // } // } // } // // return locations.toArray(new Location[locations.size()]); // } // // public Location getCampusLocation(String text) { // for (Location_Type type : location_types) { // for (int j = 0; j < type.locations.length; j++) { // for (int k = 0; k < type.locations[j].names.length; k++) { // if (text.equals(type.locations[j].names[k])) // return type.locations[j]; // } // } // } // return null; // } // // public static Campus load(int campusId) { // fileHandler.setCampusId(campusId); // // Gson gson = new Gson(); // String json = ""; // // json = fileHandler.readCampusFile(); // // return gson.fromJson(json, Campus.class); // } // }
import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.Map.Entry; import com.mapyst.campus.Building; import com.mapyst.campus.Campus;
/* * Copyright (C) 2013 Mapyst * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.mapyst.route; /* * Class: RouteFinder * Prepares to find the shortest path based on preferences and then executes to find the route * NOTE: Make sure you do NOT load any files twice as this will ruin the path finding */ public class RouteFinder { //the hashmap of the loaded nodes public HashMap<WaypointID, GraphNode<Waypoint2D>> loadedNodes;
// Path: route_lib/src/com/mapyst/campus/Building.java // public class Building { // public String[] names; //all the names by which the building can be referred to (including acronyms besides the acronym field) // public String acronym; // public int type; //type of building (see constants below) // public Floor[] floors; // public LatLngPoint location; //center of the building // // public static final int ACADEMIC = 0; // public static final int RESIDENCE = 1; // public static final int ATHLETIC = 2; // public static final int OTHER = 3; // public static final int OUTSIDE = 4; // } // // Path: route_lib/src/com/mapyst/campus/Campus.java // public class Campus { // public String name; // public String acronym; // public String description; // public String directory_url; // public String phone; // public LatLngPoint location; //center of campus // // public Building[] buildings; // public Location_Type[] location_types; // // // TODO: This is never initialized // public static FileHandlerInterface fileHandler; // // public Floor getFloor(int buildingIndex, int floorIndex) { // return buildings[buildingIndex].floors[floorIndex]; // } // // public String getFloorFile (int buildingIndex, int floorIndex, String fileExtension) { // return buildingIndex + "-" + floorIndex + "." + fileExtension; // } // // public String getFloorFile (Building building, int floorIndex, String fileExtension) { // int buildingIndex = findBuilding(building); // return buildingIndex + "-" + floorIndex + "." + fileExtension; // } // // public String getBuildingFile (int buildingIndex, String fileExtension) { // return buildingIndex + "." + fileExtension; // } // // public String getBuildingFile (Building building, String fileExtension) { // int buildingIndex = findBuilding(building); // return buildingIndex + "." + fileExtension; // } // // private int findBuilding(Building building) { // for (int i = 0; i < buildings.length; i++) { // if (buildings[i] == building) // return i; // } // return -1; // } // // public int parseFloorFromText(int buildingIndex, String floorText) { // if (buildingIndex >= 0 && buildingIndex < buildings.length) { // for (int i = 0; i < buildings[buildingIndex].floors.length; i++) { // if (floorText.equals(getFloor(buildingIndex, i).name.toLowerCase())) // return i; // } // } // return -1; // } // // public Building[] getOutsideBuildings() { // ArrayList<Building> outsideBuildings = new ArrayList<Building>(); // for (int i = 0; i < buildings.length; i++) { // if (buildingIsOutside(i)) { // outsideBuildings.add(buildings[i]); // } // } // return outsideBuildings.toArray(new Building[outsideBuildings.size()]); // } // // public boolean buildingIsOutside(int building) { // return buildings[building].type == Building.OUTSIDE; // } // // public int findLocationType(String type) { // for (int i = 0; i < location_types.length; i++) { // if (location_types[i].name.toLowerCase().equals(type.toLowerCase())) // return i; // } // return -1; // } // // public Location[] getDirectionEndLocations() { // ArrayList<Location> locations = new ArrayList<Location>(); // for (Location_Type type : location_types) { // for (int j = 0; j < type.locations.length; j++) { // Location location = type.locations[j]; // if (location.is_direction_end) { // locations.add(location); // } // } // } // // return locations.toArray(new Location[locations.size()]); // } // // public Location getCampusLocation(String text) { // for (Location_Type type : location_types) { // for (int j = 0; j < type.locations.length; j++) { // for (int k = 0; k < type.locations[j].names.length; k++) { // if (text.equals(type.locations[j].names[k])) // return type.locations[j]; // } // } // } // return null; // } // // public static Campus load(int campusId) { // fileHandler.setCampusId(campusId); // // Gson gson = new Gson(); // String json = ""; // // json = fileHandler.readCampusFile(); // // return gson.fromJson(json, Campus.class); // } // } // Path: route_lib/src/com/mapyst/route/RouteFinder.java import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.Map.Entry; import com.mapyst.campus.Building; import com.mapyst.campus.Campus; /* * Copyright (C) 2013 Mapyst * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.mapyst.route; /* * Class: RouteFinder * Prepares to find the shortest path based on preferences and then executes to find the route * NOTE: Make sure you do NOT load any files twice as this will ruin the path finding */ public class RouteFinder { //the hashmap of the loaded nodes public HashMap<WaypointID, GraphNode<Waypoint2D>> loadedNodes;
private Campus campus;
Mapyst/Mapyst
route_lib/src/com/mapyst/route/RouteFinder.java
// Path: route_lib/src/com/mapyst/campus/Building.java // public class Building { // public String[] names; //all the names by which the building can be referred to (including acronyms besides the acronym field) // public String acronym; // public int type; //type of building (see constants below) // public Floor[] floors; // public LatLngPoint location; //center of the building // // public static final int ACADEMIC = 0; // public static final int RESIDENCE = 1; // public static final int ATHLETIC = 2; // public static final int OTHER = 3; // public static final int OUTSIDE = 4; // } // // Path: route_lib/src/com/mapyst/campus/Campus.java // public class Campus { // public String name; // public String acronym; // public String description; // public String directory_url; // public String phone; // public LatLngPoint location; //center of campus // // public Building[] buildings; // public Location_Type[] location_types; // // // TODO: This is never initialized // public static FileHandlerInterface fileHandler; // // public Floor getFloor(int buildingIndex, int floorIndex) { // return buildings[buildingIndex].floors[floorIndex]; // } // // public String getFloorFile (int buildingIndex, int floorIndex, String fileExtension) { // return buildingIndex + "-" + floorIndex + "." + fileExtension; // } // // public String getFloorFile (Building building, int floorIndex, String fileExtension) { // int buildingIndex = findBuilding(building); // return buildingIndex + "-" + floorIndex + "." + fileExtension; // } // // public String getBuildingFile (int buildingIndex, String fileExtension) { // return buildingIndex + "." + fileExtension; // } // // public String getBuildingFile (Building building, String fileExtension) { // int buildingIndex = findBuilding(building); // return buildingIndex + "." + fileExtension; // } // // private int findBuilding(Building building) { // for (int i = 0; i < buildings.length; i++) { // if (buildings[i] == building) // return i; // } // return -1; // } // // public int parseFloorFromText(int buildingIndex, String floorText) { // if (buildingIndex >= 0 && buildingIndex < buildings.length) { // for (int i = 0; i < buildings[buildingIndex].floors.length; i++) { // if (floorText.equals(getFloor(buildingIndex, i).name.toLowerCase())) // return i; // } // } // return -1; // } // // public Building[] getOutsideBuildings() { // ArrayList<Building> outsideBuildings = new ArrayList<Building>(); // for (int i = 0; i < buildings.length; i++) { // if (buildingIsOutside(i)) { // outsideBuildings.add(buildings[i]); // } // } // return outsideBuildings.toArray(new Building[outsideBuildings.size()]); // } // // public boolean buildingIsOutside(int building) { // return buildings[building].type == Building.OUTSIDE; // } // // public int findLocationType(String type) { // for (int i = 0; i < location_types.length; i++) { // if (location_types[i].name.toLowerCase().equals(type.toLowerCase())) // return i; // } // return -1; // } // // public Location[] getDirectionEndLocations() { // ArrayList<Location> locations = new ArrayList<Location>(); // for (Location_Type type : location_types) { // for (int j = 0; j < type.locations.length; j++) { // Location location = type.locations[j]; // if (location.is_direction_end) { // locations.add(location); // } // } // } // // return locations.toArray(new Location[locations.size()]); // } // // public Location getCampusLocation(String text) { // for (Location_Type type : location_types) { // for (int j = 0; j < type.locations.length; j++) { // for (int k = 0; k < type.locations[j].names.length; k++) { // if (text.equals(type.locations[j].names[k])) // return type.locations[j]; // } // } // } // return null; // } // // public static Campus load(int campusId) { // fileHandler.setCampusId(campusId); // // Gson gson = new Gson(); // String json = ""; // // json = fileHandler.readCampusFile(); // // return gson.fromJson(json, Campus.class); // } // }
import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.Map.Entry; import com.mapyst.campus.Building; import com.mapyst.campus.Campus;
a.getTerrain() == Arc.Terrains.CROWDED_OUTSIDE) a.setDistance(currDistance * MODIFIER_CONSTANT); } if (prefs.elevators) { if (a.getTerrain() == Arc.Terrains.INSIDE_STAIRS || a.getTerrain() == Arc.Terrains.OUTSIDE_STAIRS) //actually remove the connections of the stairs a.setDistance(currDistance * MODIFIER_CONSTANT); } if (prefs.stairs) { if (a.getTerrain() == Arc.Terrains.ELEVATOR) a.setDistance(currDistance * MODIFIER_CONSTANT); } if (prefs.hand) { if (a.getTerrain() == Arc.Terrains.INSIDE_STAIRS || a.getTerrain() == Arc.Terrains.OUTSIDE_STAIRS) //actually remove the connections of the stairs return REMOVE_ARC; } return NO_REMOVE; } private void loadGraphFiles(InterpretResult startResult, InterpretResult endResult) { HashSet<String> floorGraphFiles = new HashSet<String>(); HashSet<String> buildingGraphFiles = new HashSet<String>(); WaypointID start = startResult.getPointID(); WaypointID end = getFarthestEnd(startResult, endResult); //distance threshold = 1.5 distance between start and end buildings
// Path: route_lib/src/com/mapyst/campus/Building.java // public class Building { // public String[] names; //all the names by which the building can be referred to (including acronyms besides the acronym field) // public String acronym; // public int type; //type of building (see constants below) // public Floor[] floors; // public LatLngPoint location; //center of the building // // public static final int ACADEMIC = 0; // public static final int RESIDENCE = 1; // public static final int ATHLETIC = 2; // public static final int OTHER = 3; // public static final int OUTSIDE = 4; // } // // Path: route_lib/src/com/mapyst/campus/Campus.java // public class Campus { // public String name; // public String acronym; // public String description; // public String directory_url; // public String phone; // public LatLngPoint location; //center of campus // // public Building[] buildings; // public Location_Type[] location_types; // // // TODO: This is never initialized // public static FileHandlerInterface fileHandler; // // public Floor getFloor(int buildingIndex, int floorIndex) { // return buildings[buildingIndex].floors[floorIndex]; // } // // public String getFloorFile (int buildingIndex, int floorIndex, String fileExtension) { // return buildingIndex + "-" + floorIndex + "." + fileExtension; // } // // public String getFloorFile (Building building, int floorIndex, String fileExtension) { // int buildingIndex = findBuilding(building); // return buildingIndex + "-" + floorIndex + "." + fileExtension; // } // // public String getBuildingFile (int buildingIndex, String fileExtension) { // return buildingIndex + "." + fileExtension; // } // // public String getBuildingFile (Building building, String fileExtension) { // int buildingIndex = findBuilding(building); // return buildingIndex + "." + fileExtension; // } // // private int findBuilding(Building building) { // for (int i = 0; i < buildings.length; i++) { // if (buildings[i] == building) // return i; // } // return -1; // } // // public int parseFloorFromText(int buildingIndex, String floorText) { // if (buildingIndex >= 0 && buildingIndex < buildings.length) { // for (int i = 0; i < buildings[buildingIndex].floors.length; i++) { // if (floorText.equals(getFloor(buildingIndex, i).name.toLowerCase())) // return i; // } // } // return -1; // } // // public Building[] getOutsideBuildings() { // ArrayList<Building> outsideBuildings = new ArrayList<Building>(); // for (int i = 0; i < buildings.length; i++) { // if (buildingIsOutside(i)) { // outsideBuildings.add(buildings[i]); // } // } // return outsideBuildings.toArray(new Building[outsideBuildings.size()]); // } // // public boolean buildingIsOutside(int building) { // return buildings[building].type == Building.OUTSIDE; // } // // public int findLocationType(String type) { // for (int i = 0; i < location_types.length; i++) { // if (location_types[i].name.toLowerCase().equals(type.toLowerCase())) // return i; // } // return -1; // } // // public Location[] getDirectionEndLocations() { // ArrayList<Location> locations = new ArrayList<Location>(); // for (Location_Type type : location_types) { // for (int j = 0; j < type.locations.length; j++) { // Location location = type.locations[j]; // if (location.is_direction_end) { // locations.add(location); // } // } // } // // return locations.toArray(new Location[locations.size()]); // } // // public Location getCampusLocation(String text) { // for (Location_Type type : location_types) { // for (int j = 0; j < type.locations.length; j++) { // for (int k = 0; k < type.locations[j].names.length; k++) { // if (text.equals(type.locations[j].names[k])) // return type.locations[j]; // } // } // } // return null; // } // // public static Campus load(int campusId) { // fileHandler.setCampusId(campusId); // // Gson gson = new Gson(); // String json = ""; // // json = fileHandler.readCampusFile(); // // return gson.fromJson(json, Campus.class); // } // } // Path: route_lib/src/com/mapyst/route/RouteFinder.java import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.Map.Entry; import com.mapyst.campus.Building; import com.mapyst.campus.Campus; a.getTerrain() == Arc.Terrains.CROWDED_OUTSIDE) a.setDistance(currDistance * MODIFIER_CONSTANT); } if (prefs.elevators) { if (a.getTerrain() == Arc.Terrains.INSIDE_STAIRS || a.getTerrain() == Arc.Terrains.OUTSIDE_STAIRS) //actually remove the connections of the stairs a.setDistance(currDistance * MODIFIER_CONSTANT); } if (prefs.stairs) { if (a.getTerrain() == Arc.Terrains.ELEVATOR) a.setDistance(currDistance * MODIFIER_CONSTANT); } if (prefs.hand) { if (a.getTerrain() == Arc.Terrains.INSIDE_STAIRS || a.getTerrain() == Arc.Terrains.OUTSIDE_STAIRS) //actually remove the connections of the stairs return REMOVE_ARC; } return NO_REMOVE; } private void loadGraphFiles(InterpretResult startResult, InterpretResult endResult) { HashSet<String> floorGraphFiles = new HashSet<String>(); HashSet<String> buildingGraphFiles = new HashSet<String>(); WaypointID start = startResult.getPointID(); WaypointID end = getFarthestEnd(startResult, endResult); //distance threshold = 1.5 distance between start and end buildings
Building startBuilding = campus.buildings[start.getBuildingIndex()];
Mapyst/Mapyst
android/Mapyst/src/com/mapyst/android/ui/map/MapViewMover.java
// Path: route_lib/src/com/mapyst/route/Direction.java // public class Direction { // private String text; // private WaypointID start, end; // private int startIcon, endIcon; // private int type, time; // private LatLngPoint[] points; // // //types of directions // public static final int SAME_FLOOR = 0; // public static final int STAIRS = 1; // public static final int ELEVATOR = 2; // public static final int RAMP = 3; // // public Direction() { // startIcon = -1; // endIcon = -1; // } // // public Direction (String text, Waypoint2D start, Waypoint2D end, Route route, int type) { // this.text = text; // this.start = start.getId(); // this.end = end.getId(); // this.type = type; // // startIcon = -1; // endIcon = -1; // // setPoints(route.getPoints(start, end)); // time = route.getTime(start, end); // } // // public boolean isOutside(Campus campus) { // return campus.buildingIsOutside(end.getBuildingIndex()); // } // // public int getBuilding() { // return end.getBuildingIndex(); // } // // public int getFloor() { // return end.getFloorIndex(); // } // // public String getText() { // return text; // } // // public WaypointID getStart() { // return start; // } // // public WaypointID getEnd() { // return end; // } // // public int getStartIcon() { // return startIcon; // } // // public int getEndIcon() { // return endIcon; // } // // public int getType() { // return type; // } // // public LatLngPoint[] getPoints() { // return points; // } // // public int getTime() { // return time; // } // // // // // public void setText(String text) { // this.text = text; // } // // public void setStart(WaypointID start) { // this.start = start; // } // // public void setEnd(WaypointID end) { // this.end = end; // } // // public void setStartIcon(int startIcon) { // this.startIcon = startIcon; // } // // public void setEndIcon(int endIcon) { // this.endIcon = endIcon; // } // // public void setType(int type) { // this.type = type; // } // // public void setPoints(LatLngPoint[] points) { // this.points = points; // } // // public void setTime(int time) { // this.time = time; // } // // public void addTime(int added) { // time += added; // } // // public String toString() { // return ("text: " + text + ", start: " + start.toString() + ", end: " + // end.toString() + ", startIcon: " + startIcon + ", endIcon: " + endIcon + // ", type: " + type); // } // } // // Path: route_lib/src/com/mapyst/route/LatLngPoint.java // public class LatLngPoint { // //latitude can be thought of as y // //longitude can be thought of as x // public int lat, lng; //multiplied by a million // // public LatLngPoint() { // lat = 0; // lng = 0; // } // // //note: use Google's GeoPoint convention lat then lng // public LatLngPoint(int lat, int lng) { // this.lng = lng; // this.lat = lat; // } // // public String toString() { // return "lat: " + lat + "; lng: " + lng; // } // // public LatLngPoint copy() { // return new LatLngPoint(this.lat, this.lng); // } // }
import android.graphics.Point; import android.graphics.Rect; import android.os.Handler; import com.google.android.maps.GeoPoint; import com.google.android.maps.MapController; import com.google.android.maps.MapView; import com.mapyst.route.Direction; import com.mapyst.route.LatLngPoint;
/* * Copyright (C) 2013 Mapyst * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.mapyst.android.ui.map; public class MapViewMover { public static void smoothFitToDirection(MapView mapView, Handler handler, double border, Direction direction) { float maxY = -Float.MAX_VALUE; float maxX = -Float.MAX_VALUE; float minY = Float.MAX_VALUE; float minX = Float.MAX_VALUE;
// Path: route_lib/src/com/mapyst/route/Direction.java // public class Direction { // private String text; // private WaypointID start, end; // private int startIcon, endIcon; // private int type, time; // private LatLngPoint[] points; // // //types of directions // public static final int SAME_FLOOR = 0; // public static final int STAIRS = 1; // public static final int ELEVATOR = 2; // public static final int RAMP = 3; // // public Direction() { // startIcon = -1; // endIcon = -1; // } // // public Direction (String text, Waypoint2D start, Waypoint2D end, Route route, int type) { // this.text = text; // this.start = start.getId(); // this.end = end.getId(); // this.type = type; // // startIcon = -1; // endIcon = -1; // // setPoints(route.getPoints(start, end)); // time = route.getTime(start, end); // } // // public boolean isOutside(Campus campus) { // return campus.buildingIsOutside(end.getBuildingIndex()); // } // // public int getBuilding() { // return end.getBuildingIndex(); // } // // public int getFloor() { // return end.getFloorIndex(); // } // // public String getText() { // return text; // } // // public WaypointID getStart() { // return start; // } // // public WaypointID getEnd() { // return end; // } // // public int getStartIcon() { // return startIcon; // } // // public int getEndIcon() { // return endIcon; // } // // public int getType() { // return type; // } // // public LatLngPoint[] getPoints() { // return points; // } // // public int getTime() { // return time; // } // // // // // public void setText(String text) { // this.text = text; // } // // public void setStart(WaypointID start) { // this.start = start; // } // // public void setEnd(WaypointID end) { // this.end = end; // } // // public void setStartIcon(int startIcon) { // this.startIcon = startIcon; // } // // public void setEndIcon(int endIcon) { // this.endIcon = endIcon; // } // // public void setType(int type) { // this.type = type; // } // // public void setPoints(LatLngPoint[] points) { // this.points = points; // } // // public void setTime(int time) { // this.time = time; // } // // public void addTime(int added) { // time += added; // } // // public String toString() { // return ("text: " + text + ", start: " + start.toString() + ", end: " + // end.toString() + ", startIcon: " + startIcon + ", endIcon: " + endIcon + // ", type: " + type); // } // } // // Path: route_lib/src/com/mapyst/route/LatLngPoint.java // public class LatLngPoint { // //latitude can be thought of as y // //longitude can be thought of as x // public int lat, lng; //multiplied by a million // // public LatLngPoint() { // lat = 0; // lng = 0; // } // // //note: use Google's GeoPoint convention lat then lng // public LatLngPoint(int lat, int lng) { // this.lng = lng; // this.lat = lat; // } // // public String toString() { // return "lat: " + lat + "; lng: " + lng; // } // // public LatLngPoint copy() { // return new LatLngPoint(this.lat, this.lng); // } // } // Path: android/Mapyst/src/com/mapyst/android/ui/map/MapViewMover.java import android.graphics.Point; import android.graphics.Rect; import android.os.Handler; import com.google.android.maps.GeoPoint; import com.google.android.maps.MapController; import com.google.android.maps.MapView; import com.mapyst.route.Direction; import com.mapyst.route.LatLngPoint; /* * Copyright (C) 2013 Mapyst * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.mapyst.android.ui.map; public class MapViewMover { public static void smoothFitToDirection(MapView mapView, Handler handler, double border, Direction direction) { float maxY = -Float.MAX_VALUE; float maxX = -Float.MAX_VALUE; float minY = Float.MAX_VALUE; float minX = Float.MAX_VALUE;
LatLngPoint[] points = direction.getPoints();
Mapyst/Mapyst
android/Mapyst/src/com/mapyst/android/asynctask/CampusLoaderTask.java
// Path: route_lib/src/com/mapyst/campus/Campus.java // public class Campus { // public String name; // public String acronym; // public String description; // public String directory_url; // public String phone; // public LatLngPoint location; //center of campus // // public Building[] buildings; // public Location_Type[] location_types; // // // TODO: This is never initialized // public static FileHandlerInterface fileHandler; // // public Floor getFloor(int buildingIndex, int floorIndex) { // return buildings[buildingIndex].floors[floorIndex]; // } // // public String getFloorFile (int buildingIndex, int floorIndex, String fileExtension) { // return buildingIndex + "-" + floorIndex + "." + fileExtension; // } // // public String getFloorFile (Building building, int floorIndex, String fileExtension) { // int buildingIndex = findBuilding(building); // return buildingIndex + "-" + floorIndex + "." + fileExtension; // } // // public String getBuildingFile (int buildingIndex, String fileExtension) { // return buildingIndex + "." + fileExtension; // } // // public String getBuildingFile (Building building, String fileExtension) { // int buildingIndex = findBuilding(building); // return buildingIndex + "." + fileExtension; // } // // private int findBuilding(Building building) { // for (int i = 0; i < buildings.length; i++) { // if (buildings[i] == building) // return i; // } // return -1; // } // // public int parseFloorFromText(int buildingIndex, String floorText) { // if (buildingIndex >= 0 && buildingIndex < buildings.length) { // for (int i = 0; i < buildings[buildingIndex].floors.length; i++) { // if (floorText.equals(getFloor(buildingIndex, i).name.toLowerCase())) // return i; // } // } // return -1; // } // // public Building[] getOutsideBuildings() { // ArrayList<Building> outsideBuildings = new ArrayList<Building>(); // for (int i = 0; i < buildings.length; i++) { // if (buildingIsOutside(i)) { // outsideBuildings.add(buildings[i]); // } // } // return outsideBuildings.toArray(new Building[outsideBuildings.size()]); // } // // public boolean buildingIsOutside(int building) { // return buildings[building].type == Building.OUTSIDE; // } // // public int findLocationType(String type) { // for (int i = 0; i < location_types.length; i++) { // if (location_types[i].name.toLowerCase().equals(type.toLowerCase())) // return i; // } // return -1; // } // // public Location[] getDirectionEndLocations() { // ArrayList<Location> locations = new ArrayList<Location>(); // for (Location_Type type : location_types) { // for (int j = 0; j < type.locations.length; j++) { // Location location = type.locations[j]; // if (location.is_direction_end) { // locations.add(location); // } // } // } // // return locations.toArray(new Location[locations.size()]); // } // // public Location getCampusLocation(String text) { // for (Location_Type type : location_types) { // for (int j = 0; j < type.locations.length; j++) { // for (int k = 0; k < type.locations[j].names.length; k++) { // if (text.equals(type.locations[j].names[k])) // return type.locations[j]; // } // } // } // return null; // } // // public static Campus load(int campusId) { // fileHandler.setCampusId(campusId); // // Gson gson = new Gson(); // String json = ""; // // json = fileHandler.readCampusFile(); // // return gson.fromJson(json, Campus.class); // } // }
import com.mapyst.campus.Campus; import android.os.AsyncTask;
/* * Copyright (C) 2013 Mapyst * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.mapyst.android.asynctask; public class CampusLoaderTask extends AsyncTask<CampusLoaderTaskPrefs, Integer, CampusLoaderTaskPrefs> { @Override protected CampusLoaderTaskPrefs doInBackground(CampusLoaderTaskPrefs... prefs) { // This runs in the background for (CampusLoaderTaskPrefs pref : prefs) {
// Path: route_lib/src/com/mapyst/campus/Campus.java // public class Campus { // public String name; // public String acronym; // public String description; // public String directory_url; // public String phone; // public LatLngPoint location; //center of campus // // public Building[] buildings; // public Location_Type[] location_types; // // // TODO: This is never initialized // public static FileHandlerInterface fileHandler; // // public Floor getFloor(int buildingIndex, int floorIndex) { // return buildings[buildingIndex].floors[floorIndex]; // } // // public String getFloorFile (int buildingIndex, int floorIndex, String fileExtension) { // return buildingIndex + "-" + floorIndex + "." + fileExtension; // } // // public String getFloorFile (Building building, int floorIndex, String fileExtension) { // int buildingIndex = findBuilding(building); // return buildingIndex + "-" + floorIndex + "." + fileExtension; // } // // public String getBuildingFile (int buildingIndex, String fileExtension) { // return buildingIndex + "." + fileExtension; // } // // public String getBuildingFile (Building building, String fileExtension) { // int buildingIndex = findBuilding(building); // return buildingIndex + "." + fileExtension; // } // // private int findBuilding(Building building) { // for (int i = 0; i < buildings.length; i++) { // if (buildings[i] == building) // return i; // } // return -1; // } // // public int parseFloorFromText(int buildingIndex, String floorText) { // if (buildingIndex >= 0 && buildingIndex < buildings.length) { // for (int i = 0; i < buildings[buildingIndex].floors.length; i++) { // if (floorText.equals(getFloor(buildingIndex, i).name.toLowerCase())) // return i; // } // } // return -1; // } // // public Building[] getOutsideBuildings() { // ArrayList<Building> outsideBuildings = new ArrayList<Building>(); // for (int i = 0; i < buildings.length; i++) { // if (buildingIsOutside(i)) { // outsideBuildings.add(buildings[i]); // } // } // return outsideBuildings.toArray(new Building[outsideBuildings.size()]); // } // // public boolean buildingIsOutside(int building) { // return buildings[building].type == Building.OUTSIDE; // } // // public int findLocationType(String type) { // for (int i = 0; i < location_types.length; i++) { // if (location_types[i].name.toLowerCase().equals(type.toLowerCase())) // return i; // } // return -1; // } // // public Location[] getDirectionEndLocations() { // ArrayList<Location> locations = new ArrayList<Location>(); // for (Location_Type type : location_types) { // for (int j = 0; j < type.locations.length; j++) { // Location location = type.locations[j]; // if (location.is_direction_end) { // locations.add(location); // } // } // } // // return locations.toArray(new Location[locations.size()]); // } // // public Location getCampusLocation(String text) { // for (Location_Type type : location_types) { // for (int j = 0; j < type.locations.length; j++) { // for (int k = 0; k < type.locations[j].names.length; k++) { // if (text.equals(type.locations[j].names[k])) // return type.locations[j]; // } // } // } // return null; // } // // public static Campus load(int campusId) { // fileHandler.setCampusId(campusId); // // Gson gson = new Gson(); // String json = ""; // // json = fileHandler.readCampusFile(); // // return gson.fromJson(json, Campus.class); // } // } // Path: android/Mapyst/src/com/mapyst/android/asynctask/CampusLoaderTask.java import com.mapyst.campus.Campus; import android.os.AsyncTask; /* * Copyright (C) 2013 Mapyst * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.mapyst.android.asynctask; public class CampusLoaderTask extends AsyncTask<CampusLoaderTaskPrefs, Integer, CampusLoaderTaskPrefs> { @Override protected CampusLoaderTaskPrefs doInBackground(CampusLoaderTaskPrefs... prefs) { // This runs in the background for (CampusLoaderTaskPrefs pref : prefs) {
pref.app.campus = Campus.load(pref.campus_id);
Mapyst/Mapyst
route_lib/src/com/mapyst/campus/Campus.java
// Path: route_lib/src/com/mapyst/FileHandlerInterface.java // public interface FileHandlerInterface { // // public int getCampusId(); // public void setCampusId(int campusId); // // public InputStream getInputStream(String path) throws IOException; // public OutputStream getOutputStream(String path) throws IOException; // // public String readCampusFile(); // public String readFile(String fileName); // } // // Path: route_lib/src/com/mapyst/route/LatLngPoint.java // public class LatLngPoint { // //latitude can be thought of as y // //longitude can be thought of as x // public int lat, lng; //multiplied by a million // // public LatLngPoint() { // lat = 0; // lng = 0; // } // // //note: use Google's GeoPoint convention lat then lng // public LatLngPoint(int lat, int lng) { // this.lng = lng; // this.lat = lat; // } // // public String toString() { // return "lat: " + lat + "; lng: " + lng; // } // // public LatLngPoint copy() { // return new LatLngPoint(this.lat, this.lng); // } // }
import java.util.ArrayList; import com.google.gson.Gson; import com.mapyst.FileHandlerInterface; import com.mapyst.route.LatLngPoint;
/* * Copyright (C) 2013 Mapyst * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.mapyst.campus; public class Campus { public String name; public String acronym; public String description; public String directory_url; public String phone;
// Path: route_lib/src/com/mapyst/FileHandlerInterface.java // public interface FileHandlerInterface { // // public int getCampusId(); // public void setCampusId(int campusId); // // public InputStream getInputStream(String path) throws IOException; // public OutputStream getOutputStream(String path) throws IOException; // // public String readCampusFile(); // public String readFile(String fileName); // } // // Path: route_lib/src/com/mapyst/route/LatLngPoint.java // public class LatLngPoint { // //latitude can be thought of as y // //longitude can be thought of as x // public int lat, lng; //multiplied by a million // // public LatLngPoint() { // lat = 0; // lng = 0; // } // // //note: use Google's GeoPoint convention lat then lng // public LatLngPoint(int lat, int lng) { // this.lng = lng; // this.lat = lat; // } // // public String toString() { // return "lat: " + lat + "; lng: " + lng; // } // // public LatLngPoint copy() { // return new LatLngPoint(this.lat, this.lng); // } // } // Path: route_lib/src/com/mapyst/campus/Campus.java import java.util.ArrayList; import com.google.gson.Gson; import com.mapyst.FileHandlerInterface; import com.mapyst.route.LatLngPoint; /* * Copyright (C) 2013 Mapyst * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.mapyst.campus; public class Campus { public String name; public String acronym; public String description; public String directory_url; public String phone;
public LatLngPoint location; //center of campus
Mapyst/Mapyst
route_lib/src/com/mapyst/campus/Campus.java
// Path: route_lib/src/com/mapyst/FileHandlerInterface.java // public interface FileHandlerInterface { // // public int getCampusId(); // public void setCampusId(int campusId); // // public InputStream getInputStream(String path) throws IOException; // public OutputStream getOutputStream(String path) throws IOException; // // public String readCampusFile(); // public String readFile(String fileName); // } // // Path: route_lib/src/com/mapyst/route/LatLngPoint.java // public class LatLngPoint { // //latitude can be thought of as y // //longitude can be thought of as x // public int lat, lng; //multiplied by a million // // public LatLngPoint() { // lat = 0; // lng = 0; // } // // //note: use Google's GeoPoint convention lat then lng // public LatLngPoint(int lat, int lng) { // this.lng = lng; // this.lat = lat; // } // // public String toString() { // return "lat: " + lat + "; lng: " + lng; // } // // public LatLngPoint copy() { // return new LatLngPoint(this.lat, this.lng); // } // }
import java.util.ArrayList; import com.google.gson.Gson; import com.mapyst.FileHandlerInterface; import com.mapyst.route.LatLngPoint;
/* * Copyright (C) 2013 Mapyst * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.mapyst.campus; public class Campus { public String name; public String acronym; public String description; public String directory_url; public String phone; public LatLngPoint location; //center of campus public Building[] buildings; public Location_Type[] location_types; // TODO: This is never initialized
// Path: route_lib/src/com/mapyst/FileHandlerInterface.java // public interface FileHandlerInterface { // // public int getCampusId(); // public void setCampusId(int campusId); // // public InputStream getInputStream(String path) throws IOException; // public OutputStream getOutputStream(String path) throws IOException; // // public String readCampusFile(); // public String readFile(String fileName); // } // // Path: route_lib/src/com/mapyst/route/LatLngPoint.java // public class LatLngPoint { // //latitude can be thought of as y // //longitude can be thought of as x // public int lat, lng; //multiplied by a million // // public LatLngPoint() { // lat = 0; // lng = 0; // } // // //note: use Google's GeoPoint convention lat then lng // public LatLngPoint(int lat, int lng) { // this.lng = lng; // this.lat = lat; // } // // public String toString() { // return "lat: " + lat + "; lng: " + lng; // } // // public LatLngPoint copy() { // return new LatLngPoint(this.lat, this.lng); // } // } // Path: route_lib/src/com/mapyst/campus/Campus.java import java.util.ArrayList; import com.google.gson.Gson; import com.mapyst.FileHandlerInterface; import com.mapyst.route.LatLngPoint; /* * Copyright (C) 2013 Mapyst * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.mapyst.campus; public class Campus { public String name; public String acronym; public String description; public String directory_url; public String phone; public LatLngPoint location; //center of campus public Building[] buildings; public Location_Type[] location_types; // TODO: This is never initialized
public static FileHandlerInterface fileHandler;
Mapyst/Mapyst
route_lib/src/com/mapyst/campus/Floor.java
// Path: route_lib/src/com/mapyst/route/LatLngPoint.java // public class LatLngPoint { // //latitude can be thought of as y // //longitude can be thought of as x // public int lat, lng; //multiplied by a million // // public LatLngPoint() { // lat = 0; // lng = 0; // } // // //note: use Google's GeoPoint convention lat then lng // public LatLngPoint(int lat, int lng) { // this.lng = lng; // this.lat = lat; // } // // public String toString() { // return "lat: " + lat + "; lng: " + lng; // } // // public LatLngPoint copy() { // return new LatLngPoint(this.lat, this.lng); // } // }
import com.mapyst.route.LatLngPoint;
/* * Copyright (C) 2013 Mapyst * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.mapyst.campus; public class Floor { public String name;
// Path: route_lib/src/com/mapyst/route/LatLngPoint.java // public class LatLngPoint { // //latitude can be thought of as y // //longitude can be thought of as x // public int lat, lng; //multiplied by a million // // public LatLngPoint() { // lat = 0; // lng = 0; // } // // //note: use Google's GeoPoint convention lat then lng // public LatLngPoint(int lat, int lng) { // this.lng = lng; // this.lat = lat; // } // // public String toString() { // return "lat: " + lat + "; lng: " + lng; // } // // public LatLngPoint copy() { // return new LatLngPoint(this.lat, this.lng); // } // } // Path: route_lib/src/com/mapyst/campus/Floor.java import com.mapyst.route.LatLngPoint; /* * Copyright (C) 2013 Mapyst * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.mapyst.campus; public class Floor { public String name;
public LatLngPoint northWest, southEast;
Mapyst/Mapyst
route_lib/src/com/mapyst/route/DataParser.java
// Path: route_lib/src/com/mapyst/FileHandlerInterface.java // public interface FileHandlerInterface { // // public int getCampusId(); // public void setCampusId(int campusId); // // public InputStream getInputStream(String path) throws IOException; // public OutputStream getOutputStream(String path) throws IOException; // // public String readCampusFile(); // public String readFile(String fileName); // }
import java.io.BufferedInputStream; import java.io.IOException; import java.util.HashMap; import com.mapyst.FileHandlerInterface;
/* * Copyright (C) 2013 Mapyst * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.mapyst.route; //parses mapyst data files containing a graph //each file represents either a floor, building, or campus public class DataParser { private static final int FLOOR = 0; private static final int BUILDING = 1; private static final int CAMPUS = 2; private static final int FILE_VERSION = 1; private static final int FILE_VERIFICATION = 0x2417DC43;
// Path: route_lib/src/com/mapyst/FileHandlerInterface.java // public interface FileHandlerInterface { // // public int getCampusId(); // public void setCampusId(int campusId); // // public InputStream getInputStream(String path) throws IOException; // public OutputStream getOutputStream(String path) throws IOException; // // public String readCampusFile(); // public String readFile(String fileName); // } // Path: route_lib/src/com/mapyst/route/DataParser.java import java.io.BufferedInputStream; import java.io.IOException; import java.util.HashMap; import com.mapyst.FileHandlerInterface; /* * Copyright (C) 2013 Mapyst * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.mapyst.route; //parses mapyst data files containing a graph //each file represents either a floor, building, or campus public class DataParser { private static final int FLOOR = 0; private static final int BUILDING = 1; private static final int CAMPUS = 2; private static final int FILE_VERSION = 1; private static final int FILE_VERIFICATION = 0x2417DC43;
public static void parseFile(String file, HashMap<WaypointID, GraphNode<Waypoint2D>> allNodes, FileHandlerInterface fileHandler) {
Mapyst/Mapyst
route_lib/src/com/mapyst/campus/Location.java
// Path: route_lib/src/com/mapyst/route/WaypointID.java // public class WaypointID { // // public final int buildingIndex; // public final int floorIndex; // public final int pointIndex; // // /* // * Constructor: Codes // * // * Parameters: buildingCode - The building code floorCode - The floor code // * floorIndex - The index // */ // public WaypointID(int buildingIndex, int floorIndex, int pointIndex) { // this.buildingIndex = buildingIndex; // this.floorIndex = floorIndex; // this.pointIndex = pointIndex; // } // // public WaypointID() { // this.buildingIndex = -1; // this.floorIndex = -1; // this.pointIndex = -1; // } // // /* // * Function: parseWaypoint // * // * Parameters: // * waypointString - waypoint in the form of "buildingIndex,floorIndex,pointIndex" // * // * Returns: // * The WaypointID for the given string // */ // public static WaypointID parseWaypoint(String waypointString) { // String[] items = waypointString.split(","); // // int buildingIndex = Integer.parseInt(items[0]); // int floorIndex = Integer.parseInt(items[1]); // int pointIndex = Integer.parseInt(items[2]); // // return new WaypointID(buildingIndex, floorIndex, pointIndex); // } // // /* // * Function: equals Tests if two codes are equal // * // * Parameters: obj - The other Codes // * // * Returns: true if the two codes are equal, false otherwise // */ // public boolean equals(Object obj) { // if (!(obj instanceof WaypointID)) // return false; // WaypointID other = (WaypointID) obj; // return this.buildingIndex == other.buildingIndex // && this.floorIndex == other.floorIndex // && this.pointIndex == other.pointIndex; // } // // /* // * Function: hashCode HashCode algorithm from // * http://eternallyconfuzzled.com/tuts/algorithms/jsw_tut_hashing.aspx Bob // * Jenkins' "One-at-a-Time hash" (mostly) // * // * Returns: The hashCode of the Codes // */ // public int hashCode() { // char[] idBytes = { (char) (buildingIndex), (char) (floorIndex), // (char) (pointIndex) }; // it will always be composed of bytes // int hash = 0; // // for (char idByte : idBytes) { // hash += idByte; // hash += (hash << 10); // hash ^= (hash >> 6); // } // hash += (hash << 3); // hash ^= (hash >> 11); // hash += (hash << 15); // // return hash; // take the id and multiply it by a large prime // } // // public int getPointIndex() { // return this.pointIndex; // } // // public int getFloorIndex() { // return this.floorIndex; // } // // public int getBuildingIndex() { // return this.buildingIndex; // } // // public String toString() { // return "" + buildingIndex + "," + floorIndex + "," + pointIndex + ""; // } // }
import com.mapyst.route.WaypointID;
/* * Copyright (C) 2013 Mapyst * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.mapyst.campus; public class Location { public String[] names; //all possible names the location goes by
// Path: route_lib/src/com/mapyst/route/WaypointID.java // public class WaypointID { // // public final int buildingIndex; // public final int floorIndex; // public final int pointIndex; // // /* // * Constructor: Codes // * // * Parameters: buildingCode - The building code floorCode - The floor code // * floorIndex - The index // */ // public WaypointID(int buildingIndex, int floorIndex, int pointIndex) { // this.buildingIndex = buildingIndex; // this.floorIndex = floorIndex; // this.pointIndex = pointIndex; // } // // public WaypointID() { // this.buildingIndex = -1; // this.floorIndex = -1; // this.pointIndex = -1; // } // // /* // * Function: parseWaypoint // * // * Parameters: // * waypointString - waypoint in the form of "buildingIndex,floorIndex,pointIndex" // * // * Returns: // * The WaypointID for the given string // */ // public static WaypointID parseWaypoint(String waypointString) { // String[] items = waypointString.split(","); // // int buildingIndex = Integer.parseInt(items[0]); // int floorIndex = Integer.parseInt(items[1]); // int pointIndex = Integer.parseInt(items[2]); // // return new WaypointID(buildingIndex, floorIndex, pointIndex); // } // // /* // * Function: equals Tests if two codes are equal // * // * Parameters: obj - The other Codes // * // * Returns: true if the two codes are equal, false otherwise // */ // public boolean equals(Object obj) { // if (!(obj instanceof WaypointID)) // return false; // WaypointID other = (WaypointID) obj; // return this.buildingIndex == other.buildingIndex // && this.floorIndex == other.floorIndex // && this.pointIndex == other.pointIndex; // } // // /* // * Function: hashCode HashCode algorithm from // * http://eternallyconfuzzled.com/tuts/algorithms/jsw_tut_hashing.aspx Bob // * Jenkins' "One-at-a-Time hash" (mostly) // * // * Returns: The hashCode of the Codes // */ // public int hashCode() { // char[] idBytes = { (char) (buildingIndex), (char) (floorIndex), // (char) (pointIndex) }; // it will always be composed of bytes // int hash = 0; // // for (char idByte : idBytes) { // hash += idByte; // hash += (hash << 10); // hash ^= (hash >> 6); // } // hash += (hash << 3); // hash ^= (hash >> 11); // hash += (hash << 15); // // return hash; // take the id and multiply it by a large prime // } // // public int getPointIndex() { // return this.pointIndex; // } // // public int getFloorIndex() { // return this.floorIndex; // } // // public int getBuildingIndex() { // return this.buildingIndex; // } // // public String toString() { // return "" + buildingIndex + "," + floorIndex + "," + pointIndex + ""; // } // } // Path: route_lib/src/com/mapyst/campus/Location.java import com.mapyst.route.WaypointID; /* * Copyright (C) 2013 Mapyst * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.mapyst.campus; public class Location { public String[] names; //all possible names the location goes by
public WaypointID[] waypoints;
bluejoe2008/elfinder-2.x-servlet
src/main/java/org/grapheco/elfinder/localfs/LocalFsItem.java
// Path: src/main/java/org/grapheco/elfinder/service/FsItem.java // public interface FsItem // { // FsVolume getVolume(); // } // // Path: src/main/java/org/grapheco/elfinder/service/FsVolume.java // public interface FsVolume // { // void createFile(FsItem fsi) throws IOException; // // void createFolder(FsItem fsi) throws IOException; // // void deleteFile(FsItem fsi) throws IOException; // // void deleteFolder(FsItem fsi) throws IOException; // // boolean exists(FsItem newFile); // // FsItem fromPath(String relativePath); // // String getDimensions(FsItem fsi); // // long getLastModified(FsItem fsi); // // String getMimeType(FsItem fsi); // // String getName(); // // String getName(FsItem fsi); // // FsItem getParent(FsItem fsi); // // String getPath(FsItem fsi) throws IOException; // // FsItem getRoot(); // // long getSize(FsItem fsi) throws IOException; // // String getThumbnailFileName(FsItem fsi); // // boolean hasChildFolder(FsItem fsi); // // boolean isFolder(FsItem fsi); // // boolean isRoot(FsItem fsi); // // FsItem[] listChildren(FsItem fsi); // // InputStream openInputStream(FsItem fsi) throws IOException; // // void writeStream(FsItem f, InputStream is) throws IOException; // // void rename(FsItem src, FsItem dst) throws IOException; // // /** // * Gets the URL for the supplied item. // * // * @param f // * The item to get the URL for. // * @return An absolute URL or <code>null</code> if we should not send back a // * URL. // */ // String getURL(FsItem f); // // /** // * This allows volumes to change the options returned to the client for a // * particular item. Implementations should update the map they are passed. // * // * @param f // * The item to filter the options for. // * @param map // * The options that are going to be returned. // */ // void filterOptions(FsItem f, Map<String, Object> map); // }
import java.io.File; import org.grapheco.elfinder.service.FsItem; import org.grapheco.elfinder.service.FsVolume;
package org.grapheco.elfinder.localfs; public class LocalFsItem implements FsItem { File _file;
// Path: src/main/java/org/grapheco/elfinder/service/FsItem.java // public interface FsItem // { // FsVolume getVolume(); // } // // Path: src/main/java/org/grapheco/elfinder/service/FsVolume.java // public interface FsVolume // { // void createFile(FsItem fsi) throws IOException; // // void createFolder(FsItem fsi) throws IOException; // // void deleteFile(FsItem fsi) throws IOException; // // void deleteFolder(FsItem fsi) throws IOException; // // boolean exists(FsItem newFile); // // FsItem fromPath(String relativePath); // // String getDimensions(FsItem fsi); // // long getLastModified(FsItem fsi); // // String getMimeType(FsItem fsi); // // String getName(); // // String getName(FsItem fsi); // // FsItem getParent(FsItem fsi); // // String getPath(FsItem fsi) throws IOException; // // FsItem getRoot(); // // long getSize(FsItem fsi) throws IOException; // // String getThumbnailFileName(FsItem fsi); // // boolean hasChildFolder(FsItem fsi); // // boolean isFolder(FsItem fsi); // // boolean isRoot(FsItem fsi); // // FsItem[] listChildren(FsItem fsi); // // InputStream openInputStream(FsItem fsi) throws IOException; // // void writeStream(FsItem f, InputStream is) throws IOException; // // void rename(FsItem src, FsItem dst) throws IOException; // // /** // * Gets the URL for the supplied item. // * // * @param f // * The item to get the URL for. // * @return An absolute URL or <code>null</code> if we should not send back a // * URL. // */ // String getURL(FsItem f); // // /** // * This allows volumes to change the options returned to the client for a // * particular item. Implementations should update the map they are passed. // * // * @param f // * The item to filter the options for. // * @param map // * The options that are going to be returned. // */ // void filterOptions(FsItem f, Map<String, Object> map); // } // Path: src/main/java/org/grapheco/elfinder/localfs/LocalFsItem.java import java.io.File; import org.grapheco.elfinder.service.FsItem; import org.grapheco.elfinder.service.FsVolume; package org.grapheco.elfinder.localfs; public class LocalFsItem implements FsItem { File _file;
FsVolume _volume;
bluejoe2008/elfinder-2.x-servlet
src/main/java/org/grapheco/elfinder/impl/StaticFsServiceFactory.java
// Path: src/main/java/org/grapheco/elfinder/service/FsService.java // public interface FsService // { // FsItem fromHash(String hash) throws IOException; // // String getHash(FsItem item) throws IOException; // // FsSecurityChecker getSecurityChecker(); // // String getVolumeId(FsVolume volume); // // FsVolume[] getVolumes(); // // FsServiceConfig getServiceConfig(); // // /** // * find files by name pattern, this provides a simple recursively iteration // * based method lucene engines can be introduced to improve it! This // * searches across all volumes. // * // * @param filter // * The filter to apply to select files. // * @return A collection of files that match the filter and gave the root as // * a parent. // */ // // TODO: bad designs: FsItemEx should not used here top level interfaces // // should only know FsItem instead of FsItemEx // FsItemEx[] find(FsItemFilter filter); // } // // Path: src/main/java/org/grapheco/elfinder/service/FsServiceFactory.java // public interface FsServiceFactory // { // /** // * sometimes a FsService should be constructed dynamically according to // * current web request. e.g users may own separated file spaces in a net // * disk service platform, in this case, getFileService() get user principal // * from current request and offers him/her different file view. // * // * @param request // * The current HttpServletRequest. // * @param servletContext // * The servlet context. // * @return The {@link FsService} for the current request. // */ // FsService getFileService(HttpServletRequest request, // ServletContext servletContext); // // }
import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import org.grapheco.elfinder.service.FsService; import org.grapheco.elfinder.service.FsServiceFactory;
package org.grapheco.elfinder.impl; /** * A StaticFsServiceFactory always returns one FsService, despite of whatever it * is requested * * @author bluejoe * */ public class StaticFsServiceFactory implements FsServiceFactory {
// Path: src/main/java/org/grapheco/elfinder/service/FsService.java // public interface FsService // { // FsItem fromHash(String hash) throws IOException; // // String getHash(FsItem item) throws IOException; // // FsSecurityChecker getSecurityChecker(); // // String getVolumeId(FsVolume volume); // // FsVolume[] getVolumes(); // // FsServiceConfig getServiceConfig(); // // /** // * find files by name pattern, this provides a simple recursively iteration // * based method lucene engines can be introduced to improve it! This // * searches across all volumes. // * // * @param filter // * The filter to apply to select files. // * @return A collection of files that match the filter and gave the root as // * a parent. // */ // // TODO: bad designs: FsItemEx should not used here top level interfaces // // should only know FsItem instead of FsItemEx // FsItemEx[] find(FsItemFilter filter); // } // // Path: src/main/java/org/grapheco/elfinder/service/FsServiceFactory.java // public interface FsServiceFactory // { // /** // * sometimes a FsService should be constructed dynamically according to // * current web request. e.g users may own separated file spaces in a net // * disk service platform, in this case, getFileService() get user principal // * from current request and offers him/her different file view. // * // * @param request // * The current HttpServletRequest. // * @param servletContext // * The servlet context. // * @return The {@link FsService} for the current request. // */ // FsService getFileService(HttpServletRequest request, // ServletContext servletContext); // // } // Path: src/main/java/org/grapheco/elfinder/impl/StaticFsServiceFactory.java import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import org.grapheco.elfinder.service.FsService; import org.grapheco.elfinder.service.FsServiceFactory; package org.grapheco.elfinder.impl; /** * A StaticFsServiceFactory always returns one FsService, despite of whatever it * is requested * * @author bluejoe * */ public class StaticFsServiceFactory implements FsServiceFactory {
FsService _fsService;
bluejoe2008/elfinder-2.x-servlet
src/main/java/org/grapheco/elfinder/controller/executor/AbstractCommandExecutor.java
// Path: src/main/java/org/grapheco/elfinder/service/FsItemFilter.java // public interface FsItemFilter // { // // TODO: bad designs: FsItemEx should not used here // // top level interfaces should only know FsItem instead of FsItemEx // public boolean accepts(FsItemEx item); // } // // Path: src/main/java/org/grapheco/elfinder/service/FsService.java // public interface FsService // { // FsItem fromHash(String hash) throws IOException; // // String getHash(FsItem item) throws IOException; // // FsSecurityChecker getSecurityChecker(); // // String getVolumeId(FsVolume volume); // // FsVolume[] getVolumes(); // // FsServiceConfig getServiceConfig(); // // /** // * find files by name pattern, this provides a simple recursively iteration // * based method lucene engines can be introduced to improve it! This // * searches across all volumes. // * // * @param filter // * The filter to apply to select files. // * @return A collection of files that match the filter and gave the root as // * a parent. // */ // // TODO: bad designs: FsItemEx should not used here top level interfaces // // should only know FsItem instead of FsItemEx // FsItemEx[] find(FsItemFilter filter); // } // // Path: src/main/java/org/grapheco/elfinder/util/FsItemFilterUtils.java // public abstract class FsItemFilterUtils // { // public static FsItemFilter FILTER_ALL = new FsItemFilter() // { // @Override // public boolean accepts(FsItemEx item) // { // return true; // } // }; // // public static FsItemFilter FILTER_FOLDER = new FsItemFilter() // { // @Override // public boolean accepts(FsItemEx item) // { // return item.isFolder(); // } // }; // // public static FsItemFilter createFileNameKeywordFilter(final String keyword) // { // return new FsItemFilter() // { // @Override // public boolean accepts(FsItemEx item) // { // return item.getName().contains(keyword); // } // }; // } // // public static FsItemEx[] filterFiles(FsItemEx[] sourceFiles, // FsItemFilter filter) // { // List<FsItemEx> filtered = new ArrayList<FsItemEx>(); // for (FsItemEx file : sourceFiles) // { // if (filter.accepts(file)) // filtered.add(file); // } // // return filtered.toArray(new FsItemEx[0]); // } // // /** // * returns a FsItemFilter according to given mimeFilters // * // * @param mimeFilters // * An array of MIME types, if <code>null</code> no filtering is // * done // * @return A filter that only accepts the supplied MIME types. // */ // public static FsItemFilter createMimeFilter(final String[] mimeFilters) // { // if (mimeFilters == null || mimeFilters.length == 0) // return FILTER_ALL; // // return new FsItemFilter() // { // @Override // public boolean accepts(FsItemEx item) // { // String mimeType = item.getMimeType().toUpperCase(); // // for (String mf : mimeFilters) // { // mf = mf.toUpperCase(); // if (mimeType.startsWith(mf + "/") || mimeType.equals(mf)) // return true; // } // return false; // } // }; // } // // } // // Path: src/main/java/org/grapheco/elfinder/util/FsServiceUtils.java // public abstract class FsServiceUtils // { // public static FsItemEx findItem(FsService fsService, String hash) // throws IOException // { // FsItem fsi = fsService.fromHash(hash); // if (fsi == null) // { // return null; // } // // return new FsItemEx(fsi, fsService); // } // }
import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.log4j.Logger; import org.grapheco.elfinder.service.FsItemFilter; import org.grapheco.elfinder.service.FsService; import org.grapheco.elfinder.util.FsItemFilterUtils; import org.grapheco.elfinder.util.FsServiceUtils;
package org.grapheco.elfinder.controller.executor; public abstract class AbstractCommandExecutor implements CommandExecutor { protected static Logger LOG = Logger .getLogger(AbstractCommandExecutor.class);
// Path: src/main/java/org/grapheco/elfinder/service/FsItemFilter.java // public interface FsItemFilter // { // // TODO: bad designs: FsItemEx should not used here // // top level interfaces should only know FsItem instead of FsItemEx // public boolean accepts(FsItemEx item); // } // // Path: src/main/java/org/grapheco/elfinder/service/FsService.java // public interface FsService // { // FsItem fromHash(String hash) throws IOException; // // String getHash(FsItem item) throws IOException; // // FsSecurityChecker getSecurityChecker(); // // String getVolumeId(FsVolume volume); // // FsVolume[] getVolumes(); // // FsServiceConfig getServiceConfig(); // // /** // * find files by name pattern, this provides a simple recursively iteration // * based method lucene engines can be introduced to improve it! This // * searches across all volumes. // * // * @param filter // * The filter to apply to select files. // * @return A collection of files that match the filter and gave the root as // * a parent. // */ // // TODO: bad designs: FsItemEx should not used here top level interfaces // // should only know FsItem instead of FsItemEx // FsItemEx[] find(FsItemFilter filter); // } // // Path: src/main/java/org/grapheco/elfinder/util/FsItemFilterUtils.java // public abstract class FsItemFilterUtils // { // public static FsItemFilter FILTER_ALL = new FsItemFilter() // { // @Override // public boolean accepts(FsItemEx item) // { // return true; // } // }; // // public static FsItemFilter FILTER_FOLDER = new FsItemFilter() // { // @Override // public boolean accepts(FsItemEx item) // { // return item.isFolder(); // } // }; // // public static FsItemFilter createFileNameKeywordFilter(final String keyword) // { // return new FsItemFilter() // { // @Override // public boolean accepts(FsItemEx item) // { // return item.getName().contains(keyword); // } // }; // } // // public static FsItemEx[] filterFiles(FsItemEx[] sourceFiles, // FsItemFilter filter) // { // List<FsItemEx> filtered = new ArrayList<FsItemEx>(); // for (FsItemEx file : sourceFiles) // { // if (filter.accepts(file)) // filtered.add(file); // } // // return filtered.toArray(new FsItemEx[0]); // } // // /** // * returns a FsItemFilter according to given mimeFilters // * // * @param mimeFilters // * An array of MIME types, if <code>null</code> no filtering is // * done // * @return A filter that only accepts the supplied MIME types. // */ // public static FsItemFilter createMimeFilter(final String[] mimeFilters) // { // if (mimeFilters == null || mimeFilters.length == 0) // return FILTER_ALL; // // return new FsItemFilter() // { // @Override // public boolean accepts(FsItemEx item) // { // String mimeType = item.getMimeType().toUpperCase(); // // for (String mf : mimeFilters) // { // mf = mf.toUpperCase(); // if (mimeType.startsWith(mf + "/") || mimeType.equals(mf)) // return true; // } // return false; // } // }; // } // // } // // Path: src/main/java/org/grapheco/elfinder/util/FsServiceUtils.java // public abstract class FsServiceUtils // { // public static FsItemEx findItem(FsService fsService, String hash) // throws IOException // { // FsItem fsi = fsService.fromHash(hash); // if (fsi == null) // { // return null; // } // // return new FsItemEx(fsi, fsService); // } // } // Path: src/main/java/org/grapheco/elfinder/controller/executor/AbstractCommandExecutor.java import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.log4j.Logger; import org.grapheco.elfinder.service.FsItemFilter; import org.grapheco.elfinder.service.FsService; import org.grapheco.elfinder.util.FsItemFilterUtils; import org.grapheco.elfinder.util.FsServiceUtils; package org.grapheco.elfinder.controller.executor; public abstract class AbstractCommandExecutor implements CommandExecutor { protected static Logger LOG = Logger .getLogger(AbstractCommandExecutor.class);
protected FsItemFilter getRequestedFilter(HttpServletRequest request)
bluejoe2008/elfinder-2.x-servlet
src/main/java/org/grapheco/elfinder/controller/executor/AbstractCommandExecutor.java
// Path: src/main/java/org/grapheco/elfinder/service/FsItemFilter.java // public interface FsItemFilter // { // // TODO: bad designs: FsItemEx should not used here // // top level interfaces should only know FsItem instead of FsItemEx // public boolean accepts(FsItemEx item); // } // // Path: src/main/java/org/grapheco/elfinder/service/FsService.java // public interface FsService // { // FsItem fromHash(String hash) throws IOException; // // String getHash(FsItem item) throws IOException; // // FsSecurityChecker getSecurityChecker(); // // String getVolumeId(FsVolume volume); // // FsVolume[] getVolumes(); // // FsServiceConfig getServiceConfig(); // // /** // * find files by name pattern, this provides a simple recursively iteration // * based method lucene engines can be introduced to improve it! This // * searches across all volumes. // * // * @param filter // * The filter to apply to select files. // * @return A collection of files that match the filter and gave the root as // * a parent. // */ // // TODO: bad designs: FsItemEx should not used here top level interfaces // // should only know FsItem instead of FsItemEx // FsItemEx[] find(FsItemFilter filter); // } // // Path: src/main/java/org/grapheco/elfinder/util/FsItemFilterUtils.java // public abstract class FsItemFilterUtils // { // public static FsItemFilter FILTER_ALL = new FsItemFilter() // { // @Override // public boolean accepts(FsItemEx item) // { // return true; // } // }; // // public static FsItemFilter FILTER_FOLDER = new FsItemFilter() // { // @Override // public boolean accepts(FsItemEx item) // { // return item.isFolder(); // } // }; // // public static FsItemFilter createFileNameKeywordFilter(final String keyword) // { // return new FsItemFilter() // { // @Override // public boolean accepts(FsItemEx item) // { // return item.getName().contains(keyword); // } // }; // } // // public static FsItemEx[] filterFiles(FsItemEx[] sourceFiles, // FsItemFilter filter) // { // List<FsItemEx> filtered = new ArrayList<FsItemEx>(); // for (FsItemEx file : sourceFiles) // { // if (filter.accepts(file)) // filtered.add(file); // } // // return filtered.toArray(new FsItemEx[0]); // } // // /** // * returns a FsItemFilter according to given mimeFilters // * // * @param mimeFilters // * An array of MIME types, if <code>null</code> no filtering is // * done // * @return A filter that only accepts the supplied MIME types. // */ // public static FsItemFilter createMimeFilter(final String[] mimeFilters) // { // if (mimeFilters == null || mimeFilters.length == 0) // return FILTER_ALL; // // return new FsItemFilter() // { // @Override // public boolean accepts(FsItemEx item) // { // String mimeType = item.getMimeType().toUpperCase(); // // for (String mf : mimeFilters) // { // mf = mf.toUpperCase(); // if (mimeType.startsWith(mf + "/") || mimeType.equals(mf)) // return true; // } // return false; // } // }; // } // // } // // Path: src/main/java/org/grapheco/elfinder/util/FsServiceUtils.java // public abstract class FsServiceUtils // { // public static FsItemEx findItem(FsService fsService, String hash) // throws IOException // { // FsItem fsi = fsService.fromHash(hash); // if (fsi == null) // { // return null; // } // // return new FsItemEx(fsi, fsService); // } // }
import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.log4j.Logger; import org.grapheco.elfinder.service.FsItemFilter; import org.grapheco.elfinder.service.FsService; import org.grapheco.elfinder.util.FsItemFilterUtils; import org.grapheco.elfinder.util.FsServiceUtils;
package org.grapheco.elfinder.controller.executor; public abstract class AbstractCommandExecutor implements CommandExecutor { protected static Logger LOG = Logger .getLogger(AbstractCommandExecutor.class); protected FsItemFilter getRequestedFilter(HttpServletRequest request) { String[] onlyMimes = request.getParameterValues("mimes[]"); if (onlyMimes == null)
// Path: src/main/java/org/grapheco/elfinder/service/FsItemFilter.java // public interface FsItemFilter // { // // TODO: bad designs: FsItemEx should not used here // // top level interfaces should only know FsItem instead of FsItemEx // public boolean accepts(FsItemEx item); // } // // Path: src/main/java/org/grapheco/elfinder/service/FsService.java // public interface FsService // { // FsItem fromHash(String hash) throws IOException; // // String getHash(FsItem item) throws IOException; // // FsSecurityChecker getSecurityChecker(); // // String getVolumeId(FsVolume volume); // // FsVolume[] getVolumes(); // // FsServiceConfig getServiceConfig(); // // /** // * find files by name pattern, this provides a simple recursively iteration // * based method lucene engines can be introduced to improve it! This // * searches across all volumes. // * // * @param filter // * The filter to apply to select files. // * @return A collection of files that match the filter and gave the root as // * a parent. // */ // // TODO: bad designs: FsItemEx should not used here top level interfaces // // should only know FsItem instead of FsItemEx // FsItemEx[] find(FsItemFilter filter); // } // // Path: src/main/java/org/grapheco/elfinder/util/FsItemFilterUtils.java // public abstract class FsItemFilterUtils // { // public static FsItemFilter FILTER_ALL = new FsItemFilter() // { // @Override // public boolean accepts(FsItemEx item) // { // return true; // } // }; // // public static FsItemFilter FILTER_FOLDER = new FsItemFilter() // { // @Override // public boolean accepts(FsItemEx item) // { // return item.isFolder(); // } // }; // // public static FsItemFilter createFileNameKeywordFilter(final String keyword) // { // return new FsItemFilter() // { // @Override // public boolean accepts(FsItemEx item) // { // return item.getName().contains(keyword); // } // }; // } // // public static FsItemEx[] filterFiles(FsItemEx[] sourceFiles, // FsItemFilter filter) // { // List<FsItemEx> filtered = new ArrayList<FsItemEx>(); // for (FsItemEx file : sourceFiles) // { // if (filter.accepts(file)) // filtered.add(file); // } // // return filtered.toArray(new FsItemEx[0]); // } // // /** // * returns a FsItemFilter according to given mimeFilters // * // * @param mimeFilters // * An array of MIME types, if <code>null</code> no filtering is // * done // * @return A filter that only accepts the supplied MIME types. // */ // public static FsItemFilter createMimeFilter(final String[] mimeFilters) // { // if (mimeFilters == null || mimeFilters.length == 0) // return FILTER_ALL; // // return new FsItemFilter() // { // @Override // public boolean accepts(FsItemEx item) // { // String mimeType = item.getMimeType().toUpperCase(); // // for (String mf : mimeFilters) // { // mf = mf.toUpperCase(); // if (mimeType.startsWith(mf + "/") || mimeType.equals(mf)) // return true; // } // return false; // } // }; // } // // } // // Path: src/main/java/org/grapheco/elfinder/util/FsServiceUtils.java // public abstract class FsServiceUtils // { // public static FsItemEx findItem(FsService fsService, String hash) // throws IOException // { // FsItem fsi = fsService.fromHash(hash); // if (fsi == null) // { // return null; // } // // return new FsItemEx(fsi, fsService); // } // } // Path: src/main/java/org/grapheco/elfinder/controller/executor/AbstractCommandExecutor.java import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.log4j.Logger; import org.grapheco.elfinder.service.FsItemFilter; import org.grapheco.elfinder.service.FsService; import org.grapheco.elfinder.util.FsItemFilterUtils; import org.grapheco.elfinder.util.FsServiceUtils; package org.grapheco.elfinder.controller.executor; public abstract class AbstractCommandExecutor implements CommandExecutor { protected static Logger LOG = Logger .getLogger(AbstractCommandExecutor.class); protected FsItemFilter getRequestedFilter(HttpServletRequest request) { String[] onlyMimes = request.getParameterValues("mimes[]"); if (onlyMimes == null)
return FsItemFilterUtils.FILTER_ALL;
bluejoe2008/elfinder-2.x-servlet
src/main/java/org/grapheco/elfinder/controller/executor/AbstractCommandExecutor.java
// Path: src/main/java/org/grapheco/elfinder/service/FsItemFilter.java // public interface FsItemFilter // { // // TODO: bad designs: FsItemEx should not used here // // top level interfaces should only know FsItem instead of FsItemEx // public boolean accepts(FsItemEx item); // } // // Path: src/main/java/org/grapheco/elfinder/service/FsService.java // public interface FsService // { // FsItem fromHash(String hash) throws IOException; // // String getHash(FsItem item) throws IOException; // // FsSecurityChecker getSecurityChecker(); // // String getVolumeId(FsVolume volume); // // FsVolume[] getVolumes(); // // FsServiceConfig getServiceConfig(); // // /** // * find files by name pattern, this provides a simple recursively iteration // * based method lucene engines can be introduced to improve it! This // * searches across all volumes. // * // * @param filter // * The filter to apply to select files. // * @return A collection of files that match the filter and gave the root as // * a parent. // */ // // TODO: bad designs: FsItemEx should not used here top level interfaces // // should only know FsItem instead of FsItemEx // FsItemEx[] find(FsItemFilter filter); // } // // Path: src/main/java/org/grapheco/elfinder/util/FsItemFilterUtils.java // public abstract class FsItemFilterUtils // { // public static FsItemFilter FILTER_ALL = new FsItemFilter() // { // @Override // public boolean accepts(FsItemEx item) // { // return true; // } // }; // // public static FsItemFilter FILTER_FOLDER = new FsItemFilter() // { // @Override // public boolean accepts(FsItemEx item) // { // return item.isFolder(); // } // }; // // public static FsItemFilter createFileNameKeywordFilter(final String keyword) // { // return new FsItemFilter() // { // @Override // public boolean accepts(FsItemEx item) // { // return item.getName().contains(keyword); // } // }; // } // // public static FsItemEx[] filterFiles(FsItemEx[] sourceFiles, // FsItemFilter filter) // { // List<FsItemEx> filtered = new ArrayList<FsItemEx>(); // for (FsItemEx file : sourceFiles) // { // if (filter.accepts(file)) // filtered.add(file); // } // // return filtered.toArray(new FsItemEx[0]); // } // // /** // * returns a FsItemFilter according to given mimeFilters // * // * @param mimeFilters // * An array of MIME types, if <code>null</code> no filtering is // * done // * @return A filter that only accepts the supplied MIME types. // */ // public static FsItemFilter createMimeFilter(final String[] mimeFilters) // { // if (mimeFilters == null || mimeFilters.length == 0) // return FILTER_ALL; // // return new FsItemFilter() // { // @Override // public boolean accepts(FsItemEx item) // { // String mimeType = item.getMimeType().toUpperCase(); // // for (String mf : mimeFilters) // { // mf = mf.toUpperCase(); // if (mimeType.startsWith(mf + "/") || mimeType.equals(mf)) // return true; // } // return false; // } // }; // } // // } // // Path: src/main/java/org/grapheco/elfinder/util/FsServiceUtils.java // public abstract class FsServiceUtils // { // public static FsItemEx findItem(FsService fsService, String hash) // throws IOException // { // FsItem fsi = fsService.fromHash(hash); // if (fsi == null) // { // return null; // } // // return new FsItemEx(fsi, fsService); // } // }
import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.log4j.Logger; import org.grapheco.elfinder.service.FsItemFilter; import org.grapheco.elfinder.service.FsService; import org.grapheco.elfinder.util.FsItemFilterUtils; import org.grapheco.elfinder.util.FsServiceUtils;
protected void createAndCopyFile(FsItemEx src, FsItemEx dst) throws IOException { dst.createFile(); InputStream is = src.openInputStream(); dst.writeStream(is); } protected void createAndCopyFolder(FsItemEx src, FsItemEx dst) throws IOException { dst.createFolder(); for (FsItemEx c : src.listChildren()) { if (c.isFolder()) { createAndCopyFolder(c, new FsItemEx(dst, c.getName())); } else { createAndCopyFile(c, new FsItemEx(dst, c.getName())); } } } @Override public void execute(CommandExecutionContext ctx) throws Exception {
// Path: src/main/java/org/grapheco/elfinder/service/FsItemFilter.java // public interface FsItemFilter // { // // TODO: bad designs: FsItemEx should not used here // // top level interfaces should only know FsItem instead of FsItemEx // public boolean accepts(FsItemEx item); // } // // Path: src/main/java/org/grapheco/elfinder/service/FsService.java // public interface FsService // { // FsItem fromHash(String hash) throws IOException; // // String getHash(FsItem item) throws IOException; // // FsSecurityChecker getSecurityChecker(); // // String getVolumeId(FsVolume volume); // // FsVolume[] getVolumes(); // // FsServiceConfig getServiceConfig(); // // /** // * find files by name pattern, this provides a simple recursively iteration // * based method lucene engines can be introduced to improve it! This // * searches across all volumes. // * // * @param filter // * The filter to apply to select files. // * @return A collection of files that match the filter and gave the root as // * a parent. // */ // // TODO: bad designs: FsItemEx should not used here top level interfaces // // should only know FsItem instead of FsItemEx // FsItemEx[] find(FsItemFilter filter); // } // // Path: src/main/java/org/grapheco/elfinder/util/FsItemFilterUtils.java // public abstract class FsItemFilterUtils // { // public static FsItemFilter FILTER_ALL = new FsItemFilter() // { // @Override // public boolean accepts(FsItemEx item) // { // return true; // } // }; // // public static FsItemFilter FILTER_FOLDER = new FsItemFilter() // { // @Override // public boolean accepts(FsItemEx item) // { // return item.isFolder(); // } // }; // // public static FsItemFilter createFileNameKeywordFilter(final String keyword) // { // return new FsItemFilter() // { // @Override // public boolean accepts(FsItemEx item) // { // return item.getName().contains(keyword); // } // }; // } // // public static FsItemEx[] filterFiles(FsItemEx[] sourceFiles, // FsItemFilter filter) // { // List<FsItemEx> filtered = new ArrayList<FsItemEx>(); // for (FsItemEx file : sourceFiles) // { // if (filter.accepts(file)) // filtered.add(file); // } // // return filtered.toArray(new FsItemEx[0]); // } // // /** // * returns a FsItemFilter according to given mimeFilters // * // * @param mimeFilters // * An array of MIME types, if <code>null</code> no filtering is // * done // * @return A filter that only accepts the supplied MIME types. // */ // public static FsItemFilter createMimeFilter(final String[] mimeFilters) // { // if (mimeFilters == null || mimeFilters.length == 0) // return FILTER_ALL; // // return new FsItemFilter() // { // @Override // public boolean accepts(FsItemEx item) // { // String mimeType = item.getMimeType().toUpperCase(); // // for (String mf : mimeFilters) // { // mf = mf.toUpperCase(); // if (mimeType.startsWith(mf + "/") || mimeType.equals(mf)) // return true; // } // return false; // } // }; // } // // } // // Path: src/main/java/org/grapheco/elfinder/util/FsServiceUtils.java // public abstract class FsServiceUtils // { // public static FsItemEx findItem(FsService fsService, String hash) // throws IOException // { // FsItem fsi = fsService.fromHash(hash); // if (fsi == null) // { // return null; // } // // return new FsItemEx(fsi, fsService); // } // } // Path: src/main/java/org/grapheco/elfinder/controller/executor/AbstractCommandExecutor.java import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.log4j.Logger; import org.grapheco.elfinder.service.FsItemFilter; import org.grapheco.elfinder.service.FsService; import org.grapheco.elfinder.util.FsItemFilterUtils; import org.grapheco.elfinder.util.FsServiceUtils; protected void createAndCopyFile(FsItemEx src, FsItemEx dst) throws IOException { dst.createFile(); InputStream is = src.openInputStream(); dst.writeStream(is); } protected void createAndCopyFolder(FsItemEx src, FsItemEx dst) throws IOException { dst.createFolder(); for (FsItemEx c : src.listChildren()) { if (c.isFolder()) { createAndCopyFolder(c, new FsItemEx(dst, c.getName())); } else { createAndCopyFile(c, new FsItemEx(dst, c.getName())); } } } @Override public void execute(CommandExecutionContext ctx) throws Exception {
FsService fileService = ctx.getFsServiceFactory().getFileService(
bluejoe2008/elfinder-2.x-servlet
src/main/java/org/grapheco/elfinder/controller/executor/AbstractCommandExecutor.java
// Path: src/main/java/org/grapheco/elfinder/service/FsItemFilter.java // public interface FsItemFilter // { // // TODO: bad designs: FsItemEx should not used here // // top level interfaces should only know FsItem instead of FsItemEx // public boolean accepts(FsItemEx item); // } // // Path: src/main/java/org/grapheco/elfinder/service/FsService.java // public interface FsService // { // FsItem fromHash(String hash) throws IOException; // // String getHash(FsItem item) throws IOException; // // FsSecurityChecker getSecurityChecker(); // // String getVolumeId(FsVolume volume); // // FsVolume[] getVolumes(); // // FsServiceConfig getServiceConfig(); // // /** // * find files by name pattern, this provides a simple recursively iteration // * based method lucene engines can be introduced to improve it! This // * searches across all volumes. // * // * @param filter // * The filter to apply to select files. // * @return A collection of files that match the filter and gave the root as // * a parent. // */ // // TODO: bad designs: FsItemEx should not used here top level interfaces // // should only know FsItem instead of FsItemEx // FsItemEx[] find(FsItemFilter filter); // } // // Path: src/main/java/org/grapheco/elfinder/util/FsItemFilterUtils.java // public abstract class FsItemFilterUtils // { // public static FsItemFilter FILTER_ALL = new FsItemFilter() // { // @Override // public boolean accepts(FsItemEx item) // { // return true; // } // }; // // public static FsItemFilter FILTER_FOLDER = new FsItemFilter() // { // @Override // public boolean accepts(FsItemEx item) // { // return item.isFolder(); // } // }; // // public static FsItemFilter createFileNameKeywordFilter(final String keyword) // { // return new FsItemFilter() // { // @Override // public boolean accepts(FsItemEx item) // { // return item.getName().contains(keyword); // } // }; // } // // public static FsItemEx[] filterFiles(FsItemEx[] sourceFiles, // FsItemFilter filter) // { // List<FsItemEx> filtered = new ArrayList<FsItemEx>(); // for (FsItemEx file : sourceFiles) // { // if (filter.accepts(file)) // filtered.add(file); // } // // return filtered.toArray(new FsItemEx[0]); // } // // /** // * returns a FsItemFilter according to given mimeFilters // * // * @param mimeFilters // * An array of MIME types, if <code>null</code> no filtering is // * done // * @return A filter that only accepts the supplied MIME types. // */ // public static FsItemFilter createMimeFilter(final String[] mimeFilters) // { // if (mimeFilters == null || mimeFilters.length == 0) // return FILTER_ALL; // // return new FsItemFilter() // { // @Override // public boolean accepts(FsItemEx item) // { // String mimeType = item.getMimeType().toUpperCase(); // // for (String mf : mimeFilters) // { // mf = mf.toUpperCase(); // if (mimeType.startsWith(mf + "/") || mimeType.equals(mf)) // return true; // } // return false; // } // }; // } // // } // // Path: src/main/java/org/grapheco/elfinder/util/FsServiceUtils.java // public abstract class FsServiceUtils // { // public static FsItemEx findItem(FsService fsService, String hash) // throws IOException // { // FsItem fsi = fsService.fromHash(hash); // if (fsi == null) // { // return null; // } // // return new FsItemEx(fsi, fsService); // } // }
import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.log4j.Logger; import org.grapheco.elfinder.service.FsItemFilter; import org.grapheco.elfinder.service.FsService; import org.grapheco.elfinder.util.FsItemFilterUtils; import org.grapheco.elfinder.util.FsServiceUtils;
FsItemEx[] list) throws IOException { List<Map<String, Object>> los = new ArrayList<Map<String, Object>>(); for (FsItemEx fi : list) { los.add(getFsItemInfo(request, fi)); } return los.toArray(); } protected FsItemEx findCwd(FsService fsService, String target) throws IOException { // current selected directory FsItemEx cwd = null; if (target != null) { cwd = findItem(fsService, target); } if (cwd == null) cwd = new FsItemEx(fsService.getVolumes()[0].getRoot(), fsService); return cwd; } protected FsItemEx findItem(FsService fsService, String hash) throws IOException {
// Path: src/main/java/org/grapheco/elfinder/service/FsItemFilter.java // public interface FsItemFilter // { // // TODO: bad designs: FsItemEx should not used here // // top level interfaces should only know FsItem instead of FsItemEx // public boolean accepts(FsItemEx item); // } // // Path: src/main/java/org/grapheco/elfinder/service/FsService.java // public interface FsService // { // FsItem fromHash(String hash) throws IOException; // // String getHash(FsItem item) throws IOException; // // FsSecurityChecker getSecurityChecker(); // // String getVolumeId(FsVolume volume); // // FsVolume[] getVolumes(); // // FsServiceConfig getServiceConfig(); // // /** // * find files by name pattern, this provides a simple recursively iteration // * based method lucene engines can be introduced to improve it! This // * searches across all volumes. // * // * @param filter // * The filter to apply to select files. // * @return A collection of files that match the filter and gave the root as // * a parent. // */ // // TODO: bad designs: FsItemEx should not used here top level interfaces // // should only know FsItem instead of FsItemEx // FsItemEx[] find(FsItemFilter filter); // } // // Path: src/main/java/org/grapheco/elfinder/util/FsItemFilterUtils.java // public abstract class FsItemFilterUtils // { // public static FsItemFilter FILTER_ALL = new FsItemFilter() // { // @Override // public boolean accepts(FsItemEx item) // { // return true; // } // }; // // public static FsItemFilter FILTER_FOLDER = new FsItemFilter() // { // @Override // public boolean accepts(FsItemEx item) // { // return item.isFolder(); // } // }; // // public static FsItemFilter createFileNameKeywordFilter(final String keyword) // { // return new FsItemFilter() // { // @Override // public boolean accepts(FsItemEx item) // { // return item.getName().contains(keyword); // } // }; // } // // public static FsItemEx[] filterFiles(FsItemEx[] sourceFiles, // FsItemFilter filter) // { // List<FsItemEx> filtered = new ArrayList<FsItemEx>(); // for (FsItemEx file : sourceFiles) // { // if (filter.accepts(file)) // filtered.add(file); // } // // return filtered.toArray(new FsItemEx[0]); // } // // /** // * returns a FsItemFilter according to given mimeFilters // * // * @param mimeFilters // * An array of MIME types, if <code>null</code> no filtering is // * done // * @return A filter that only accepts the supplied MIME types. // */ // public static FsItemFilter createMimeFilter(final String[] mimeFilters) // { // if (mimeFilters == null || mimeFilters.length == 0) // return FILTER_ALL; // // return new FsItemFilter() // { // @Override // public boolean accepts(FsItemEx item) // { // String mimeType = item.getMimeType().toUpperCase(); // // for (String mf : mimeFilters) // { // mf = mf.toUpperCase(); // if (mimeType.startsWith(mf + "/") || mimeType.equals(mf)) // return true; // } // return false; // } // }; // } // // } // // Path: src/main/java/org/grapheco/elfinder/util/FsServiceUtils.java // public abstract class FsServiceUtils // { // public static FsItemEx findItem(FsService fsService, String hash) // throws IOException // { // FsItem fsi = fsService.fromHash(hash); // if (fsi == null) // { // return null; // } // // return new FsItemEx(fsi, fsService); // } // } // Path: src/main/java/org/grapheco/elfinder/controller/executor/AbstractCommandExecutor.java import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.log4j.Logger; import org.grapheco.elfinder.service.FsItemFilter; import org.grapheco.elfinder.service.FsService; import org.grapheco.elfinder.util.FsItemFilterUtils; import org.grapheco.elfinder.util.FsServiceUtils; FsItemEx[] list) throws IOException { List<Map<String, Object>> los = new ArrayList<Map<String, Object>>(); for (FsItemEx fi : list) { los.add(getFsItemInfo(request, fi)); } return los.toArray(); } protected FsItemEx findCwd(FsService fsService, String target) throws IOException { // current selected directory FsItemEx cwd = null; if (target != null) { cwd = findItem(fsService, target); } if (cwd == null) cwd = new FsItemEx(fsService.getVolumes()[0].getRoot(), fsService); return cwd; } protected FsItemEx findItem(FsService fsService, String hash) throws IOException {
return FsServiceUtils.findItem(fsService, hash);
bluejoe2008/elfinder-2.x-servlet
src/main/java/org/grapheco/elfinder/controller/ConnectorController.java
// Path: src/main/java/org/grapheco/elfinder/controller/executor/CommandExecutionContext.java // public interface CommandExecutionContext // { // FsServiceFactory getFsServiceFactory(); // // HttpServletRequest getRequest(); // // HttpServletResponse getResponse(); // // ServletContext getServletContext(); // } // // Path: src/main/java/org/grapheco/elfinder/controller/executor/CommandExecutor.java // public interface CommandExecutor // { // void execute(CommandExecutionContext commandExecutionContext) // throws Exception; // } // // Path: src/main/java/org/grapheco/elfinder/controller/executor/CommandExecutorFactory.java // public interface CommandExecutorFactory // { // CommandExecutor get(String commandName); // } // // Path: src/main/java/org/grapheco/elfinder/service/FsServiceFactory.java // public interface FsServiceFactory // { // /** // * sometimes a FsService should be constructed dynamically according to // * current web request. e.g users may own separated file spaces in a net // * disk service platform, in this case, getFileService() get user principal // * from current request and offers him/her different file view. // * // * @param request // * The current HttpServletRequest. // * @param servletContext // * The servlet context. // * @return The {@link FsService} for the current request. // */ // FsService getFileService(HttpServletRequest request, // ServletContext servletContext); // // }
import org.grapheco.elfinder.controller.executor.CommandExecutionContext; import org.grapheco.elfinder.controller.executor.CommandExecutor; import org.grapheco.elfinder.controller.executor.CommandExecutorFactory; import org.grapheco.elfinder.service.FsServiceFactory; import org.apache.commons.fileupload.FileItemIterator; import org.apache.commons.fileupload.FileItemStream; import org.apache.commons.fileupload.servlet.ServletFileUpload; import org.apache.commons.fileupload.util.Streams; import org.apache.log4j.Logger; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import javax.annotation.Resource; import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.lang.reflect.Proxy; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map;
package org.grapheco.elfinder.controller; @Controller @RequestMapping("connector") public class ConnectorController { Logger _logger = Logger.getLogger(this.getClass()); @Resource(name = "commandExecutorFactory")
// Path: src/main/java/org/grapheco/elfinder/controller/executor/CommandExecutionContext.java // public interface CommandExecutionContext // { // FsServiceFactory getFsServiceFactory(); // // HttpServletRequest getRequest(); // // HttpServletResponse getResponse(); // // ServletContext getServletContext(); // } // // Path: src/main/java/org/grapheco/elfinder/controller/executor/CommandExecutor.java // public interface CommandExecutor // { // void execute(CommandExecutionContext commandExecutionContext) // throws Exception; // } // // Path: src/main/java/org/grapheco/elfinder/controller/executor/CommandExecutorFactory.java // public interface CommandExecutorFactory // { // CommandExecutor get(String commandName); // } // // Path: src/main/java/org/grapheco/elfinder/service/FsServiceFactory.java // public interface FsServiceFactory // { // /** // * sometimes a FsService should be constructed dynamically according to // * current web request. e.g users may own separated file spaces in a net // * disk service platform, in this case, getFileService() get user principal // * from current request and offers him/her different file view. // * // * @param request // * The current HttpServletRequest. // * @param servletContext // * The servlet context. // * @return The {@link FsService} for the current request. // */ // FsService getFileService(HttpServletRequest request, // ServletContext servletContext); // // } // Path: src/main/java/org/grapheco/elfinder/controller/ConnectorController.java import org.grapheco.elfinder.controller.executor.CommandExecutionContext; import org.grapheco.elfinder.controller.executor.CommandExecutor; import org.grapheco.elfinder.controller.executor.CommandExecutorFactory; import org.grapheco.elfinder.service.FsServiceFactory; import org.apache.commons.fileupload.FileItemIterator; import org.apache.commons.fileupload.FileItemStream; import org.apache.commons.fileupload.servlet.ServletFileUpload; import org.apache.commons.fileupload.util.Streams; import org.apache.log4j.Logger; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import javax.annotation.Resource; import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.lang.reflect.Proxy; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; package org.grapheco.elfinder.controller; @Controller @RequestMapping("connector") public class ConnectorController { Logger _logger = Logger.getLogger(this.getClass()); @Resource(name = "commandExecutorFactory")
private CommandExecutorFactory _commandExecutorFactory;
bluejoe2008/elfinder-2.x-servlet
src/main/java/org/grapheco/elfinder/controller/ConnectorController.java
// Path: src/main/java/org/grapheco/elfinder/controller/executor/CommandExecutionContext.java // public interface CommandExecutionContext // { // FsServiceFactory getFsServiceFactory(); // // HttpServletRequest getRequest(); // // HttpServletResponse getResponse(); // // ServletContext getServletContext(); // } // // Path: src/main/java/org/grapheco/elfinder/controller/executor/CommandExecutor.java // public interface CommandExecutor // { // void execute(CommandExecutionContext commandExecutionContext) // throws Exception; // } // // Path: src/main/java/org/grapheco/elfinder/controller/executor/CommandExecutorFactory.java // public interface CommandExecutorFactory // { // CommandExecutor get(String commandName); // } // // Path: src/main/java/org/grapheco/elfinder/service/FsServiceFactory.java // public interface FsServiceFactory // { // /** // * sometimes a FsService should be constructed dynamically according to // * current web request. e.g users may own separated file spaces in a net // * disk service platform, in this case, getFileService() get user principal // * from current request and offers him/her different file view. // * // * @param request // * The current HttpServletRequest. // * @param servletContext // * The servlet context. // * @return The {@link FsService} for the current request. // */ // FsService getFileService(HttpServletRequest request, // ServletContext servletContext); // // }
import org.grapheco.elfinder.controller.executor.CommandExecutionContext; import org.grapheco.elfinder.controller.executor.CommandExecutor; import org.grapheco.elfinder.controller.executor.CommandExecutorFactory; import org.grapheco.elfinder.service.FsServiceFactory; import org.apache.commons.fileupload.FileItemIterator; import org.apache.commons.fileupload.FileItemStream; import org.apache.commons.fileupload.servlet.ServletFileUpload; import org.apache.commons.fileupload.util.Streams; import org.apache.log4j.Logger; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import javax.annotation.Resource; import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.lang.reflect.Proxy; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map;
package org.grapheco.elfinder.controller; @Controller @RequestMapping("connector") public class ConnectorController { Logger _logger = Logger.getLogger(this.getClass()); @Resource(name = "commandExecutorFactory") private CommandExecutorFactory _commandExecutorFactory; @Resource(name = "fsServiceFactory")
// Path: src/main/java/org/grapheco/elfinder/controller/executor/CommandExecutionContext.java // public interface CommandExecutionContext // { // FsServiceFactory getFsServiceFactory(); // // HttpServletRequest getRequest(); // // HttpServletResponse getResponse(); // // ServletContext getServletContext(); // } // // Path: src/main/java/org/grapheco/elfinder/controller/executor/CommandExecutor.java // public interface CommandExecutor // { // void execute(CommandExecutionContext commandExecutionContext) // throws Exception; // } // // Path: src/main/java/org/grapheco/elfinder/controller/executor/CommandExecutorFactory.java // public interface CommandExecutorFactory // { // CommandExecutor get(String commandName); // } // // Path: src/main/java/org/grapheco/elfinder/service/FsServiceFactory.java // public interface FsServiceFactory // { // /** // * sometimes a FsService should be constructed dynamically according to // * current web request. e.g users may own separated file spaces in a net // * disk service platform, in this case, getFileService() get user principal // * from current request and offers him/her different file view. // * // * @param request // * The current HttpServletRequest. // * @param servletContext // * The servlet context. // * @return The {@link FsService} for the current request. // */ // FsService getFileService(HttpServletRequest request, // ServletContext servletContext); // // } // Path: src/main/java/org/grapheco/elfinder/controller/ConnectorController.java import org.grapheco.elfinder.controller.executor.CommandExecutionContext; import org.grapheco.elfinder.controller.executor.CommandExecutor; import org.grapheco.elfinder.controller.executor.CommandExecutorFactory; import org.grapheco.elfinder.service.FsServiceFactory; import org.apache.commons.fileupload.FileItemIterator; import org.apache.commons.fileupload.FileItemStream; import org.apache.commons.fileupload.servlet.ServletFileUpload; import org.apache.commons.fileupload.util.Streams; import org.apache.log4j.Logger; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import javax.annotation.Resource; import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.lang.reflect.Proxy; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; package org.grapheco.elfinder.controller; @Controller @RequestMapping("connector") public class ConnectorController { Logger _logger = Logger.getLogger(this.getClass()); @Resource(name = "commandExecutorFactory") private CommandExecutorFactory _commandExecutorFactory; @Resource(name = "fsServiceFactory")
private FsServiceFactory _fsServiceFactory;
bluejoe2008/elfinder-2.x-servlet
src/main/java/org/grapheco/elfinder/controller/ConnectorController.java
// Path: src/main/java/org/grapheco/elfinder/controller/executor/CommandExecutionContext.java // public interface CommandExecutionContext // { // FsServiceFactory getFsServiceFactory(); // // HttpServletRequest getRequest(); // // HttpServletResponse getResponse(); // // ServletContext getServletContext(); // } // // Path: src/main/java/org/grapheco/elfinder/controller/executor/CommandExecutor.java // public interface CommandExecutor // { // void execute(CommandExecutionContext commandExecutionContext) // throws Exception; // } // // Path: src/main/java/org/grapheco/elfinder/controller/executor/CommandExecutorFactory.java // public interface CommandExecutorFactory // { // CommandExecutor get(String commandName); // } // // Path: src/main/java/org/grapheco/elfinder/service/FsServiceFactory.java // public interface FsServiceFactory // { // /** // * sometimes a FsService should be constructed dynamically according to // * current web request. e.g users may own separated file spaces in a net // * disk service platform, in this case, getFileService() get user principal // * from current request and offers him/her different file view. // * // * @param request // * The current HttpServletRequest. // * @param servletContext // * The servlet context. // * @return The {@link FsService} for the current request. // */ // FsService getFileService(HttpServletRequest request, // ServletContext servletContext); // // }
import org.grapheco.elfinder.controller.executor.CommandExecutionContext; import org.grapheco.elfinder.controller.executor.CommandExecutor; import org.grapheco.elfinder.controller.executor.CommandExecutorFactory; import org.grapheco.elfinder.service.FsServiceFactory; import org.apache.commons.fileupload.FileItemIterator; import org.apache.commons.fileupload.FileItemStream; import org.apache.commons.fileupload.servlet.ServletFileUpload; import org.apache.commons.fileupload.util.Streams; import org.apache.log4j.Logger; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import javax.annotation.Resource; import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.lang.reflect.Proxy; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map;
package org.grapheco.elfinder.controller; @Controller @RequestMapping("connector") public class ConnectorController { Logger _logger = Logger.getLogger(this.getClass()); @Resource(name = "commandExecutorFactory") private CommandExecutorFactory _commandExecutorFactory; @Resource(name = "fsServiceFactory") private FsServiceFactory _fsServiceFactory; private File _tempDir = null; String _tempDirPath = "./tmp"; /** * set temp file dir path, relative path is allowed (web root as base dir) * * @param value */ public void setTempDirPath(String value) { _tempDirPath = value; } @RequestMapping public void connector(HttpServletRequest request, final HttpServletResponse response) throws IOException { try { request = parseMultipartContent(request); } catch (Exception e) { throw new IOException(e.getMessage()); } String cmd = request.getParameter("cmd");
// Path: src/main/java/org/grapheco/elfinder/controller/executor/CommandExecutionContext.java // public interface CommandExecutionContext // { // FsServiceFactory getFsServiceFactory(); // // HttpServletRequest getRequest(); // // HttpServletResponse getResponse(); // // ServletContext getServletContext(); // } // // Path: src/main/java/org/grapheco/elfinder/controller/executor/CommandExecutor.java // public interface CommandExecutor // { // void execute(CommandExecutionContext commandExecutionContext) // throws Exception; // } // // Path: src/main/java/org/grapheco/elfinder/controller/executor/CommandExecutorFactory.java // public interface CommandExecutorFactory // { // CommandExecutor get(String commandName); // } // // Path: src/main/java/org/grapheco/elfinder/service/FsServiceFactory.java // public interface FsServiceFactory // { // /** // * sometimes a FsService should be constructed dynamically according to // * current web request. e.g users may own separated file spaces in a net // * disk service platform, in this case, getFileService() get user principal // * from current request and offers him/her different file view. // * // * @param request // * The current HttpServletRequest. // * @param servletContext // * The servlet context. // * @return The {@link FsService} for the current request. // */ // FsService getFileService(HttpServletRequest request, // ServletContext servletContext); // // } // Path: src/main/java/org/grapheco/elfinder/controller/ConnectorController.java import org.grapheco.elfinder.controller.executor.CommandExecutionContext; import org.grapheco.elfinder.controller.executor.CommandExecutor; import org.grapheco.elfinder.controller.executor.CommandExecutorFactory; import org.grapheco.elfinder.service.FsServiceFactory; import org.apache.commons.fileupload.FileItemIterator; import org.apache.commons.fileupload.FileItemStream; import org.apache.commons.fileupload.servlet.ServletFileUpload; import org.apache.commons.fileupload.util.Streams; import org.apache.log4j.Logger; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import javax.annotation.Resource; import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.lang.reflect.Proxy; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; package org.grapheco.elfinder.controller; @Controller @RequestMapping("connector") public class ConnectorController { Logger _logger = Logger.getLogger(this.getClass()); @Resource(name = "commandExecutorFactory") private CommandExecutorFactory _commandExecutorFactory; @Resource(name = "fsServiceFactory") private FsServiceFactory _fsServiceFactory; private File _tempDir = null; String _tempDirPath = "./tmp"; /** * set temp file dir path, relative path is allowed (web root as base dir) * * @param value */ public void setTempDirPath(String value) { _tempDirPath = value; } @RequestMapping public void connector(HttpServletRequest request, final HttpServletResponse response) throws IOException { try { request = parseMultipartContent(request); } catch (Exception e) { throw new IOException(e.getMessage()); } String cmd = request.getParameter("cmd");
CommandExecutor ce = _commandExecutorFactory.get(cmd);
bluejoe2008/elfinder-2.x-servlet
src/main/java/org/grapheco/elfinder/controller/ConnectorController.java
// Path: src/main/java/org/grapheco/elfinder/controller/executor/CommandExecutionContext.java // public interface CommandExecutionContext // { // FsServiceFactory getFsServiceFactory(); // // HttpServletRequest getRequest(); // // HttpServletResponse getResponse(); // // ServletContext getServletContext(); // } // // Path: src/main/java/org/grapheco/elfinder/controller/executor/CommandExecutor.java // public interface CommandExecutor // { // void execute(CommandExecutionContext commandExecutionContext) // throws Exception; // } // // Path: src/main/java/org/grapheco/elfinder/controller/executor/CommandExecutorFactory.java // public interface CommandExecutorFactory // { // CommandExecutor get(String commandName); // } // // Path: src/main/java/org/grapheco/elfinder/service/FsServiceFactory.java // public interface FsServiceFactory // { // /** // * sometimes a FsService should be constructed dynamically according to // * current web request. e.g users may own separated file spaces in a net // * disk service platform, in this case, getFileService() get user principal // * from current request and offers him/her different file view. // * // * @param request // * The current HttpServletRequest. // * @param servletContext // * The servlet context. // * @return The {@link FsService} for the current request. // */ // FsService getFileService(HttpServletRequest request, // ServletContext servletContext); // // }
import org.grapheco.elfinder.controller.executor.CommandExecutionContext; import org.grapheco.elfinder.controller.executor.CommandExecutor; import org.grapheco.elfinder.controller.executor.CommandExecutorFactory; import org.grapheco.elfinder.service.FsServiceFactory; import org.apache.commons.fileupload.FileItemIterator; import org.apache.commons.fileupload.FileItemStream; import org.apache.commons.fileupload.servlet.ServletFileUpload; import org.apache.commons.fileupload.util.Streams; import org.apache.log4j.Logger; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import javax.annotation.Resource; import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.lang.reflect.Proxy; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map;
package org.grapheco.elfinder.controller; @Controller @RequestMapping("connector") public class ConnectorController { Logger _logger = Logger.getLogger(this.getClass()); @Resource(name = "commandExecutorFactory") private CommandExecutorFactory _commandExecutorFactory; @Resource(name = "fsServiceFactory") private FsServiceFactory _fsServiceFactory; private File _tempDir = null; String _tempDirPath = "./tmp"; /** * set temp file dir path, relative path is allowed (web root as base dir) * * @param value */ public void setTempDirPath(String value) { _tempDirPath = value; } @RequestMapping public void connector(HttpServletRequest request, final HttpServletResponse response) throws IOException { try { request = parseMultipartContent(request); } catch (Exception e) { throw new IOException(e.getMessage()); } String cmd = request.getParameter("cmd"); CommandExecutor ce = _commandExecutorFactory.get(cmd); if (ce == null) { // This shouldn't happen as we should have a fallback command set. throw new FsException(String.format("unknown command: %s", cmd)); } try { final HttpServletRequest finalRequest = request;
// Path: src/main/java/org/grapheco/elfinder/controller/executor/CommandExecutionContext.java // public interface CommandExecutionContext // { // FsServiceFactory getFsServiceFactory(); // // HttpServletRequest getRequest(); // // HttpServletResponse getResponse(); // // ServletContext getServletContext(); // } // // Path: src/main/java/org/grapheco/elfinder/controller/executor/CommandExecutor.java // public interface CommandExecutor // { // void execute(CommandExecutionContext commandExecutionContext) // throws Exception; // } // // Path: src/main/java/org/grapheco/elfinder/controller/executor/CommandExecutorFactory.java // public interface CommandExecutorFactory // { // CommandExecutor get(String commandName); // } // // Path: src/main/java/org/grapheco/elfinder/service/FsServiceFactory.java // public interface FsServiceFactory // { // /** // * sometimes a FsService should be constructed dynamically according to // * current web request. e.g users may own separated file spaces in a net // * disk service platform, in this case, getFileService() get user principal // * from current request and offers him/her different file view. // * // * @param request // * The current HttpServletRequest. // * @param servletContext // * The servlet context. // * @return The {@link FsService} for the current request. // */ // FsService getFileService(HttpServletRequest request, // ServletContext servletContext); // // } // Path: src/main/java/org/grapheco/elfinder/controller/ConnectorController.java import org.grapheco.elfinder.controller.executor.CommandExecutionContext; import org.grapheco.elfinder.controller.executor.CommandExecutor; import org.grapheco.elfinder.controller.executor.CommandExecutorFactory; import org.grapheco.elfinder.service.FsServiceFactory; import org.apache.commons.fileupload.FileItemIterator; import org.apache.commons.fileupload.FileItemStream; import org.apache.commons.fileupload.servlet.ServletFileUpload; import org.apache.commons.fileupload.util.Streams; import org.apache.log4j.Logger; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import javax.annotation.Resource; import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.lang.reflect.Proxy; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; package org.grapheco.elfinder.controller; @Controller @RequestMapping("connector") public class ConnectorController { Logger _logger = Logger.getLogger(this.getClass()); @Resource(name = "commandExecutorFactory") private CommandExecutorFactory _commandExecutorFactory; @Resource(name = "fsServiceFactory") private FsServiceFactory _fsServiceFactory; private File _tempDir = null; String _tempDirPath = "./tmp"; /** * set temp file dir path, relative path is allowed (web root as base dir) * * @param value */ public void setTempDirPath(String value) { _tempDirPath = value; } @RequestMapping public void connector(HttpServletRequest request, final HttpServletResponse response) throws IOException { try { request = parseMultipartContent(request); } catch (Exception e) { throw new IOException(e.getMessage()); } String cmd = request.getParameter("cmd"); CommandExecutor ce = _commandExecutorFactory.get(cmd); if (ce == null) { // This shouldn't happen as we should have a fallback command set. throw new FsException(String.format("unknown command: %s", cmd)); } try { final HttpServletRequest finalRequest = request;
ce.execute(new CommandExecutionContext() {
bluejoe2008/elfinder-2.x-servlet
src/main/java/org/grapheco/elfinder/controller/executors/MissingCommandExecutor.java
// Path: src/main/java/org/grapheco/elfinder/controller/ErrorException.java // public class ErrorException extends RuntimeException // { // // private final String error; // private final String[] args; // // /** // * See /elfinder/js/i18n/elfinder.??.js for error codes. // * // * @param error // * The error code. // * @param args // * Any arguments needed by the error message. // */ // public ErrorException(String error, String... args) // { // this.error = error; // this.args = args; // } // // /** // * @return The error code that will translated by elfinder to a nice // * message. // */ // public String getError() // { // return error; // } // // /** // * @return The arguments needed by the error message. // */ // public String[] getArgs() // { // return args; // } // } // // Path: src/main/java/org/grapheco/elfinder/controller/executor/CommandExecutor.java // public interface CommandExecutor // { // void execute(CommandExecutionContext commandExecutionContext) // throws Exception; // } // // Path: src/main/java/org/grapheco/elfinder/controller/executor/AbstractJsonCommandExecutor.java // public abstract class AbstractJsonCommandExecutor extends // AbstractCommandExecutor // { // @Override // final public void execute(FsService fsService, HttpServletRequest request, // HttpServletResponse response, ServletContext servletContext) // throws Exception // { // JSONObject json = new JSONObject(); // try // { // execute(fsService, request, servletContext, json); // } // catch (ErrorException e) // { // if (e.getArgs() == null || e.getArgs().length == 0) // { // json.put("error", e.getError()); // } // else // { // JSONArray errors = new JSONArray(); // errors.put(e.getError()); // for (String arg : e.getArgs()) // { // errors.put(arg); // } // json.put("error", errors); // } // } // catch (Exception e) // { // e.printStackTrace(); // json.put("error", e.getMessage()); // } // finally // { // // response.setContentType("application/json; charset=UTF-8"); // response.setContentType("text/html; charset=UTF-8"); // // PrintWriter writer = response.getWriter(); // json.write(writer); // writer.flush(); // writer.close(); // } // } // // protected abstract void execute(FsService fsService, // HttpServletRequest request, ServletContext servletContext, // JSONObject json) throws Exception; // // } // // Path: src/main/java/org/grapheco/elfinder/service/FsService.java // public interface FsService // { // FsItem fromHash(String hash) throws IOException; // // String getHash(FsItem item) throws IOException; // // FsSecurityChecker getSecurityChecker(); // // String getVolumeId(FsVolume volume); // // FsVolume[] getVolumes(); // // FsServiceConfig getServiceConfig(); // // /** // * find files by name pattern, this provides a simple recursively iteration // * based method lucene engines can be introduced to improve it! This // * searches across all volumes. // * // * @param filter // * The filter to apply to select files. // * @return A collection of files that match the filter and gave the root as // * a parent. // */ // // TODO: bad designs: FsItemEx should not used here top level interfaces // // should only know FsItem instead of FsItemEx // FsItemEx[] find(FsItemFilter filter); // }
import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import org.grapheco.elfinder.controller.ErrorException; import org.grapheco.elfinder.controller.executor.CommandExecutor; import org.json.JSONObject; import org.grapheco.elfinder.controller.executor.AbstractJsonCommandExecutor; import org.grapheco.elfinder.service.FsService;
package org.grapheco.elfinder.controller.executors; /** * This is a command that should be executed when a matching command can't be * found. */ public class MissingCommandExecutor extends AbstractJsonCommandExecutor implements CommandExecutor { @Override
// Path: src/main/java/org/grapheco/elfinder/controller/ErrorException.java // public class ErrorException extends RuntimeException // { // // private final String error; // private final String[] args; // // /** // * See /elfinder/js/i18n/elfinder.??.js for error codes. // * // * @param error // * The error code. // * @param args // * Any arguments needed by the error message. // */ // public ErrorException(String error, String... args) // { // this.error = error; // this.args = args; // } // // /** // * @return The error code that will translated by elfinder to a nice // * message. // */ // public String getError() // { // return error; // } // // /** // * @return The arguments needed by the error message. // */ // public String[] getArgs() // { // return args; // } // } // // Path: src/main/java/org/grapheco/elfinder/controller/executor/CommandExecutor.java // public interface CommandExecutor // { // void execute(CommandExecutionContext commandExecutionContext) // throws Exception; // } // // Path: src/main/java/org/grapheco/elfinder/controller/executor/AbstractJsonCommandExecutor.java // public abstract class AbstractJsonCommandExecutor extends // AbstractCommandExecutor // { // @Override // final public void execute(FsService fsService, HttpServletRequest request, // HttpServletResponse response, ServletContext servletContext) // throws Exception // { // JSONObject json = new JSONObject(); // try // { // execute(fsService, request, servletContext, json); // } // catch (ErrorException e) // { // if (e.getArgs() == null || e.getArgs().length == 0) // { // json.put("error", e.getError()); // } // else // { // JSONArray errors = new JSONArray(); // errors.put(e.getError()); // for (String arg : e.getArgs()) // { // errors.put(arg); // } // json.put("error", errors); // } // } // catch (Exception e) // { // e.printStackTrace(); // json.put("error", e.getMessage()); // } // finally // { // // response.setContentType("application/json; charset=UTF-8"); // response.setContentType("text/html; charset=UTF-8"); // // PrintWriter writer = response.getWriter(); // json.write(writer); // writer.flush(); // writer.close(); // } // } // // protected abstract void execute(FsService fsService, // HttpServletRequest request, ServletContext servletContext, // JSONObject json) throws Exception; // // } // // Path: src/main/java/org/grapheco/elfinder/service/FsService.java // public interface FsService // { // FsItem fromHash(String hash) throws IOException; // // String getHash(FsItem item) throws IOException; // // FsSecurityChecker getSecurityChecker(); // // String getVolumeId(FsVolume volume); // // FsVolume[] getVolumes(); // // FsServiceConfig getServiceConfig(); // // /** // * find files by name pattern, this provides a simple recursively iteration // * based method lucene engines can be introduced to improve it! This // * searches across all volumes. // * // * @param filter // * The filter to apply to select files. // * @return A collection of files that match the filter and gave the root as // * a parent. // */ // // TODO: bad designs: FsItemEx should not used here top level interfaces // // should only know FsItem instead of FsItemEx // FsItemEx[] find(FsItemFilter filter); // } // Path: src/main/java/org/grapheco/elfinder/controller/executors/MissingCommandExecutor.java import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import org.grapheco.elfinder.controller.ErrorException; import org.grapheco.elfinder.controller.executor.CommandExecutor; import org.json.JSONObject; import org.grapheco.elfinder.controller.executor.AbstractJsonCommandExecutor; import org.grapheco.elfinder.service.FsService; package org.grapheco.elfinder.controller.executors; /** * This is a command that should be executed when a matching command can't be * found. */ public class MissingCommandExecutor extends AbstractJsonCommandExecutor implements CommandExecutor { @Override
protected void execute(FsService fsService, HttpServletRequest request,
bluejoe2008/elfinder-2.x-servlet
src/main/java/org/grapheco/elfinder/controller/executors/MissingCommandExecutor.java
// Path: src/main/java/org/grapheco/elfinder/controller/ErrorException.java // public class ErrorException extends RuntimeException // { // // private final String error; // private final String[] args; // // /** // * See /elfinder/js/i18n/elfinder.??.js for error codes. // * // * @param error // * The error code. // * @param args // * Any arguments needed by the error message. // */ // public ErrorException(String error, String... args) // { // this.error = error; // this.args = args; // } // // /** // * @return The error code that will translated by elfinder to a nice // * message. // */ // public String getError() // { // return error; // } // // /** // * @return The arguments needed by the error message. // */ // public String[] getArgs() // { // return args; // } // } // // Path: src/main/java/org/grapheco/elfinder/controller/executor/CommandExecutor.java // public interface CommandExecutor // { // void execute(CommandExecutionContext commandExecutionContext) // throws Exception; // } // // Path: src/main/java/org/grapheco/elfinder/controller/executor/AbstractJsonCommandExecutor.java // public abstract class AbstractJsonCommandExecutor extends // AbstractCommandExecutor // { // @Override // final public void execute(FsService fsService, HttpServletRequest request, // HttpServletResponse response, ServletContext servletContext) // throws Exception // { // JSONObject json = new JSONObject(); // try // { // execute(fsService, request, servletContext, json); // } // catch (ErrorException e) // { // if (e.getArgs() == null || e.getArgs().length == 0) // { // json.put("error", e.getError()); // } // else // { // JSONArray errors = new JSONArray(); // errors.put(e.getError()); // for (String arg : e.getArgs()) // { // errors.put(arg); // } // json.put("error", errors); // } // } // catch (Exception e) // { // e.printStackTrace(); // json.put("error", e.getMessage()); // } // finally // { // // response.setContentType("application/json; charset=UTF-8"); // response.setContentType("text/html; charset=UTF-8"); // // PrintWriter writer = response.getWriter(); // json.write(writer); // writer.flush(); // writer.close(); // } // } // // protected abstract void execute(FsService fsService, // HttpServletRequest request, ServletContext servletContext, // JSONObject json) throws Exception; // // } // // Path: src/main/java/org/grapheco/elfinder/service/FsService.java // public interface FsService // { // FsItem fromHash(String hash) throws IOException; // // String getHash(FsItem item) throws IOException; // // FsSecurityChecker getSecurityChecker(); // // String getVolumeId(FsVolume volume); // // FsVolume[] getVolumes(); // // FsServiceConfig getServiceConfig(); // // /** // * find files by name pattern, this provides a simple recursively iteration // * based method lucene engines can be introduced to improve it! This // * searches across all volumes. // * // * @param filter // * The filter to apply to select files. // * @return A collection of files that match the filter and gave the root as // * a parent. // */ // // TODO: bad designs: FsItemEx should not used here top level interfaces // // should only know FsItem instead of FsItemEx // FsItemEx[] find(FsItemFilter filter); // }
import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import org.grapheco.elfinder.controller.ErrorException; import org.grapheco.elfinder.controller.executor.CommandExecutor; import org.json.JSONObject; import org.grapheco.elfinder.controller.executor.AbstractJsonCommandExecutor; import org.grapheco.elfinder.service.FsService;
package org.grapheco.elfinder.controller.executors; /** * This is a command that should be executed when a matching command can't be * found. */ public class MissingCommandExecutor extends AbstractJsonCommandExecutor implements CommandExecutor { @Override protected void execute(FsService fsService, HttpServletRequest request, ServletContext servletContext, JSONObject json) throws Exception { String cmd = request.getParameter("cmd");
// Path: src/main/java/org/grapheco/elfinder/controller/ErrorException.java // public class ErrorException extends RuntimeException // { // // private final String error; // private final String[] args; // // /** // * See /elfinder/js/i18n/elfinder.??.js for error codes. // * // * @param error // * The error code. // * @param args // * Any arguments needed by the error message. // */ // public ErrorException(String error, String... args) // { // this.error = error; // this.args = args; // } // // /** // * @return The error code that will translated by elfinder to a nice // * message. // */ // public String getError() // { // return error; // } // // /** // * @return The arguments needed by the error message. // */ // public String[] getArgs() // { // return args; // } // } // // Path: src/main/java/org/grapheco/elfinder/controller/executor/CommandExecutor.java // public interface CommandExecutor // { // void execute(CommandExecutionContext commandExecutionContext) // throws Exception; // } // // Path: src/main/java/org/grapheco/elfinder/controller/executor/AbstractJsonCommandExecutor.java // public abstract class AbstractJsonCommandExecutor extends // AbstractCommandExecutor // { // @Override // final public void execute(FsService fsService, HttpServletRequest request, // HttpServletResponse response, ServletContext servletContext) // throws Exception // { // JSONObject json = new JSONObject(); // try // { // execute(fsService, request, servletContext, json); // } // catch (ErrorException e) // { // if (e.getArgs() == null || e.getArgs().length == 0) // { // json.put("error", e.getError()); // } // else // { // JSONArray errors = new JSONArray(); // errors.put(e.getError()); // for (String arg : e.getArgs()) // { // errors.put(arg); // } // json.put("error", errors); // } // } // catch (Exception e) // { // e.printStackTrace(); // json.put("error", e.getMessage()); // } // finally // { // // response.setContentType("application/json; charset=UTF-8"); // response.setContentType("text/html; charset=UTF-8"); // // PrintWriter writer = response.getWriter(); // json.write(writer); // writer.flush(); // writer.close(); // } // } // // protected abstract void execute(FsService fsService, // HttpServletRequest request, ServletContext servletContext, // JSONObject json) throws Exception; // // } // // Path: src/main/java/org/grapheco/elfinder/service/FsService.java // public interface FsService // { // FsItem fromHash(String hash) throws IOException; // // String getHash(FsItem item) throws IOException; // // FsSecurityChecker getSecurityChecker(); // // String getVolumeId(FsVolume volume); // // FsVolume[] getVolumes(); // // FsServiceConfig getServiceConfig(); // // /** // * find files by name pattern, this provides a simple recursively iteration // * based method lucene engines can be introduced to improve it! This // * searches across all volumes. // * // * @param filter // * The filter to apply to select files. // * @return A collection of files that match the filter and gave the root as // * a parent. // */ // // TODO: bad designs: FsItemEx should not used here top level interfaces // // should only know FsItem instead of FsItemEx // FsItemEx[] find(FsItemFilter filter); // } // Path: src/main/java/org/grapheco/elfinder/controller/executors/MissingCommandExecutor.java import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import org.grapheco.elfinder.controller.ErrorException; import org.grapheco.elfinder.controller.executor.CommandExecutor; import org.json.JSONObject; import org.grapheco.elfinder.controller.executor.AbstractJsonCommandExecutor; import org.grapheco.elfinder.service.FsService; package org.grapheco.elfinder.controller.executors; /** * This is a command that should be executed when a matching command can't be * found. */ public class MissingCommandExecutor extends AbstractJsonCommandExecutor implements CommandExecutor { @Override protected void execute(FsService fsService, HttpServletRequest request, ServletContext servletContext, JSONObject json) throws Exception { String cmd = request.getParameter("cmd");
throw new ErrorException("errUnknownCmd", cmd);
bluejoe2008/elfinder-2.x-servlet
src/main/java/org/grapheco/elfinder/controller/executor/FsItemEx.java
// Path: src/main/java/org/grapheco/elfinder/service/FsItem.java // public interface FsItem // { // FsVolume getVolume(); // } // // Path: src/main/java/org/grapheco/elfinder/service/FsItemFilter.java // public interface FsItemFilter // { // // TODO: bad designs: FsItemEx should not used here // // top level interfaces should only know FsItem instead of FsItemEx // public boolean accepts(FsItemEx item); // } // // Path: src/main/java/org/grapheco/elfinder/service/FsService.java // public interface FsService // { // FsItem fromHash(String hash) throws IOException; // // String getHash(FsItem item) throws IOException; // // FsSecurityChecker getSecurityChecker(); // // String getVolumeId(FsVolume volume); // // FsVolume[] getVolumes(); // // FsServiceConfig getServiceConfig(); // // /** // * find files by name pattern, this provides a simple recursively iteration // * based method lucene engines can be introduced to improve it! This // * searches across all volumes. // * // * @param filter // * The filter to apply to select files. // * @return A collection of files that match the filter and gave the root as // * a parent. // */ // // TODO: bad designs: FsItemEx should not used here top level interfaces // // should only know FsItem instead of FsItemEx // FsItemEx[] find(FsItemFilter filter); // } // // Path: src/main/java/org/grapheco/elfinder/service/FsVolume.java // public interface FsVolume // { // void createFile(FsItem fsi) throws IOException; // // void createFolder(FsItem fsi) throws IOException; // // void deleteFile(FsItem fsi) throws IOException; // // void deleteFolder(FsItem fsi) throws IOException; // // boolean exists(FsItem newFile); // // FsItem fromPath(String relativePath); // // String getDimensions(FsItem fsi); // // long getLastModified(FsItem fsi); // // String getMimeType(FsItem fsi); // // String getName(); // // String getName(FsItem fsi); // // FsItem getParent(FsItem fsi); // // String getPath(FsItem fsi) throws IOException; // // FsItem getRoot(); // // long getSize(FsItem fsi) throws IOException; // // String getThumbnailFileName(FsItem fsi); // // boolean hasChildFolder(FsItem fsi); // // boolean isFolder(FsItem fsi); // // boolean isRoot(FsItem fsi); // // FsItem[] listChildren(FsItem fsi); // // InputStream openInputStream(FsItem fsi) throws IOException; // // void writeStream(FsItem f, InputStream is) throws IOException; // // void rename(FsItem src, FsItem dst) throws IOException; // // /** // * Gets the URL for the supplied item. // * // * @param f // * The item to get the URL for. // * @return An absolute URL or <code>null</code> if we should not send back a // * URL. // */ // String getURL(FsItem f); // // /** // * This allows volumes to change the options returned to the client for a // * particular item. Implementations should update the map they are passed. // * // * @param f // * The item to filter the options for. // * @param map // * The options that are going to be returned. // */ // void filterOptions(FsItem f, Map<String, Object> map); // }
import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.List; import java.util.Map; import org.grapheco.elfinder.service.FsItem; import org.grapheco.elfinder.service.FsItemFilter; import org.grapheco.elfinder.service.FsService; import org.grapheco.elfinder.service.FsVolume;
package org.grapheco.elfinder.controller.executor; /** * FsItemEx is a helper class of a FsItem, A FsItemEx wraps a FsItem and its * context including FsService, FsVolume, etc * * @author bluejoe * */ public class FsItemEx {
// Path: src/main/java/org/grapheco/elfinder/service/FsItem.java // public interface FsItem // { // FsVolume getVolume(); // } // // Path: src/main/java/org/grapheco/elfinder/service/FsItemFilter.java // public interface FsItemFilter // { // // TODO: bad designs: FsItemEx should not used here // // top level interfaces should only know FsItem instead of FsItemEx // public boolean accepts(FsItemEx item); // } // // Path: src/main/java/org/grapheco/elfinder/service/FsService.java // public interface FsService // { // FsItem fromHash(String hash) throws IOException; // // String getHash(FsItem item) throws IOException; // // FsSecurityChecker getSecurityChecker(); // // String getVolumeId(FsVolume volume); // // FsVolume[] getVolumes(); // // FsServiceConfig getServiceConfig(); // // /** // * find files by name pattern, this provides a simple recursively iteration // * based method lucene engines can be introduced to improve it! This // * searches across all volumes. // * // * @param filter // * The filter to apply to select files. // * @return A collection of files that match the filter and gave the root as // * a parent. // */ // // TODO: bad designs: FsItemEx should not used here top level interfaces // // should only know FsItem instead of FsItemEx // FsItemEx[] find(FsItemFilter filter); // } // // Path: src/main/java/org/grapheco/elfinder/service/FsVolume.java // public interface FsVolume // { // void createFile(FsItem fsi) throws IOException; // // void createFolder(FsItem fsi) throws IOException; // // void deleteFile(FsItem fsi) throws IOException; // // void deleteFolder(FsItem fsi) throws IOException; // // boolean exists(FsItem newFile); // // FsItem fromPath(String relativePath); // // String getDimensions(FsItem fsi); // // long getLastModified(FsItem fsi); // // String getMimeType(FsItem fsi); // // String getName(); // // String getName(FsItem fsi); // // FsItem getParent(FsItem fsi); // // String getPath(FsItem fsi) throws IOException; // // FsItem getRoot(); // // long getSize(FsItem fsi) throws IOException; // // String getThumbnailFileName(FsItem fsi); // // boolean hasChildFolder(FsItem fsi); // // boolean isFolder(FsItem fsi); // // boolean isRoot(FsItem fsi); // // FsItem[] listChildren(FsItem fsi); // // InputStream openInputStream(FsItem fsi) throws IOException; // // void writeStream(FsItem f, InputStream is) throws IOException; // // void rename(FsItem src, FsItem dst) throws IOException; // // /** // * Gets the URL for the supplied item. // * // * @param f // * The item to get the URL for. // * @return An absolute URL or <code>null</code> if we should not send back a // * URL. // */ // String getURL(FsItem f); // // /** // * This allows volumes to change the options returned to the client for a // * particular item. Implementations should update the map they are passed. // * // * @param f // * The item to filter the options for. // * @param map // * The options that are going to be returned. // */ // void filterOptions(FsItem f, Map<String, Object> map); // } // Path: src/main/java/org/grapheco/elfinder/controller/executor/FsItemEx.java import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.List; import java.util.Map; import org.grapheco.elfinder.service.FsItem; import org.grapheco.elfinder.service.FsItemFilter; import org.grapheco.elfinder.service.FsService; import org.grapheco.elfinder.service.FsVolume; package org.grapheco.elfinder.controller.executor; /** * FsItemEx is a helper class of a FsItem, A FsItemEx wraps a FsItem and its * context including FsService, FsVolume, etc * * @author bluejoe * */ public class FsItemEx {
private FsItem _f;
bluejoe2008/elfinder-2.x-servlet
src/main/java/org/grapheco/elfinder/controller/executor/FsItemEx.java
// Path: src/main/java/org/grapheco/elfinder/service/FsItem.java // public interface FsItem // { // FsVolume getVolume(); // } // // Path: src/main/java/org/grapheco/elfinder/service/FsItemFilter.java // public interface FsItemFilter // { // // TODO: bad designs: FsItemEx should not used here // // top level interfaces should only know FsItem instead of FsItemEx // public boolean accepts(FsItemEx item); // } // // Path: src/main/java/org/grapheco/elfinder/service/FsService.java // public interface FsService // { // FsItem fromHash(String hash) throws IOException; // // String getHash(FsItem item) throws IOException; // // FsSecurityChecker getSecurityChecker(); // // String getVolumeId(FsVolume volume); // // FsVolume[] getVolumes(); // // FsServiceConfig getServiceConfig(); // // /** // * find files by name pattern, this provides a simple recursively iteration // * based method lucene engines can be introduced to improve it! This // * searches across all volumes. // * // * @param filter // * The filter to apply to select files. // * @return A collection of files that match the filter and gave the root as // * a parent. // */ // // TODO: bad designs: FsItemEx should not used here top level interfaces // // should only know FsItem instead of FsItemEx // FsItemEx[] find(FsItemFilter filter); // } // // Path: src/main/java/org/grapheco/elfinder/service/FsVolume.java // public interface FsVolume // { // void createFile(FsItem fsi) throws IOException; // // void createFolder(FsItem fsi) throws IOException; // // void deleteFile(FsItem fsi) throws IOException; // // void deleteFolder(FsItem fsi) throws IOException; // // boolean exists(FsItem newFile); // // FsItem fromPath(String relativePath); // // String getDimensions(FsItem fsi); // // long getLastModified(FsItem fsi); // // String getMimeType(FsItem fsi); // // String getName(); // // String getName(FsItem fsi); // // FsItem getParent(FsItem fsi); // // String getPath(FsItem fsi) throws IOException; // // FsItem getRoot(); // // long getSize(FsItem fsi) throws IOException; // // String getThumbnailFileName(FsItem fsi); // // boolean hasChildFolder(FsItem fsi); // // boolean isFolder(FsItem fsi); // // boolean isRoot(FsItem fsi); // // FsItem[] listChildren(FsItem fsi); // // InputStream openInputStream(FsItem fsi) throws IOException; // // void writeStream(FsItem f, InputStream is) throws IOException; // // void rename(FsItem src, FsItem dst) throws IOException; // // /** // * Gets the URL for the supplied item. // * // * @param f // * The item to get the URL for. // * @return An absolute URL or <code>null</code> if we should not send back a // * URL. // */ // String getURL(FsItem f); // // /** // * This allows volumes to change the options returned to the client for a // * particular item. Implementations should update the map they are passed. // * // * @param f // * The item to filter the options for. // * @param map // * The options that are going to be returned. // */ // void filterOptions(FsItem f, Map<String, Object> map); // }
import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.List; import java.util.Map; import org.grapheco.elfinder.service.FsItem; import org.grapheco.elfinder.service.FsItemFilter; import org.grapheco.elfinder.service.FsService; import org.grapheco.elfinder.service.FsVolume;
package org.grapheco.elfinder.controller.executor; /** * FsItemEx is a helper class of a FsItem, A FsItemEx wraps a FsItem and its * context including FsService, FsVolume, etc * * @author bluejoe * */ public class FsItemEx { private FsItem _f;
// Path: src/main/java/org/grapheco/elfinder/service/FsItem.java // public interface FsItem // { // FsVolume getVolume(); // } // // Path: src/main/java/org/grapheco/elfinder/service/FsItemFilter.java // public interface FsItemFilter // { // // TODO: bad designs: FsItemEx should not used here // // top level interfaces should only know FsItem instead of FsItemEx // public boolean accepts(FsItemEx item); // } // // Path: src/main/java/org/grapheco/elfinder/service/FsService.java // public interface FsService // { // FsItem fromHash(String hash) throws IOException; // // String getHash(FsItem item) throws IOException; // // FsSecurityChecker getSecurityChecker(); // // String getVolumeId(FsVolume volume); // // FsVolume[] getVolumes(); // // FsServiceConfig getServiceConfig(); // // /** // * find files by name pattern, this provides a simple recursively iteration // * based method lucene engines can be introduced to improve it! This // * searches across all volumes. // * // * @param filter // * The filter to apply to select files. // * @return A collection of files that match the filter and gave the root as // * a parent. // */ // // TODO: bad designs: FsItemEx should not used here top level interfaces // // should only know FsItem instead of FsItemEx // FsItemEx[] find(FsItemFilter filter); // } // // Path: src/main/java/org/grapheco/elfinder/service/FsVolume.java // public interface FsVolume // { // void createFile(FsItem fsi) throws IOException; // // void createFolder(FsItem fsi) throws IOException; // // void deleteFile(FsItem fsi) throws IOException; // // void deleteFolder(FsItem fsi) throws IOException; // // boolean exists(FsItem newFile); // // FsItem fromPath(String relativePath); // // String getDimensions(FsItem fsi); // // long getLastModified(FsItem fsi); // // String getMimeType(FsItem fsi); // // String getName(); // // String getName(FsItem fsi); // // FsItem getParent(FsItem fsi); // // String getPath(FsItem fsi) throws IOException; // // FsItem getRoot(); // // long getSize(FsItem fsi) throws IOException; // // String getThumbnailFileName(FsItem fsi); // // boolean hasChildFolder(FsItem fsi); // // boolean isFolder(FsItem fsi); // // boolean isRoot(FsItem fsi); // // FsItem[] listChildren(FsItem fsi); // // InputStream openInputStream(FsItem fsi) throws IOException; // // void writeStream(FsItem f, InputStream is) throws IOException; // // void rename(FsItem src, FsItem dst) throws IOException; // // /** // * Gets the URL for the supplied item. // * // * @param f // * The item to get the URL for. // * @return An absolute URL or <code>null</code> if we should not send back a // * URL. // */ // String getURL(FsItem f); // // /** // * This allows volumes to change the options returned to the client for a // * particular item. Implementations should update the map they are passed. // * // * @param f // * The item to filter the options for. // * @param map // * The options that are going to be returned. // */ // void filterOptions(FsItem f, Map<String, Object> map); // } // Path: src/main/java/org/grapheco/elfinder/controller/executor/FsItemEx.java import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.List; import java.util.Map; import org.grapheco.elfinder.service.FsItem; import org.grapheco.elfinder.service.FsItemFilter; import org.grapheco.elfinder.service.FsService; import org.grapheco.elfinder.service.FsVolume; package org.grapheco.elfinder.controller.executor; /** * FsItemEx is a helper class of a FsItem, A FsItemEx wraps a FsItem and its * context including FsService, FsVolume, etc * * @author bluejoe * */ public class FsItemEx { private FsItem _f;
private FsService _s;
bluejoe2008/elfinder-2.x-servlet
src/main/java/org/grapheco/elfinder/controller/executor/FsItemEx.java
// Path: src/main/java/org/grapheco/elfinder/service/FsItem.java // public interface FsItem // { // FsVolume getVolume(); // } // // Path: src/main/java/org/grapheco/elfinder/service/FsItemFilter.java // public interface FsItemFilter // { // // TODO: bad designs: FsItemEx should not used here // // top level interfaces should only know FsItem instead of FsItemEx // public boolean accepts(FsItemEx item); // } // // Path: src/main/java/org/grapheco/elfinder/service/FsService.java // public interface FsService // { // FsItem fromHash(String hash) throws IOException; // // String getHash(FsItem item) throws IOException; // // FsSecurityChecker getSecurityChecker(); // // String getVolumeId(FsVolume volume); // // FsVolume[] getVolumes(); // // FsServiceConfig getServiceConfig(); // // /** // * find files by name pattern, this provides a simple recursively iteration // * based method lucene engines can be introduced to improve it! This // * searches across all volumes. // * // * @param filter // * The filter to apply to select files. // * @return A collection of files that match the filter and gave the root as // * a parent. // */ // // TODO: bad designs: FsItemEx should not used here top level interfaces // // should only know FsItem instead of FsItemEx // FsItemEx[] find(FsItemFilter filter); // } // // Path: src/main/java/org/grapheco/elfinder/service/FsVolume.java // public interface FsVolume // { // void createFile(FsItem fsi) throws IOException; // // void createFolder(FsItem fsi) throws IOException; // // void deleteFile(FsItem fsi) throws IOException; // // void deleteFolder(FsItem fsi) throws IOException; // // boolean exists(FsItem newFile); // // FsItem fromPath(String relativePath); // // String getDimensions(FsItem fsi); // // long getLastModified(FsItem fsi); // // String getMimeType(FsItem fsi); // // String getName(); // // String getName(FsItem fsi); // // FsItem getParent(FsItem fsi); // // String getPath(FsItem fsi) throws IOException; // // FsItem getRoot(); // // long getSize(FsItem fsi) throws IOException; // // String getThumbnailFileName(FsItem fsi); // // boolean hasChildFolder(FsItem fsi); // // boolean isFolder(FsItem fsi); // // boolean isRoot(FsItem fsi); // // FsItem[] listChildren(FsItem fsi); // // InputStream openInputStream(FsItem fsi) throws IOException; // // void writeStream(FsItem f, InputStream is) throws IOException; // // void rename(FsItem src, FsItem dst) throws IOException; // // /** // * Gets the URL for the supplied item. // * // * @param f // * The item to get the URL for. // * @return An absolute URL or <code>null</code> if we should not send back a // * URL. // */ // String getURL(FsItem f); // // /** // * This allows volumes to change the options returned to the client for a // * particular item. Implementations should update the map they are passed. // * // * @param f // * The item to filter the options for. // * @param map // * The options that are going to be returned. // */ // void filterOptions(FsItem f, Map<String, Object> map); // }
import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.List; import java.util.Map; import org.grapheco.elfinder.service.FsItem; import org.grapheco.elfinder.service.FsItemFilter; import org.grapheco.elfinder.service.FsService; import org.grapheco.elfinder.service.FsVolume;
package org.grapheco.elfinder.controller.executor; /** * FsItemEx is a helper class of a FsItem, A FsItemEx wraps a FsItem and its * context including FsService, FsVolume, etc * * @author bluejoe * */ public class FsItemEx { private FsItem _f; private FsService _s;
// Path: src/main/java/org/grapheco/elfinder/service/FsItem.java // public interface FsItem // { // FsVolume getVolume(); // } // // Path: src/main/java/org/grapheco/elfinder/service/FsItemFilter.java // public interface FsItemFilter // { // // TODO: bad designs: FsItemEx should not used here // // top level interfaces should only know FsItem instead of FsItemEx // public boolean accepts(FsItemEx item); // } // // Path: src/main/java/org/grapheco/elfinder/service/FsService.java // public interface FsService // { // FsItem fromHash(String hash) throws IOException; // // String getHash(FsItem item) throws IOException; // // FsSecurityChecker getSecurityChecker(); // // String getVolumeId(FsVolume volume); // // FsVolume[] getVolumes(); // // FsServiceConfig getServiceConfig(); // // /** // * find files by name pattern, this provides a simple recursively iteration // * based method lucene engines can be introduced to improve it! This // * searches across all volumes. // * // * @param filter // * The filter to apply to select files. // * @return A collection of files that match the filter and gave the root as // * a parent. // */ // // TODO: bad designs: FsItemEx should not used here top level interfaces // // should only know FsItem instead of FsItemEx // FsItemEx[] find(FsItemFilter filter); // } // // Path: src/main/java/org/grapheco/elfinder/service/FsVolume.java // public interface FsVolume // { // void createFile(FsItem fsi) throws IOException; // // void createFolder(FsItem fsi) throws IOException; // // void deleteFile(FsItem fsi) throws IOException; // // void deleteFolder(FsItem fsi) throws IOException; // // boolean exists(FsItem newFile); // // FsItem fromPath(String relativePath); // // String getDimensions(FsItem fsi); // // long getLastModified(FsItem fsi); // // String getMimeType(FsItem fsi); // // String getName(); // // String getName(FsItem fsi); // // FsItem getParent(FsItem fsi); // // String getPath(FsItem fsi) throws IOException; // // FsItem getRoot(); // // long getSize(FsItem fsi) throws IOException; // // String getThumbnailFileName(FsItem fsi); // // boolean hasChildFolder(FsItem fsi); // // boolean isFolder(FsItem fsi); // // boolean isRoot(FsItem fsi); // // FsItem[] listChildren(FsItem fsi); // // InputStream openInputStream(FsItem fsi) throws IOException; // // void writeStream(FsItem f, InputStream is) throws IOException; // // void rename(FsItem src, FsItem dst) throws IOException; // // /** // * Gets the URL for the supplied item. // * // * @param f // * The item to get the URL for. // * @return An absolute URL or <code>null</code> if we should not send back a // * URL. // */ // String getURL(FsItem f); // // /** // * This allows volumes to change the options returned to the client for a // * particular item. Implementations should update the map they are passed. // * // * @param f // * The item to filter the options for. // * @param map // * The options that are going to be returned. // */ // void filterOptions(FsItem f, Map<String, Object> map); // } // Path: src/main/java/org/grapheco/elfinder/controller/executor/FsItemEx.java import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.List; import java.util.Map; import org.grapheco.elfinder.service.FsItem; import org.grapheco.elfinder.service.FsItemFilter; import org.grapheco.elfinder.service.FsService; import org.grapheco.elfinder.service.FsVolume; package org.grapheco.elfinder.controller.executor; /** * FsItemEx is a helper class of a FsItem, A FsItemEx wraps a FsItem and its * context including FsService, FsVolume, etc * * @author bluejoe * */ public class FsItemEx { private FsItem _f; private FsService _s;
private FsVolume _v;
bluejoe2008/elfinder-2.x-servlet
src/main/java/org/grapheco/elfinder/controller/executor/FsItemEx.java
// Path: src/main/java/org/grapheco/elfinder/service/FsItem.java // public interface FsItem // { // FsVolume getVolume(); // } // // Path: src/main/java/org/grapheco/elfinder/service/FsItemFilter.java // public interface FsItemFilter // { // // TODO: bad designs: FsItemEx should not used here // // top level interfaces should only know FsItem instead of FsItemEx // public boolean accepts(FsItemEx item); // } // // Path: src/main/java/org/grapheco/elfinder/service/FsService.java // public interface FsService // { // FsItem fromHash(String hash) throws IOException; // // String getHash(FsItem item) throws IOException; // // FsSecurityChecker getSecurityChecker(); // // String getVolumeId(FsVolume volume); // // FsVolume[] getVolumes(); // // FsServiceConfig getServiceConfig(); // // /** // * find files by name pattern, this provides a simple recursively iteration // * based method lucene engines can be introduced to improve it! This // * searches across all volumes. // * // * @param filter // * The filter to apply to select files. // * @return A collection of files that match the filter and gave the root as // * a parent. // */ // // TODO: bad designs: FsItemEx should not used here top level interfaces // // should only know FsItem instead of FsItemEx // FsItemEx[] find(FsItemFilter filter); // } // // Path: src/main/java/org/grapheco/elfinder/service/FsVolume.java // public interface FsVolume // { // void createFile(FsItem fsi) throws IOException; // // void createFolder(FsItem fsi) throws IOException; // // void deleteFile(FsItem fsi) throws IOException; // // void deleteFolder(FsItem fsi) throws IOException; // // boolean exists(FsItem newFile); // // FsItem fromPath(String relativePath); // // String getDimensions(FsItem fsi); // // long getLastModified(FsItem fsi); // // String getMimeType(FsItem fsi); // // String getName(); // // String getName(FsItem fsi); // // FsItem getParent(FsItem fsi); // // String getPath(FsItem fsi) throws IOException; // // FsItem getRoot(); // // long getSize(FsItem fsi) throws IOException; // // String getThumbnailFileName(FsItem fsi); // // boolean hasChildFolder(FsItem fsi); // // boolean isFolder(FsItem fsi); // // boolean isRoot(FsItem fsi); // // FsItem[] listChildren(FsItem fsi); // // InputStream openInputStream(FsItem fsi) throws IOException; // // void writeStream(FsItem f, InputStream is) throws IOException; // // void rename(FsItem src, FsItem dst) throws IOException; // // /** // * Gets the URL for the supplied item. // * // * @param f // * The item to get the URL for. // * @return An absolute URL or <code>null</code> if we should not send back a // * URL. // */ // String getURL(FsItem f); // // /** // * This allows volumes to change the options returned to the client for a // * particular item. Implementations should update the map they are passed. // * // * @param f // * The item to filter the options for. // * @param map // * The options that are going to be returned. // */ // void filterOptions(FsItem f, Map<String, Object> map); // }
import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.List; import java.util.Map; import org.grapheco.elfinder.service.FsItem; import org.grapheco.elfinder.service.FsItemFilter; import org.grapheco.elfinder.service.FsService; import org.grapheco.elfinder.service.FsVolume;
public boolean isWritable(FsItemEx fsi) throws IOException { return _s.getSecurityChecker().isWritable(_s, _f); } public List<FsItemEx> listChildren() { List<FsItemEx> list = new ArrayList<FsItemEx>(); for (FsItem child : _v.listChildren(_f)) { list.add(new FsItemEx(child, _s)); } return list; } public InputStream openInputStream() throws IOException { return _v.openInputStream(_f); } public void writeStream(InputStream is) throws IOException { _v.writeStream(_f, is); } public void renameTo(FsItemEx dst) throws IOException { _v.rename(_f, dst._f); }
// Path: src/main/java/org/grapheco/elfinder/service/FsItem.java // public interface FsItem // { // FsVolume getVolume(); // } // // Path: src/main/java/org/grapheco/elfinder/service/FsItemFilter.java // public interface FsItemFilter // { // // TODO: bad designs: FsItemEx should not used here // // top level interfaces should only know FsItem instead of FsItemEx // public boolean accepts(FsItemEx item); // } // // Path: src/main/java/org/grapheco/elfinder/service/FsService.java // public interface FsService // { // FsItem fromHash(String hash) throws IOException; // // String getHash(FsItem item) throws IOException; // // FsSecurityChecker getSecurityChecker(); // // String getVolumeId(FsVolume volume); // // FsVolume[] getVolumes(); // // FsServiceConfig getServiceConfig(); // // /** // * find files by name pattern, this provides a simple recursively iteration // * based method lucene engines can be introduced to improve it! This // * searches across all volumes. // * // * @param filter // * The filter to apply to select files. // * @return A collection of files that match the filter and gave the root as // * a parent. // */ // // TODO: bad designs: FsItemEx should not used here top level interfaces // // should only know FsItem instead of FsItemEx // FsItemEx[] find(FsItemFilter filter); // } // // Path: src/main/java/org/grapheco/elfinder/service/FsVolume.java // public interface FsVolume // { // void createFile(FsItem fsi) throws IOException; // // void createFolder(FsItem fsi) throws IOException; // // void deleteFile(FsItem fsi) throws IOException; // // void deleteFolder(FsItem fsi) throws IOException; // // boolean exists(FsItem newFile); // // FsItem fromPath(String relativePath); // // String getDimensions(FsItem fsi); // // long getLastModified(FsItem fsi); // // String getMimeType(FsItem fsi); // // String getName(); // // String getName(FsItem fsi); // // FsItem getParent(FsItem fsi); // // String getPath(FsItem fsi) throws IOException; // // FsItem getRoot(); // // long getSize(FsItem fsi) throws IOException; // // String getThumbnailFileName(FsItem fsi); // // boolean hasChildFolder(FsItem fsi); // // boolean isFolder(FsItem fsi); // // boolean isRoot(FsItem fsi); // // FsItem[] listChildren(FsItem fsi); // // InputStream openInputStream(FsItem fsi) throws IOException; // // void writeStream(FsItem f, InputStream is) throws IOException; // // void rename(FsItem src, FsItem dst) throws IOException; // // /** // * Gets the URL for the supplied item. // * // * @param f // * The item to get the URL for. // * @return An absolute URL or <code>null</code> if we should not send back a // * URL. // */ // String getURL(FsItem f); // // /** // * This allows volumes to change the options returned to the client for a // * particular item. Implementations should update the map they are passed. // * // * @param f // * The item to filter the options for. // * @param map // * The options that are going to be returned. // */ // void filterOptions(FsItem f, Map<String, Object> map); // } // Path: src/main/java/org/grapheco/elfinder/controller/executor/FsItemEx.java import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.List; import java.util.Map; import org.grapheco.elfinder.service.FsItem; import org.grapheco.elfinder.service.FsItemFilter; import org.grapheco.elfinder.service.FsService; import org.grapheco.elfinder.service.FsVolume; public boolean isWritable(FsItemEx fsi) throws IOException { return _s.getSecurityChecker().isWritable(_s, _f); } public List<FsItemEx> listChildren() { List<FsItemEx> list = new ArrayList<FsItemEx>(); for (FsItem child : _v.listChildren(_f)) { list.add(new FsItemEx(child, _s)); } return list; } public InputStream openInputStream() throws IOException { return _v.openInputStream(_f); } public void writeStream(InputStream is) throws IOException { _v.writeStream(_f, is); } public void renameTo(FsItemEx dst) throws IOException { _v.rename(_f, dst._f); }
public List<FsItemEx> listChildren(FsItemFilter filter)
bluejoe2008/elfinder-2.x-servlet
src/main/java/org/grapheco/elfinder/localfs/LocalFsVolume.java
// Path: src/main/java/org/grapheco/elfinder/service/FsItem.java // public interface FsItem // { // FsVolume getVolume(); // } // // Path: src/main/java/org/grapheco/elfinder/service/FsVolume.java // public interface FsVolume // { // void createFile(FsItem fsi) throws IOException; // // void createFolder(FsItem fsi) throws IOException; // // void deleteFile(FsItem fsi) throws IOException; // // void deleteFolder(FsItem fsi) throws IOException; // // boolean exists(FsItem newFile); // // FsItem fromPath(String relativePath); // // String getDimensions(FsItem fsi); // // long getLastModified(FsItem fsi); // // String getMimeType(FsItem fsi); // // String getName(); // // String getName(FsItem fsi); // // FsItem getParent(FsItem fsi); // // String getPath(FsItem fsi) throws IOException; // // FsItem getRoot(); // // long getSize(FsItem fsi) throws IOException; // // String getThumbnailFileName(FsItem fsi); // // boolean hasChildFolder(FsItem fsi); // // boolean isFolder(FsItem fsi); // // boolean isRoot(FsItem fsi); // // FsItem[] listChildren(FsItem fsi); // // InputStream openInputStream(FsItem fsi) throws IOException; // // void writeStream(FsItem f, InputStream is) throws IOException; // // void rename(FsItem src, FsItem dst) throws IOException; // // /** // * Gets the URL for the supplied item. // * // * @param f // * The item to get the URL for. // * @return An absolute URL or <code>null</code> if we should not send back a // * URL. // */ // String getURL(FsItem f); // // /** // * This allows volumes to change the options returned to the client for a // * particular item. Implementations should update the map they are passed. // * // * @param f // * The item to filter the options for. // * @param map // * The options that are going to be returned. // */ // void filterOptions(FsItem f, Map<String, Object> map); // } // // Path: src/main/java/org/grapheco/elfinder/util/MimeTypesUtils.java // public abstract class MimeTypesUtils // { // private static Map<String, String> _map; // // public static final String UNKNOWN_MIME_TYPE = "application/oct-stream"; // // static // { // _map = new HashMap<String, String>(); // try // { // load(); // } // catch (Throwable e) // { // e.printStackTrace(); // } // } // // public static String getMimeType(String ext) // { // return _map.get(ext.toLowerCase()); // } // // public static boolean isUnknownType(String mime) // { // return mime == null || UNKNOWN_MIME_TYPE.equals(mime); // } // // private static void load() throws IOException // { // InputStream is = new ClassPathResource("/mime.types").getInputStream(); // BufferedReader fr = new BufferedReader(new InputStreamReader(is)); // String line; // while ((line = fr.readLine()) != null) // { // line = line.trim(); // if (line.startsWith("#") || line.isEmpty()) // { // continue; // } // // String[] tokens = line.split("\\s+"); // if (tokens.length < 2) // continue; // // for (int i = 1; i < tokens.length; i++) // { // putMimeType(tokens[i], tokens[0]); // } // } // // is.close(); // } // // public static void putMimeType(String ext, String type) // { // if (ext == null || type == null) // return; // // _map.put(ext.toLowerCase(), type); // } // }
import java.io.File; import java.io.FileFilter; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.nio.file.FileVisitResult; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.SimpleFileVisitor; import java.nio.file.attribute.BasicFileAttributes; import java.util.ArrayList; import java.util.List; import java.util.Map; import org.apache.commons.io.FileUtils; import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.IOUtils; import org.grapheco.elfinder.service.FsItem; import org.grapheco.elfinder.service.FsVolume; import org.grapheco.elfinder.util.MimeTypesUtils;
package org.grapheco.elfinder.localfs; public class LocalFsVolume implements FsVolume { /** * Used to calculate total file size when walking the tree. */ private static class FileSizeFileVisitor extends SimpleFileVisitor<Path> { private long totalSize; public long getTotalSize() { return totalSize; } @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { totalSize += file.toFile().length(); return FileVisitResult.CONTINUE; } } String _name; File _rootDir;
// Path: src/main/java/org/grapheco/elfinder/service/FsItem.java // public interface FsItem // { // FsVolume getVolume(); // } // // Path: src/main/java/org/grapheco/elfinder/service/FsVolume.java // public interface FsVolume // { // void createFile(FsItem fsi) throws IOException; // // void createFolder(FsItem fsi) throws IOException; // // void deleteFile(FsItem fsi) throws IOException; // // void deleteFolder(FsItem fsi) throws IOException; // // boolean exists(FsItem newFile); // // FsItem fromPath(String relativePath); // // String getDimensions(FsItem fsi); // // long getLastModified(FsItem fsi); // // String getMimeType(FsItem fsi); // // String getName(); // // String getName(FsItem fsi); // // FsItem getParent(FsItem fsi); // // String getPath(FsItem fsi) throws IOException; // // FsItem getRoot(); // // long getSize(FsItem fsi) throws IOException; // // String getThumbnailFileName(FsItem fsi); // // boolean hasChildFolder(FsItem fsi); // // boolean isFolder(FsItem fsi); // // boolean isRoot(FsItem fsi); // // FsItem[] listChildren(FsItem fsi); // // InputStream openInputStream(FsItem fsi) throws IOException; // // void writeStream(FsItem f, InputStream is) throws IOException; // // void rename(FsItem src, FsItem dst) throws IOException; // // /** // * Gets the URL for the supplied item. // * // * @param f // * The item to get the URL for. // * @return An absolute URL or <code>null</code> if we should not send back a // * URL. // */ // String getURL(FsItem f); // // /** // * This allows volumes to change the options returned to the client for a // * particular item. Implementations should update the map they are passed. // * // * @param f // * The item to filter the options for. // * @param map // * The options that are going to be returned. // */ // void filterOptions(FsItem f, Map<String, Object> map); // } // // Path: src/main/java/org/grapheco/elfinder/util/MimeTypesUtils.java // public abstract class MimeTypesUtils // { // private static Map<String, String> _map; // // public static final String UNKNOWN_MIME_TYPE = "application/oct-stream"; // // static // { // _map = new HashMap<String, String>(); // try // { // load(); // } // catch (Throwable e) // { // e.printStackTrace(); // } // } // // public static String getMimeType(String ext) // { // return _map.get(ext.toLowerCase()); // } // // public static boolean isUnknownType(String mime) // { // return mime == null || UNKNOWN_MIME_TYPE.equals(mime); // } // // private static void load() throws IOException // { // InputStream is = new ClassPathResource("/mime.types").getInputStream(); // BufferedReader fr = new BufferedReader(new InputStreamReader(is)); // String line; // while ((line = fr.readLine()) != null) // { // line = line.trim(); // if (line.startsWith("#") || line.isEmpty()) // { // continue; // } // // String[] tokens = line.split("\\s+"); // if (tokens.length < 2) // continue; // // for (int i = 1; i < tokens.length; i++) // { // putMimeType(tokens[i], tokens[0]); // } // } // // is.close(); // } // // public static void putMimeType(String ext, String type) // { // if (ext == null || type == null) // return; // // _map.put(ext.toLowerCase(), type); // } // } // Path: src/main/java/org/grapheco/elfinder/localfs/LocalFsVolume.java import java.io.File; import java.io.FileFilter; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.nio.file.FileVisitResult; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.SimpleFileVisitor; import java.nio.file.attribute.BasicFileAttributes; import java.util.ArrayList; import java.util.List; import java.util.Map; import org.apache.commons.io.FileUtils; import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.IOUtils; import org.grapheco.elfinder.service.FsItem; import org.grapheco.elfinder.service.FsVolume; import org.grapheco.elfinder.util.MimeTypesUtils; package org.grapheco.elfinder.localfs; public class LocalFsVolume implements FsVolume { /** * Used to calculate total file size when walking the tree. */ private static class FileSizeFileVisitor extends SimpleFileVisitor<Path> { private long totalSize; public long getTotalSize() { return totalSize; } @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { totalSize += file.toFile().length(); return FileVisitResult.CONTINUE; } } String _name; File _rootDir;
private File asFile(FsItem fsi)
bluejoe2008/elfinder-2.x-servlet
src/main/java/org/grapheco/elfinder/localfs/LocalFsVolume.java
// Path: src/main/java/org/grapheco/elfinder/service/FsItem.java // public interface FsItem // { // FsVolume getVolume(); // } // // Path: src/main/java/org/grapheco/elfinder/service/FsVolume.java // public interface FsVolume // { // void createFile(FsItem fsi) throws IOException; // // void createFolder(FsItem fsi) throws IOException; // // void deleteFile(FsItem fsi) throws IOException; // // void deleteFolder(FsItem fsi) throws IOException; // // boolean exists(FsItem newFile); // // FsItem fromPath(String relativePath); // // String getDimensions(FsItem fsi); // // long getLastModified(FsItem fsi); // // String getMimeType(FsItem fsi); // // String getName(); // // String getName(FsItem fsi); // // FsItem getParent(FsItem fsi); // // String getPath(FsItem fsi) throws IOException; // // FsItem getRoot(); // // long getSize(FsItem fsi) throws IOException; // // String getThumbnailFileName(FsItem fsi); // // boolean hasChildFolder(FsItem fsi); // // boolean isFolder(FsItem fsi); // // boolean isRoot(FsItem fsi); // // FsItem[] listChildren(FsItem fsi); // // InputStream openInputStream(FsItem fsi) throws IOException; // // void writeStream(FsItem f, InputStream is) throws IOException; // // void rename(FsItem src, FsItem dst) throws IOException; // // /** // * Gets the URL for the supplied item. // * // * @param f // * The item to get the URL for. // * @return An absolute URL or <code>null</code> if we should not send back a // * URL. // */ // String getURL(FsItem f); // // /** // * This allows volumes to change the options returned to the client for a // * particular item. Implementations should update the map they are passed. // * // * @param f // * The item to filter the options for. // * @param map // * The options that are going to be returned. // */ // void filterOptions(FsItem f, Map<String, Object> map); // } // // Path: src/main/java/org/grapheco/elfinder/util/MimeTypesUtils.java // public abstract class MimeTypesUtils // { // private static Map<String, String> _map; // // public static final String UNKNOWN_MIME_TYPE = "application/oct-stream"; // // static // { // _map = new HashMap<String, String>(); // try // { // load(); // } // catch (Throwable e) // { // e.printStackTrace(); // } // } // // public static String getMimeType(String ext) // { // return _map.get(ext.toLowerCase()); // } // // public static boolean isUnknownType(String mime) // { // return mime == null || UNKNOWN_MIME_TYPE.equals(mime); // } // // private static void load() throws IOException // { // InputStream is = new ClassPathResource("/mime.types").getInputStream(); // BufferedReader fr = new BufferedReader(new InputStreamReader(is)); // String line; // while ((line = fr.readLine()) != null) // { // line = line.trim(); // if (line.startsWith("#") || line.isEmpty()) // { // continue; // } // // String[] tokens = line.split("\\s+"); // if (tokens.length < 2) // continue; // // for (int i = 1; i < tokens.length; i++) // { // putMimeType(tokens[i], tokens[0]); // } // } // // is.close(); // } // // public static void putMimeType(String ext, String type) // { // if (ext == null || type == null) // return; // // _map.put(ext.toLowerCase(), type); // } // }
import java.io.File; import java.io.FileFilter; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.nio.file.FileVisitResult; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.SimpleFileVisitor; import java.nio.file.attribute.BasicFileAttributes; import java.util.ArrayList; import java.util.List; import java.util.Map; import org.apache.commons.io.FileUtils; import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.IOUtils; import org.grapheco.elfinder.service.FsItem; import org.grapheco.elfinder.service.FsVolume; import org.grapheco.elfinder.util.MimeTypesUtils;
} @Override public FsItem fromPath(String relativePath) { return fromFile(new File(_rootDir, relativePath)); } @Override public String getDimensions(FsItem fsi) { return null; } @Override public long getLastModified(FsItem fsi) { return asFile(fsi).lastModified() / 1000; } @Override public String getMimeType(FsItem fsi) { File file = asFile(fsi); if (file.isDirectory()) return "directory"; String ext = FilenameUtils.getExtension(file.getName()); if (ext != null && !ext.isEmpty()) {
// Path: src/main/java/org/grapheco/elfinder/service/FsItem.java // public interface FsItem // { // FsVolume getVolume(); // } // // Path: src/main/java/org/grapheco/elfinder/service/FsVolume.java // public interface FsVolume // { // void createFile(FsItem fsi) throws IOException; // // void createFolder(FsItem fsi) throws IOException; // // void deleteFile(FsItem fsi) throws IOException; // // void deleteFolder(FsItem fsi) throws IOException; // // boolean exists(FsItem newFile); // // FsItem fromPath(String relativePath); // // String getDimensions(FsItem fsi); // // long getLastModified(FsItem fsi); // // String getMimeType(FsItem fsi); // // String getName(); // // String getName(FsItem fsi); // // FsItem getParent(FsItem fsi); // // String getPath(FsItem fsi) throws IOException; // // FsItem getRoot(); // // long getSize(FsItem fsi) throws IOException; // // String getThumbnailFileName(FsItem fsi); // // boolean hasChildFolder(FsItem fsi); // // boolean isFolder(FsItem fsi); // // boolean isRoot(FsItem fsi); // // FsItem[] listChildren(FsItem fsi); // // InputStream openInputStream(FsItem fsi) throws IOException; // // void writeStream(FsItem f, InputStream is) throws IOException; // // void rename(FsItem src, FsItem dst) throws IOException; // // /** // * Gets the URL for the supplied item. // * // * @param f // * The item to get the URL for. // * @return An absolute URL or <code>null</code> if we should not send back a // * URL. // */ // String getURL(FsItem f); // // /** // * This allows volumes to change the options returned to the client for a // * particular item. Implementations should update the map they are passed. // * // * @param f // * The item to filter the options for. // * @param map // * The options that are going to be returned. // */ // void filterOptions(FsItem f, Map<String, Object> map); // } // // Path: src/main/java/org/grapheco/elfinder/util/MimeTypesUtils.java // public abstract class MimeTypesUtils // { // private static Map<String, String> _map; // // public static final String UNKNOWN_MIME_TYPE = "application/oct-stream"; // // static // { // _map = new HashMap<String, String>(); // try // { // load(); // } // catch (Throwable e) // { // e.printStackTrace(); // } // } // // public static String getMimeType(String ext) // { // return _map.get(ext.toLowerCase()); // } // // public static boolean isUnknownType(String mime) // { // return mime == null || UNKNOWN_MIME_TYPE.equals(mime); // } // // private static void load() throws IOException // { // InputStream is = new ClassPathResource("/mime.types").getInputStream(); // BufferedReader fr = new BufferedReader(new InputStreamReader(is)); // String line; // while ((line = fr.readLine()) != null) // { // line = line.trim(); // if (line.startsWith("#") || line.isEmpty()) // { // continue; // } // // String[] tokens = line.split("\\s+"); // if (tokens.length < 2) // continue; // // for (int i = 1; i < tokens.length; i++) // { // putMimeType(tokens[i], tokens[0]); // } // } // // is.close(); // } // // public static void putMimeType(String ext, String type) // { // if (ext == null || type == null) // return; // // _map.put(ext.toLowerCase(), type); // } // } // Path: src/main/java/org/grapheco/elfinder/localfs/LocalFsVolume.java import java.io.File; import java.io.FileFilter; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.nio.file.FileVisitResult; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.SimpleFileVisitor; import java.nio.file.attribute.BasicFileAttributes; import java.util.ArrayList; import java.util.List; import java.util.Map; import org.apache.commons.io.FileUtils; import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.IOUtils; import org.grapheco.elfinder.service.FsItem; import org.grapheco.elfinder.service.FsVolume; import org.grapheco.elfinder.util.MimeTypesUtils; } @Override public FsItem fromPath(String relativePath) { return fromFile(new File(_rootDir, relativePath)); } @Override public String getDimensions(FsItem fsi) { return null; } @Override public long getLastModified(FsItem fsi) { return asFile(fsi).lastModified() / 1000; } @Override public String getMimeType(FsItem fsi) { File file = asFile(fsi); if (file.isDirectory()) return "directory"; String ext = FilenameUtils.getExtension(file.getName()); if (ext != null && !ext.isEmpty()) {
String mimeType = MimeTypesUtils.getMimeType(ext);