Refactor Auth and HDFS controllers, fix User model, and improve HDFS config
- Rewrote AuthController to inject all dependencies via constructor - Fixed token refresh/login logic and added rate limiter and blacklist support - Implemented getters in LoginRequest DTO - Updated User model to implement UserDetails and extend entity.User - Switched HDFScontroller to use entity.User instead of models.User - Rewrote HDFSConfig to include static getHDFS() method and secure config via env vars - Simplified JwtService, added overload for entity.User, and fixed key handling
This commit is contained in:
@@ -8,13 +8,35 @@ import org.springframework.context.annotation.Bean;
|
||||
import java.net.URI;
|
||||
import java.security.PrivilegedExceptionAction;
|
||||
|
||||
|
||||
// HDFS configuration bean to securely connect to a remote Hadoop cluster.
|
||||
@Configuration
|
||||
public class HDFSConfig {
|
||||
public static FileSystem getHDFS() throws Exception {
|
||||
Configuration conf = new Configuration();
|
||||
conf.set("fs.defaultFS", "hdfs://namenode:9000");
|
||||
return FileSystem.get(new URI("hdfs://namenode:9000"), conf);
|
||||
|
||||
private static final String HDFS_URI = System.getenv("HDFS_URI"); // export HDFS_URI=hdfs://192.168.29.30:9000
|
||||
private static final String HDFS_USER = System.getenv("HDFS_USER"); // Hadoop user (if needed)
|
||||
|
||||
// Configures and returns a secured HDFS FileSystem instance.
|
||||
@Bean
|
||||
public FileSystem fileSystem() throws Exception {
|
||||
return getHDFS(); // use the static method internally
|
||||
}
|
||||
|
||||
// Static method to get a FileSystem instance. Used by other classes like HDFSController.
|
||||
public static FileSystem getHDFS() throws Exception {
|
||||
if (HDFS_URI == null || HDFS_URI.isBlank()) {
|
||||
throw new IllegalStateException("HDFS_URI environment variable not set.");
|
||||
}
|
||||
|
||||
}
|
||||
Configuration conf = new Configuration();
|
||||
conf.set("fs.defaultFS", HDFS_URI);
|
||||
|
||||
if (HDFS_USER != null && !HDFS_USER.isBlank()) {
|
||||
return UserGroupInformation.createRemoteUser(HDFS_USER)
|
||||
.doAs((PrivilegedExceptionAction<FileSystem>) () ->
|
||||
FileSystem.get(new URI(HDFS_URI), conf)
|
||||
);
|
||||
} else {
|
||||
return FileSystem.get(new URI(HDFS_URI), conf);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user