Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: donreno/proyecto-universidad
base: bc0f112156
...
head fork: donreno/proyecto-universidad
compare: a4a0cd17f3
Checking mergeability… Don't worry, you can still create the pull request.
  • 11 commits
  • 22 files changed
  • 0 commit comments
  • 1 contributor
Showing with 487 additions and 250 deletions.
  1. +2 −2 EnvaflexUI/src/main/webapp/WEB-INF/web.xml
  2. BIN  envaflex-business/evxBase.h2.db
  3. +13 −2 envaflex-business/src/main/java/cl/envaflex/bootstrap/DataCreator.java
  4. +8 −6 envaflex-business/src/main/resources/spring-config.xml
  5. +65 −65 envaflex-business/src/test/java/cl/envaflex/jpa/dao/EmpleadoDaoTest.java
  6. +1 −1  envaflex-core/.classpath
  7. +59 −9 envaflex-core/pom.xml
  8. +0 −32 envaflex-core/src/main/java/cl/envaflex/util/HibernateUtils.java
  9. +4 −4 envaflex-core/src/main/resources/spring-config.xml
  10. BIN  envaflex-core/target/classes/cl/envaflex/util/HibernateUtils.class
  11. +0 −65 envaflex-core/target/classes/spring-config.xml
  12. +12 −18 envaflex-rest-business/pom.xml
  13. +7 −0 envaflex-rest-business/src/main/java/cl/envaflex/rest/object/CargoObject.java
  14. +23 −0 envaflex-rest-business/src/main/java/cl/envaflex/rest/service/CargoWS.java
  15. +82 −0 envaflex-rest-business/src/main/java/cl/envaflex/rest/service/SecurityWS.java
  16. +80 −0 envaflex-rest-business/src/main/resources/spring-config.xml
  17. +30 −0 envaflex-rest-business/src/main/webapp/WEB-INF/security-config.xml
  18. +39 −27 envaflex-rest-business/src/main/webapp/WEB-INF/web-config.xml
  19. +13 −2 envaflex-rest-business/src/main/webapp/WEB-INF/web.xml
  20. +6 −2 envaflex-rest-core/.classpath
  21. +1 −1  envaflex-rest-core/.settings/org.eclipse.wst.common.component
  22. +42 −14 envaflex-rest-core/pom.xml
View
4 EnvaflexUI/src/main/webapp/WEB-INF/web.xml
@@ -10,8 +10,8 @@
<listener-class>org.zkoss.zk.ui.http.HttpSessionListener</listener-class>
</listener>
<context-param>
- <param-name>conspring-config.xmltextConfigLocation</param-name>
- <param-value>resources/spring-context.xml</param-value>
+ <param-name>contextConfigLocation</param-name>
+ <param-value>resources/spring-config.xml</param-value>
</context-param>
<servlet>
<description>
View
BIN  envaflex-business/evxBase.h2.db
Binary file not shown
View
15 envaflex-business/src/main/java/cl/envaflex/bootstrap/DataCreator.java
@@ -30,6 +30,7 @@ public DataCreator(@Qualifier(EmpleadoDao.BEAN_NAME) EmpleadoDao empDao,
public void createData(){
Cargo admin = createCargoAdmin();
Cargo cargoVndr = createCargoVNDR();
+ createCargoSupervisor();
//Creamos usuarios
Empleado gustavo = new Empleado();
@@ -55,7 +56,7 @@ private Cargo createCargoVNDR(){
Cargo cargo = new Cargo();
cargo.setIdCargo("VNDR");
cargo.setNombreCargo("VENDEDOR");
- cargo.setDescCargo("...");
+ cargo.setDescCargo("Ejecutivo de ventas");
cargoDao.insertar(cargo);
System.out.println("Cargo creado...");
return cargo;
@@ -65,7 +66,17 @@ private Cargo createCargoAdmin(){
Cargo cargo = new Cargo();
cargo.setIdCargo("ADMN");
cargo.setNombreCargo("ADMINISTRADOR");
- cargo.setDescCargo("...");
+ cargo.setDescCargo("Administrador de sistema");
+ cargoDao.insertar(cargo);
+ System.out.println("Cargo creado...");
+ return cargo;
+ }
+
+ private Cargo createCargoSupervisor(){
+ Cargo cargo = new Cargo();
+ cargo.setIdCargo("SUPR");
+ cargo.setNombreCargo("SUPERVISOR");
+ cargo.setDescCargo("Supervisor de Ventas");
cargoDao.insertar(cargo);
System.out.println("Cargo creado...");
return cargo;
View
14 envaflex-business/src/main/resources/spring-config.xml
@@ -4,14 +4,16 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
- http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
- http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
- http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
-http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd"
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
+ http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
+ http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
+http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd"
default-init-method="init">
<context:annotation-config />
- <context:component-scan base-package="cl.envaflex" />
+ <context:component-scan base-package="cl.envaflex.jpa" />
+ <context:component-scan base-package="cl.envaflex.service" />
+ <context:component-scan base-package="cl.envaflex.bootstrap" />
<tx:annotation-driven transaction-manager="transactionManager"
proxy-target-class="true" />
@@ -41,7 +43,7 @@ http://www.springframework.org/schema/context http://www.springframework.org/sch
<!-- Hibernate Configuration -->
<bean id="hibernateProperties"
class="org.springframework.beans.factory.config.PropertiesFactoryBean">
- <property name="properties">
+ <property name="properties" >
<props>
<prop key="hibernate.hbm2ddl.auto">create-drop</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.H2Dialect</prop>
View
130 envaflex-business/src/test/java/cl/envaflex/jpa/dao/EmpleadoDaoTest.java
@@ -29,70 +29,70 @@ public void testContext(){
System.out.println("Context UP!");
}
-// private Cargo createCargoVNDR(){
-// Cargo cargo = new Cargo();
-// cargo.setIdCargo("VNDR");
-// cargo.setNombreCargo("VENDEDOR");
-// cargo.setDescCargo("...");
-// cargoDao.insertar(cargo);
-//// cargoDao.getHibernateTemplate().flush();
-// System.out.println("Cargo creado...");
-// return cargo;
-// }
-//
-// private Cargo createCargoOPR(){
-// Cargo cargo = new Cargo();
-// cargo.setIdCargo("OPR");
-// cargo.setNombreCargo("Operario");
-// cargo.setDescCargo("...");
-// cargoDao.insertar(cargo);
-//// cargoDao.getHibernateTemplate().flush();
-// System.out.println("Cargo creado...");
-// return cargo;
-// }
-//
-// public void testCreateEmpleados(){
-// Cargo cargoVndr = createCargoVNDR();
-// Cargo cargoOpr = createCargoOPR();
-//
-// Empleado emp = new Empleado();
-// emp.setRutEmpleado("12345679");
-// emp.setDvEmpleado("8");
-// emp.setCargo(cargoVndr);
-// emp.setEsUsuario(true);
-// emp.setUser("vendedor");
-// emp.setPassword("password");
-// emp.setFechaNacimiento(new Date());
-// emp.setNombreEmpleado("Mister");
-// emp.setApellidoPaterno("Vende");
-// emp.setApellidoMaterno("Door");
-// empleadoDao.insertar(emp);
-// System.out.println("Empleado 1 Creado...");
-//
-// Empleado emp2 = new Empleado();
-// emp2.setRutEmpleado("12345678");
-// emp2.setDvEmpleado("9");
-// emp2.setCargo(cargoOpr);
-// emp2.setEsUsuario(true);
-// emp2.setUser("operador");
-// emp2.setPassword("password");
-// emp2.setFechaNacimiento(new Date());
-// emp2.setNombreEmpleado("Mister");
-// emp2.setApellidoPaterno("Oper");
-// emp2.setApellidoMaterno("Ario");
-// empleadoDao.insertar(emp2);
-// System.out.println("Empleado 2 Creado...");
-// }
-//
-// public void testFindEmpleadosJpa(){
-// List<Empleado> empleados = empleadoDao.findAll();
-// for(Empleado empl:empleados){
-// System.out.println("***************************");
-// System.out.println("ID: "+empl.getRutEmpleado());
-// System.out.println("Nombre: "+empl.getNombreEmpleado());
-// System.out.println("Cargo: "+empl.getCargo().getNombreCargo());
-// System.out.println("***************************");
-// }
-// }
+ private Cargo createCargoVNDR(){
+ Cargo cargo = new Cargo();
+ cargo.setIdCargo("VNDR");
+ cargo.setNombreCargo("VENDEDOR");
+ cargo.setDescCargo("...");
+ cargoDao.insertar(cargo);
+// cargoDao.getHibernateTemplate().flush();
+ System.out.println("Cargo creado...");
+ return cargo;
+ }
+
+ private Cargo createCargoOPR(){
+ Cargo cargo = new Cargo();
+ cargo.setIdCargo("OPR");
+ cargo.setNombreCargo("Operario");
+ cargo.setDescCargo("...");
+ cargoDao.insertar(cargo);
+// cargoDao.getHibernateTemplate().flush();
+ System.out.println("Cargo creado...");
+ return cargo;
+ }
+
+ public void testCreateEmpleados(){
+ Cargo cargoVndr = createCargoVNDR();
+ Cargo cargoOpr = createCargoOPR();
+
+ Empleado emp = new Empleado();
+ emp.setRutEmpleado("12345679");
+ emp.setDvEmpleado("8");
+ emp.setCargo(cargoVndr);
+ emp.setEsUsuario(true);
+ emp.setUser("vendedor");
+ emp.setPassword("password");
+ emp.setFechaNacimiento(new Date());
+ emp.setNombreEmpleado("Mister");
+ emp.setApellidoPaterno("Vende");
+ emp.setApellidoMaterno("Door");
+ empleadoDao.insertar(emp);
+ System.out.println("Empleado 1 Creado...");
+
+ Empleado emp2 = new Empleado();
+ emp2.setRutEmpleado("12345678");
+ emp2.setDvEmpleado("9");
+ emp2.setCargo(cargoOpr);
+ emp2.setEsUsuario(true);
+ emp2.setUser("operador");
+ emp2.setPassword("password");
+ emp2.setFechaNacimiento(new Date());
+ emp2.setNombreEmpleado("Mister");
+ emp2.setApellidoPaterno("Oper");
+ emp2.setApellidoMaterno("Ario");
+ empleadoDao.insertar(emp2);
+ System.out.println("Empleado 2 Creado...");
+ }
+
+ public void testFindEmpleadosJpa(){
+ List<Empleado> empleados = empleadoDao.findAll();
+ for(Empleado empl:empleados){
+ System.out.println("***************************");
+ System.out.println("ID: "+empl.getRutEmpleado());
+ System.out.println("Nombre: "+empl.getNombreEmpleado());
+ System.out.println("Cargo: "+empl.getCargo().getNombreCargo());
+ System.out.println("***************************");
+ }
+ }
}
View
2  envaflex-core/.classpath
@@ -4,7 +4,7 @@
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
View
68 envaflex-core/pom.xml
@@ -6,6 +6,18 @@
<version>1.0.0-SNAPSHOT</version>
<name>envaflexCore</name>
<!-- Project compilation configuration -->
+ <properties>
+ <aspectj.version>1.6.6</aspectj.version>
+ <commons-dbcp.version>1.2.2</commons-dbcp.version>
+ <hibernate-annotations.version>3.3.1.GA</hibernate-annotations.version>
+ <hibernate-core.version>3.2.6.ga</hibernate-core.version>
+ <hsqldb.version>1.8.0.10</hsqldb.version>
+ <javassist.version>3.7.ga</javassist.version>
+ <log4j.version>1.2.15</log4j.version>
+ <slf4j-log4j12.version>1.5.6</slf4j-log4j12.version>
+ <springframework.version>3.1.0.RELEASE</springframework.version>
+ <jta.version>1.0.1B</jta.version>
+ </properties>
<build>
<plugins>
<plugin>
@@ -22,24 +34,43 @@
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate</artifactId>
- <version>3.2.6.ga</version>
+ <version>${hibernate-core.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-annotations</artifactId>
- <version>3.3.1.GA</version>
+ <version>${hibernate-annotations.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
- <groupId>javax.persistence</groupId>
- <artifactId>persistence-api</artifactId>
- <version>1.0</version>
- <scope>compile</scope>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-beans</artifactId>
+ <version>${springframework.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-context</artifactId>
+ <version>${springframework.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-core</artifactId>
+ <version>${springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
- <artifactId>spring</artifactId>
- <version>2.5.4</version>
+ <artifactId>spring-orm</artifactId>
+ <version>${springframework.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-test</artifactId>
+ <version>${springframework.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.persistence</groupId>
+ <artifactId>persistence-api</artifactId>
+ <version>1.0</version>
<scope>compile</scope>
</dependency>
<dependency>
@@ -57,7 +88,8 @@
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
- <version>1.0.60</version>
+ <version>1.2.138</version>
+ <scope>compile</scope>
</dependency>
<!-- <dependency> -->
<!-- <groupId>postgresql</groupId> -->
@@ -76,5 +108,23 @@
<version>4.4</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>javax.transaction</groupId>
+ <artifactId>jta</artifactId>
+ <version>${jta.version}</version>
+ </dependency>
</dependencies>
+ <repositories>
+ <repository>
+ <id>JBoss</id>
+ <name>JBoss repository</name>
+ <url>https://repository.jboss.org/nexus/content/groups/public-jboss</url>
+ </repository>
+ <repository>
+ <id>maven2-repository.dev.java.net</id>
+ <name>Java.net Repository for Maven</name>
+ <url>http://download.java.net/maven/2/</url>
+ <layout>default</layout>
+ </repository>
+ </repositories>
</project>
View
32 envaflex-core/src/main/java/cl/envaflex/util/HibernateUtils.java
@@ -1,32 +0,0 @@
-package cl.envaflex.util;
-
-import java.io.File;
-
-import org.hibernate.HibernateException;
-import org.hibernate.Session;
-import org.hibernate.SessionFactory;
-import org.hibernate.cfg.AnnotationConfiguration;
-
-/**
- * Clase de utilidad para obtener la sesion de hibernate.
- *
- */
-public class HibernateUtils {
-
- private static final SessionFactory sessionFactory;
- private static final String HIBERNATE_CONFIG_FILE = "hibernate.cfg.xml";
-
- static {
- try {
- sessionFactory = new AnnotationConfiguration().configure(
- new File(HIBERNATE_CONFIG_FILE)).buildSessionFactory();
- } catch (Throwable ex) {
- // Log exception!
- throw new ExceptionInInitializerError(ex);
- }
- }
-
- public static Session getSession() throws HibernateException {
- return sessionFactory.openSession();
- }
-}
View
8 envaflex-core/src/main/resources/spring-config.xml
@@ -4,10 +4,10 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
- http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
- http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
- http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
-http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd"
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
+ http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
+ http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
+http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd"
default-init-method="init">
<context:annotation-config />
View
BIN  envaflex-core/target/classes/cl/envaflex/util/HibernateUtils.class
Binary file not shown
View
65 envaflex-core/target/classes/spring-config.xml
@@ -1,65 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-
-<beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
- xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
- xsi:schemaLocation="
- http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
- http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
- http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
-http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd"
- default-init-method="init">
-
- <context:annotation-config />
- <context:component-scan base-package="cl.envaflex" />
-
- <tx:annotation-driven transaction-manager="transactionManager"
- proxy-target-class="true" />
-
- <!-- DataSourceAdapter connection pooling -->
- <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
- <property name="driverClassName" value="org.h2.Driver" />
- <property name="url" value="jdbc:h2:evxBase" />
- <property name="username" value="evx" />
- <property name="password" value="evx" />
-<!-- <property name="driverClassName" value="org.postgresql.Driver" /> -->
-<!-- <property name="url" value="jdbc:postgresql://localhost:5432/envaflex-db" /> -->
-<!-- <property name="username" value="postgres" /> -->
-<!-- <property name="password" value="postgres" /> -->
-<!-- <property name="minIdle" value="1" /> -->
-<!-- <property name="maxActive" value="10" /> -->
- </bean>
-
- <!-- Transaction Manager -->
- <bean id="transactionManager"
- class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
- <property name="dataSource">
- <ref bean="dataSource" />
- </property>
- </bean>
-
- <!-- Hibernate Configuration -->
- <bean id="hibernateProperties"
- class="org.springframework.beans.factory.config.PropertiesFactoryBean">
- <property name="properties">
- <props>
- <prop key="hibernate.hbm2ddl.auto">create-drop</prop>
- <prop key="hibernate.dialect">org.hibernate.dialect.H2Dialect</prop>
-<!-- <prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop> -->
- <prop key="hibernate.show_sql">false</prop>
- </props>
- </property>
- </bean>
-
- <bean id="sessionFactory"
- class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
- <property name="dataSource" ref="dataSource" />
- <property name="annotatedClasses">
- <list>
-
- </list>
- </property>
- <property name="hibernateProperties" ref="hibernateProperties" />
- </bean>
-
-</beans>
View
30 envaflex-rest-business/pom.xml
@@ -23,18 +23,11 @@
</plugin>
<plugin>
<groupId>org.mortbay.jetty</groupId>
- <artifactId>maven-jetty-plugin</artifactId>
- <version>6.1.15</version>
- <configuration>
- <!-- By default the artifactId is taken, override it with something
- simple -->
- <contextPath>/</contextPath>
- </configuration>
+ <artifactId>jetty-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<properties>
- <!-- <servlet-api.version>2.5.0</servlet-api.version> -->
<commons-fileupload.version>1.2.1</commons-fileupload.version>
<commons-io.version>1.4</commons-io.version>
<commons-lang.version>2.4</commons-lang.version>
@@ -44,18 +37,14 @@
<groupId>cl.envaflex</groupId>
<artifactId>envaflex-rest-core</artifactId>
<version>1.0.0-SNAPSHOT</version>
+ <scope>compile</scope>
</dependency>
<dependency>
<groupId>cl.envaflex</groupId>
<artifactId>envaflex-business</artifactId>
<version>0.0.1-SNAPSHOT</version>
+ <scope>compile</scope>
</dependency>
- <!-- <dependency> -->
- <!-- <groupId>javax.servlet</groupId> -->
- <!-- <artifactId>com.springsource.javax.servlet</artifactId> -->
- <!-- <version>${servlet-api.version}</version> -->
- <!-- <scope>provided</scope> -->
- <!-- </dependency> -->
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
@@ -72,10 +61,15 @@
<version>${commons-io.version}</version>
</dependency>
<dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring</artifactId>
- <version>2.5.4</version>
- <scope>runtime</scope>
+ <groupId>cglib</groupId>
+ <artifactId>cglib-nodep</artifactId>
+ <version>2.2</version>
+ </dependency>
+ <!-- DB DEPENDENCY -->
+ <dependency>
+ <groupId>postgresql</groupId>
+ <artifactId>postgresql</artifactId>
+ <version>8.4-702.jdbc3</version>
</dependency>
</dependencies>
</project>
View
7 envaflex-rest-business/src/main/java/cl/envaflex/rest/object/CargoObject.java
@@ -11,6 +11,7 @@
private String nombre;
private String desc;
+ private String algo;
public String getNombre() {
return nombre;
@@ -24,5 +25,11 @@ public String getDesc() {
public void setDesc(String desc) {
this.desc = desc;
}
+ public String getAlgo() {
+ return algo;
+ }
+ public void setAlgo(String algo) {
+ this.algo = algo;
+ }
}
View
23 envaflex-rest-business/src/main/java/cl/envaflex/rest/service/CargoWS.java
@@ -1,12 +1,17 @@
package cl.envaflex.rest.service;
+import java.util.List;
+
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import org.springframework.stereotype.Service;
+import cl.envaflex.jpa.dao.CargoDao;
+import cl.envaflex.jpa.model.Cargo;
import cl.envaflex.rest.object.CargoObject;
+import cl.envaflex.util.SpringContext;
@@ -14,12 +19,30 @@
@Path("/cargo")
public class CargoWS {
+ private CargoDao cargoDao;
+
+ public CargoWS() {
+ super();
+ cargoDao = (CargoDao) SpringContext.getInstance().getBean(CargoDao.BEAN_NAME);
+ }
+
+
+
@GET
@Produces("application/json")
+ @Path("/hola")
public CargoObject diHola(){
CargoObject obj = new CargoObject();
obj.setNombre("AURELIO");
obj.setDesc("SHORT DESC...");
+ obj.setAlgo("Algo.... :O");
return obj;
}
+
+ @GET
+ @Produces("application/json")
+ @Path("/list")
+ public List<Cargo> listAllCargo(){
+ return cargoDao.findAll();
+ }
}
View
82 envaflex-rest-business/src/main/java/cl/envaflex/rest/service/SecurityWS.java
@@ -0,0 +1,82 @@
+package cl.envaflex.rest.service;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.security.authentication.AuthenticationManager;
+import org.springframework.security.authentication.BadCredentialsException;
+import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
+import org.springframework.security.core.Authentication;
+import org.springframework.security.core.context.SecurityContextHolder;
+import org.springframework.stereotype.Service;
+
+import cl.envaflex.jpa.model.Empleado;
+
+@Service("SecurityWS")
+@Path("/security")
+public class SecurityWS {
+
+ @Autowired
+ @Qualifier("authenticationManager")
+ AuthenticationManager authenticationManager;
+
+ @GET
+ @Produces("application/json")
+ @Path("/status")
+ public LoginStatus getStatus() {
+ Authentication auth = SecurityContextHolder.getContext()
+ .getAuthentication();
+ if (auth != null && !auth.getName().equals("anonymousUser")
+ && auth.isAuthenticated()) {
+ return new LoginStatus(true, auth.getName());
+ } else {
+ return new LoginStatus(false, null);
+ }
+ }
+
+ @GET
+ @Produces("application/json")
+ @Path("/login/{j_username}/{j_password}")
+ public LoginStatus login(@PathParam("j_username") String username,
+ @PathParam("j_password") String password) {
+
+ UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(
+ username, password);
+ Empleado details = new Empleado();
+ details.setUser(username);
+ details.setPassword(password);
+ token.setDetails(details);
+
+ try {
+ Authentication auth = authenticationManager.authenticate(token);
+ SecurityContextHolder.getContext().setAuthentication(auth);
+ return new LoginStatus(auth.isAuthenticated(), auth.getName());
+ } catch (BadCredentialsException e) {
+ return new LoginStatus(false, null);
+ }
+ }
+
+ public class LoginStatus {
+
+ private final boolean loggedIn;
+ private final String username;
+
+ public LoginStatus(boolean loggedIn, String username) {
+ this.loggedIn = loggedIn;
+ this.username = username;
+ }
+
+ public boolean isLoggedIn() {
+ return loggedIn;
+ }
+
+ public String getUsername() {
+ return username;
+ }
+ }
+
+}
View
80 envaflex-rest-business/src/main/resources/spring-config.xml
@@ -0,0 +1,80 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
+ xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
+ http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
+ http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
+http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd"
+ default-init-method="init">
+
+ <context:annotation-config />
+ <context:component-scan base-package="cl.envaflex.jpa" />
+ <context:component-scan base-package="cl.envaflex.service" />
+ <context:component-scan base-package="cl.envaflex.bootstrap" />
+
+ <!-- DataSourceAdapter connection pooling -->
+ <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
+<!-- <property name="driverClassName" value="org.h2.Driver" /> -->
+<!-- <property name="url" value="jdbc:h2:evxBase" /> -->
+<!-- <property name="username" value="evx" /> -->
+<!-- <property name="password" value="evx" /> -->
+ <property name="driverClassName" value="org.postgresql.Driver" />
+ <property name="url" value="jdbc:postgresql://localhost:5432/envaflex-db" />
+ <property name="username" value="postgres" />
+ <property name="password" value="postgres" />
+<!-- <property name="minIdle" value="1" /> -->
+<!-- <property name="maxActive" value="10" /> -->
+ </bean>
+
+ <!-- Transaction Manager -->
+ <bean id="transactionManager"
+ class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
+ <property name="dataSource">
+ <ref bean="dataSource" />
+ </property>
+ </bean>
+
+ <!-- Hibernate Configuration -->
+ <bean id="hibernateProperties"
+ class="org.springframework.beans.factory.config.PropertiesFactoryBean">
+ <property name="properties" >
+ <props>
+ <prop key="hibernate.hbm2ddl.auto">update</prop>
+<!-- <prop key="hibernate.dialect">org.hibernate.dialect.H2Dialect</prop> -->
+ <prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop>
+ <prop key="hibernate.show_sql">false</prop>
+ </props>
+ </property>
+ </bean>
+
+ <bean id="sessionFactory"
+ class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
+ <property name="dataSource" ref="dataSource" />
+ <property name="annotatedClasses">
+ <list>
+ <value>cl.envaflex.jpa.model.Cargo</value>
+ <value>cl.envaflex.jpa.model.Empleado</value>
+ <value>cl.envaflex.jpa.model.Cliente</value>
+ <value>cl.envaflex.jpa.model.Despacho</value>
+ <value>cl.envaflex.jpa.model.DetalleEntrega</value>
+ <value>cl.envaflex.jpa.model.DetalleNotaVenta</value>
+ <value>cl.envaflex.jpa.model.Entrega</value>
+ <value>cl.envaflex.jpa.model.Menu</value>
+ <value>cl.envaflex.jpa.model.NotaVenta</value>
+ <value>cl.envaflex.jpa.model.ParametroSistema</value>
+ <value>cl.envaflex.jpa.model.Producto</value>
+ <value>cl.envaflex.jpa.model.Servicio</value>
+ <value>cl.envaflex.jpa.model.TipoProducto</value>
+ <value>cl.envaflex.jpa.model.Vehiculo</value>
+ </list>
+ </property>
+ <property name="hibernateProperties" ref="hibernateProperties" />
+ </bean>
+
+ <tx:annotation-driven transaction-manager="transactionManager"
+ proxy-target-class="true" />
+
+</beans>
View
30 envaflex-rest-business/src/main/webapp/WEB-INF/security-config.xml
@@ -0,0 +1,30 @@
+<beans:beans xmlns="http://www.springframework.org/schema/security"
+ xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
+
+ <http auto-config="true" use-expressions="true">
+ <intercept-url pattern="/service/cargo/list" access="hasRole('ADMINISTRADOR')" />
+ <intercept-url pattern="/service/cargo/hola" access="hasAnyRole('ADMINISTRADOR','VENDEDOR','SUPERVISOR')" />
+ <form-login login-page="/service/security/login" />
+ </http>
+
+ <global-method-security
+ secured-annotations="enabled" />
+ <authentication-manager alias="authenticationManager">
+ <authentication-provider >
+ <jdbc-user-service data-source-ref="securityDataSource"
+ users-by-username-query="
+ select user_name,password, true
+ from empleado
+ where user_name=?"
+
+ authorities-by-username-query=
+ "select e.user_name,c.nombre_cargo from empleado e, cargo c
+ where e.id_cargo = c.id_cargo
+ and e.user_name = ?"
+
+ role-prefix=""/>
+ </authentication-provider>
+ </authentication-manager>
+</beans:beans>
View
66 envaflex-rest-business/src/main/webapp/WEB-INF/web-config.xml
@@ -1,35 +1,47 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:jaxrs="http://cxf.apache.org/jaxrs"
- xmlns:context="http://www.springframework.org/schema/context"
- xsi:schemaLocation="
- http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
+xmlns:security="http://www.springframework.org/schema/security"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxrs="http://cxf.apache.org/jaxrs"
+ xmlns:context="http://www.springframework.org/schema/context"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
- <import resource="classpath:META-INF/cxf/cxf.xml"/>
- <import resource="classpath:META-INF/cxf/cxf-extension-jaxrs-binding.xml"/>
- <import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>
-
- <!-- JACKSON BEANS -->
- <bean id="jaxbProvider" class="org.apache.cxf.jaxrs.provider.JAXBElementProvider"/>
- <bean id="jacksonProvider" class="org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider"/>
+ <import resource="classpath:META-INF/cxf/cxf.xml" />
+ <import resource="classpath:META-INF/cxf/cxf-extension-jaxrs-binding.xml" />
+ <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
- <context:component-scan base-package="cl.envaflex.rest.service"/>
+ <!-- JACKSON BEANS -->
+ <bean id="jaxbProvider" class="org.apache.cxf.jaxrs.provider.JAXBElementProvider" />
+ <bean id="jacksonProvider" class="org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider" />
- <jaxrs:server id="restContainer" address="/">
- <jaxrs:serviceBeans>
- <ref bean="CargoWS"/>
- </jaxrs:serviceBeans>
- <jaxrs:extensionMappings>
- <entry key="json" value="application/json"/>
- <entry key="xml" value="application/xml"/>
- </jaxrs:extensionMappings>
- <jaxrs:providers>
- <ref bean="jaxbProvider"/>
- <ref bean="jacksonProvider"/>
- </jaxrs:providers>
- </jaxrs:server>
-<!-- <import resource="classpath:resources/spring-config.xml"/> -->
+ <context:annotation-config />
+ <context:component-scan base-package="cl.envaflex.rest.service" />
+
+ <jaxrs:server id="restContainer" address="/">
+ <jaxrs:serviceBeans>
+ <ref bean="CargoWS" />
+ <ref bean="SecurityWS" />
+ </jaxrs:serviceBeans>
+ <jaxrs:extensionMappings>
+ <entry key="json" value="application/json" />
+ <entry key="xml" value="application/xml" />
+ </jaxrs:extensionMappings>
+ <jaxrs:providers>
+ <ref bean="jaxbProvider" />
+ <ref bean="jacksonProvider" />
+ </jaxrs:providers>
+ </jaxrs:server>
+ <!-- Config de seguridad -->
+
+ <!-- DataSourceAdapter connection pooling -->
+ <bean id="securityDataSource" class="org.apache.commons.dbcp.BasicDataSource">
+ <property name="driverClassName" value="org.postgresql.Driver" />
+ <property name="url" value="jdbc:postgresql://localhost:5432/envaflex-db" />
+ <property name="username" value="postgres" />
+ <property name="password" value="postgres" />
+ </bean>
+
+ <import resource="security-config.xml"/>
</beans>
View
15 envaflex-rest-business/src/main/webapp/WEB-INF/web.xml
@@ -5,7 +5,9 @@
<display-name>envaflex-rest-business</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
- <param-value>WEB-INF/web-config.xml</param-value>
+ <param-value>
+ WEB-INF/web-config.xml
+ </param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
@@ -18,7 +20,16 @@
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
- <url-pattern>/*</url-pattern>
+ <url-pattern>/service/*</url-pattern>
</servlet-mapping>
+ <!-- Agregamos los filtros -->
+ <filter>
+ <filter-name>springSecurityFilterChain</filter-name>
+ <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
+ </filter>
+ <filter-mapping>
+ <filter-name>springSecurityFilterChain</filter-name>
+ <url-pattern>/service/*</url-pattern>
+ </filter-mapping>
</web-app>
View
8 envaflex-rest-core/.classpath
@@ -4,8 +4,12 @@
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
- <classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER">
+ <attributes>
+ <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
+ </attributes>
+ </classpathentry>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
<classpathentry kind="output" path="target/classes"/>
View
2  envaflex-rest-core/.settings/org.eclipse.wst.common.component
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="envaflex-rest-core">
- <wb-resource deploy-path="/" source-path="/src/main/webapp"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
+ <wb-resource deploy-path="/" source-path="/src/main/webapp"/>
<property name="context-root" value="envaflex-rest-core"/>
<property name="java-output-path" value="/envaflex-rest-core/target/classes"/>
</wb-module>
View
56 envaflex-rest-core/pom.xml
@@ -5,14 +5,21 @@
<artifactId>envaflex-rest-core</artifactId>
<version>1.0.0-SNAPSHOT</version>
<properties>
- <spring.version>3.0.1.RELEASE</spring.version>
+ <spring-security.version>3.0.5.RELEASE</spring-security.version>
+ <spring.version>3.1.0.RELEASE</spring.version>
<servlet-api.version>2.5.0</servlet-api.version>
<jackson.version>1.9.3</jackson.version>
+ <http.version>4.1.4</http.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
- <artifactId>spring-context</artifactId>
+ <artifactId>spring-beans</artifactId>
+ <version>${spring.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
@@ -21,6 +28,26 @@
<version>${spring.version}</version>
</dependency>
<dependency>
+ <groupId>org.springframework.security</groupId>
+ <artifactId>spring-security-web</artifactId>
+ <version>${spring-security.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.security</groupId>
+ <artifactId>spring-security-config</artifactId>
+ <version>${spring-security.version}</version>
+ </dependency>
+<!-- <dependency> -->
+<!-- <groupId>org.springframework</groupId> -->
+<!-- <artifactId>spring-tx</artifactId> -->
+<!-- <version>${spring.version}</version> -->
+<!-- </dependency> -->
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-aop</artifactId>
+ <version>${spring.version}</version>
+ </dependency>
+ <dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
<version>2.2.3</version>
@@ -44,17 +71,18 @@
</dependency>
</dependencies>
<repositories>
- <repository>
- <id>SpringSource Enterprise Bundle Repository – External Bundle Milestones</id>
- <url>http://repository.springsource.com/maven/bundles/milestone</url>
- </repository>
- <repository>
- <id>SpringSource Enterprise Bundle Repository – SpringSource Bundle Releases</id>
- <url>http://repository.springsource.com/maven/bundles/release</url>
- </repository>
- <repository>
- <id>SpringSource Enterprise Bundle Repository – External Bundle Releases</id>
- <url>http://repository.springsource.com/maven/bundles/external</url>
- </repository>
+ <!-- <repository> -->
+ <!-- <id>SpringSource Enterprise Bundle Repository – External Bundle Milestones</id> -->
+ <!-- <url>http://repository.springsource.com/maven/bundles/milestone</url> -->
+ <!-- </repository> -->
+ <!-- <repository> -->
+ <!-- <id>SpringSource Enterprise Bundle Repository – SpringSource Bundle
+ Releases</id> -->
+ <!-- <url>http://repository.springsource.com/maven/bundles/release</url> -->
+ <!-- </repository> -->
+ <!-- <repository> -->
+ <!-- <id>SpringSource Enterprise Bundle Repository – External Bundle Releases</id> -->
+ <!-- <url>http://repository.springsource.com/maven/bundles/external</url> -->
+ <!-- </repository> -->
</repositories>
</project>

No commit comments for this range

Something went wrong with that request. Please try again.