Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java 21, Tomcat 9 #12

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
1 change: 0 additions & 1 deletion EuPathDB/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
</dependency>

</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public String getNextGuestId() {
String id = new AccountManager(_accountDb, _schema, USER_PROPERTY_DEFS).createGuestAccount("guest_").getUserId().toString();
// FIXME: since this code directly accesses the DB, it should live in AccountManager;
// however that complicates FgpUtil releases prior to move to bearer tokens, so adding it here.
String sql = "insert into useraccounts.guest_ids (user_id, creation_time) values (?, TO_DATE(SYSDATE))";
String sql = "insert into useraccounts.guest_ids (user_id, creation_time) values (?, current_date)";
int inserted = new SQLRunner(_accountDb.getDataSource(), sql, "insert-guest-id")
.executeUpdate(new Object[]{ Long.valueOf(id) }, new Integer[]{ Types.BIGINT });
if (inserted != 1) throw new IllegalStateException("Tried to insert duplicate guest ID " + id + ". Check ID sequence to make sure it is big enough.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@ public class BearerTokenGenerator extends ToolBase {
private static final String PROP_KEYSTORE_PASSPHRASE = "keyStorePassPhrase";
private static final String PROP_ACCOUNTDB_LOGIN = "accountDbLogin";
private static final String PROP_ACCOUNTDB_PASSWORD = "accountDbPassword";
private static final String PROP_DB_PLATFORM = "dbPlatform";
private static final String PROP_USER_ID = "userId";

public static void main(String[] args) throws Exception {
new BearerTokenGenerator(args).execute();
}

public BearerTokenGenerator(String[] args) {
super(args, new String[] { PROP_KEYSTORE_FILE, PROP_KEYSTORE_PASSPHRASE, PROP_ACCOUNTDB_LOGIN, PROP_ACCOUNTDB_PASSWORD, PROP_USER_ID });
super(args, new String[] { PROP_KEYSTORE_FILE, PROP_KEYSTORE_PASSPHRASE, PROP_ACCOUNTDB_LOGIN, PROP_ACCOUNTDB_PASSWORD, PROP_USER_ID, PROP_DB_PLATFORM });
}

public void execute() throws Exception {
Expand All @@ -43,14 +44,16 @@ public void execute() throws Exception {
String keyStorePassPhrase = findProp(PROP_KEYSTORE_PASSPHRASE);
String accountDbLogin = findProp(PROP_ACCOUNTDB_LOGIN);
String accountDbPassword = findProp(PROP_ACCOUNTDB_PASSWORD);
String platform = findProp(PROP_DB_PLATFORM);
String userId = findProp(PROP_USER_ID);

SigningKeyStore keyStore = new SigningKeyStore(new KeyPairReader().readKeyPair(Paths.get(keyStoreFile), keyStorePassPhrase));

// dummy up a client; SigningKeyStore requires >0 but will not be used here
keyStore.setClientSigningKeys("abc", Set.of("mug2kfCI8qhXzrnuE/nh1gK9JbSFaXaih+zdsfD8io25MWH4b3V5u+U8E7SW4x7iBAHdq6yWWrF/TP9p098lfQ=="));

// generate a new token for this account
String token = generateToken(keyStore, accountDbLogin, accountDbPassword, userId);
String token = generateToken(keyStore, accountDbLogin, accountDbPassword, userId, platform);
System.out.println("Bearer Token\n\n" + token + "\n");

// verify token using same method as the client
Expand All @@ -71,13 +74,13 @@ public void execute() throws Exception {
System.out.println("Subject after parsing token: " + claims.getSubject());
}

private static String generateToken(SigningKeyStore keyStore, String accountDbLogin, String accountDbPassword, String userId) throws Exception {
private static String generateToken(SigningKeyStore keyStore, String accountDbLogin, String accountDbPassword, String userId, String dbPlatform) throws Exception {

JsonObject authenticatorConfig = Json.createObjectBuilder()
.add("login", accountDbLogin)
.add("password", accountDbPassword)
.add("connectionUrl", "jdbc:oracle:thin:@localhost:5011/acctdb.upenn.edu")
.add("platform", "Oracle")
.add("platform", dbPlatform)
.add("poolSize", 1)
.add("schema", "useraccounts.")
.build();
Expand Down
8 changes: 4 additions & 4 deletions EuPathDB/src/main/resources/log4j2.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"appender": [{
"type": "RollingFile",
"name": "oauth-log",
"fileName": "${sys:catalina.base}/logs/oauth/oauth.log",
"filePattern": "${sys:catalina.base}/logs/oauth/oauth.log.%i",
"fileName": "/opt/logs/tomcat/oauth/oauth.log",
"filePattern": "/opt/logs/tomcat/oauth/oauth.log.%i",
"append": "true",
"PatternLayout": { "pattern": "%-9r [%-5p] [%d{yyyy/MM/dd|HH:mm:ss}] - %C:%L - %m%n" },
"Policies": {
Expand All @@ -15,8 +15,8 @@
},{
"type": "RollingFile",
"name": "login-log",
"fileName": "${sys:catalina.base}/logs/oauth/logins.log",
"filePattern": "${sys:catalina.base}/logs/oauth/logins.log.%i",
"fileName": "/opt/logs/tomcat/oauth/logins.log",
"filePattern": "/opt/logs/tomcat/oauth/logins.log.%i",
"append": "true",
"PatternLayout": { "pattern": "%d{yyyy-MM-dd|HH:mm:ss} %m%n" },
"Policies": {
Expand Down
10 changes: 4 additions & 6 deletions EuPathDB/src/main/webapp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app
id="oauth" version="3.0"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<web-app version="4.0"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd">

<!-- Need to add this so connection pool to apicomm is shut down -->
<listener>
Expand Down
11 changes: 8 additions & 3 deletions Server/src/main/java/org/gusdb/oauth2/service/OAuthService.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;
import javax.ws.rs.core.Response.Status;
import javax.ws.rs.core.UriInfo;
import javax.ws.rs.core.Variant;

import org.apache.logging.log4j.LogManager;
Expand Down Expand Up @@ -100,6 +101,9 @@ private static enum LoginFormStatus { failed, error, accessdenied; }
@Context
private HttpHeaders _headers;

@Context
private UriInfo _uriInfo;

@GET
@Path(Endpoints.ASSETS + "{name:.+}")
public Response getStaticFile(@PathParam("name") String name) {
Expand Down Expand Up @@ -147,8 +151,8 @@ public Response attemptLogin(
AuthzRequest originalRequest = (formId == null ? null : session.clearFormId(formId));
if (originalRequest == null) {
// formId doesn't exist on this session; give user generic success page
return Response.seeOther(new URI(RESOURCE_PREFIX +
config.getLoginSuccessPage())).build();
String baseUri = _uriInfo.getBaseUri().toString().replace("http://", "https://");
return Response.seeOther(new URI(baseUri + RESOURCE_PREFIX + config.getLoginSuccessPage())).build();
}
authenticator.logSuccessfulLogin(loginName, validUserId.get(), originalRequest.getClientId(), originalRequest.getRedirectUri(), _request.getRemoteAddr());
return OAuthRequestHandler.handleAuthorizationRequest(originalRequest, validUserId.get(), config.getTokenExpirationSecs());
Expand Down Expand Up @@ -262,7 +266,8 @@ private URI getLoginUri(String formId, String redirectUri, LoginFormStatus statu
if (status != null) {
queryString += (queryString.isEmpty() ? "" : "&") + "status=" + status.name();
}
return new URI(RESOURCE_PREFIX + OAuthServlet.getApplicationConfig(_context).getLoginFormPage() +
String baseUri = _uriInfo.getBaseUri().toString().replace("http://", "https://");
return new URI(baseUri + RESOURCE_PREFIX + OAuthServlet.getApplicationConfig(_context).getLoginFormPage() +
(queryString.isEmpty() ? "" : "?" + queryString));
}

Expand Down