-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
135 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,7 +32,7 @@ | |
import jakarta.enterprise.context.ApplicationScoped; | ||
|
||
/** | ||
* The one and only application bean. | ||
* The one and only application. | ||
* | ||
* @author Manfred Riem ([email protected]) | ||
*/ | ||
|
@@ -50,7 +50,14 @@ public class GitApplication { | |
private File repositoriesDirectory; | ||
|
||
/** | ||
* Initialize. | ||
* Initialize the application. | ||
* | ||
* This method is called once after the application is constructed. It sets | ||
* up the repositories directory where Git repositories will be stored. The | ||
* directory path is determined by the "ROOT_DIRECTORY" environment variable | ||
* or system property. If neither is set, it defaults to a directory under | ||
* the user's home directory. If the repositories directory does not exist, | ||
* it is created. | ||
*/ | ||
@PostConstruct | ||
public void initialize() { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,7 +41,7 @@ | |
import org.eclipse.jgit.http.server.GitFilter; | ||
|
||
/** | ||
* The Git HTTP servlet. | ||
* The Git HttpServlet. | ||
* | ||
* @author Manfred Riem ([email protected]) | ||
*/ | ||
|
@@ -81,6 +81,18 @@ public void destroy() { | |
filter.destroy(); | ||
} | ||
|
||
/** | ||
* Initialize the servlet. | ||
* | ||
* This method is called once when the servlet is first loaded into memory. | ||
* It initializes the Git filter and sets up the repository resolver and | ||
* upload size limit based on the servlet configuration. | ||
* | ||
* @param config the ServletConfig object that contains | ||
* configuration information for this servlet. | ||
* @throws ServletException if an exception occurs that interrupts | ||
* the servlet's normal operation. | ||
*/ | ||
@Override | ||
public void init(final ServletConfig config) throws ServletException { | ||
|
||
|
@@ -132,6 +144,23 @@ public ServletContext getServletContext() { | |
}); | ||
} | ||
|
||
/** | ||
* Process an HTTP request. | ||
* | ||
* This method is called for each HTTP request to the servlet. It uses the | ||
* Git filter to handle the request. If the request is not an HTTP-based | ||
* request that the Git filter can process, it sends a 404 error indicating | ||
* that the requested resource is not found. | ||
* | ||
* @param request the HttpServletRequest object that contains | ||
* the request the client has made of the servlet. | ||
* @param response the HttpServletResponse object that contains | ||
* the response the servlet sends to the client. | ||
* @throws ServletException if an exception occurs that interferes | ||
* with the servlet's normal operation. | ||
* @throws IOException if an input or output error is detected | ||
* when the servlet handles the request. | ||
*/ | ||
@Override | ||
protected void service(HttpServletRequest request, HttpServletResponse response) | ||
throws ServletException, IOException { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,7 +43,9 @@ | |
import java.util.Base64; | ||
|
||
/** | ||
* The "admin" filter. | ||
* The Security Filter. | ||
* | ||
* @author Manfred Riem ([email protected]) | ||
*/ | ||
public class SecurityFilter implements Filter { | ||
|
||
|
@@ -53,10 +55,35 @@ public class SecurityFilter implements Filter { | |
@Inject | ||
private IdentityStore identityStore; | ||
|
||
/** | ||
* Initialize the filter. | ||
* | ||
* @param filterConfig the filter configuration | ||
* @throws ServletException if an error occurs during initialization | ||
*/ | ||
@Override | ||
public void init(FilterConfig filterConfig) throws ServletException { | ||
} | ||
|
||
/** | ||
* Perform filtering on the request and response. | ||
* | ||
* This method checks if anonymous access is disabled by reading the "anonymousDisabled" | ||
* context parameter. If anonymous access is disabled, it sends a 403 Forbidden response. | ||
* | ||
* If the "Authorization" header is present and starts with "Basic ", it decodes the | ||
* Base64-encoded credentials, extracts the username and password, and validates them | ||
* using the IdentityStore. If the credentials are valid, it wraps the HttpServletRequest | ||
* to provide the authenticated user's principal, roles, and remote user. | ||
* | ||
* Finally, it passes the request and response to the next filter in the chain. | ||
* | ||
* @param request the servlet request | ||
* @param response the servlet response | ||
* @param chain the filter chain | ||
* @throws IOException if an I/O error occurs | ||
* @throws ServletException if a servlet error occurs | ||
*/ | ||
@Override | ||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) | ||
throws IOException, ServletException { | ||
|
@@ -104,6 +131,9 @@ public String getRemoteUser() { | |
chain.doFilter(httpRequest, httpResponse); | ||
} | ||
|
||
/** | ||
* Destroy the filter. | ||
*/ | ||
@Override | ||
public void destroy() { | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,7 +38,9 @@ | |
import java.util.logging.Logger; | ||
|
||
/** | ||
* The "admin" identity store. | ||
* The Security IdentityStore. | ||
* | ||
* @author Manfred Riem ([email protected]) | ||
*/ | ||
@ApplicationScoped | ||
public class SecurityIdentityStore implements IdentityStore { | ||
|
@@ -66,19 +68,33 @@ public class SecurityIdentityStore implements IdentityStore { | |
|
||
/** | ||
* Initialize the identity store. | ||
* <p> | ||
* This method is called after the bean's properties have been initialized. | ||
* It retrieves the admin username and password from the servlet context's | ||
* initialization parameters and logs the initialization status. | ||
*/ | ||
@PostConstruct | ||
public void init() { | ||
adminUsername = servletContext.getInitParameter("adminUsername"); | ||
adminPassword = servletContext.getInitParameter("adminPassword"); | ||
if (adminUsername != null && !adminUsername.isEmpty()) { | ||
LOGGER.info("AdminIdentityStore initialized with adminUsername: " + adminUsername); | ||
LOGGER.info("SecurityIdentityStore initialized with adminUsername: " + adminUsername); | ||
} | ||
if (adminPassword != null && !adminPassword.isEmpty()) { | ||
LOGGER.info("AdminIdentityStore initialized with adminPassword: " + "********"); | ||
LOGGER.info("SecurityIdentityStore initialized with adminPassword: " + "********"); | ||
} | ||
} | ||
|
||
/** | ||
* Validate the provided credential. | ||
* <p> | ||
* This method checks if the provided credential matches the admin username | ||
* and password. If they match, it returns a valid CredentialValidationResult | ||
* with the admin role. Otherwise, it returns a not validated result. | ||
* | ||
* @param credential the credential to validate | ||
* @return the result of the credential validation | ||
*/ | ||
@Override | ||
public CredentialValidationResult validate(Credential credential) { | ||
if (adminUsername == null || adminUsername.isEmpty() || adminPassword == null || adminPassword.isEmpty()) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,10 +7,7 @@ | |
import java.util.logging.Logger; | ||
|
||
/** | ||
* The Admin Servlet Container Initializer. | ||
* | ||
* This initializer sets the admin username and password context parameters | ||
* based on the environment variables or system properties AEGEAN_ADMIN_USERNAME and AEGEAN_ADMIN_PASSWORD. | ||
* The Security ServletContainerInitializer. | ||
* | ||
* @author Manfred Riem ([email protected]) | ||
*/ | ||
|
@@ -21,8 +18,19 @@ public class SecurityServletContainerInitializer implements ServletContainerInit | |
*/ | ||
private static final Logger LOGGER = Logger.getLogger(SecurityServletContainerInitializer.class.getName()); | ||
|
||
/** | ||
* Called when the application is starting up. | ||
* <p> | ||
* This method sets the context parameters for admin username, admin password, | ||
* and anonymous access disabled based on environment variables or system | ||
* properties when found. | ||
* | ||
* @param classes the set of classes | ||
* @param servletContext the servlet context | ||
* @throws ServletException when a servlet error occurs | ||
*/ | ||
@Override | ||
public void onStartup(Set<Class<?>> c, ServletContext ctx) throws ServletException { | ||
public void onStartup(Set<Class<?>> classes, ServletContext servletContext) throws ServletException { | ||
String adminUsername = System.getenv("AEGEAN_ADMIN_USERNAME"); | ||
if (adminUsername != null) { | ||
LOGGER.info("Admin username obtained from environment variable AEGEAN_ADMIN_USERNAME"); | ||
|
@@ -34,7 +42,7 @@ public void onStartup(Set<Class<?>> c, ServletContext ctx) throws ServletExcepti | |
} | ||
|
||
if (adminUsername != null) { | ||
ctx.setInitParameter("adminUsername", adminUsername); | ||
servletContext.setInitParameter("adminUsername", adminUsername); | ||
} | ||
|
||
String adminPassword = System.getenv("AEGEAN_ADMIN_PASSWORD"); | ||
|
@@ -48,7 +56,7 @@ public void onStartup(Set<Class<?>> c, ServletContext ctx) throws ServletExcepti | |
} | ||
|
||
if (adminPassword != null) { | ||
ctx.setInitParameter("adminPassword", adminPassword); | ||
servletContext.setInitParameter("adminPassword", adminPassword); | ||
} | ||
|
||
String anonymousDisabled = System.getenv("AEGEAN_ANONYMOUS_DISABLED"); | ||
|
@@ -57,12 +65,13 @@ public void onStartup(Set<Class<?>> c, ServletContext ctx) throws ServletExcepti | |
} else { | ||
anonymousDisabled = System.getProperty("com.manorrock.aegean.anonymousDisabled"); | ||
if (anonymousDisabled != null) { | ||
LOGGER.info("Anonymous access disabled obtained from system property com.manorrock.aegean.anonymousDisabled"); | ||
LOGGER.info( | ||
"Anonymous access disabled obtained from system property com.manorrock.aegean.anonymousDisabled"); | ||
} | ||
} | ||
|
||
if (anonymousDisabled != null) { | ||
ctx.setInitParameter("anonymousDisabled", anonymousDisabled); | ||
servletContext.setInitParameter("anonymousDisabled", anonymousDisabled); | ||
} | ||
} | ||
} |