Proudly debugging the system since 1981

Tag: java (Pagina 1 di 3)

Plugin gradle per la migrazione da javax a jakarta

Il plugin si trova qua : https://plugins.gradle.org/plugin/com.netflix.nebula.jakartaee-migration

La spiegazione su cosa puo fare e come si usa qua : https://github.com/nebula-plugins/gradle-jakartaee-migration-plugin

Lo scenario in cui l’ho utilizzato e’ quando si devono usare due librerie o framework, una con dipendenze “vecchie” sotto javax e una con dipendenze “nuove” sotto jakarta su un application server “nuovo”.

Il plugin aggiorna automaticamente le dipendenze vecchie, al momento della compilazione, rendendo tutto funzionante e interoperabile.

Un sentito ringraziamento a chi ha reso necessario il cambio di nome.

Proxy Dinamico per logging

Può essere necessario loggare tutto ciò che fa una determinata classe che però fa parte di una libreria e non contiene tutti i log desiderati. Supponendo che non sia necessario debuggare la classe in sè, che fa quello che deve fare nel modo giusto, ma come viene utilizzata all’interno del progetto ho trovato che realizzare un proxy dinamico sia una soluzione efficace e molto versatile. Anche perchè fatto uno, va bene per qualsiasi classe.

La classe che andiamo da realizzare fa due cose :

  • implementa InvocationHandler in modo che venga richiamata tutte le volte che viene chiamato un metodo dall’utilizzatore del target da loggare
  • ha un factory method di comodo che crea una nuova istanza di proxy dinamico attaccando se stessa come InvocationHandler

Implementare InvocationHandler significa implementare il metodo invoke:

invoke di fatto richiama il metodo del target e logga nome del metodo, parametri e risultati. Più la gestione delle eccezioni del metodo target e di tutte le altre possibili eccezioni.

Il metodo wrap permette di avere la nostra classe ben wrappata con un solo comando.

Visto che tutto questo mi ha permesso oggi di scoprire un utilizzo un pò insensato dell’accesso ai dati con conseguente lentezza ho pensato di condividerlo.

Perchè?

Contesto: classe Java, framework Wicket (ma non è significativo), IDE Intellij.

Quale sarà mai il motivo percui, un anonimo programmatore che mi ha preceduto, può aver pensato che avesse senso fare un metodo privato, che nel nome richiama l’idea di un factory method, che ritorna un campo della sua stessa classe?

E poi perchè commentarlo con // (5) ?

Continua a leggere

alibaba/Sentinel

A lightweight powerful flow control component enabling reliability and monitoring for microservices. (????????????? Java ?) – alibaba/Sentinel

As distributed systems become increasingly popular, the reliability between services is becoming more important than ever before. Sentinel takes “flow” as breakthrough point, and works on multiple fields including flow control, circuit breaking and system adaptive protection, to guarantee reliability of microservices.

Sentinel has the following features:

  • Rich applicable scenarios: Sentinel has been wildly used in Alibaba, and has covered almost all the core-scenarios in Double-11 (11.11) Shopping Festivals in the past 10 years, such as “Second Kill” which needs to limit burst flow traffic to meet the system capacity, message peak clipping and valley fills, circuit breaking for unreliable downstream services, cluster flow control, etc. […]

Sorgente: alibaba/Sentinel

Hacking YI Dome / YI Home Ip camera – 4° Puntata

Diversamente da quanto detto nella puntata precedente mi sono concentrato sul verificare l’algoritmo di codifica della password, realizzando un programmino allo scopo:

package net.b0sh.yiCameraClient.test;

import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.security.InvalidKeyException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Base64;

public class EncryptionTest {

    public static void main(String[] params) {

        String toBoFound = "OMESSO";
        String cleanPassword = "OMESSO";
        byte[] secret = "secret".getBytes();

        if (digest(cleanPassword, "SHA-256").equals(toBoFound)) {
            System.out.println("success");
        }
        if (digest(cleanPassword, "SHA-1").equals(toBoFound)) {
            System.out.println("success");
        }
        if (digest(cleanPassword, "MD5").equals(toBoFound)) {
            System.out.println("success");
        }
        if (hmac(cleanPassword,"HmacSHA256",secret).equals(toBoFound)) {
            System.out.println("success");
        }
    }

    private static String digest(String password, String alg) {
        try {
            MessageDigest md = MessageDigest.getInstance(alg);
            byte[] bytes = md.digest(password.getBytes());

            System.out.println(alg + " Bytes " + new String(bytes));

            System.out.println(alg + " Base64 " + new String(Base64.getEncoder().encode(bytes)));

            return new String(Base64.getEncoder().encode(bytes));

        } catch (NoSuchAlgorithmException e) {
            System.out.println("NoSuchAlgorithmException");
            return "";
        }
    }

    private static String hmac(String password, String alg, byte[] secret) {

        try {
            SecretKeySpec keySpec = new SecretKeySpec(secret, alg);
            Mac mac = Mac.getInstance(alg);
            mac.init(keySpec);
            mac.update(password.getBytes());

            byte[] bytes = mac.doFinal();


            System.out.println(alg + " Bytes " + new String(bytes));

            System.out.println(alg + " Base64 " + new String(Base64.getEncoder().encode(bytes)));

            return new String(Base64.getEncoder().encode(bytes));

        } catch (NoSuchAlgorithmException e) {
            return "";
        } catch (InvalidKeyException i) {
            return "";
        }

    }

}

Avendo definitiva conferma che l’algoritmo utilizzato è HMAC SHA256, quindi un hash “salato” con un segreto. Il problema quindi resta individuare il segreto. HashCat pare supportare il bruteforce del sale dell’HmacSHA256. Qualcuno ha qualche PetaFLOP da prestarmi?

WSO2 Microservices Framework for Java the Spring Way

Spring is a very popular framework among Java developers. Those who are familiar with the Spring framework tend to follow the same practice wherever possible and generally seek Spring integration support from other Java frameworks as well. The ability to use the Spring framework to develop MSF4J services and MSF4J extensions was one of the main objectives of the MSF4J 2.0.0 release.

Sorgente: [Article] WSO2 Microservices Framework for Java the Spring Way – Part 1

B4J – Modern “VB6 like” development tool for cross platform desktop, server and IoT solutions

Non sò se quello che segue è più genio o follia. Ma qualcuno ha pensato che il basic non meritasse la fine che gli ha fatto fare Microsoft e ha ricostruito un ecosistema intero.

B4J is a 100% free development tool for desktop, server and IoT solutions. With B4J you can easily create desktop applications (UI), console programs (non-UI) and server solutions. The compiled apps can run on Windows, Mac, Linux and ARM boards (such as Raspberry Pi).

Sorgente: B4J – Modern “VB6 like” development tool for cross platform desktop, server and IoT solutions

ABMaterial is a modern framework combining a tuned Materialize CSS with the free programming tool Basic4Java (B4J).

It allows creating WebApps that not only look great thanks to Googles Material Design, but can be programmed in an Object-Oriented way with the powerful free tool from Anywhere Software without any knowledge of HTML, JavaScript or CSS!

Sorgente: alwaysbusycorner

« Articoli meno recenti

© 2024 b0sh.net

Tema di Anders NorenSu ↑