Skip to content

Commit bd15d11

Browse files
committed
Use system's base URI
1 parent 94fda7f commit bd15d11

6 files changed

Lines changed: 20 additions & 130 deletions

File tree

src/main/java/com/atomgraph/linkeddatahub/resource/oauth2/AuthorizeBase.java

Lines changed: 14 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -49,22 +49,25 @@ public abstract class AuthorizeBase
4949

5050
private final HttpServletRequest httpServletRequest;
5151
private final Application application;
52+
private final com.atomgraph.linkeddatahub.Application system;
5253
private final String clientID;
5354

5455
/**
5556
* Constructs resource from current request info.
5657
*
5758
* @param httpServletRequest servlet request
5859
* @param application application
60+
* @param system JAX-RS application
5961
* @param clientID OAuth client ID
6062
*/
61-
public AuthorizeBase(HttpServletRequest httpServletRequest, Application application, String clientID)
63+
public AuthorizeBase(HttpServletRequest httpServletRequest, Application application, com.atomgraph.linkeddatahub.Application system, String clientID)
6264
{
6365
if (!application.canAs(EndUserApplication.class))
6466
throw new IllegalStateException("The " + getClass() + " endpoint is only available on end-user applications");
65-
67+
6668
this.httpServletRequest = httpServletRequest;
6769
this.application = application;
70+
this.system = system;
6871
this.clientID = clientID;
6972
if (log.isDebugEnabled()) log.debug("Constructing {}", getClass());
7073
}
@@ -79,7 +82,7 @@ public AuthorizeBase(HttpServletRequest httpServletRequest, Application applicat
7982
public Response get(@QueryParam(REFERER_PARAM_NAME) String originUri)
8083
{
8184
// the redirect URI must be on the domain, not sub-domains (i.e. on the root dataspace)
82-
URI redirectUri = UriBuilder.fromUri(getRootContextURI()).
85+
URI redirectUri = UriBuilder.fromUri(getSystem().getBaseURI()).
8386
path(getLoginClass()).
8487
build();
8588

@@ -166,49 +169,23 @@ public HttpServletRequest getHttpServletRequest()
166169
}
167170

168171
/**
169-
* Returns the base URI of this LinkedDataHub instance.
170-
* It equals to the base URI of the root dataspace.
172+
* Returns matched application.
171173
*
172-
* @return root base URI
174+
* @return application resource
173175
*/
174-
public URI getRootContextURI()
176+
public Application getApplication()
175177
{
176-
URI requestUri = URI.create(getHttpServletRequest().getRequestURL().toString());
177-
String host = requestUri.getHost();
178-
179-
// Strip all subdomains to get root domain
180-
String rootDomain;
181-
String[] parts = host.split("\\.");
182-
183-
if (host.equals("localhost") || host.endsWith(".localhost"))
184-
{
185-
// Special case: localhost domains
186-
rootDomain = "localhost";
187-
}
188-
else if (parts.length >= 2)
189-
{
190-
// Regular domains: take last 2 parts (e.g., example.com)
191-
rootDomain = parts[parts.length - 2] + "." + parts[parts.length - 1];
192-
}
193-
else rootDomain = host;
194-
195-
// Rebuild URI with root domain
196-
String scheme = requestUri.getScheme();
197-
int port = requestUri.getPort();
198-
String contextPath = getHttpServletRequest().getContextPath();
199-
200-
if (port == -1) return URI.create("%s://%s%s/".formatted(scheme, rootDomain, contextPath));
201-
else return URI.create("%s://%s:%d%s/".formatted(scheme, rootDomain, port, contextPath));
178+
return application;
202179
}
203180

204181
/**
205-
* Returns matched application.
182+
* Returns system application.
206183
*
207-
* @return application resource
184+
* @return JAX-RS application
208185
*/
209-
public Application getApplication()
186+
public com.atomgraph.linkeddatahub.Application getSystem()
210187
{
211-
return application;
188+
return system;
212189
}
213190

214191
/**

src/main/java/com/atomgraph/linkeddatahub/resource/oauth2/google/Authorize.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public class Authorize extends AuthorizeBase
4343
@Inject
4444
public Authorize(@Context HttpServletRequest httpServletRequest, com.atomgraph.linkeddatahub.apps.model.Application application, com.atomgraph.linkeddatahub.Application system)
4545
{
46-
super(httpServletRequest, application, (String)system.getProperty(Google.clientID.getURI()));
46+
super(httpServletRequest, application, system, (String)system.getProperty(Google.clientID.getURI()));
4747
}
4848

4949
@Override

src/main/java/com/atomgraph/linkeddatahub/resource/oauth2/orcid/Authorize.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public class Authorize extends AuthorizeBase
4242
@Inject
4343
public Authorize(@Context HttpServletRequest httpServletRequest, com.atomgraph.linkeddatahub.apps.model.Application application, com.atomgraph.linkeddatahub.Application system)
4444
{
45-
super(httpServletRequest, application, (String)system.getProperty(ORCID.clientID.getURI()));
45+
super(httpServletRequest, application, system, (String)system.getProperty(ORCID.clientID.getURI()));
4646
}
4747

4848
@Override

src/main/java/com/atomgraph/linkeddatahub/server/filter/request/auth/IDTokenFilterBase.java

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -334,32 +334,7 @@ public HttpServletRequest getHttpServletRequest()
334334
*/
335335
public URI getContextURI()
336336
{
337-
URI requestUri = URI.create(getHttpServletRequest().getRequestURL().toString());
338-
String host = requestUri.getHost();
339-
340-
// Strip all subdomains to get root domain
341-
String rootDomain;
342-
String[] parts = host.split("\\.");
343-
344-
if (host.equals("localhost") || host.endsWith(".localhost"))
345-
{
346-
// Special case: localhost domains
347-
rootDomain = "localhost";
348-
}
349-
else if (parts.length >= 2)
350-
{
351-
// Regular domains: take last 2 parts (e.g., example.com)
352-
rootDomain = parts[parts.length - 2] + "." + parts[parts.length - 1];
353-
}
354-
else rootDomain = host;
355-
356-
// Rebuild URI with root domain
357-
String scheme = requestUri.getScheme();
358-
int port = requestUri.getPort();
359-
String contextPath = getHttpServletRequest().getContextPath();
360-
361-
if (port == -1) return URI.create("%s://%s%s/".formatted(scheme, rootDomain, contextPath));
362-
else return URI.create("%s://%s:%d%s/".formatted(scheme, rootDomain, port, contextPath));
337+
return getSystem().getBaseURI();
363338
}
364339

365340
/**

src/main/java/com/atomgraph/linkeddatahub/writer/XSLTWriterBase.java

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -422,38 +422,13 @@ public ContainerRequestContext getContainerRequestContext()
422422
/**
423423
* Returns the base URI of this LinkedDataHub instance.
424424
* It equals to the base URI of the root dataspace.
425-
*
425+
*
426426
* @return root context URI
427427
*/
428428
@Override
429429
public URI getContextURI()
430430
{
431-
URI requestUri = URI.create(getHttpServletRequest().getRequestURL().toString());
432-
String host = requestUri.getHost();
433-
434-
// Strip all subdomains to get root domain
435-
String rootDomain;
436-
String[] parts = host.split("\\.");
437-
438-
if (host.equals("localhost") || host.endsWith(".localhost"))
439-
{
440-
// Special case: localhost domains
441-
rootDomain = "localhost";
442-
}
443-
else if (parts.length >= 2)
444-
{
445-
// Regular domains: take last 2 parts (e.g., example.com)
446-
rootDomain = parts[parts.length - 2] + "." + parts[parts.length - 1];
447-
}
448-
else rootDomain = host;
449-
450-
// Rebuild URI with root domain
451-
String scheme = requestUri.getScheme();
452-
int port = requestUri.getPort();
453-
String contextPath = getHttpServletRequest().getContextPath();
454-
455-
if (port == -1) return URI.create(scheme + "://" + rootDomain + contextPath + "/");
456-
else return URI.create(scheme + "://" + rootDomain + ":" + port + contextPath + "/");
431+
return getSystem().getBaseURI();
457432
}
458433

459434
}

src/main/java/com/atomgraph/linkeddatahub/writer/factory/DataManagerFactory.java

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -90,47 +90,10 @@ public DataManager getDataManager(Optional<Application> appOpt)
9090
// copy cached models over from the app's FileManager
9191
return new DataManagerImpl(LocationMapper.get(), new HashMap<>(baseManager.getModelCache()),
9292
ldc, true, getSystem().isPreemptiveAuth(), getSystem().isResolvingUncached(),
93-
getRootContextURI(getHttpServletRequest()),
93+
getSystem().getBaseURI(),
9494
getAgentContext());
9595
}
96-
97-
/**
98-
* Returns the base URI of this LinkedDataHub instance.
99-
* It equals to the base URI of the root dataspace.
100-
*
101-
* @param httpServletRequest servlet request
102-
* @return root context URI
103-
*/
104-
public URI getRootContextURI(HttpServletRequest httpServletRequest)
105-
{
106-
URI requestUri = URI.create(httpServletRequest.getRequestURL().toString());
107-
String host = requestUri.getHost();
10896

109-
// Strip all subdomains to get root domain
110-
String rootDomain;
111-
String[] parts = host.split("\\.");
112-
113-
if (host.equals("localhost") || host.endsWith(".localhost"))
114-
{
115-
// Special case: localhost domains
116-
rootDomain = "localhost";
117-
}
118-
else if (parts.length >= 2)
119-
{
120-
// Regular domains: take last 2 parts (e.g., example.com)
121-
rootDomain = parts[parts.length - 2] + "." + parts[parts.length - 1];
122-
}
123-
else rootDomain = host;
124-
125-
// Rebuild URI with root domain
126-
String scheme = requestUri.getScheme();
127-
int port = requestUri.getPort();
128-
String contextPath = getHttpServletRequest().getContextPath();
129-
130-
if (port == -1) return URI.create(scheme + "://" + rootDomain + contextPath + "/");
131-
else return URI.create(scheme + "://" + rootDomain + ":" + port + contextPath + "/");
132-
}
133-
13497
/**
13598
* Returns system application.
13699
*

0 commit comments

Comments
 (0)