prepare version 2.0.0

remove shiro support
This commit is contained in:
Joern Muehlencord
2023-10-25 12:04:43 +02:00
parent bc0493b094
commit 66be348fd3
30 changed files with 9 additions and 1159 deletions

View File

@ -20,7 +20,7 @@ limitations under the License.
<parent>
<artifactId>shared</artifactId>
<groupId>de.muehlencord</groupId>
<version>1.3.2-SNAPSHOT</version>
<version>2.0.0-SNAPSHOT</version>
</parent>
<groupId>de.muehlencord.shared</groupId>
@ -55,11 +55,6 @@ limitations under the License.
<type>jar</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-web</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<build>

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;
}
}