feature/jakrtaee10 (#1)

Co-authored-by: Joern Muehlencord <joern.muehlencord@vitroconnect.com>
Reviewed-on: https://jomu.timelord.de/git/jomu/shared/pulls/1
This commit is contained in:
2023-12-10 21:24:45 +00:00
parent b9482de3b1
commit c4a5f12511
66 changed files with 375 additions and 1607 deletions

View File

@ -15,63 +15,70 @@ See the License for the specific language governing permissions and
limitations under the License.
-->
<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>
<parent>
<artifactId>shared</artifactId>
<groupId>de.muehlencord</groupId>
<version>1.3.2-SNAPSHOT</version>
</parent>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
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>
<parent>
<artifactId>shared</artifactId>
<groupId>de.muehlencord</groupId>
<version>2.0.0-SNAPSHOT</version>
</parent>
<groupId>de.muehlencord.shared</groupId>
<artifactId>shared-jeeutil</artifactId>
<packaging>ejb</packaging>
<groupId>de.muehlencord.shared</groupId>
<artifactId>shared-jeeutil</artifactId>
<packaging>jar</packaging>
<name>shared-jeeutil</name>
<name>shared-jeeutil</name>
<dependencies>
<dependency>
<groupId>io.fusionauth</groupId>
<artifactId>fusionauth-jwt</artifactId>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<type>jar</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-web</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<dependencies>
<!-- Faces Support -->
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>jakarta.faces</artifactId>
</dependency>
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<type>jar</type>
<scope>provided</scope>
</dependency>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ejb-plugin</artifactId>
<configuration>
<ejbVersion>3.1</ejbVersion>
</configuration>
</plugin>
</plugins>
</build>
<!-- jakarta api -->
<dependency>
<groupId>jakarta.ws.rs</groupId>
<artifactId>jakarta.ws.rs-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jakarta.validation</groupId>
<artifactId>jakarta.validation-api</artifactId>
</dependency>
<dependency>
<groupId>jakarta.interceptor</groupId>
<artifactId>jakarta.interceptor-api</artifactId>
</dependency>
<!-- Logging -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<!-- unsorted -->
<dependency>
<groupId>io.fusionauth</groupId>
<artifactId>fusionauth-jwt</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@ -15,8 +15,8 @@
*/
package de.muehlencord.shared.jeeutil;
import javax.faces.application.FacesMessage;
import javax.faces.application.FacesMessage.Severity;
import jakarta.faces.application.FacesMessage;
import jakarta.faces.application.FacesMessage.Severity;
/**
*

View File

@ -15,9 +15,9 @@
*/
package de.muehlencord.shared.jeeutil;
import jakarta.faces.application.FacesMessage;
import jakarta.faces.context.FacesContext;
import java.util.List;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
/**
* Helper class for java faces application.

View File

@ -15,8 +15,8 @@
*/
package de.muehlencord.shared.jeeutil;
import jakarta.faces.application.FacesMessage;
import java.io.Serializable;
import javax.faces.application.FacesMessage;
/**
*

View File

@ -1,87 +0,0 @@
/*
* Copyright 2019 Joern Muehlencord (joern@muehlencord.de).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.muehlencord.shared.jeeutil.jwt;
import io.fusionauth.jwt.Verifier;
import io.fusionauth.jwt.domain.JWT;
import io.fusionauth.jwt.hmac.HMACVerifier;
import java.time.ZonedDateTime;
/**
* @author Joern Muehlencord (joern@muehlencord.de)
*/
public class JWTDecoder {
private boolean parsedSuccessfully;
private JWT jwt = null;
public JWTDecoder(String password, String issuer, String jwtString) throws JWTException {
if ((password == null) || (issuer == null) || (jwtString == null)) {
throw new JWTException("password, issuer and jwt must not be null");
}
Verifier verifier = HMACVerifier.newVerifier(password);
jwt = JWT.getDecoder().decode(jwtString, verifier);
parsedSuccessfully = jwt != null && jwt.issuer.equals(issuer);
}
public String getIssuer() {
if (jwt == null) {
return null;
} else {
return jwt.issuer;
}
}
public ZonedDateTime getIssuedAt() {
if (jwt == null) {
return null;
} else {
return jwt.issuedAt;
}
}
public String getSubject() {
if (jwt == null) {
return null;
} else {
return jwt.subject;
}
}
public String getUniqueId() {
if (jwt == null) {
return null;
} else {
return jwt.uniqueId;
}
}
public ZonedDateTime getExpiration() {
if (jwt == null) {
return null;
} else {
return jwt.expiration;
}
}
public boolean isValid() {
if ((jwt == null) || (jwt.isExpired())) {
return false;
} else {
return this.parsedSuccessfully;
}
}
}

View File

@ -1,46 +0,0 @@
/*
* Copyright 2019 Joern Muehlencord (joern@muehlencord.de).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.muehlencord.shared.jeeutil.jwt;
import io.fusionauth.jwt.Signer;
import io.fusionauth.jwt.domain.JWT;
import io.fusionauth.jwt.hmac.HMACSigner;
import java.time.ZonedDateTime;
/**
*
* @author Joern Muehlencord (joern@muehlencord.de)
*/
public abstract class JWTEncoder {
public static String encode(String password, String issuer, ZonedDateTime issuedAt, String subject, String uniqueId, short expirationInMinutes ) throws JWTException {
if ((password == null) || (issuer == null)) {
throw new JWTException("password and issuer must not be null");
}
Signer signer = HMACSigner.newSHA256Signer(password);
// Signer signer = RSASigner.newSHA256Signer(new String(Files.readAllBytes(Paths.get("private_key.pem"))));
JWT jwt = new JWT().setIssuer(issuer) // FIXME - make configurable
.setIssuedAt(issuedAt)
.setSubject(subject)
.setUniqueId(uniqueId)
.setExpiration(issuedAt.plusMinutes(expirationInMinutes));
return JWT.getEncoder().encode(jwt, signer);
}
}

View File

@ -1,49 +0,0 @@
/*
* Copyright 2019 Joern Muehlencord (joern@muehlencord.de).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.muehlencord.shared.jeeutil.jwt;
/**
*
* @author Joern Muehlencord (joern@muehlencord.de)
*/
public class JWTException extends Exception {
private static final long serialVersionUID = 423992803027530544L;
/**
* Creates a new instance of <code>JWTException</code> without detail message.
*/
public JWTException() {
}
/**
* Constructs an instance of <code>JWTException</code> with the specified detail message.
* @param msg the detail message.
*/
public JWTException(String msg) {
super(msg);
}
/**
* Constructs an instance of <code>JWTException</code> with the specified detail message and root cause.
* @param msg the detail message.
* @param th the root cause
*/
public JWTException(String msg, Throwable th) {
super(msg,th);
}
}

View File

@ -1,35 +0,0 @@
/*
* Copyright 2019 Joern Muehlencord (joern@muehlencord.de).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.muehlencord.shared.jeeutil.jwt;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletResponse;
import org.apache.shiro.web.filter.authc.AuthenticationFilter;
/**
*
* @author Joern Muehlencord (joern@muehlencord.de)
*/
public class JWTGuard extends AuthenticationFilter {
@Override
protected boolean onAccessDenied(ServletRequest request, ServletResponse response) throws Exception {
HttpServletResponse httpResponse = (HttpServletResponse) response;
httpResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED);
return false;
}
}

View File

@ -15,7 +15,7 @@
*/
package de.muehlencord.shared.jeeutil.restexfw;
import javax.ws.rs.core.Response;
import jakarta.ws.rs.core.Response;
/**
*

View File

@ -15,6 +15,7 @@
*/
package de.muehlencord.shared.jeeutil.restexfw;
import jakarta.ws.rs.core.Response;
import jakarta.xml.bind.annotation.XmlAccessType;
import jakarta.xml.bind.annotation.XmlAccessorType;
import jakarta.xml.bind.annotation.XmlRootElement;
@ -22,7 +23,6 @@ import jakarta.xml.bind.annotation.XmlType;
import jakarta.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import java.util.Locale;
import java.util.ResourceBundle;
import javax.ws.rs.core.Response;
/**
*

View File

@ -16,9 +16,9 @@
package de.muehlencord.shared.jeeutil.restexfw;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.Response.ResponseBuilder;
import java.util.Locale;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;
/**
*

View File

@ -15,12 +15,12 @@
*/
package de.muehlencord.shared.jeeutil.restexfw;
import jakarta.inject.Inject;
import jakarta.interceptor.AroundInvoke;
import jakarta.interceptor.InvocationContext;
import jakarta.validation.ConstraintViolationException;
import jakarta.ws.rs.core.Response;
import java.util.Locale;
import javax.inject.Inject;
import javax.interceptor.AroundInvoke;
import javax.interceptor.InvocationContext;
import javax.validation.ConstraintViolationException;
import javax.ws.rs.core.Response;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

View File

@ -15,10 +15,10 @@
*/
package de.muehlencord.shared.jeeutil.restexfw;
import javax.ws.rs.BadRequestException;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;
import jakarta.ws.rs.BadRequestException;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.ext.ExceptionMapper;
import jakarta.ws.rs.ext.Provider;
/**
*

View File

@ -15,12 +15,12 @@
*/
package de.muehlencord.shared.jeeutil.restexfw;
import jakarta.validation.ConstraintViolation;
import jakarta.validation.Path;
import jakarta.xml.bind.annotation.XmlAccessType;
import jakarta.xml.bind.annotation.XmlAccessorType;
import jakarta.xml.bind.annotation.XmlRootElement;
import java.util.Iterator;
import javax.validation.ConstraintViolation;
import javax.validation.Path;
/**
*

View File

@ -15,19 +15,19 @@
*/
package de.muehlencord.shared.jeeutil.restexfw;
import jakarta.validation.ConstraintViolation;
import jakarta.validation.ConstraintViolationException;
import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.GenericEntity;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Request;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.Variant;
import jakarta.ws.rs.ext.ExceptionMapper;
import jakarta.ws.rs.ext.Provider;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.GenericEntity;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Request;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Variant;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;
/**
*

View File

@ -15,10 +15,10 @@
*/
package de.muehlencord.shared.jeeutil.restexfw;
import javax.ws.rs.ForbiddenException;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;
import jakarta.ws.rs.ForbiddenException;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.ext.ExceptionMapper;
import jakarta.ws.rs.ext.Provider;
/**
*

View File

@ -15,10 +15,10 @@
*/
package de.muehlencord.shared.jeeutil.restexfw;
import javax.ws.rs.NotAcceptableException;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;
import jakarta.ws.rs.NotAcceptableException;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.ext.ExceptionMapper;
import jakarta.ws.rs.ext.Provider;
/**
*

View File

@ -15,10 +15,10 @@
*/
package de.muehlencord.shared.jeeutil.restexfw;
import javax.ws.rs.NotAllowedException;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;
import jakarta.ws.rs.NotAllowedException;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.ext.ExceptionMapper;
import jakarta.ws.rs.ext.Provider;
/**
*

View File

@ -15,10 +15,10 @@
*/
package de.muehlencord.shared.jeeutil.restexfw;
import javax.ws.rs.NotAuthorizedException;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;
import jakarta.ws.rs.NotAuthorizedException;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.ext.ExceptionMapper;
import jakarta.ws.rs.ext.Provider;
/**
*

View File

@ -15,10 +15,10 @@
*/
package de.muehlencord.shared.jeeutil.restexfw;
import javax.ws.rs.NotFoundException;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;
import jakarta.ws.rs.NotFoundException;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.ext.ExceptionMapper;
import jakarta.ws.rs.ext.Provider;
/**
*

View File

@ -15,10 +15,10 @@
*/
package de.muehlencord.shared.jeeutil.restexfw;
import javax.ws.rs.NotSupportedException;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;
import jakarta.ws.rs.NotSupportedException;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.ext.ExceptionMapper;
import jakarta.ws.rs.ext.Provider;
/**
*

View File

@ -15,9 +15,9 @@
*/
package de.muehlencord.shared.jeeutil.restexfw;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.Response.Status;
import jakarta.xml.bind.annotation.adapters.XmlAdapter;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
/**
* @author Joern Muehlencord (joern@muehlencord.de)

View File

@ -15,12 +15,12 @@
*/
package de.muehlencord.shared.jeeutil.restexfw;
import jakarta.validation.ConstraintViolation;
import jakarta.validation.ConstraintViolationException;
import jakarta.validation.Validation;
import jakarta.validation.Validator;
import jakarta.validation.ValidatorFactory;
import java.util.Set;
import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException;
import javax.validation.Validation;
import javax.validation.Validator;
import javax.validation.ValidatorFactory;
/**
*

View File

@ -15,16 +15,16 @@
*/
package de.muehlencord.shared.jeeutil.validator;
import java.lang.annotation.Documented;
import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import java.lang.annotation.Retention;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import jakarta.validation.Constraint;
import jakarta.validation.Payload;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import javax.validation.Constraint;
import javax.validation.Payload;
import org.primefaces.validate.bean.ClientConstraint;
/**
*
@ -33,7 +33,8 @@ import org.primefaces.validate.bean.ClientConstraint;
@Target({METHOD, FIELD, ANNOTATION_TYPE})
@Retention(RUNTIME)
@Constraint(validatedBy = EmailConstraintValidator.class)
@ClientConstraint(resolvedBy = EmailClientValidationConstraint.class)
// FIXME - broken ClientValidationConstraint from Primefaces 13 still uses javax.xx
//@ClientConstraint(resolvedBy = EmailClientValidationConstraint.class)
@Documented
public @interface Email {

View File

@ -15,21 +15,20 @@
*/
package de.muehlencord.shared.jeeutil.validator;
import jakarta.validation.metadata.ConstraintDescriptor;
import java.util.HashMap;
import java.util.Map;
import javax.validation.metadata.ConstraintDescriptor;
import org.primefaces.validate.bean.ClientValidationConstraint;
/**
*
* FIXME - broken ClientValidationConstraint from Primefaces 13 still uses javax.xx
* @author Joern Muehlencord (joern@muehlencord.de)
*/
public class EmailClientValidationConstraint implements ClientValidationConstraint {
public class EmailClientValidationConstraint { // {implements ClientValidationConstraint {
public static final String MESSAGE_METADATA = "data-p-email-msg";
@Override
public Map<String, Object> getMetadata(ConstraintDescriptor constraintDescriptor) {
// @Override
public Map<String, Object> getMetadata(ConstraintDescriptor<?> constraintDescriptor) {
Map<String, Object> metadata = new HashMap<>();
Map<?, ?> attrs = constraintDescriptor.getAttributes();
Object message = attrs.get("message");
@ -40,7 +39,7 @@ public class EmailClientValidationConstraint implements ClientValidationConstrai
return metadata;
}
@Override
// @Override
public String getValidatorId() {
return Email.class.getSimpleName();
}

View File

@ -15,9 +15,9 @@
*/
package de.muehlencord.shared.jeeutil.validator;
import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;
import java.util.regex.Pattern;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
/**
*

View File

@ -15,14 +15,14 @@
*/
package de.muehlencord.shared.jeeutil.validator;
import jakarta.faces.application.FacesMessage;
import jakarta.faces.component.UIComponent;
import jakarta.faces.context.FacesContext;
import jakarta.faces.validator.FacesValidator;
import jakarta.faces.validator.Validator;
import jakarta.faces.validator.ValidatorException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.FacesValidator;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;
/**
*