Skip to content

Commit

Permalink
s3 auth
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangjunfeng committed May 15, 2024
1 parent 418cd51 commit c5af317
Show file tree
Hide file tree
Showing 24 changed files with 163 additions and 180 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ Ignite can be used as a Gremlin server, it is fast and distributed, it supports

## Redis
Ignite can also be used as a distributed redis server. To execute below script, run an Ignite instance with 'redis-ignite-internal-cache-0' cache specified and configured.

```
import redis

Expand All @@ -101,6 +102,7 @@ Ignite can also be used as a distributed redis server. To execute below script,
Ignite is also available as a distributed memcached server.

php code:

```

// Create client instance.
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

12 changes: 5 additions & 7 deletions ignite-extensions/modules/filemanager/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>11</java.version>
<fastjson.version>1.2.70</fastjson.version>
<fastjson.version>1.2.83</fastjson.version>

<jmail.version>1.6.7</jmail.version>
<ignite.version>2.16.999-SNAPSHOT</ignite.version>
Expand All @@ -49,15 +49,13 @@
<dependency>
<groupId>org.apache.ignite</groupId>
<artifactId>ignite-core</artifactId>
<scope>provided</scope>
<version>${ignite.version}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.apache.ignite</groupId>
<artifactId>ignite-spring</artifactId>
<scope>provided</scope>
<version>${ignite.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.ignite</groupId>
Expand All @@ -69,13 +67,13 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
<version>${spring.version}</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
<version>${spring.version}</version>
</dependency>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@
import org.apache.ignite.Ignite;
import org.apache.ignite.Ignition;
import org.apache.ignite.internal.GridKernalContext;
import org.shaofan.s3.config.SystemConfig;
import org.shaofan.s3.config.WebConfig;
import org.shaofan.s3.service.Impl.IgfsDatasetPersistenceProvider;
import org.shaofan.s3.service.Impl.S3IgfsServiceImpl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.ApplicationContext;
Expand All @@ -25,6 +22,7 @@

@Component
public class FileManagerInitializer implements WebApplicationInitializer {

public static Ignite ignite;


Expand Down Expand Up @@ -58,8 +56,7 @@ public void onStartup(ServletContext context) throws ServletException {

MultipartConfigElement MULTI_PART_CONFIG = new MultipartConfigElement(System.getProperty("java.io.tmpdir"));

dispatcher.setMultipartConfig(MULTI_PART_CONFIG);

dispatcher.setMultipartConfig(MULTI_PART_CONFIG);


}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,5 @@ public class WebConfig implements WebMvcConfigurer {

@Autowired
private SystemConfig config;

@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(s3Intecept).addPathPatterns("/s3/**");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public Object upload(@RequestParam("destination") String destination, MultipartH

String filename = part.getOriginalFilename();

s3Util.upload(bucketName, path+filename, part.getInputStream());
s3Util.upload(bucketName, path+"/"+filename, part.getInputStream());

part.getInputStream().close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public class S3Intecept implements HandlerInterceptor {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
boolean flag = false;

String authorization = request.getHeader("Authorization");
if(!StringUtils.isEmpty(authorization)){
flag = validAuthorizationHead(request, systemConfig.getAccessKey(), systemConfig.getSecretAccessKey());
Expand All @@ -48,6 +49,9 @@ public boolean preHandle(HttpServletRequest request, HttpServletResponse respons
if(!StringUtils.isEmpty(authorization)){
flag = validAuthorizationUrl(request, systemConfig.getAccessKey(), systemConfig.getSecretAccessKey());
}
else {
flag = true; // 匿名访问
}
}
if(!flag){
response.setStatus(HttpStatus.UNAUTHORIZED.value());
Expand Down Expand Up @@ -147,6 +151,7 @@ public boolean validAuthorizationHead(HttpServletRequest request, String accessK
///endregion

if (signature.equals(strHexSignature)) {
request.setAttribute("accessKey", accessKey);
return true;
}
return false;
Expand Down Expand Up @@ -257,6 +262,7 @@ public boolean validAuthorizationUrl(HttpServletRequest request, String accessKe
///endregion

if (signature.equals(strHexSignature)) {
request.setAttribute("accessKey", accessKey);
return true;
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
package org.shaofan.s3.service.Impl;

import org.apache.commons.io.FilenameUtils;
import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteException;
import org.apache.ignite.IgniteFileSystem;
Expand All @@ -43,8 +42,6 @@
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
Expand All @@ -59,7 +56,6 @@
import java.util.Date;
import java.util.List;

import javax.servlet.ServletException;

/**
* An {@link DatasetPersistenceProvider} that uses AWS Igfs for storage.
Expand Down Expand Up @@ -107,19 +103,15 @@ IgniteFileSystem fs(String bucketName) {
if(ignite==null) {
ignite = FileManagerInitializer.ignite;
}
if(ignite.fileSystems().size()==1) {
igfs = ignite.fileSystems().iterator().next();
}
else {
s3BucketName = systemConfig.getS3BucketName();
if (StringUtils.isEmpty(s3BucketName)) {
throw new IllegalArgumentException("The property '" + BUCKET_NAME_PROP + "' must be provided");
}

if(!StringUtils.isEmpty(systemConfig.getEndpointOverride()))
endpointOverride = URI.create(systemConfig.getEndpointOverride());
igfs = ignite.fileSystem(s3BucketName);
}
s3BucketName = systemConfig.getS3BucketName();
if (StringUtils.isEmpty(s3BucketName)) {
throw new IllegalArgumentException("The property '" + BUCKET_NAME_PROP + "' must be provided");
}

if(!StringUtils.isEmpty(systemConfig.getEndpointOverride()))
endpointOverride = URI.create(systemConfig.getEndpointOverride());

igfs = ignite.fileSystem(s3BucketName);
return igfs;
}

Expand Down Expand Up @@ -350,6 +342,10 @@ public ObjectMetadata getObjectMetadata(IgfsFile file) {
metadata.setContentEncoding(file.property("contentEncoding",null));
metadata.setLastModified(new Date(file.modificationTime()));
metadata.setUserMetadata(file.properties());
if(endpointOverride!=null) {
String url = endpointOverride.toString()+"/"+s3BucketName+"/"+file.path().name();
metadata.getUserMetadata().put("endpointURL",url);
}
return metadata;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,19 @@
</mvc:message-converters>
</mvc:annotation-driven>

<mvc:interceptors>
<mvc:interceptor>
<mvc:mapping path="/**" />
<bean id="s3Intecepter" class="org.shaofan.s3.intecept.S3Intecept"/>
</mvc:interceptor>
</mvc:interceptors>

<bean class="org.springframework.web.servlet.view.BeanNameViewResolver">
<property name="order" value="1" />
</bean>



<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">

<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="defaultEncoding" value="UTF-8" />
<property name="maxUploadSize" value="5242880" />
<property name="maxInMemorySize" value="40960" />
Expand All @@ -43,8 +48,6 @@
<property name="secretAccessKey" value="123456" />
<property name="dataPath" value="work/data/" />
<property name="s3BucketName" value="igfs" />
</bean>


</bean>

</beans>
2 changes: 1 addition & 1 deletion ignite-extensions/modules/ignite-janus/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<encoding>UTF-8</encoding>

<ignite.version>2.16.999-SNAPSHOT</ignite.version>
<janus.version>1.1.0-20231108-040802.ba4b083</janus.version>
<janus.version>1.0.0</janus.version>
<lucene-solr.version>8.11.2</lucene-solr.version>
<gremlin.version>3.7.0</gremlin.version>
</properties>
Expand Down
3 changes: 2 additions & 1 deletion ignite-extensions/modules/mongodb-relay/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
<version>1</version>
<relativePath>../../parent-internal/pom.xml</relativePath>
</parent>


<version>1.45.0-SNAPSHOT</version>
<artifactId>ignite-mongodb-realy</artifactId>

<url>http://ignite.apache.org</url>
Expand Down
Loading

0 comments on commit c5af317

Please sign in to comment.