Saturday, March 28, 2020

Kotlin + OAuth2 + JWT + SpringBoot2 + JPA

I share example how to integrate Kotlin + OAuth2 + Spring Rest API + SpringBoot 2  + JWT +JPA.

Technologies used:

1. Spring Boot 2.2.6.RELEASE
2. Maven
3. OAuth2
4. Intellij IDEA Community
5. Spring Tools Suite (STS) 4
6. MySql
7. Postman

Code on GitHub:

https://github.com/HenryXiloj/Kotlin-OAuth2-SpringBoot2-JPA

Steps:


Create table on MySql:

CREATE TABLE `users` 
( 
 `id`       INT(11) NOT NULL auto_increment, 
 `username` VARCHAR(255) NOT NULL, 
 `password` VARCHAR(255) NOT NULL, 
 `created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP() on 
  UPDATE CURRENT_TIMESTAMP(), 
  PRIMARY KEY (`id`) 
)


I saved the password field with Security - Password Enconding (org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder)

INSERT INTO users 
VALUES      (1, 
             'henry', 
             '$2a$04$I9Q2sDc4QGGg5WNTLmsz0.fvGv3OjoZyj81PrSFyGOqMphqfS2qKu'); 



IntelliJ:  File -> open --> choose folder backend


Change the configuration on file application.yml




Run project from IntelliJ :

View -> Tool Windows -> Maven -> Execute Maven Goal-> mvn install











Run project backend.jar with java -jar backend.jar,  in the file configuration you can define context for application, i define context --> backend and port 9000.


Credencials for test:





Test: Get token





Test: Error when you try to access ws, you need to add access_token




Add access_token -> url?access_token=your_token.




























References:
https://www.devglan.com/spring-security/spring-boot-security-oauth2-example










Wednesday, March 25, 2020

Configure Tomcat reverseproxy https to http

If your site using https and you need to access http tomcat, you need to make reverseproxy.

Edit file conf/server.xml and add yellow paragraph:

<Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               proxyName="server.company.com" scheme="https" secure="true" proxyPort="443" />


Restart tomcat.

Try again.





















References:
https://serverfault.com/questions/742922/configure-tomcat-behind-reverseproxy












Thursday, March 19, 2020

GIT Tips


1.  Install git

sudo apt install git

2. create file .ssh

sudo mkdir /home/your_user/.ssh  

3. On folder .ssh run next command, (enter and enter doesn't write anything).

ssh-key

4. copy content on file id_rsa.pub

cat /home/your_user/.ssh/id_rsa.pub

5. Open in your browser GitHub or GitLab

GitHub: https://github.com/settings/keys  -> New SSH key

GitLab:https://your_ip_or_hostname/profile/keys --> Add and SSH Key

6. Clone branch or specific branch

Any branch:
git clone <remote-repo>
Specific branch:
git clone --single-branch --branch <branchname> <remote-repo>

8. Discard unstaged changes

git stash

9. Git Checkout Specific file

git checkout <branch_name> -- <paths>

10. Override comment in commit

git commit --amend -m "My_new_comment"

11. Remove local commits

git reset --hard origin/<branch_name>

12. To rollback to commit

git reset --hard sha1_id

13. Create GitHub Branch from Commit

Clone the Repository:
git clone https://github.com/your-username/your-repository.git
cd your-repository
Find the Commit Hash:
git log
Create a New Branch:
git checkout -b new-branch-name commit-hash
Push the New Branch to GitHub:
git push origin new-branch-name

14. Long path file:

git config --system core.longpaths true

Wednesday, March 4, 2020

Please check if the configured key or specified key file is a valid SSH Private Key - Rancher Kubernetes

Solution next error Rancher on Centos8:

Please check if the configured key or specified key file is a valid SSH Private Key. Error: Error configuring SSH: ssh: no key found


Steps:

WORKSTATION.

Save the key of your nodes on workstation.

Step 1 — Create the RSA Key Pair


ssh-keygen

Enter and enter doesn't write anything.

Step 2 — Copy the Public Key to CentOS Server


ssh-copy-id username@remote_host

Copying Public Key Using SSH

cat ~/.ssh/id_rsa.pub | ssh username@remote_host "mkdir -p ~/.ssh && touch ~/.ssh/authorized_keys && chmod -R go= ~/.ssh && cat >> ~/.ssh/authorized_keys"


Check connect with ssh without password.











References:



Creating REST APIs with OpenAPI, Spring Boot 3.3.3, Java 21, and Jakarta

 Introduction In today's software landscape, designing robust and scalable REST APIs is a crucial aspect of application development. Wit...