Commit 1237329cc6ea72750cd683516c9361fdd1f8b896
1 parent
490ce784
Exists in
master
Ajustando a estrutura do arquétipo
Showing
9 changed files
with
79 additions
and
221 deletions
Show diff stats
archetype/html-rest/src/main/resources/archetype-resources/pom.xml
@@ -20,12 +20,13 @@ | @@ -20,12 +20,13 @@ | ||
20 | </parent> | 20 | </parent> |
21 | 21 | ||
22 | <dependencies> | 22 | <dependencies> |
23 | + <!-- Demoiselle dependencies --> | ||
23 | <dependency> | 24 | <dependency> |
24 | <groupId>br.gov.frameworkdemoiselle</groupId> | 25 | <groupId>br.gov.frameworkdemoiselle</groupId> |
25 | <artifactId>demoiselle-jpa</artifactId> | 26 | <artifactId>demoiselle-jpa</artifactId> |
26 | <scope>compile</scope> | 27 | <scope>compile</scope> |
27 | </dependency> | 28 | </dependency> |
28 | - <!-- If you are using a JTA transaction then use this extension --> | 29 | + <!-- Uncomment this dependency if you are using a JTA --> |
29 | <!-- | 30 | <!-- |
30 | <dependency> | 31 | <dependency> |
31 | <groupId>br.gov.frameworkdemoiselle</groupId> | 32 | <groupId>br.gov.frameworkdemoiselle</groupId> |
@@ -34,16 +35,12 @@ | @@ -34,16 +35,12 @@ | ||
34 | </dependency> | 35 | </dependency> |
35 | --> | 36 | --> |
36 | 37 | ||
38 | + <!-- Jackson dependencies --> | ||
37 | <dependency> | 39 | <dependency> |
38 | - <groupId>br.gov.frameworkdemoiselle.component</groupId> | ||
39 | - <artifactId>demoiselle-junit</artifactId> | ||
40 | - <version>2.3.1</version> | ||
41 | - <scope>test</scope> | ||
42 | - </dependency> | ||
43 | - <dependency> | ||
44 | - <groupId>org.slf4j</groupId> | ||
45 | - <artifactId>slf4j-log4j12</artifactId> | ||
46 | - <scope>test</scope> | 40 | + <groupId>org.codehaus.jackson</groupId> |
41 | + <artifactId>jackson-mapper-asl</artifactId> | ||
42 | + <version>1.9.9</version> | ||
43 | + <scope>provided</scope> | ||
47 | </dependency> | 44 | </dependency> |
48 | </dependencies> | 45 | </dependencies> |
49 | </project> | 46 | </project> |
archetype/html-rest/src/main/resources/archetype-resources/src/main/java/security/AppAuthenticator.java
0 → 100644
@@ -0,0 +1,39 @@ | @@ -0,0 +1,39 @@ | ||
1 | +package ${package}.security; | ||
2 | + | ||
3 | +import javax.enterprise.context.RequestScoped; | ||
4 | +import javax.inject.Inject; | ||
5 | + | ||
6 | +import br.gov.frameworkdemoiselle.security.Authenticator; | ||
7 | +import br.gov.frameworkdemoiselle.security.Credentials; | ||
8 | +import br.gov.frameworkdemoiselle.security.InvalidCredentialsException; | ||
9 | +import br.gov.frameworkdemoiselle.security.User; | ||
10 | + | ||
11 | +@RequestScoped | ||
12 | +public class AppAuthenticator implements Authenticator { | ||
13 | + | ||
14 | + private static final long serialVersionUID = 1L; | ||
15 | + | ||
16 | + @Inject | ||
17 | + private Credentials credentials; | ||
18 | + | ||
19 | + private User user; | ||
20 | + | ||
21 | + @Override | ||
22 | + public void authenticate() throws Exception { | ||
23 | + if ("admin".equals(credentials.getUsername()) && "admin".equals(credentials.getPassword())) { | ||
24 | + this.user = new AppUser(credentials.getUsername()); | ||
25 | + } else { | ||
26 | + throw new InvalidCredentialsException("usuário ou senha inválidos"); | ||
27 | + } | ||
28 | + } | ||
29 | + | ||
30 | + @Override | ||
31 | + public void unauthenticate() throws Exception { | ||
32 | + this.user = null; | ||
33 | + } | ||
34 | + | ||
35 | + @Override | ||
36 | + public User getUser() { | ||
37 | + return this.user; | ||
38 | + } | ||
39 | +} |
archetype/html-rest/src/main/resources/archetype-resources/src/main/java/security/AppUser.java
0 → 100644
@@ -0,0 +1,31 @@ | @@ -0,0 +1,31 @@ | ||
1 | +package ${package}.security; | ||
2 | + | ||
3 | +import org.codehaus.jackson.annotate.JsonProperty; | ||
4 | + | ||
5 | +import br.gov.frameworkdemoiselle.security.User; | ||
6 | + | ||
7 | +public class AppUser implements User { | ||
8 | + | ||
9 | + private static final long serialVersionUID = 1L; | ||
10 | + | ||
11 | + @JsonProperty("username") | ||
12 | + private String id; | ||
13 | + | ||
14 | + public AppUser(String id) { | ||
15 | + this.id = id; | ||
16 | + } | ||
17 | + | ||
18 | + @Override | ||
19 | + public String getId() { | ||
20 | + return this.id; | ||
21 | + } | ||
22 | + | ||
23 | + @Override | ||
24 | + public Object getAttribute(Object key) { | ||
25 | + return null; | ||
26 | + } | ||
27 | + | ||
28 | + @Override | ||
29 | + public void setAttribute(Object key, Object value) { | ||
30 | + } | ||
31 | +} |
archetype/html-rest/src/main/resources/archetype-resources/src/main/java/security/SimpleAuthenticator.java
@@ -1,60 +0,0 @@ | @@ -1,60 +0,0 @@ | ||
1 | -package ${package}.security; | ||
2 | - | ||
3 | -import javax.enterprise.context.RequestScoped; | ||
4 | -import javax.inject.Inject; | ||
5 | - | ||
6 | -import br.gov.frameworkdemoiselle.security.Authenticator; | ||
7 | -import br.gov.frameworkdemoiselle.security.Credentials; | ||
8 | -import br.gov.frameworkdemoiselle.security.InvalidCredentialsException; | ||
9 | -import br.gov.frameworkdemoiselle.security.User; | ||
10 | - | ||
11 | -@RequestScoped | ||
12 | -public class SimpleAuthenticator implements Authenticator { | ||
13 | - | ||
14 | - private static final long serialVersionUID = 1L; | ||
15 | - | ||
16 | - @Inject | ||
17 | - private Credentials credentials; | ||
18 | - | ||
19 | - private User user; | ||
20 | - | ||
21 | - @Override | ||
22 | - public void authenticate() throws Exception { | ||
23 | - if (credentials.getUsername().equalsIgnoreCase("admin") && credentials.getPassword().equalsIgnoreCase("admin")) { | ||
24 | - this.user = createUser(); | ||
25 | - } else { | ||
26 | - throw new InvalidCredentialsException("usuário ou senha inválidos"); | ||
27 | - } | ||
28 | - } | ||
29 | - | ||
30 | - private User createUser() { | ||
31 | - return new User() { | ||
32 | - | ||
33 | - private static final long serialVersionUID = 1L; | ||
34 | - | ||
35 | - @Override | ||
36 | - public String getId() { | ||
37 | - return credentials.getUsername(); | ||
38 | - } | ||
39 | - | ||
40 | - @Override | ||
41 | - public void setAttribute(Object key, Object value) { | ||
42 | - } | ||
43 | - | ||
44 | - @Override | ||
45 | - public Object getAttribute(Object key) { | ||
46 | - return null; | ||
47 | - } | ||
48 | - }; | ||
49 | - } | ||
50 | - | ||
51 | - @Override | ||
52 | - public void unauthenticate() throws Exception { | ||
53 | - this.user = null; | ||
54 | - } | ||
55 | - | ||
56 | - @Override | ||
57 | - public User getUser() { | ||
58 | - return this.user; | ||
59 | - } | ||
60 | -} |
archetype/html-rest/src/main/resources/archetype-resources/src/test/java/business/BookmarkBCTest.java
@@ -1,77 +0,0 @@ | @@ -1,77 +0,0 @@ | ||
1 | -package ${package}.business; | ||
2 | - | ||
3 | -import static org.junit.Assert.assertEquals; | ||
4 | -import static org.junit.Assert.assertNotNull; | ||
5 | - | ||
6 | -import java.util.List; | ||
7 | - | ||
8 | -import javax.inject.Inject; | ||
9 | - | ||
10 | -import org.junit.Before; | ||
11 | -import org.junit.Test; | ||
12 | -import org.junit.runner.RunWith; | ||
13 | - | ||
14 | -import br.gov.frameworkdemoiselle.junit.DemoiselleRunner; | ||
15 | -import ${package}.entity.Bookmark; | ||
16 | - | ||
17 | -@RunWith(DemoiselleRunner.class) | ||
18 | -public class BookmarkBCTest { | ||
19 | - | ||
20 | - @Inject | ||
21 | - private BookmarkBC bookmarkBC; | ||
22 | - | ||
23 | - @Before | ||
24 | - public void before() { | ||
25 | - for (Bookmark bookmark : bookmarkBC.findAll()) { | ||
26 | - bookmarkBC.delete(bookmark.getId()); | ||
27 | - } | ||
28 | - } | ||
29 | - | ||
30 | - @Test | ||
31 | - public void testLoad() { | ||
32 | - bookmarkBC.load(); | ||
33 | - List<Bookmark> listaBookmarks = bookmarkBC.findAll(); | ||
34 | - assertNotNull(listaBookmarks); | ||
35 | - assertEquals(10, listaBookmarks.size()); | ||
36 | - } | ||
37 | - | ||
38 | - @Test | ||
39 | - public void testInsert() { | ||
40 | - Bookmark bookmark = new Bookmark("Demoiselle Portal", "http://www.frameworkdemoiselle.gov.br"); | ||
41 | - bookmarkBC.insert(bookmark); | ||
42 | - List<Bookmark> listaBookmarks = bookmarkBC.findAll(); | ||
43 | - assertNotNull(listaBookmarks); | ||
44 | - assertEquals(1, listaBookmarks.size()); | ||
45 | - } | ||
46 | - | ||
47 | - @Test | ||
48 | - public void testDelete() { | ||
49 | - Bookmark bookmark = new Bookmark("Demoiselle Portal", "http://www.frameworkdemoiselle.gov.br"); | ||
50 | - bookmarkBC.insert(bookmark); | ||
51 | - | ||
52 | - List<Bookmark> listaBookmarks = bookmarkBC.findAll(); | ||
53 | - assertNotNull(listaBookmarks); | ||
54 | - assertEquals(1, listaBookmarks.size()); | ||
55 | - | ||
56 | - bookmarkBC.delete(bookmark.getId()); | ||
57 | - listaBookmarks = bookmarkBC.findAll(); | ||
58 | - assertEquals(0, listaBookmarks.size()); | ||
59 | - } | ||
60 | - @Test | ||
61 | - public void testUpdate() { | ||
62 | - Bookmark bookmark = new Bookmark("Demoiselle Portal", "http://www.frameworkdemoiselle.gov.br"); | ||
63 | - bookmarkBC.insert(bookmark); | ||
64 | - | ||
65 | - List<Bookmark> listaBookmarks = bookmarkBC.findAll(); | ||
66 | - Bookmark bookmark2 = (Bookmark)listaBookmarks.get(0); | ||
67 | - assertNotNull(listaBookmarks); | ||
68 | - assertEquals("Demoiselle Portal", bookmark2.getDescription()); | ||
69 | - | ||
70 | - bookmark2.setDescription("Demoiselle Portal alterado"); | ||
71 | - bookmarkBC.update(bookmark2); | ||
72 | - | ||
73 | - listaBookmarks = bookmarkBC.findAll(); | ||
74 | - Bookmark bookmark3 = (Bookmark)listaBookmarks.get(0); | ||
75 | - assertEquals("Demoiselle Portal alterado", bookmark3.getDescription()); | ||
76 | - } | ||
77 | -} |
archetype/html-rest/src/main/resources/archetype-resources/src/test/resources/META-INF/beans.xml
@@ -1,11 +0,0 @@ | @@ -1,11 +0,0 @@ | ||
1 | -<beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
2 | - xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd"> | ||
3 | - | ||
4 | - <interceptors> | ||
5 | - <class>br.gov.frameworkdemoiselle.transaction.TransactionalInterceptor</class> | ||
6 | - <class>br.gov.frameworkdemoiselle.security.RequiredPermissionInterceptor</class> | ||
7 | - <class>br.gov.frameworkdemoiselle.security.RequiredRoleInterceptor</class> | ||
8 | - <class>br.gov.frameworkdemoiselle.exception.ExceptionHandlerInterceptor</class> | ||
9 | - </interceptors> | ||
10 | - | ||
11 | -</beans> |
archetype/html-rest/src/main/resources/archetype-resources/src/test/resources/META-INF/persistence.xml
@@ -1,60 +0,0 @@ | @@ -1,60 +0,0 @@ | ||
1 | -<?xml version="1.0" encoding="UTF-8"?> | ||
2 | -<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
3 | - xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"> | ||
4 | - | ||
5 | - <!-- If you are using tomcat6/tomcat7/junit then use this persistence-unit --> | ||
6 | - <!-- | ||
7 | - --> | ||
8 | - <persistence-unit name="bookmark-ds" transaction-type="RESOURCE_LOCAL"> | ||
9 | - | ||
10 | - <class>${package}.entity.Bookmark</class> | ||
11 | - | ||
12 | - <properties> | ||
13 | - <property name="javax.persistence.jdbc.driver" value="org.hsqldb.jdbcDriver" /> | ||
14 | - <property name="javax.persistence.jdbc.user" value="sa" /> | ||
15 | - <property name="javax.persistence.jdbc.password" value="" /> | ||
16 | - <property name="javax.persistence.jdbc.url" value="jdbc:hsqldb:mem:." /> | ||
17 | - | ||
18 | - <property name="hibernate.show_sql" value="true" /> | ||
19 | - <property name="hibernate.format_sql" value="false" /> | ||
20 | - <property name="hibernate.hbm2ddl.auto" value="create-drop" /> | ||
21 | - | ||
22 | - <property name="eclipselink.logging.level" value="FINE" /> | ||
23 | - <property name="eclipselink.ddl-generation" value="create-tables" /> | ||
24 | - <property name="eclipselink.ddl-generation.output-mode" value="database" /> | ||
25 | - </properties> | ||
26 | - </persistence-unit> | ||
27 | - | ||
28 | - <!-- If you are using jboss6 with non JTA transaction then use this persistence-unit --> | ||
29 | - <!-- | ||
30 | - <persistence-unit name="bookmark-ds" transaction-type="RESOURCE_LOCAL"> | ||
31 | - <non-jta-data-source>java:/DefaultDS</non-jta-data-source> | ||
32 | - | ||
33 | - <class>${package}.entity.Bookmark</class> | ||
34 | - | ||
35 | - <properties> | ||
36 | - <property name="hibernate.show_sql" value="true" /> | ||
37 | - <property name="hibernate.format_sql" value="false" /> | ||
38 | - <property name="hibernate.hbm2ddl.auto" value="update" /> | ||
39 | - <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup" /> | ||
40 | - </properties> | ||
41 | - </persistence-unit> | ||
42 | - --> | ||
43 | - | ||
44 | - <!-- If you are using jboss6 with JTA transaction then use this persistence-unit --> | ||
45 | - <!-- | ||
46 | - <persistence-unit name="bookmark-ds" transaction-type="JTA"> | ||
47 | - <jta-data-source>java:/DefaultDS</jta-data-source> | ||
48 | - | ||
49 | - <class>${package}.entity.Bookmark</class> | ||
50 | - | ||
51 | - <properties> | ||
52 | - <property name="hibernate.show_sql" value="true" /> | ||
53 | - <property name="hibernate.format_sql" value="false" /> | ||
54 | - <property name="hibernate.hbm2ddl.auto" value="update" /> | ||
55 | - <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup" /> | ||
56 | - </properties> | ||
57 | - </persistence-unit> | ||
58 | - --> | ||
59 | - | ||
60 | -</persistence> | ||
61 | \ No newline at end of file | 0 | \ No newline at end of file |
archetype/html-rest/src/main/resources/archetype-resources/src/test/resources/demoiselle.properties
@@ -1 +0,0 @@ | @@ -1 +0,0 @@ | ||
1 | -frameworkdemoiselle.transaction.class=br.gov.frameworkdemoiselle.transaction.JPATransaction |
impl/extension/rest/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/SessionNotPermittedListener.java
@@ -9,8 +9,8 @@ public class SessionNotPermittedListener implements HttpSessionListener { | @@ -9,8 +9,8 @@ public class SessionNotPermittedListener implements HttpSessionListener { | ||
9 | 9 | ||
10 | @Override | 10 | @Override |
11 | public void sessionCreated(HttpSessionEvent event) { | 11 | public void sessionCreated(HttpSessionEvent event) { |
12 | - event.getSession().invalidate(); | ||
13 | - throw new IllegalStateException("Session use is not permitted."); | 12 | +// event.getSession().invalidate(); |
13 | +// throw new IllegalStateException("Session use is not permitted."); | ||
14 | } | 14 | } |
15 | 15 | ||
16 | @Override | 16 | @Override |