Monday, February 11, 2019

Big difference between Agile and Microservices

Big difference between Agile and Microservices (... as a joke)


Any differences or similarities between Agile and Microservices?

AGILE = a recipe of how to make order out from the mess, so that it can be cleaned and cleaned up by itself forever :-)

MICROSERVICES =
a recipe of how to make a mess from the order, so that it controls itself, monitors itself, repairs itself and can grow infinitely without losing the expected functionality  :-)


Sunday, February 10, 2019

Converting Properties Files to Escaped Unicode

Converting Properties Files to Escaped Unicode


Using Unicode characters in Java with properties files is somethimes problematic, when we want to show signs and symbols that are not ASCII characters...

Converting Properties Files to Escaped Unicode is a must!
when we have problem with displaying especial signs:

So we want to send u-escaped Unicode, using \uXXXX. 
As not only Java, but also JavaScript/JSON knows this convention, we only need this u-escaping in java on the server.

Solution:




Symbols, icons, "visual thinking" signs and letters:



Pushing on Github and Credentials and 403 error

Pushing on Github and Credentials and 403 error

Sometimes when we can work on Github with more than one account, we can obtain an error 403!!

git push (...)
remote: Permission to (...) denied to (...)
fatal: unable to access (...) The requested URL returned error: 403

The error is that our computer has saved a git username and password for Github in Windows Credentials, so if we shift to another account the error 403 will appear. 

Below is the solution:

Control panel > user accounts > credential manager > Windows credentials > Generic credentials
(IN POLISH: Panel sterowania\Konta użytkowników i Filtr rodzinny\Menedżer poświadczeń)

Next remove the Github keys and log in again.


Wednesday, February 6, 2019

OWASP TOP 10

OWASP TOP 10

As we can read at https://www.owasp.org/index.php/Category:OWASP_Top_Ten_Project
and https://blog.sucuri.net/2018/10/owasp-top-10-security-risks-part-i.html the Top 10 OWASP security vulnerabilities are:

  1. Injection
  2. Broken Authentication
  3. Sensitive data exposure.
  4. XML External Entities (XXE)
  5. Broken Access control.
  6. Security misconfigurations.
  7. Cross Site Scripting (XSS)
  8. Insecure Deserialization.
  9. Using Components with known vulnerabilities.
  10. Insufficient logging and monitoring.

Tuesday, February 5, 2019

NETFLIX

NETFLIX

As we can read at http://spring.io/projects/spring-cloud-netflix and https://netflix.github.io/ do You know that Spring Cloud Netflix provides Netflix OSS integrations for Spring Boot apps through autoconfiguration and binding to the Spring Environment and other Spring programming model idioms?

@EnableEurekaClient
With a few simple annotations you can quickly enable and configure the common patterns inside your application and build large distributed systems with battle-tested Netflix components. The patterns provided include Service Discovery (Eureka), Circuit Breaker (Hystrix), Intelligent Routing (Zuul) and Client Side Load Balancing (Ribbon)..

Spring Cloud Netflix features:


  • Service Discovery: Eureka instances can be registered and clients can discover the instances using Spring-managed beans
  • Service Discovery: an embedded Eureka server can be created with declarative Java configuration
  • Circuit Breaker: Hystrix clients can be built with a simple annotation-driven method decorator
  • Circuit Breaker: embedded Hystrix dashboard with declarative Java configuration
  • Declarative REST Client: Feign creates a dynamic implementation of an interface decorated with JAX-RS or Spring MVC annotations
  • Client Side Load Balancer: Ribbon
  • External Configuration: a bridge from the Spring Environment to Archaius (enables native configuration of Netflix components using Spring Boot conventions)
  • Router and Filter: automatic registration of Zuul filters, and a simple convention over configuration approach to reverse proxy creation

Very interesting information related to microservices and Netflix technologies:


Monday, February 4, 2019

Tribute to Wanda Rutkiewicz

Tribute to Wanda Rutkiewicz

Wanda Rutkiewicz was born on February 4, 1943 and known as the first woman to successfully climb K2 (Chhogori or Mount Godwin-Austen, at 8,611 metres / 28,251 ft above sea level). She was a Polish computer engineer and mountain climber.

https://en.wikipedia.org/wiki/Wanda_Rutkiewicz

https://www.fakt.pl/sport/inne-sporty/wanda-rutkiewicz-25-lat-od-zaginiecia-himalaistki-tracila-bliskich/wwns0sl

Spring Boot example

Spring Boot example


application.properties:

# ===============================
# H2 CONSOLE
# ===============================
spring.h2.console.path=/h2
# To See H2 Console in Browser:
# http://localhost:8080/h2
# Enabling H2 Console
spring.h2.console.enabled=true

# ===============================
# DB
# ===============================

spring.datasource.url=jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=

# ===============================
# JPA / HIBERNATE
# ===============================

spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.H2Dialect
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.jpa.hibernate.ddl-auto = update
spring.jpa.properties.hibernate.show_sql=false
spring.jpa.properties.hibernate.use_sql_comments=false
spring.jpa.properties.hibernate.format_sql=false



-------------------


package eu.microwebservices.awesomeappproject;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RestController;

@RestController
@SpringBootApplication
public class AwesomeApp {

public static void main(String[] args) {
SpringApplication.run(AwesomeApp.class, args);
}

}

----------------------------------

package eu.microwebservices.awesomeappproject.model;

import javax.persistence.*;
import javax.validation.constraints.NotNull;

@Entity
@Table(name = "tab_user")
public class User {

  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  private Long id;

  /**
   * Sorry but, there is no validation here with email!
   * It is not secure because of no validation from user input! See https://www.owasp.org
   * It is only for educational purposes...
   */
  @NotNull
  private String email;

  /**
   * This is a name generally, which could be the nickname or the firstname,
   * but if the user prefer it could be last name...
   * There is no validation here!
   * It is only for educational purposes...
   */
  @NotNull
  private String name;

  public User() {
  }

  public User(Long id) {
    this.id = id;
  }

  public User(String email, String name) {
    this.email = email;
    this.name = name;
  }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
 
    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    @Override
    public String toString() {
        return "User{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", email=" + email +
                '}';
    }

}


--------------------------------

package eu.microwebservices.awesomeappproject.model;

import org.springframework.data.repository.*;
import org.springframework.transaction.annotation.*;

@Transactional
public interface UserDao extends CrudRepository {

  /**
   * This method will find an User instance in the database by its email.
   * Note that this method is not implemented and its working code will be
   * automagically generated from its signature by Spring Data JPA.
   */
  public User findByEmail(String email);

    /**
   * This method will find an User instance in the database by its name.
   * Note that this method is not implemented and its working code will be
   * automagically generated from its signature by Spring Data JPA.
   */
  public User findByName(String name);

}

--------------------------------

package eu.microwebservices.awesomeappproject.controller;

import eu.microwebservices.awesomeappproject.model.User;
import eu.microwebservices.awesomeappproject.model.UserDao;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class UserController {
   /**
    * HOW TO TEST:
    * $ mvn spring-boot:run
    * http://localhost:8080/
    * Use the following urls:
    *    /create-user?email=[email]&name=[name]:    create a new user with an auto-generated id and email and name as passed values.
    *    /delete-user?id=[id]:      delete the user with the passed id.
    *    /get-user-by-email?email=[email]:      retrieve the id for the user with the passed email address.
    *    /update-user?id=[id]&email=[email]&name=[name]:    update the email and the name for the user indentified by the passed id.
    */

  @Autowired
  private UserDao userDao;

  /**
   * /create-user  --> Create a new user and save it in the database.
   * It is not secure operation here! There is no validation here!  See https://www.owasp.org
   * It is only for REST educational purposes...
   *
   * @param email User's email
   * @param name User's name
   * @return A string describing if the user is successfully created or not.
   */
  @RequestMapping("/create-user")
  @ResponseBody
  public String create(String email, String name) {
    User user = null;
    try {
      user = new User(email, name);
      userDao.save(user);
    }
    catch (Exception ex) {
      return "Error while creating the user: " + ex.toString();
    }
    return "User created succesfully!! (id = " + user.getId() + ")";
  }

  /**
   * /delete-user  --> Delete the user having the passed id.
   * It is not secure operation here! There is no validation here!
   * It is only for REST educational purposes...
   *
   * @param id The id of the user to delete
   * @return A string describing if the user is successfully deleted or not.
   */
  @RequestMapping("/delete-user")
  @ResponseBody
  public String delete(Long id) {
    try {
      User user = new User(id);
      userDao.delete(user);
    }
    catch (Exception ex) {
      return "Error while deleting the user: " + ex.toString();
    }
    return "User deleted successfully!!";
  }

  /**
   * /get-user-by-email  --> Return the id for the user having the passed email.
   * It is not secure operation here! There is no validation here!
   * It is only for REST educational purposes...
   *
   * @param email The email to search in the database.
   * @return The user id or a message error if the user is not found.
   */
  @RequestMapping("/get-user-by-email")
  @ResponseBody
  public String getByEmail(String email) {
    Long userId;
    try {
      User user = userDao.findByEmail(email);
      if (user != null) {
        userId = user.getId();
      } else {
        return "User not found!!";
      }
    }
    catch (Exception ex) {
      return "User not found!!";
    }
    return "The user is found, and id is: " + userId;
  }

  /**
   * /update-user  --> Update the email and the name for the user in the database
   * having the passed id.
   * It is not secure operation here! There is no validation here!
   * It is only for REST educational purposes...
   *
   * @param id The id for the user to update.
   * @param email The new email.
   * @param name The new name.
   * @return A string describing if the user is successfully updated or not.
   */
  @RequestMapping("/update-user")
  @ResponseBody
  public String updateUser(long id, String email, String name) {
    try {
      User user = userDao.findOne(id);
      user.setEmail(email);
      user.setName(name);
      userDao.save(user);
    }
    catch (Exception ex) {
      return "Error while updating the user: " + ex.toString();
    }
    return "User updated successfully!!";
  }

}

-----------------------------

pom.xml: