Spring Login (Stack Templates) with HTTPS

Spring Login (Stack Templates) with HTTPS.

sl-jsp-djpa-jc-hib-ehc3-ssl on GitHub
Spring Login (Stack Templates)
Spring Login (Stack Templates) on GitHub

Demo project (Spring, Spring Boot, Spring-Security, JSP, Apache Tiles, Spring-Jpa, Spring-Data-Jpa, JCache, Ehcache, Hibernate, MySQL, Logback, Maven, Gradle) with HTTPS has been added to Spring Login Suite:

sl-jsp-djpa-jc-hib-ehc3-ssl (Spring Login with HTTPS)

  • Spring Boot
  • JSP + Apache Tiles 3
  • Spring MVC + Spring-Security
  • DAO (Spring Data JPA)
  • JCache
  • Hibernate
  • Ehcache3

Project sl-jsp-djpa-jc-hib-ehc3-ssl  contains functionality like in sl-jsp-djpa-eclnk-cache project.

Application sl-jsp-djpa-jc-hib-ehc3-ssl creates default Root Admin (login: ‘root‘ passw: ‘root‘). Root Admin can’t be removed, but can be updated (for ex. passw value).

You can launch built application as using java -jar sl-jsp-djpa-jc-hib-ehc3-ssl.war as you can deploy him to your Java Servlet Container.

If you build sl-jsp-djpa-jc-hib-ehc3-ssl with current version of  src/main/resources/srv.sl.p12, you will need to import CA certificate (as trusted, for ex. Trusted Root CA) from current version ssl/ssl.ecdsa.ca/out/ca.sl.pem. Also you can extract CA certificate from src/main/resources/srv.sl.p12.

Please, and send your notes and questions to info@smansoft.com.

Spring Login (Stack Templates)

Spring Login (Stack Templates).

Spring Login (Stack Templates) on GitHub

Suite of demo projects (Spring, Spring Boot, Spring-Security, JSP, Apache Tiles, Thymeleaf, Spring-Jpa, Spring-Data-Jpa, JCache, Ehcache, Infinispan, Hibernate, EclipseLink, MySQL, Logback, Maven, Gradle).

This Suite contains follow demo/template projects:

print-tool (Print Tool)

scripts

  • Scripts for creating/init/drop of database;

sl-jsp-hib-ehc2 (Spring Login)

  • Spring Boot
  • JSP
  • Spring MVC + Spring-Security
  • DAO (using Hibernate Session Factory)
  • Hibernate
  • Ehcache2

sl-jsp-jpa-hib-ehc2 (Spring Login)

  • Spring Boot
  • JSP
  • Spring MVC + Spring-Security
  • DAO (using JPA EntityManager)
  • Hibernate
  • Ehcache2

sl-jsp-djpa-jc-hib-ehc3 (Spring Login)

  • Spring Boot
  • JSP
  • Spring MVC + Spring-Security
  • DAO (Spring Data JPA)
  • JCache
  • Hibernate
  • Ehcache3

sl-jsp-djpa-jc-hib-infsp (Spring Login)

  • Spring Boot
  • JSP
  • Spring MVC + Spring-Security
  • DAO (Spring Data JPA)
  • JCache
  • Hibernate
  • Infinispan

sl-jsp-djpa-eclnk-cache (Spring Login)

  • Spring Boot
  • JSP + Apache Tiles 3
  • Spring MVC + Spring-Security
  • DAO (Spring Data JPA)
  • EclipseLink
  • EclipseLink Cache

These projects can be used as templates for creation of new Java Spring Framework projects.

Project sl-jsp-djpa-eclnk-cache contains more advanced gui, more roles and more advanced implementation of auth (please, see screenshots here: screenshots).
Also sl-jsp-djpa-eclnk-cache creates default Root Admin (login: ‘root‘ passw: ‘root‘). Root Admin cann’t be removed, but can be updated (for ex. passw value).

You can launch built applications as using java -jar sl-xxx.war as you can deploy them to your Java Servlet Container.

Please, and send your notes and questions to info@smansoft.com.

Java Print Tool

Reflection-based suite of facades over Logger, that provides logging of complex objects.

Print Tool (print-tool) on GitHub

Overview
—————–

Some time, it’s necessary to save in log complex objects (VO, DTO, Entities and some other POJO).

The main features of Print Tool:

– facade over Logger, that allows to solve (using reflection) and print header and footer of output of some function; in this case you don’t need to care about name of function, if it has been renamed/re-factored;

private static final IPrintTool printTool = PrintTool.getPrintToolInstance(LoggerFactory.getLogger(TestPrintTool.class));

public void testPrintTool() {
	printTool.debug(PrintSfx.SFX_IN);
	// some code here
	printTool.debug(PrintSfx.SFX_OUT);
}
 

– provides solving of all fields of complex objects (including aggregated objects) and print values of all fields; in this case you need to use only:

IpVO ipVO;
AddressReqVO addressReqVO;

// init of objects ipVO and addressReqVO

printTool.info(ipVO);
printTool.info(addressReqVO);

– provides interface, that allow to override print of complex objects
(please, see interface com.smansoft.tools.print.api.IPrintable in sources);

As result, usage of Print Tool in function:

private static final IPrintTool printTool = PrintTool.getPrintToolInstance(LoggerFactory.getLogger(TestPrintTool.class));

@Test
public void testPrintTool() {
	printTool.debug(PrintSfx.SFX_IN);

	printTool.info(ipVO);
	printTool.info(addressReqVO);

	printTool.debug(PrintSfx.SFX_OUT);
	Assert.assertTrue(true);
}

generates follow log output:
print-tool-tests.log

You can find sources of Print Tool here:
Print Tool (print-tool) on GitHub

Please, see example of usage of the Print Tool in Unit Test code. Also you can find usage of this project here:
Spring Login (Stack Templates)

Number Pattern #1

Here is the solution of simple algorithmic task – generation of integer sequences. There is a some challenge (easy level) at the site codenirvana.in :

CHALLENGE DESCRIPTION:
Write a program that prints out the pattern generated according to the input (number) from the user.
Pattern input and output sample is given below, check the input and the following pattern generated for that condition (number). Make sure you program follow the same pattern logic for every input.

INPUT SAMPLE:
Your program should ask for a number F first and than print the pattern accordingly. E.g.

Enter a number: 4

OUTPUT SAMPLE:
For the input N=4 output will be

4444444
4333334
4322234
4321234
4322234
4333334
4444444

Here is my solution (“С” for Windows). I’ve implemented two sequences generators – iterative and recursive:

// lines_gen.cpp : Defines the entry point for the console application.
//

#include <stdio.h>
#include <tchar.h>
#include <windows.h>

VOID init_line                          (PUINT	punLine, UINT unN);
VOID print_line                         (PUINT	punLine, UINT unN);
UINT proc_elem                          (PUINT	punLine, UINT unN, UINT unIdx);
UINT proc_array_rec                     (PUINT	punLine, UINT unN);
UINT proc_array_iter                    (PUINT	punLine, UINT unN);
UINT proc_array_iter_bak                (PUINT	punLine, UINT unN);

VOID init_line(PUINT	punLine, UINT unN)
{
  UINT unIdx;
  for(unIdx = 0; unIdx < unN; unIdx++)
    punLine[unIdx] = unIdx+1;
}

VOID print_line(PUINT	punLine, UINT unN)
{
  UINT unIdx;
  _tprintf(_T("line = "));
  for(unIdx = 0; unIdx < unN; unIdx++)
    _tprintf(_T("%d "),punLine[unIdx]);
  _tprintf(_T("\n"));
  return;
}

UINT proc_elem(PUINT	punLine, UINT unN, UINT unIdx)
{
  UINT unRes = 0;

  if((unIdx + 1) >= unN)
    return 0;

  if(punLine[unIdx] >= punLine[unIdx+1])
    unRes = proc_elem(punLine, unN, unIdx+1);
  else
    unRes = punLine[unIdx+1];

  if(unRes)
  {
    punLine[unIdx] = unRes;
    return punLine[unIdx];
  }
  else
    return 0;
}

UINT proc_array_rec(PUINT	punLine, UINT unN)
{
  UINT unCount = 0;

  print_line(punLine, unN);
  while(TRUE)
  {
    unCount++;
    if(!proc_elem	(punLine, unN, 0))
      break;
    print_line(punLine, unN);
  }

  return unCount;
}

UINT proc_array_iter(PUINT punLine, UINT unN)
{
  UINT unIdx;
  UINT unIdxIn;

  print_line(punLine, unN);
  for(unIdx = 1; unIdx < unN; unIdx++)
  {
    for(unIdxIn = 0; unIdxIn <= unIdx; unIdxIn++)
      punLine[unIdxIn] = unIdx+1;
    print_line(punLine, unN);
  }
  return unIdx;
}

UINT proc_array_iter_bak(PUINT punLine, UINT unN)
{
  UINT unIdx;
  UINT unIdxIn;

  print_line(punLine, unN);
  for(unIdx = 1; unIdx < unN; unIdx++)
  {
    UINT unBackIdx = unN-unIdx;
    for(unIdxIn = 0; unIdxIn <= (unBackIdx-1); unIdxIn++)
      punLine[unIdxIn] = unBackIdx;
    print_line(punLine, unN);
  }
  return unIdx;
}

INT _tmain(int argc, _TCHAR* argv[])
{
  UINT	unN		= 0;
  PUINT	punLine	= NULL;
  UINT	unCount;

  _tprintf(_T("Enter a number : "));
  _tscanf_s(_T("%d"), &unN);

  if(!unN)
    return 0;

  punLine = (PUINT) malloc(unN*sizeof(UINT));

  init_line(punLine, unN);
  unCount = proc_array_iter(punLine, unN);
  _tprintf(_T("Total count = %d\n"), unCount);
  _tprintf(_T("-----------------\n"));
  unCount = proc_array_iter_bak(punLine, unN);
  _tprintf(_T("Total count = %d\n"), unCount);
  _tprintf(_T("-----------------\n"));
  unCount = proc_array_rec(punLine, unN);
  _tprintf(_T("Total count = %d\n"), unCount);

  free(punLine);

  return 0;
}

Output:

Enter a number : 5
line = 1 2 3 4 5
line = 2 2 3 4 5
line = 3 3 3 4 5
line = 4 4 4 4 5
line = 5 5 5 5 5
Total count = 5
-----------------
line = 5 5 5 5 5
line = 4 4 4 4 5
line = 3 3 3 4 5
line = 2 2 3 4 5
line = 1 2 3 4 5
Total count = 5
-----------------
line = 1 2 3 4 5
line = 2 2 3 4 5
line = 3 3 3 4 5
line = 4 4 4 4 5
line = 5 5 5 5 5
Total count = 5

lines_gen.c
output.txt

Java:

/**
 * 
 */
package com.smansoft;

/**
 * @author SMan
 * 
 */
public class LinesGen {

  /**
   * 
   */
  int line[] = null;
  
  /**
   * @param args
   */
  public static void main(String[] args) {
    int inNum = Integer.parseInt(args[0]);		
    
    System.out.printf("Number = %d\n", inNum);

    LinesGen linesGen = new LinesGen(inNum);
    linesGen.initLine();

    int count = linesGen.procArrayIter();
    System.out.printf("Total count = %d\n", count);
    count = linesGen.procArrayIterBak();
    System.out.printf("Total count = %d\n", count);
    count = linesGen.procArrayRec();
    System.out.printf("Total count = %d\n", count);
  }

  /**
   * 
   * @param size
   */
  public LinesGen(int size) {
    line = new int[size];
  }

  /**
   * 
   */
  public void initLine() {
    for (int idx = 0; idx < line.length; idx++) {
      line[idx] = (idx + 1);
    }
  }

  /**
   * 
   */
  public void printLine() {
    System.out.print("line = ");
    for (int idx = 0; idx < line.length; idx++) {
      System.out.printf("%d ", line[idx]);
    }
    System.out.println("");
  }

  /**
   * 
   * @return
   */
  public int procArrayRec() {
    int count = 0;
    printLine();
    while (true) {
      count++;
      if (procElem(0) == 0)
        break;
      printLine();
    }
    return count;
  }

  /**
   * 
   * @return
   */
  public int procArrayIter() {
    int idx;
    printLine();
    for (idx = 1; idx < line.length; idx++) {
      for (int idxIn = 0; idxIn <= idx; idxIn++) {
        line[idxIn] = idx + 1;
      }
      printLine();
    }
    return idx;
  }

  /**
   * 
   * @return
   */
  public int procArrayIterBak() {
    int idx;
    printLine();
    for (idx = 1; idx < line.length; idx++) {
      for (int idxIn = 0; idxIn <= (line.length - idx - 1); idxIn++) {
        line[idxIn] = line.length - idx;
      }
      printLine();
    }
    return idx;
  }
  
  /**
   * 
   * @param idx
   * @return
   */
  private int procElem(int idx) {
    int res = 0;

    if ((idx + 1) >= line.length)
      return 0;

    if (line[idx] >= line[idx + 1])
      res = procElem(idx + 1);
    else
      res = line[idx + 1];

    if (res > 0) {
      line[idx] = res;
      return line[idx];
    } else
      return 0;
  }
}

Output (ant run.LinesGen):

run.LinesGen:
[java] Number = 5
[java] line = 1 2 3 4 5
[java] line = 2 2 3 4 5
[java] line = 3 3 3 4 5
[java] line = 4 4 4 4 5
[java] line = 5 5 5 5 5
[java] Total count = 5
[java] line = 5 5 5 5 5
[java] line = 4 4 4 4 5
[java] line = 3 3 3 4 5
[java] line = 2 2 3 4 5
[java] line = 1 2 3 4 5
[java] Total count = 5
[java] line = 1 2 3 4 5
[java] line = 2 2 3 4 5
[java] line = 3 3 3 4 5
[java] line = 4 4 4 4 5
[java] line = 5 5 5 5 5
[java] Total count = 5

LinesGen.java
LinesGen.zip (including ant script)
joutput.txt

SManSoft Ltd.

SManSoft Ltd.

This site has been created and supported by Sergey Manoylo to document software development activity in Software Development (C/C++, Java, Windows, Linux, Android, Kernel Level).

Blog Mirrors:

mirror: http://blog.smansoft.com
mirror: http://smansoft.wordpress.com

 

Contact info:

Sergey Manoylo

mobile phone: +380-67-150-2244
e-mail: sman(at)smansoft.com
e-mail: blog(at)smansoft.com
e-mail: smansoft(at)ukr.net
Skype ID: smansoft.net
Telegram: https://t.me/smansoft (+380671502244)
GitHub: https://github.com/smansoft

Kharkov (Kharkiv), Ukraine