1
0
mirror of https://github.com/sismics/docs.git synced 2025-12-15 10:46:26 +00:00
This commit is contained in:
Benjamin Gamard
2018-03-14 14:53:41 +01:00
parent db721a9d10
commit 1e57ee5fb3
4 changed files with 23 additions and 33 deletions

View File

@@ -1,7 +1,6 @@
package com.sismics.docs.core.util;
import java.io.IOException;
import com.sismics.docs.core.model.context.AppContext;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig;
@@ -10,7 +9,7 @@ import org.apache.lucene.store.Directory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.sismics.docs.core.model.context.AppContext;
import java.io.IOException;
/**
* Lucene utils.
@@ -26,8 +25,7 @@ public class LuceneUtil {
/**
* Encapsulate a process into a Lucene context.
*
* @param runnable
* @throws IOException
* @param runnable Runnable
*/
public static void handle(LuceneRunnable runnable) {
// Standard analyzer
@@ -53,14 +51,18 @@ public class LuceneUtil {
} catch (Exception e) {
log.error("Error in running index writing transaction", e);
try {
indexWriter.rollback();
if (indexWriter != null) {
indexWriter.rollback();
}
} catch (IOException e1) {
log.error("Cannot rollback index writing transaction", e1);
}
}
try {
indexWriter.close();
if (indexWriter != null) {
indexWriter.close();
}
} catch (IOException e) {
log.error("Cannot commit and close IndexWriter", e);
}
@@ -75,9 +77,9 @@ public class LuceneUtil {
/**
* Code to run in a Lucene context.
*
* @param indexWriter
* @throws Exception
* @param indexWriter Index writer
* @throws Exception e
*/
public abstract void run(IndexWriter indexWriter) throws Exception;
void run(IndexWriter indexWriter) throws Exception;
}
}

View File

@@ -30,19 +30,14 @@
package com.sismics.util.totp;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Random;
import org.apache.commons.codec.binary.Base32;
import org.apache.commons.codec.binary.Base64;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import org.apache.commons.codec.binary.Base32;
import org.apache.commons.codec.binary.Base64;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.*;
/**
* This class implements the functionality described in RFC 6238 (TOTP: Time
@@ -116,7 +111,7 @@ public final class GoogleAuthenticator {
/**
* Modulus used to truncate the scratch code.
*/
public static final int SCRATCH_CODE_MODULUS = (int) Math.pow(10, SCRATCH_CODE_LENGTH);
private static final int SCRATCH_CODE_MODULUS = (int) Math.pow(10, SCRATCH_CODE_LENGTH);
/**
* Magic number representing an invalid scratch code.
@@ -171,14 +166,6 @@ public final class GoogleAuthenticator {
config = new GoogleAuthenticatorConfig();
}
public GoogleAuthenticator(GoogleAuthenticatorConfig config) {
if (config == null) {
throw new IllegalArgumentException("Configuration cannot be null.");
}
this.config = config;
}
/**
* @return the random number generator algorithm.
* @since 0.5.0
@@ -227,7 +214,7 @@ public final class GoogleAuthenticator {
* @return the validation code for the provided key at the specified instant
* of time.
*/
int calculateCode(byte[] key, long tm) {
private int calculateCode(byte[] key, long tm) {
// Allocating an array of bytes to represent the specified instant
// of time.
byte[] data = new byte[8];
@@ -439,7 +426,7 @@ public final class GoogleAuthenticator {
return authorize(secret, verificationCode, new Date().getTime());
}
public boolean authorize(String secret, int verificationCode, long time) throws GoogleAuthenticatorException {
private boolean authorize(String secret, int verificationCode, long time) throws GoogleAuthenticatorException {
// Checking user input and failing if the secret key was not provided.
if (secret == null) {
throw new IllegalArgumentException("Secret cannot be null.");