Skip to content

Instantly share code, notes, and snippets.

View mkuehle's full-sized avatar
🏠
Working from home

Markus Kühle mkuehle

🏠
Working from home
View GitHub Profile
@mkuehle
mkuehle / web.xml
Last active October 19, 2016 09:49
Java EE WildFly Basic Authentication web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<security-constraint>
<web-resource-collection>
<web-resource-name>HtmlAuth</web-resource-name>
<description>application security constraints</description>
<url-pattern>/*</url-pattern>
@mkuehle
mkuehle / create-wildfly-application-user.sh
Last active October 19, 2016 09:50
Java EE WildFly Basic Authentication - WildFly Application User erstellen
MacBook-Markus:~ Markus$ wildfly-10.0.0.Final/bin/add-user.sh
What type of user do you wish to add?
a) Management User (mgmt-users.properties)
b) Application User (application-users.properties)
(a): b
Enter the details of the new user to add.
Using realm 'ApplicationRealm' as discovered from the existing property files.
Username : markus
@mkuehle
mkuehle / AuthResource.java
Created October 20, 2016 09:40
Java EE 7 - JAX-RS Response mit Cookie
@Path("/auth")
@RequestScoped
@Produces(MediaType.APPLICATION_JSON)
public class AuthResource {
@GET
@Path("/login")
public Response login() {
// Do the login stuff and generate the token
@mkuehle
mkuehle / UserResource.java
Last active October 20, 2016 09:45
Java EE 7 - JAX-RS Bean Validation - Query Parameter
@Path("/users")
public class UserResource {
...
@GET
@Path("/username-unique")
public Response isEmailUnique(
@QueryParam("name")
@NotNull
@Size(min=3, max=10, message="Der Name muss zwischen {min} und {max} Zeichen lang sein")
String username) {
@mkuehle
mkuehle / bean-validation-curl.sh
Created October 20, 2016 09:46
Java EE 7 - JAX-RS Bean Validation - Query Parameter Test
Markus$ curl -i http://localhost:8080/jee-jaxrs-validation/resources/users/username-unique
HTTP/1.1 400 Bad Request
[PARAMETER]
[isEmailUnique.arg0]
[darf nicht null sein]
[]
@mkuehle
mkuehle / bean-validation-test.sh
Created October 20, 2016 09:47
Java EE 7 - JAX-RS Bean Validation - Query Parameter Test size
Markus$ curl -i http://localhost:8080/jee-jaxrs-validation/resources/users/username-unique?name=d
HTTP/1.1 400 Bad Request
[PARAMETER]
[isEmailUnique.arg0]
[Der Name muss zwischen 3 und 10 Zeichen lang sein]
[d]
@mkuehle
mkuehle / User.java
Created October 20, 2016 09:47
Java EE 7 - JAX-RS Bean Validation - DTO
public class User {
@NotNull(message="Der Name muss angegeben werden")
@Size(min=3, max=10, message="Der Name muss zwischen {min} und {max} Zeichen lang sein")
private String name;
@NotNull(message="Die E-Mail Adresse ist ein Pflichtfeld")
private String email;
}
@mkuehle
mkuehle / UserResource.java
Created October 20, 2016 09:49
Java EE 7 - JAX-RS Bean Validation - DTO Validaierung bei POST
@Path("/users")
public class UserResource {
@POST
@Path("/")
public User createUser(@Valid User user) {
user.setId(1l);
return user;
}
}
@mkuehle
mkuehle / bean-validation-dto-test.sh
Created October 20, 2016 09:50
Java EE 7 - JAX-RS Bean Validation - DTO Test
curl -i -XPOST -H "Content-Type: application/json" -d "{\"name\": null,\"email\": null}" http://localhost:8080/jee-jaxrs-validation/resources/users
HTTP/1.1 400 Bad Request
{
"exception": null,
"fieldViolations": [],
"propertyViolations": [],
"classViolations": [],
"parameterViolations": [
{
@mkuehle
mkuehle / bean-validation-dto-test.sh
Created October 20, 2016 09:51
Java EE 7 - JAX-RS Bean Validation - DTO Test
curl -i -XPOST -H "Content-Type: application/json" -d "{\"name\": \"d\",\"email\": \"[email protected]\"}" http://localhost:8080/jee-jaxrs-validation/resources/users
HTTP/1.1 400 Bad Request
{
"exception": null,
"fieldViolations": [],
"propertyViolations": [],
"classViolations": [],
"parameterViolations": [
{