Merge branch 'master' of github.com:esensar/steleks_web_app

master
esensar 2017-06-10 14:20:36 +02:00
commit ee2715bfd8
5 changed files with 44 additions and 23 deletions

View File

@ -0,0 +1,29 @@
package ba.steleks;
/**
* Created by admin on 06/05/2017.
*/
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
@Configuration
public class CrossOriginConfig {
@Bean
public CorsFilter corsFilter() {
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
CorsConfiguration config = new CorsConfiguration();
config.setAllowCredentials(true);
config.addAllowedOrigin("*");
config.addAllowedHeader("*");
config.addAllowedMethod("OPTIONS");
config.addAllowedMethod("GET");
config.addAllowedMethod("POST");
config.addAllowedMethod("PUT");
config.addAllowedMethod("DELETE");
source.registerCorsConfiguration("/**", config);
return new CorsFilter(source);
}
}

View File

@ -41,7 +41,7 @@ public class EventGalleryController {
@ResponseBody
public ResponseEntity<Resource> serveFile(@PathVariable String filename) {
Resource file = storageService.loadAsResource("mediaEvent/"+filename);
Resource file = storageService.loadAsResource("eventPictures/"+filename);
return ResponseEntity
.ok()
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\""+file.getFilename()+"\"")
@ -54,15 +54,21 @@ public class EventGalleryController {
String mediaServiceBase = discoveryClient.getServiceUrl(Service.EVENTS);
System.out.println(mediaServiceBase);
String[] names = file.getOriginalFilename().split("\\.");
String dest = String.valueOf("mediaEvent/" + mediaId + "_" + new Date().getTime()) + "." + names[names.length - 1];
String dest = String.valueOf("eventPictures/" + mediaId + "_" + new Date().getTime()) + "." + names[names.length - 1];
storageService.store(file, dest);
redirectAttributes.addFlashAttribute("message",
"You successfully uploaded " + file.getOriginalFilename() + "!");
System.out.println(dest);
Media media = repository.findOne(mediaId);
media.setContentUrl(mediaServiceBase +"/" + dest);
if(media==null){
media= new Media();
media.setContentUrl(mediaServiceBase +"/" + dest);
media.setCreatedById(0);
repository.save(media);
}else
media.setContentUrl(mediaServiceBase +"/" + dest);
repository.save(media);

View File

@ -14,24 +14,6 @@ import org.springframework.web.filter.CorsFilter;
@SpringBootApplication
public class SteleksProxyApplication {
@Bean
public CorsFilter corsFilter() {
final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
final CorsConfiguration config = new CorsConfiguration();
config.setAllowCredentials(true);
config.addAllowedOrigin("*");
config.addAllowedHeader("*");
config.addAllowedMethod("OPTIONS");
config.addAllowedMethod("HEAD");
config.addAllowedMethod("GET");
config.addAllowedMethod("PUT");
config.addAllowedMethod("POST");
config.addAllowedMethod("DELETE");
config.addAllowedMethod("PATCH");
source.registerCorsConfiguration("/**", config);
return new CorsFilter(source);
}
public static void main(String[] args) {
SpringApplication.run(SteleksProxyApplication.class, args);
}

View File

@ -40,6 +40,7 @@ dependencies {
compile('org.springframework.cloud:spring-cloud-starter-eureka')
compile('io.jsonwebtoken:jjwt:0.7.0')
compile project(':common')
compile('org.springframework.security:spring-security-jwt')
testCompile('org.springframework.cloud:spring-cloud-starter-eureka-server')
}

View File

@ -10,6 +10,7 @@ import ba.steleks.security.token.TokenStore;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.web.bind.annotation.*;
@ -27,6 +28,7 @@ public class AuthenticationController {
private TokenStore tokenStore;
@Autowired
public AuthenticationController(UsersJpaRepository usersJpaRepository, PasswordEncoder passwordEncoder, TokenStore tokenStore) {
this.usersJpaRepository = usersJpaRepository;
this.passwordEncoder = passwordEncoder;
@ -59,6 +61,7 @@ public class AuthenticationController {
throw new CustomHttpStatusException(HttpStatus.UNAUTHORIZED,
"Invalid password!");
}
}
@RequestMapping(path = "/accesstoken/{token}", method = RequestMethod.DELETE)