Tuesday, May 29, 2018

Spring-Boot-Security-RestAPI-OAuth2 'JOT'

I Share Example, how to integrate Spring Boot, Security and RestAPI with OAuth2.

Technologies used:

1. Spring Boot 1.5.6.RELEASE
2. Maven 4
3. Java 8
4. Eclipse: Oxygen.1.a Release (4.7.1a)
5. Tomcat 8.5

Code on GitHub:

https://github.com/HenryXiloj/Spring-Boot-Security-RestAPI-OAuth2

Proyect.



Steps:

1. Import maven proyect in eclipse.

2. Right click on Spring-Boot-Security-RestAPI-OAuth2 project -Run as -> Run on Server.



3.  package: com.hxiloj.controller -> RestClient.java -> Right click on Class -> Run as -> Java Application






References: http://websystique.com/spring-security/secure-spring-rest-api-using-oauth2/














Thursday, April 19, 2018

Integration spring-boot-security-dataJPA-oauth2-google-angular5

I share basic example, how to integrate Spring-boot-security-dataJPA-oauth2-googe with angular 5

Technologies used:

1. Spring Boot 2.0.1.RELEASE
2. Oracle (Ojdbc) 11.2.0.4
3. Tomcat Embed
4. Maven 4
5. Java 8
6. Angular CLI: 1.7.4
7. Node: 8.9.4
8. Eclipse: Oxygen.1.a Release (4.7.1a)


Steps:

1. Create your project in google for get your clientId and clientSecret, we need both for use OAuth2 with google.  go to 

https://console.developers.google.com

And create your project and credentials for OAuth2

check images.








2. In Backend App -> file application.yml set your Client ID and Client secret

Check image.




3. Import projects in eclipse then your import backend project: 

Right click on backend project -Show in -> Terminal.

build and run the SpringBoot server again with commands:

– Build: mvn clean install

– Run:  mvn spring-boot:run


4. if you want to know, how to integrate step to step spring boot with angular 5
check my blog: http://jarmx.blogspot.com/2018/04/integration-springboot-springdatajpa.html


5. if you to do the steps succes then. -request url: http://localhost:8080/google/login

check images:















Code on GitHub: 

Backend: https://github.com/HenryXiloj/spring-boot-security-dataJPA-oauth2-google
Front-end: https://github.com/HenryXiloj/angular5-front-end


References: https://dzone.com/articles/build-a-secure-spa-with-spring-boot-and-oauth


Wednesday, April 18, 2018

ORA-01034: ORACLE not available, ORA-27101: shared memory realm does not exist

I share solution the next error:

ERROR:
ORA-01034: ORACLE not available
ORA-27101: shared memory realm does not exist
Linux-x86_64 Error: 2: No such file or directory
Process ID: 0
Session ID: 0 Serial number: 0

Steps:

Step 1:

Connect user from linux or unix.

*oracle is my user.

sudo su - oracle

* set your password.
* if you don't remmeber your password change password with the next command.

sudo passwd oracle

Step 2:

Use the lsnrctl command to start service

lsnrctl start

Step 3:

Start database:

dbstart

* Try connect your database.
* if you have the next error: try with the step 4.






Step 4:

* Try to login sysdba user:

sqlplus '/ as sysdba'


Step 5:

* Type startup command:

startup.

* Try connect your database

Check image below with commands:




































Great :).


References: https://www.cyberciti.biz/faq/how-do-i-start-oracle-service-in-unix/




Wednesday, April 11, 2018

Create maven archetype from existing project

I share basic example, how to create maven archetype from existing project.

Steps:

Step 1.

-cd your_project

run next command: mvn archetype:create-from-project





































It then generates the directory tree of the archetype in the target/generated-sources/archetype directory.
Step 2. Move directory.

- cd target/generated-sources/archetype/

- And run command mvn install






























Step 3. Move to a fresh directory and use your archetype.

- mkdir /tmp/archetype

- cd /tmp/archetype

- mvn archetype:generate -DarchetypeCatalog=local































References: https://maven.apache.org/archetype/maven-archetype-plugin/advanced-usage.html






Monday, April 9, 2018

Integration-SpringBoot-SpringDataJPA-Angular5

I share basic example, how to integrate Spring Boot - SpringDataJPA-Angular5


Technologies used:


1. Spring Boot 2.0.1.RELEASE
2. Oracle (Ojdbc) 11.2.0.4
3. Tomcat Embed
4. Maven 4
5. Java 8
6. Angular CLI: 1.7.4
7. Node: 8.9.4
8. Eclipse: Oxygen.1.a Release (4.7.1a)

Steps:

1. Create project angular

  



if you want to test and start application,  you have to run the next command in your console.

















Open your browser: http://localhost:4200/

2. Import your project angular to eclipse:

Import -> General -> Projects from Folder or Archieve -> Directory, press finish


























3. To clean the sourcecode in STS, we need to remove node_modules:
– Right click on angular5-client project, choose Properties, then choose:  Resource --> Resource Filter.
– Press Add Filter, choose Filter Type, press OK -> Apply and Close





























4. Create a file proxy.conf.json


{

"/ws": {

"target": "http://localhost:8080",

"secure": false

}
}



5. Edit package.json file for “start” script:

Edit next line: "start": "ng serve --proxy-config proxy.conf.json",













6. Right click on angular5-client project
  -Show in -> Terminal.

 Build angular5 client with command  ng build --env=prod










Result is a dist folder:






















7. References folder dist from pom.xml Eclipse project.






                         





















8. build and run the SpringBoot server again with commands:

– Build: mvn clean install






















– Run:  mvn spring-boot:run




































--request url from test: http://localhost:8080/









--





request url web service rest: http://localhost:8080/ws/read












Code on GitHub: 

Backend: https://github.com/HenryXiloj/SpringBoot-SprinDataJPA
Front-end: https://github.com/HenryXiloj/angular5-client









References: http://javasampleapproach.com/java-integration/integrate-angular-4-springboot-web-app-springtoolsuite


Tuesday, March 20, 2018

Generic method Marshalling and Unmarshalling JAXB

I share example JAXB.

public static  <T> String convertObjectToXML(T object) 
{
        try {

            StringWriter stringWriter = new StringWriter();
            JAXBContext context = JAXBContext.newInstance(object.getClass());
            Marshaller marshaller = context.createMarshaller();
            marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
            marshaller.marshal(object, stringWriter);
            return stringWriter.toString();
        } 
        catch (JAXBException e){
         throw new RuntimeException(String.format("Exception while marshalling: %s", e.getMessage()));
        }
   }
 
    @SuppressWarnings("unchecked")
  public static <T> T convertXMLToObject(Class<T> clazz, String xml) 
    {
        try {

            JAXBContext context = JAXBContext.newInstance(clazz);
            Unmarshaller um = context.createUnmarshaller();
            return (T) um.unmarshal(new StringReader(xml));
        } 
        catch (JAXBException je){
            throw new RuntimeException(String.format("Exception while Unmarshaller: %s", je.getMessage()));
        }
    }

@SuppressWarnings("unchecked")
public static <T> T convertXMLToObject(Class<T> clazz, InputStream file) {
   
   
    try {
    JAXBContext jaxbContext = JAXBContext.newInstance(clazz);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
T obj = (T) jaxbUnmarshaller.unmarshal(file);
return obj;

} catch (JAXBException e) {
// TODO Auto-generated catch block
e.printStackTrace();
throw new RuntimeException(String.format("Exception while Unmarshaller: %s", e.getMessage()));
}
    }

Friday, March 16, 2018

Habilitar conexion remota en MySQL (Linux Ubuntu)

A continuacion les dejo unos sencillos pasos para habilitar conexion remota en MySQL en Linux Ubuntu espero que les sea de mucha utilidad.

Editar el archivo my.cnf

sudo gedit /etc/mysql/my.cnf
OR
sudo gedit /etc/mysql/mysql.conf.d/mysqld.cnf

Buscar la secciรณn: [mysqld]

y buscamos la siguiente linea:

bind-address = 127.0.0.1

Y lo comentamos poniendo un '#' al principio de esta, quedando de la siguiente forma:

#bind-address = 127.0.0.1

Guardamos los cambios y reiniciamos el servidor:

sudo service mysql restart

Accedemos a la terminar y ejecutamos mysql

mysql -u root -p

Dentro de mysql ejecutamos los siguientes comandos

1) GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'PASSWORD' WITH GRANT OPTION;

y en password seteamos el password que va tener la cuenta root que va el usuario

que se va a loguear remotamente

2) FLUSH PRIVILEGES;

3) exit

Luego realizar prueba correspondiente, para ello les recomiendo utilizar MySQL Workbench IDE, sencillo de utilizar. :)

Saludos

๐Ÿš€ Spring Boot 3.5 → 4.0.3 Migration Summary

Import Changes, API Adjustments & Compatibility Results Migration summary from Spring Boot 3.5 → 4.0, including breaking changes, depend...