Skip to content

Commit

Permalink
Bump qulice to 0.18.5 for yegor256#880
Browse files Browse the repository at this point in the history
  • Loading branch information
victornoel committed Dec 11, 2018
1 parent 1a11256 commit 2444148
Show file tree
Hide file tree
Showing 92 changed files with 341 additions and 150 deletions.
7 changes: 1 addition & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ SOFTWARE.
<properties>
<timestamp>${maven.build.timestamp}</timestamp>
<jdk.version>1.8</jdk.version>
<qulice.version>0.17.5</qulice.version>
<qulice.version>0.18.5</qulice.version>
</properties>
<dependencies>
<!--
Expand Down Expand Up @@ -370,11 +370,6 @@ SOFTWARE.
<groupId>com.qulice</groupId>
<artifactId>qulice-maven-plugin</artifactId>
<!--
@todo #837:30min Upgrade qulice to latest 0.17.x and if possible
to latest 0.18.x and fix all the issues it detects for the build
to pass. In 0.17.6, some changes impact a lot of file, while in
0.18 there should be less new issues. Don't forget about the IT
test ran by maven-invoker-plugin.
@todo #837:30min Finish the upgrade to qulice 0.17.5 by reviewing
all diamond usage: it was required until now to explicit the
type in generics but it is not needed anymore. For example in
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/org/takes/facets/auth/Identity.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,12 @@ public interface Identity {
public String toString() {
return "anonymous";
}

@Override
public String urn() {
throw new UnsupportedOperationException("#urn()");
}

@Override
public Map<String, String> properties() {
throw new UnsupportedOperationException("#properties()");
Expand All @@ -73,17 +75,20 @@ final class Simple implements Identity {
* URN.
*/
private final String name;

/**
* Map of properties.
*/
private final Map<String, String> props;

/**
* Ctor.
* @param urn URN of the identity
*/
public Simple(final String urn) {
this(urn, Collections.<String, String>emptyMap());
}

/**
* Ctor.
* @param urn URN of the identity
Expand All @@ -93,10 +98,12 @@ public Simple(final String urn, final Map<String, String> map) {
this.name = urn;
this.props = Collections.unmodifiableMap(map);
}

@Override
public String urn() {
return this.name;
}

@Override
public Map<String, String> properties() {
return Collections.unmodifiableMap(this.props);
Expand Down
14 changes: 12 additions & 2 deletions src/main/java/org/takes/facets/auth/PsBasic.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,18 +157,20 @@ public static final class Fake implements PsBasic.Entry {
* Should we authenticate a user?
*/
private final boolean condition;

/**
* Ctor.
* @param cond Condition
*/
public Fake(final boolean cond) {
this.condition = cond;
}

@Override
public Opt<Identity> enter(final String usr, final String pwd) {
final Opt<Identity> user;
if (this.condition) {
user = new Opt.Single<Identity>(
user = new Opt.Single<>(
new Identity.Simple(
String.format("urn:basic:%s", usr)
)
Expand Down Expand Up @@ -204,14 +206,17 @@ public static final class Default implements PsBasic.Entry {
* formatted.
*/
private static final String KEY_FORMAT = "%s %s";

/**
* Encoding for URLEncode#encode.
*/
private static final String ENCODING = "UTF-8";

/**
* Map from login/password pairs to URNs.
*/
private final Map<String, String> usernames;

/**
* Public ctor.
* @param users Strings with user's login, password and URN with
Expand All @@ -229,7 +234,7 @@ public Opt<Identity> enter(final String user, final String pwd) {
final Opt<Identity> identity;
if (urn.has()) {
try {
identity = new Opt.Single<Identity>(
identity = new Opt.Single<>(
new Identity.Simple(
URLDecoder.decode(
urn.get(), PsBasic.Default.ENCODING
Expand All @@ -244,6 +249,7 @@ public Opt<Identity> enter(final String user, final String pwd) {
}
return identity;
}

/**
* Converts Strings with user's login, password and URN to Map.
* @param users Strings with user's login, password and URN with
Expand All @@ -264,6 +270,7 @@ private static Map<String, String> converted(final String... users) {
}
return result;
}

/**
* Returns an URN corresponding to a login-password pair.
* @param user Login.
Expand Down Expand Up @@ -298,6 +305,7 @@ private Opt<String> urn(final String user, final String pwd) {
}
return opt;
}

/**
* Creates a key for
* {@link org.takes.facets.auth.PsBasic.Default#usernames} map.
Expand All @@ -316,6 +324,7 @@ private static String key(final String unified) {
)
);
}

/**
* Checks if a unified user string is correctly formatted.
* @param unified String with urlencoded user login, password and urn
Expand All @@ -334,6 +343,7 @@ private static void validateUser(final String unified) {
);
}
}

/**
* Counts spaces in a string.
* @param txt Any string.
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/takes/facets/auth/PsByFlag.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ public static final class Pair
* Serialization marker.
*/
private static final long serialVersionUID = 7362482770166663015L;

/**
* Ctor.
* @param key Key
Expand All @@ -148,6 +149,7 @@ public static final class Pair
public Pair(final String key, final Pass pass) {
this(Pattern.compile(Pattern.quote(key)), pass);
}

/**
* Ctor.
* @param key Key
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/takes/facets/auth/PsToken.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public Opt<Identity> enter(final Request req) throws IOException {
tocheck.put(jwtheader).put(".".getBytes()).put(jwtpayload);
final byte[] checked = this.signature.sign(tocheck.array());
if (Arrays.equals(jwtsign, checked)) {
try (final JsonReader rdr = Json.createReader(
try (JsonReader rdr = Json.createReader(
new StringReader(
new String(Base64.getDecoder().decode(jwtpayload))
)
Expand Down Expand Up @@ -164,7 +164,7 @@ public Response exit(final Response res,
tosign.put(".".getBytes());
tosign.put(jwtpayload);
final byte[] sign = this.signature.sign(tosign.array());
try (final JsonReader reader = Json.createReader(res.body())) {
try (JsonReader reader = Json.createReader(res.body())) {
final JsonObject target = Json.createObjectBuilder()
.add("response", reader.read())
.add(
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/takes/facets/auth/RsLogout.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public final class RsLogout extends RsWrap {
public RsLogout(final Response res) {
this(res, PsCookie.class.getSimpleName());
}

/**
* Ctor.
* @param res Original response
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/takes/facets/auth/Token.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public JsonObject json() {
public byte[] encoded() throws IOException {
return Base64.getEncoder().encode(this.joseo.toString().getBytes());
}
};
}

/**
* JSON Web Token.
Expand Down Expand Up @@ -165,5 +165,5 @@ public JsonObject json() {
public byte[] encoded() throws IOException {
return Base64.getEncoder().encode(this.jwto.toString().getBytes());
}
};
}
}
2 changes: 2 additions & 0 deletions src/main/java/org/takes/facets/auth/codecs/CcAes.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public final class CcAes implements Codec {
* The encryption key.
*/
private final Key key;

/**
* Random.
*/
Expand All @@ -86,6 +87,7 @@ public final class CcAes implements Codec {
public CcAes(final Codec codec, final String key) {
this(codec, key.getBytes(Charset.defaultCharset()));
}

/**
* Constructor for the class.
*
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/takes/facets/auth/codecs/CcBase64.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ public Identity decode(final byte[] bytes) throws IOException {
*/
private static byte[] checkIllegalCharacters(final byte[] bytes) {
final ByteArrayOutputStream out = new ByteArrayOutputStream();
for (int pos = 0; pos < bytes.length; ++pos) {
if (BASE64CHARS.indexOf(bytes[pos]) < 0) {
out.write(bytes[pos]);
for (final byte byt: bytes) {
if (BASE64CHARS.indexOf(byt) < 0) {
out.write(byt);
}
}
return out.toByteArray();
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/takes/facets/auth/codecs/CcSalted.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ private static byte[] salt(final byte[] text) {
* @param text Salted text
* @return Original text
*/
@SuppressWarnings("PMD.CyclomaticComplexity")
private static byte[] unsalt(final byte[] text) {
if (text.length == 0) {
throw new DecodingException("empty input");
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/takes/facets/auth/codecs/CcSigned.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,17 @@ public final class CcSigned implements Codec {
* Origin codec.
*/
private final Codec cdc;

/**
* MAC algorithm.
*/
private final String alg;

/**
* Secret key.
*/
private final Key key;

/**
* Ctor.
* @param origin Origin codec
Expand Down
9 changes: 3 additions & 6 deletions src/main/java/org/takes/facets/auth/signatures/SiHmac.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ private static int bitLength(final int bits) {
* for all unexpected exceptions
*/
private byte[] encrypt(final byte[] bytes) throws IOException {
try (final Formatter formatter = new Formatter()) {
try (Formatter formatter = new Formatter()) {
for (final byte byt : this.create().doFinal(bytes)) {
formatter.format("%02x", byt);
}
Expand All @@ -165,13 +165,10 @@ private Mac create()
final SecretKeySpec secret = new SecretKeySpec(
this.key, algo
);
final Mac mac = Mac
.getInstance(algo);
final Mac mac = Mac.getInstance(algo);
mac.init(secret);
return mac;
} catch (final InvalidKeyException ex) {
throw new IOException(ex);
} catch (final NoSuchAlgorithmException ex) {
} catch (final NoSuchAlgorithmException | InvalidKeyException ex) {
throw new IOException(ex);
}
}
Expand Down
19 changes: 7 additions & 12 deletions src/main/java/org/takes/facets/fallback/FbStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,9 @@ public final class FbStatus extends FbWrap {
* @since 0.16.10
*/
public FbStatus(final int code) {
this(
new Filtered<>(
(value) -> code == value.intValue(), code
)
);
this(new Filtered<>(value -> code == value.intValue(), code));
}

/**
* Ctor.
* @param check HTTP status code predicate
Expand All @@ -76,7 +73,7 @@ public FbStatus(final Iterable<Integer> check) {
public Opt<Response> route(final RqFallback req)
throws IOException {
final Response res = new RsWithStatus(req.code());
return new Opt.Single<Response>(
return new Opt.Single<>(
new RsWithType(
new RsWithBody(
res,
Expand All @@ -92,6 +89,7 @@ public Opt<Response> route(final RqFallback req)
}
});
}

/**
* Ctor.
* @param code HTTP status code
Expand Down Expand Up @@ -127,9 +125,7 @@ public Opt<Response> route(final RqFallback req)
*/
public FbStatus(final int code, final Fallback fallback) {
this(
new Filtered<Integer>(
(status) -> code == status.intValue(), code
),
new Filtered<>(status -> code == status.intValue(), code),
fallback
);
}
Expand All @@ -141,9 +137,7 @@ public FbStatus(final int code, final Fallback fallback) {
*/
public FbStatus(final int code, final Scalar<Fallback> fallback) {
this(
new Filtered<Integer>(
(status) -> code == status.intValue(), code
),
new Filtered<>(status -> code == status.intValue(), code),
fallback
);
}
Expand All @@ -164,6 +158,7 @@ public Fallback get() {
}
);
}

/**
* Ctor.
* @param check Check
Expand Down

0 comments on commit 2444148

Please sign in to comment.