Skip to content

Commit fd8e1cb

Browse files
committed
first commit
0 parents  commit fd8e1cb

24 files changed

+533
-0
lines changed

.classpath

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" output="target/classes" path="src/main/java">
4+
<attributes>
5+
<attribute name="optional" value="true"/>
6+
<attribute name="maven.pomderived" value="true"/>
7+
</attributes>
8+
</classpathentry>
9+
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
10+
<attributes>
11+
<attribute name="optional" value="true"/>
12+
<attribute name="maven.pomderived" value="true"/>
13+
</attributes>
14+
</classpathentry>
15+
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
16+
<attributes>
17+
<attribute name="maven.pomderived" value="true"/>
18+
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
19+
</attributes>
20+
</classpathentry>
21+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
22+
<classpathentry kind="output" path="target/classes"/>
23+
</classpath>

.project

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>file-integration-security</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>org.eclipse.wst.common.project.facet.core.builder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
<buildCommand>
19+
<name>org.eclipse.wst.validation.validationbuilder</name>
20+
<arguments>
21+
</arguments>
22+
</buildCommand>
23+
<buildCommand>
24+
<name>org.eclipse.m2e.core.maven2Builder</name>
25+
<arguments>
26+
</arguments>
27+
</buildCommand>
28+
</buildSpec>
29+
<natures>
30+
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
31+
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
32+
<nature>org.eclipse.jdt.core.javanature</nature>
33+
<nature>org.eclipse.m2e.core.maven2Nature</nature>
34+
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
35+
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
36+
</natures>
37+
</projectDescription>

.settings/.jsdtscope

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" path="src/main/webapp"/>
4+
<classpathentry excluding="**/bower_components/*|**/node_modules/*|**/*.min.js" kind="src" path="target/m2e-wtp/web-resources"/>
5+
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.JRE_CONTAINER"/>
6+
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.WebProject">
7+
<attributes>
8+
<attribute name="hide" value="true"/>
9+
</attributes>
10+
</classpathentry>
11+
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.baseBrowserLibrary"/>
12+
<classpathentry kind="output" path=""/>
13+
</classpath>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
eclipse.preferences.version=1
2+
encoding/<project>=UTF-8

.settings/org.eclipse.jdt.core.prefs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3+
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
4+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
5+
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
6+
org.eclipse.jdt.core.compiler.compliance=1.8
7+
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
8+
org.eclipse.jdt.core.compiler.debug.localVariable=generate
9+
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
10+
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
11+
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
12+
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
13+
org.eclipse.jdt.core.compiler.source=1.8

.settings/org.eclipse.m2e.core.prefs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
activeProfiles=
2+
eclipse.preferences.version=1
3+
resolveWorkspaceProjects=true
4+
version=1
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
2+
<wb-module deploy-name="file-integration-security">
3+
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
4+
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
5+
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
6+
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/test/java"/>
7+
<property name="context-root" value="file-integration-security"/>
8+
<property name="java-output-path" value="/file-integration-security/target/classes"/>
9+
</wb-module>
10+
</project-modules>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<faceted-project>
3+
<fixed facet="wst.jsdt.web"/>
4+
<installed facet="jst.web" version="2.3"/>
5+
<installed facet="wst.jsdt.web" version="1.0"/>
6+
<installed facet="java" version="1.8"/>
7+
</faceted-project>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
org.eclipse.wst.jsdt.launching.baseBrowserLibrary
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Window
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
disabled=06target
2+
eclipse.preferences.version=1

bala.jpg

41.3 KB
Loading

pom.xml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>org.poc.file</groupId>
8+
<artifactId>file-integration-security</artifactId>
9+
<version>0.0.1-SNAPSHOT</version>
10+
<packaging>war</packaging>
11+
12+
<name>file-integration-security</name>
13+
14+
<parent>
15+
<groupId>org.springframework.boot</groupId>
16+
<artifactId>spring-boot-starter-parent</artifactId>
17+
<version>2.0.3.RELEASE</version>
18+
<relativePath />
19+
</parent>
20+
21+
<properties>
22+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
23+
<maven.compiler.source>1.8</maven.compiler.source>
24+
<maven.compiler.target>1.8</maven.compiler.target>
25+
<java.version>1.8</java.version>
26+
</properties>
27+
28+
<dependencies>
29+
<dependency>
30+
<groupId>org.springframework.boot</groupId>
31+
<artifactId>spring-boot-starter-security</artifactId>
32+
</dependency>
33+
<dependency>
34+
<groupId>org.springframework.boot</groupId>
35+
<artifactId>spring-boot-starter-web</artifactId>
36+
</dependency>
37+
<dependency>
38+
<groupId>org.springframework.boot</groupId>
39+
<artifactId>spring-boot-starter-integration</artifactId>
40+
</dependency>
41+
<dependency>
42+
<groupId>org.springframework.integration</groupId>
43+
<artifactId>spring-integration-file</artifactId>
44+
</dependency>
45+
<dependency>
46+
<groupId>org.springframework.integration</groupId>
47+
<artifactId>spring-integration-ftp</artifactId>
48+
</dependency>
49+
<dependency>
50+
<groupId>org.springframework.boot</groupId>
51+
<artifactId>spring-boot-starter-test</artifactId>
52+
<scope>test</scope>
53+
</dependency>
54+
</dependencies>
55+
56+
<build>
57+
<finalName>file-integration-security</finalName>
58+
59+
<plugins>
60+
<plugin>
61+
<groupId>org.springframework.boot</groupId>
62+
<artifactId>spring-boot-maven-plugin</artifactId>
63+
</plugin>
64+
</plugins>
65+
</build>
66+
</project>
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package org.poc.file.app;
2+
3+
import java.io.File;
4+
5+
import org.springframework.boot.context.properties.EnableConfigurationProperties;
6+
import org.springframework.context.annotation.Bean;
7+
import org.springframework.context.annotation.Configuration;
8+
import org.springframework.expression.common.LiteralExpression;
9+
import org.springframework.integration.annotation.Gateway;
10+
import org.springframework.integration.annotation.MessagingGateway;
11+
import org.springframework.integration.annotation.ServiceActivator;
12+
import org.springframework.integration.ftp.outbound.FtpMessageHandler;
13+
import org.springframework.integration.ftp.session.DefaultFtpSessionFactory;
14+
import org.springframework.integration.ftp.session.FtpRemoteFileTemplate;
15+
import org.springframework.messaging.MessageHandler;
16+
17+
@Configuration
18+
@EnableConfigurationProperties(FtpProperties.class)
19+
public class FtpConfig {
20+
21+
private final FtpProperties ftpProperties;
22+
23+
public FtpConfig(FtpProperties ftpProperties) {
24+
this.ftpProperties = ftpProperties;
25+
}
26+
27+
@Bean
28+
DefaultFtpSessionFactory ftpSessionFactory(){
29+
DefaultFtpSessionFactory ftpSessionFactory = new DefaultFtpSessionFactory();
30+
ftpSessionFactory.setHost(ftpProperties.getHost());
31+
ftpSessionFactory.setPort(ftpProperties.getPort());
32+
ftpSessionFactory.setUsername(ftpProperties.getUsername());
33+
ftpSessionFactory.setPassword(ftpProperties.getPassword());
34+
return ftpSessionFactory;
35+
}
36+
37+
@Bean
38+
@ServiceActivator(inputChannel = "toFtpChannel")
39+
public MessageHandler handler() {
40+
FtpMessageHandler handler = new FtpMessageHandler(ftpSessionFactory());
41+
handler.setRemoteDirectoryExpression(new LiteralExpression(ftpProperties.getDirectory()));
42+
handler.setFileNameGenerator(message -> {
43+
if (message.getPayload() instanceof File) {
44+
return ((File) message.getPayload()).getName();
45+
} else {
46+
throw new IllegalArgumentException("File expected as payload.");
47+
}
48+
});
49+
return handler;
50+
}
51+
52+
@MessagingGateway
53+
public interface FtpGateway {
54+
55+
@Gateway(requestChannel = "toFtpChannel")
56+
void send(File file);
57+
}
58+
59+
@Bean
60+
public FtpRemoteFileTemplate template(){
61+
return new FtpRemoteFileTemplate(ftpSessionFactory());
62+
}
63+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package org.poc.file.app;
2+
3+
import org.springframework.boot.context.properties.ConfigurationProperties;
4+
5+
@ConfigurationProperties(prefix = "ftp")
6+
public class FtpProperties {
7+
8+
private String host;
9+
private int port;
10+
private String username;
11+
private String password;
12+
private String directory;
13+
14+
public String getHost() {
15+
return host;
16+
}
17+
18+
public void setHost(String host) {
19+
this.host = host;
20+
}
21+
22+
public String getUsername() {
23+
return username;
24+
}
25+
26+
public void setUsername(String username) {
27+
this.username = username;
28+
}
29+
30+
public String getPassword() {
31+
return password;
32+
}
33+
34+
public void setPassword(String password) {
35+
this.password = password;
36+
}
37+
38+
public int getPort() {
39+
return port;
40+
}
41+
42+
public void setPort(int port) {
43+
this.port = port;
44+
}
45+
46+
public String getDirectory() {
47+
return directory;
48+
}
49+
50+
public void setDirectory(String directory) {
51+
this.directory = directory;
52+
}
53+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package org.poc.file.app;
2+
3+
import org.springframework.beans.factory.annotation.Autowired;
4+
import org.springframework.context.annotation.Bean;
5+
import org.springframework.context.annotation.Configuration;
6+
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
7+
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
8+
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
9+
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
10+
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
11+
12+
@Configuration
13+
@EnableWebSecurity
14+
public class RbacConfig extends WebSecurityConfigurerAdapter {
15+
16+
@Override
17+
protected void configure(HttpSecurity http) throws Exception {
18+
http.csrf().disable().authorizeRequests()
19+
.antMatchers("/api/file/**").hasRole("ADMIN")
20+
.antMatchers("/api/**").permitAll()
21+
.anyRequest().authenticated()
22+
.and().httpBasic();
23+
}
24+
25+
@Autowired
26+
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
27+
auth.inMemoryAuthentication().withUser("admin").password("$2a$04$ZTvLZTtcq2l6L60/9/WMdeDTFKqwj5alMZjWo7tbWEQ9D.wLu8tNe").roles("ADMIN")
28+
.and()
29+
.withUser("user").password("$2a$04$ZTvLZTtcq2l6L60/9/WMdeDTFKqwj5alMZjWo7tbWEQ9D.wLu8tNe").roles("USER");
30+
}
31+
32+
@Bean
33+
public BCryptPasswordEncoder encoder() {
34+
return new BCryptPasswordEncoder();
35+
}
36+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package org.poc.file.app;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class StartService {
8+
9+
public static void main(String[] args) {
10+
SpringApplication.run(StartService.class, args);
11+
}
12+
13+
}

0 commit comments

Comments
 (0)