-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
712 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,5 @@ buildNumber.properties | |
*.jar | ||
*.crt | ||
*.key | ||
*.cer | ||
*.p12 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<artifactId>javaee-cafe</artifactId> | ||
<groupId>javaee-cafe</groupId> | ||
<version>0.1-SNAPSHOT</version> | ||
<packaging>war</packaging> | ||
<name>${project.artifactId}</name> | ||
<description>This is the basic Java EE application used in the demo. | ||
It is a simple CRUD application. It uses Maven and Java EE 8 (JAX-RS, EJB, CDI, JSON-B, JSF, Bean Validation). | ||
</description> | ||
<properties> | ||
<javaee.api.version>8.0</javaee.api.version> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
<failOnMissingWebXml>false</failOnMissingWebXml> | ||
<ldap.server.host></ldap.server.host> | ||
<ldap.server.port></ldap.server.port> | ||
<ldap.server.baseDN></ldap.server.baseDN> | ||
<ldap.server.bindDN></ldap.server.bindDN> | ||
<ldap.server.bindPassword></ldap.server.bindPassword> | ||
<keystore.name></keystore.name> | ||
<keystore.pass></keystore.pass> | ||
<admin.group.name></admin.group.name> | ||
</properties> | ||
<dependencies> | ||
<dependency> | ||
<groupId>javax</groupId> | ||
<artifactId>javaee-api</artifactId> | ||
<version>${javaee.api.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>javax.xml.bind</groupId> | ||
<artifactId>jaxb-api</artifactId> | ||
<version>2.3.1</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.ibm.websphere.appserver.api</groupId> | ||
<artifactId>com.ibm.websphere.appserver.api.jwt</artifactId> | ||
<version>1.0.16</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.microprofile</groupId> | ||
<artifactId>microprofile</artifactId> | ||
<version>3.2</version> | ||
<type>pom</type> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<finalName>${project.artifactId}</finalName> | ||
</build> | ||
<profiles> | ||
<profile> | ||
<id>liberty</id> | ||
<activation> | ||
<activeByDefault>true</activeByDefault> | ||
</activation> | ||
<build> | ||
<plugins> | ||
<!-- Enable liberty-maven-plugin --> | ||
<plugin> | ||
<groupId>io.openliberty.tools</groupId> | ||
<artifactId>liberty-maven-plugin</artifactId> | ||
<version>3.2</version> | ||
<executions> | ||
<execution> | ||
<id>package-server</id> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>create</goal> | ||
<goal>install-feature</goal> | ||
<goal>deploy</goal> | ||
</goals> | ||
<configuration> | ||
<libertyRuntimeVersion>[20.0.0.1,)</libertyRuntimeVersion> | ||
<outputDirectory>${project.build.directory}/wlp-package</outputDirectory> | ||
<bootstrapProperties> | ||
<ldap.server.host>${ldap.server.host}</ldap.server.host> | ||
<ldap.server.port>${ldap.server.port}</ldap.server.port> | ||
<ldap.server.baseDN>${ldap.server.baseDN}</ldap.server.baseDN> | ||
<ldap.server.bindDN>${ldap.server.bindDN}</ldap.server.bindDN> | ||
<ldap.server.bindPassword>${ldap.server.bindPassword}</ldap.server.bindPassword> | ||
<keystore.name>${keystore.name}</keystore.name> | ||
<keystore.pass>${keystore.pass}</keystore.pass> | ||
<admin.group.name>${admin.group.name}</admin.group.name> | ||
</bootstrapProperties> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</profile> | ||
</profiles> | ||
</project> |
54 changes: 54 additions & 0 deletions
54
3-integration/aad-ldap/src/main/java/cafe/model/CafeRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package cafe.model; | ||
|
||
import java.lang.invoke.MethodHandles; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.concurrent.atomic.AtomicLong; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
|
||
import cafe.model.entity.Coffee; | ||
|
||
@ApplicationScoped | ||
public class CafeRepository { | ||
|
||
private static final Logger logger = Logger.getLogger(MethodHandles.lookup().lookupClass().getName()); | ||
private List<Coffee> coffeeList = null; | ||
private AtomicLong counter; | ||
|
||
public CafeRepository() { | ||
coffeeList = new ArrayList<Coffee>(); | ||
counter = new AtomicLong(); | ||
|
||
persistCoffee(new Coffee("Coffee 1", 10.0)); | ||
persistCoffee(new Coffee("Coffee 2", 20.0)); | ||
} | ||
|
||
public List<Coffee> getAllCoffees() { | ||
logger.log(Level.INFO, "Finding all coffees."); | ||
|
||
return coffeeList; | ||
} | ||
|
||
public Coffee persistCoffee(Coffee coffee) { | ||
logger.log(Level.INFO, "Persisting the new coffee {0}.", coffee); | ||
|
||
coffee.setId(counter.incrementAndGet()); | ||
coffeeList.add(coffee); | ||
return coffee; | ||
} | ||
|
||
public void removeCoffeeById(Long coffeeId) { | ||
logger.log(Level.INFO, "Removing a coffee {0}.", coffeeId); | ||
|
||
coffeeList.removeIf(coffee -> coffee.getId().equals(coffeeId)); | ||
} | ||
|
||
public Coffee findCoffeeById(Long coffeeId) { | ||
logger.log(Level.INFO, "Finding the coffee with id {0}.", coffeeId); | ||
|
||
return coffeeList.stream().filter(coffee -> coffee.getId().equals(coffeeId)).findFirst().get(); | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
3-integration/aad-ldap/src/main/java/cafe/model/entity/Coffee.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package cafe.model.entity; | ||
|
||
import java.io.Serializable; | ||
|
||
import javax.xml.bind.annotation.XmlRootElement; | ||
|
||
@XmlRootElement | ||
public class Coffee implements Serializable { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
private Long id; | ||
protected String name; | ||
protected Double price; | ||
|
||
public Coffee() { | ||
} | ||
|
||
public Coffee(String name, Double price) { | ||
this.name = name; | ||
this.price = price; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public Double getPrice() { | ||
return price; | ||
} | ||
|
||
public void setPrice(Double price) { | ||
this.price = price; | ||
} | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public void setId(Long id) { | ||
this.id = id; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int hash = 0; | ||
hash += (id != null ? id.hashCode() : 0); | ||
return hash; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object object) { | ||
if (!(object instanceof Coffee)) { | ||
return false; | ||
} | ||
Coffee other = (Coffee) object; | ||
if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "cafe.model.entity.Coffee[id=" + id + ", name=" + name + ", price=" + price + "]"; | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
3-integration/aad-ldap/src/main/java/cafe/web/rest/CafeResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package cafe.web.rest; | ||
|
||
import java.util.List; | ||
|
||
import javax.inject.Inject; | ||
import javax.ws.rs.Consumes; | ||
import javax.ws.rs.DELETE; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.POST; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.PathParam; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.WebApplicationException; | ||
import javax.ws.rs.core.MediaType; | ||
import javax.ws.rs.core.Response; | ||
|
||
import org.eclipse.microprofile.jwt.JsonWebToken; | ||
|
||
import cafe.model.CafeRepository; | ||
import cafe.model.entity.Coffee; | ||
|
||
@Path("coffees") | ||
public class CafeResource { | ||
|
||
@Inject | ||
private CafeRepository cafeRepository; | ||
|
||
@Inject | ||
private JsonWebToken jwtPrincipal; | ||
|
||
@GET | ||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) | ||
public List<Coffee> getAllCoffees() { | ||
return this.cafeRepository.getAllCoffees(); | ||
} | ||
|
||
@POST | ||
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) | ||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) | ||
public Coffee createCoffee(Coffee coffee) { | ||
return this.cafeRepository.persistCoffee(coffee); | ||
} | ||
|
||
@GET | ||
@Path("{id}") | ||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) | ||
public Coffee getCoffeeById(@PathParam("id") Long coffeeId) { | ||
return this.cafeRepository.findCoffeeById(coffeeId); | ||
} | ||
|
||
@DELETE | ||
@Path("{id}") | ||
public void deleteCoffee(@PathParam("id") Long coffeeId) { | ||
if (!this.jwtPrincipal.getGroups().contains("admin")) { | ||
throw new WebApplicationException(Response.Status.FORBIDDEN); | ||
} | ||
|
||
this.cafeRepository.removeCoffeeById(coffeeId); | ||
} | ||
} |
Oops, something went wrong.