Thursday, January 23, 2020

SSO OAuth2 Spring Boot2 Security JDBC Authentication


I share example how to integration OAuth2 - Spring Boot2 - Security - JDBC Authentication.


Technologies used:

1. Spring Boot 2.0.3.RELEASE
2. Maven 4
3. Java 8
4. OAuth2
5. Eclipse: Oxygen.1.a Release (4.7.1a)
6. Spring Tools Suite (STS) 4
7. MySql

Code on GitHub:

https://github.com/HenryXiloj/SSO-OAuth2-SpringBoot2-JDBC

Steps:

Step 1:

Create tables on mysql:

CREATE TABLE users 
  ( 
     username VARCHAR(50) NOT NULL PRIMARY KEY, 
     password VARCHAR(100) NOT NULL, 
     enabled  BOOLEAN NOT NULL 
  ); 

CREATE TABLE authorities 
  ( 
     username  VARCHAR(50) NOT NULL, 
     authority VARCHAR(50) NOT NULL, 
     CONSTRAINT fk_authorities_users FOREIGN KEY(username) REFERENCES users( 
     username) 
  ); 

CREATE UNIQUE INDEX ix_auth_username ON authorities (username, authority); 


Step 2: Insert your user, example:

For insert password on Databases you need to passwordEncoder, for example use Test.java for generate passwordEncoder:




Resul is : $2a$08$sqfU5.UM.oEqgzVniREsvOsQ9eDtSD/xX8RXT2Bc4AmXWHo4fcchG


INSERT INTO users 
VALUES      ('henry', 
             '$2a$08$ykZFaf/pmTxnShaj5dqXZeWXiK3JJSJr5f20hqiVGSO35KNyQ0lgO' 
             /*123*/, 
             true); 

INSERT INTO authorities 
            (username, 
             authority) 
VALUES     ('henry', 
            'ROLE_ADMIN'); 



Step 3:

On the proyect spring-security-sso-auth-server change the configuration in application.yml




Step 4:

Run 2 proyects on Eclipse or if you prefer use command line on console:

First: auth server

Righ click on proyect -> Run As -> Spring Boot App

Expose on port: 8081



Second: sso-ui

Expose on port: 8082




Step 5:

http://localhost:8082/ui/




























References:

https://www.baeldung.com/sso-spring-security-oauth2
https://www.baeldung.com/spring-security-jdbc-authentication
https://mkyong.com/spring-security/spring-security-form-login-using-database/





Saturday, January 18, 2020

Permission Denied (publickey) error when I push (GitHub)


I share solution next error:

Permission Denied (publickey)' error when I push!

Steps:

Step 1:

Search de folder .ssh, you find the folder on your user:  (if the folder doesn´t exist then you need to create the folder with the command mkdir inside on your_user)

Linux:  /home/my_user/.ssh
Windows: C:\Users/my_user/.ssh


Step 2: Run the next command and press enter: (Leave blank what they ask)

ssh-keygen


Step 3:

Before command generate the file id_rsa.pub, open the file by command or any editor and copy of content.

Step 4:

Go to your profile on  GitHub:

Choose Settings --> SSH and GPG Keys --> New SSH Key --> Copy content from file id_rsa.pub


And try to git push again.


















References:
https://gist.github.com/adamjohnson/5682757


Multiple Data Sources in Spring Boot 3 with Java 21

  In this blog post, we'll explore the configuration and setup for a Spring Boot 3 application with Java 21 that uses multiple data sour...