Skip to content

Commit

Permalink
no message
Browse files Browse the repository at this point in the history
  • Loading branch information
grada84 committed Nov 4, 2024
1 parent fdcde2a commit 6ed1b94
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 67 deletions.
62 changes: 32 additions & 30 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<java.version>17</java.version>
<sonar.organization>lacnic</sonar.organization>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
<sonar.exclusions>**/*.css,**/*.js</sonar.exclusions>
<sonar.exclusions>**/*.css,**/*.js</sonar.exclusions>
</properties>

<dependencies>
Expand Down Expand Up @@ -116,36 +116,38 @@
<artifactId>sonar-maven-plugin</artifactId>
<version>4.0.0.4121</version>
</plugin>

<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.7</version>
<executions>
<!-- Attach Jacoco agent during test phase -->
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<!-- Generate Jacoco report after tests -->
<execution>
<id>report</id>
<phase>verify</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/site/jacoco</outputDirectory>
<dataFile>${project.build.directory}/jacoco.exec</dataFile>
<reportsDirectory>${project.reporting.outputDirectory}/jacoco</reportsDirectory>
<formats>
<format>XML</format>
</formats>
</configuration>
</execution>
</executions>
</plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.7</version>
<executions>
<!-- Attach Jacoco agent during test phase -->
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<!-- Generate Jacoco report after tests -->
<execution>
<id>report</id>
<phase>verify</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<outputDirectory>
${project.build.directory}/site/jacoco</outputDirectory>
<dataFile>${project.build.directory}/jacoco.exec</dataFile>
<reportsDirectory>
${project.reporting.outputDirectory}/jacoco</reportsDirectory>
<formats>
<format>XML</format>
</formats>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
16 changes: 0 additions & 16 deletions src/main/java/net/lacnic/portal/auth/client/Utils2FA.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,4 @@ public static void createQRCode(String barCodeData, String filePath, int height,
MatrixToImageWriter.writeToFile(matrix, "png", out);
}

public static void infinityGeneratingCodes(String secretKey) {
String lastCode = null;
while (true) {
String code = getTOTPCode(secretKey);
if (!code.equals(lastCode)) {
System.out.println(code);
}
lastCode = code;
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
;
}
}

}
42 changes: 21 additions & 21 deletions src/main/java/net/lacnic/portal/auth/client/UtilsFiles.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,40 +29,40 @@ public static byte[] calcularBytesImgQR(String secretKey) {
}

public static byte[] getBytesFromFile(File file) throws IOException {
InputStream is = new FileInputStream(file);
try (InputStream is = new FileInputStream(file)) {

long length = file.length();
long length = file.length();
if (length > Integer.MAX_VALUE) {
throw new IOException("File is too large to process");
}

if (length > Integer.MAX_VALUE) {
// File is too large
}
byte[] bytes = new byte[(int) length];

byte[] bytes = new byte[(int) length];
int offset = 0;
int numRead;
while (offset < bytes.length && (numRead = is.read(bytes, offset, bytes.length - offset)) >= 0) {
offset += numRead;
}

int offset = 0;
int numRead = 0;
while (offset < bytes.length && (numRead = is.read(bytes, offset, bytes.length - offset)) >= 0) {
offset += numRead;
}
if (offset < bytes.length) {
throw new IOException("Could not completely read file " + file.getName());
}

if (offset < bytes.length) {
throw new IOException("Could not completely read file " + file.getName());
return bytes;
}

is.close();

return bytes;
}

public static File obtenerFile(byte[] bytes, String extension) {
try {
String uuid = UUID.randomUUID().toString();
File file = new File(System.getProperty("jboss.server.temp.dir").concat("/") + uuid + "." + extension);
file.createNewFile();
FileOutputStream fos = new FileOutputStream(file);
fos.write(bytes);
fos.flush();
fos.close();

try (FileOutputStream fos = new FileOutputStream(file)) {
fos.write(bytes);
fos.flush();
}

return file;
} catch (FileNotFoundException e) {
e.printStackTrace();
Expand Down

0 comments on commit 6ed1b94

Please sign in to comment.