Commit 82fc2634 authored by zh9314's avatar zh9314

Merge branch 'package' of github.com:skoulouzis/DRIP into package

Update for pushing.
parents 09b05117 7ca77afd
......@@ -17,18 +17,12 @@ package nl.uva.sne.drip.api.conf;
import com.mongodb.Mongo;
import com.mongodb.MongoClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.annotation.PropertySources;
import org.springframework.data.mongodb.MongoDbFactory;
import org.springframework.data.mongodb.config.AbstractMongoConfiguration;
import org.springframework.data.mongodb.core.convert.DbRefResolver;
import org.springframework.data.mongodb.core.convert.DefaultDbRefResolver;
import org.springframework.data.mongodb.core.convert.MappingMongoConverter;
import org.springframework.data.mongodb.core.mapping.MongoMappingContext;
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
/**
......@@ -41,6 +35,7 @@ import org.springframework.data.mongodb.repository.config.EnableMongoRepositorie
@PropertySource(value = "classpath:drip.properties", ignoreResourceNotFound = true),
@PropertySource(value = "file:etc/drip.properties", ignoreResourceNotFound = true)
})
@ComponentScan("nl.uva.sne.drip")
public class MongoConfig extends AbstractMongoConfiguration {
@Value("${db.name}")
......@@ -54,7 +49,6 @@ public class MongoConfig extends AbstractMongoConfiguration {
// private MongoDbFactory mongoFactory;
// @Autowired
// private MongoMappingContext mongoMappingContext;
@Override
protected String getDatabaseName() {
return dbName;
......@@ -69,14 +63,4 @@ public class MongoConfig extends AbstractMongoConfiguration {
protected String getMappingBasePackage() {
return "nl.uva.sne.drip";
}
// @Bean
// public MappingMongoConverter mongoConverter() throws Exception {
// DbRefResolver dbRefResolver = new DefaultDbRefResolver(mongoFactory);
// MappingMongoConverter mongoConverter = new MappingMongoConverter(dbRefResolver, mongoMappingContext);
// mongoConverter.setMapKeyDotReplacement('\uff0E');
// mongoConverter.afterPropertiesSet();
// return mongoConverter;
// }
}
......@@ -30,7 +30,7 @@ import org.springframework.web.servlet.config.annotation.EnableWebMvc;
})
@EnableWebMvc
public class Config {
public class MultipartConfig {
@Bean(name = "multipartResolver")
public CommonsMultipartResolver createMultipartResolver() {
......
......@@ -15,34 +15,42 @@
*/
package nl.uva.sne.drip.api.conf;
import nl.uva.sne.drip.api.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import nl.uva.sne.drip.api.dao.UserDao;
/**
*
* @author S. Koulouzis
*/
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(jsr250Enabled = true)
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
// auth.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder());
UserService userService;
auth.inMemoryAuthentication()
.withUser("user").password("password").roles("USER");
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userService).passwordEncoder(passwordEncoder());
}
// @Override
// protected void configure(HttpSecurity http) throws Exception {
//// http.authorizeRequests().antMatchers("/**").hasRole("USER").and().formLogin();
// http.csrf().disable();
// }
@Bean
public PasswordEncoder passwordEncoder() {
PasswordEncoder encoder = new BCryptPasswordEncoder();
return encoder;
}
}
......@@ -15,6 +15,8 @@
*/
package nl.uva.sne.drip.api.conf;
public class MessageSecurityWebApplicationInitializer{
//extends AbstractSecurityWebApplicationInitializer {
import org.springframework.security.web.context.AbstractSecurityWebApplicationInitializer;
public class SpringSecurityInitializer extends AbstractSecurityWebApplicationInitializer {
}
......@@ -25,9 +25,9 @@ public class WebAppInitializer implements WebApplicationInitializer {
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
ctx.register(Config.class);
ctx.register(MultipartConfig.class);
ctx.register(MongoConfig.class);
// ctx.register(SecurityConfig.class);
ctx.register(SecurityConfig.class);
ctx.setServletContext(servletContext);
......
......@@ -24,4 +24,6 @@ import org.springframework.data.mongodb.repository.MongoRepository;
*/
public interface UserDao extends MongoRepository<User, String> {
public User findByUsername(String username);
}
......@@ -32,7 +32,7 @@ import org.springframework.web.bind.annotation.PathVariable;
* @author S. Koulouzis
*/
@RestController
@RequestMapping("/rest/configuration")
@RequestMapping("/configuration/cloud")
@Component
public class CloudConfigurationController {
......@@ -40,7 +40,7 @@ public class CloudConfigurationController {
private CloudCredentialsDao cloudCredentialsDao;
// curl -H "Content-Type: application/json" -X POST -d '{"key":"my_secret_password","keyIdAlias":"geni","logineKys":[{"attributes":null,"key":"-----BEGINRSAPUBLICKEY-----\nMIIBCgKCAQEA+xGZ/wcz9ugFpP07Nspo6U17l0YhFiFpxxU4pTk3Lifz9R3zsIsu\nERwta7+fWIfxOo208ett/jhskiVodSEt3QBGh4XBipyWopKwZ93HHaDVZAALi/2A\n+xTBtWdEo7XGUujKDvC2/aZKukfjpOiUI8AhLAfjmlcD/UZ1QPh0mHsglRNCmpCw\nmwSXA9VNmhz+PiB+Dml4WWnKW/VHo2ujTXxq7+efMU4H2fny3Se3KYOsFPFGZ1TN\nQSYlFuShWrHPtiLmUdPoP6CV2mML1tk+l7DIIqXrQhLUKDACeM5roMx0kLhUWB8P\n+0uj1CNlNN4JRZlC7xFfqiMbFRU9Z4N6YwIDAQAB\n-----ENDRSAPUBLICKEY-----","type":"PUBLIC"},{"attributes":null,"key":"-----BEGINRSAPRIVATEKEY-----\nMIICXAIBAAKBgQCqGKukO1De7zhZj6+H0qtjTkVxwTCpvKe4eCZ0FPqri0cb2JZfXJ/DgYSF6vUp\nwmJG8wVQZKjeGcjDOL5UlsuusFncCzWBQ7RKNUSesmQRMSGkVb1/3j+skZ6UtW+5u09lHNsj6tQ5\n1s1SPrCBkedbNf0Tp0GbMJDyR4e9T04ZZwIDAQABAoGAFijko56+qGyN8M0RVyaRAXz++xTqHBLh\n3tx4VgMtrQ+WEgCjhoTwo23KMBAuJGSYnRmoBZM3lMfTKevIkAidPExvYCdm5dYq3XToLkkLv5L2\npIIVOFMDG+KESnAFV7l2c+cnzRMW0+b6f8mR1CJzZuxVLL6Q02fvLi55/mbSYxECQQDeAw6fiIQX\nGukBI4eMZZt4nscy2o12KyYner3VpoeE+Np2q+Z3pvAMd/aNzQ/W9WaI+NRfcxUJrmfPwIGm63il\nAkEAxCL5HQb2bQr4ByorcMWm/hEP2MZzROV73yF41hPsRC9m66KrheO9HPTJuo3/9s5p+sqGxOlF\nL0NDt4SkosjgGwJAFklyR1uZ/wPJjj611cdBcztlPdqoxssQGnh85BzCj/u3WqBpE2vjvyyvyI5k\nX6zk7S0ljKtt2jny2+00VsBerQJBAJGC1Mg5Oydo5NwD6BiROrPxGo2bpTbu/fhrT8ebHkTz2epl\nU9VQQSQzY1oZMVX8i1m5WUTLPz2yLJIBQVdXqhMCQBGoiuSoSjafUhV7i1cEGpb88h5NBYZzWXGZ\n37sJ5QsW+sJyoNde3xH8vdXhzU7eT82D6X/scw9RZz+/6rCJ4p0=\n-----ENDRSAPRIVATEKEY-----","type":"PRIVATE"}],"cloudProviderName":"exogeni"}' http://localhost:8080/drip-api/rest/configuration
// curl -H "Content-Type: application/json" -X POST -d '{"key":"my_secret_password","keyIdAlias":"geni","logineKys":[{"attributes":null,"key":"-----BEGINRSAPUBLICKEY-----\nMIIBCgKCAQEA+xGZ/wcz9ugFpP07Nspo6U17l0YhFiFpxxU4pTk3Lifz9R3zsIsu\nERwta7+fWIfxOo208ett/jhskiVodSEt3QBGh4XBipyWopKwZ93HHaDVZAALi/2A\n+xTBtWdEo7XGUujKDvC2/aZKukfjpOiUI8AhLAfjmlcD/UZ1QPh0mHsglRNCmpCw\nmwSXA9VNmhz+PiB+Dml4WWnKW/VHo2ujTXxq7+efMU4H2fny3Se3KYOsFPFGZ1TN\nQSYlFuShWrHPtiLmUdPoP6CV2mML1tk+l7DIIqXrQhLUKDACeM5roMx0kLhUWB8P\n+0uj1CNlNN4JRZlC7xFfqiMbFRU9Z4N6YwIDAQAB\n-----ENDRSAPUBLICKEY-----","type":"PUBLIC"},{"attributes":null,"key":"-----BEGINRSAPRIVATEKEY-----\nMIICXAIBAAKBgQCqGKukO1De7zhZj6+H0qtjTkVxwTCpvKe4eCZ0FPqri0cb2JZfXJ/DgYSF6vUp\nwmJG8wVQZKjeGcjDOL5UlsuusFncCzWBQ7RKNUSesmQRMSGkVb1/3j+skZ6UtW+5u09lHNsj6tQ5\n1s1SPrCBkedbNf0Tp0GbMJDyR4e9T04ZZwIDAQABAoGAFijko56+qGyN8M0RVyaRAXz++xTqHBLh\n3tx4VgMtrQ+WEgCjhoTwo23KMBAuJGSYnRmoBZM3lMfTKevIkAidPExvYCdm5dYq3XToLkkLv5L2\npIIVOFMDG+KESnAFV7l2c+cnzRMW0+b6f8mR1CJzZuxVLL6Q02fvLi55/mbSYxECQQDeAw6fiIQX\nGukBI4eMZZt4nscy2o12KyYner3VpoeE+Np2q+Z3pvAMd/aNzQ/W9WaI+NRfcxUJrmfPwIGm63il\nAkEAxCL5HQb2bQr4ByorcMWm/hEP2MZzROV73yF41hPsRC9m66KrheO9HPTJuo3/9s5p+sqGxOlF\nL0NDt4SkosjgGwJAFklyR1uZ/wPJjj611cdBcztlPdqoxssQGnh85BzCj/u3WqBpE2vjvyyvyI5k\nX6zk7S0ljKtt2jny2+00VsBerQJBAJGC1Mg5Oydo5NwD6BiROrPxGo2bpTbu/fhrT8ebHkTz2epl\nU9VQQSQzY1oZMVX8i1m5WUTLPz2yLJIBQVdXqhMCQBGoiuSoSjafUhV7i1cEGpb88h5NBYZzWXGZ\n37sJ5QsW+sJyoNde3xH8vdXhzU7eT82D6X/scw9RZz+/6rCJ4p0=\n-----ENDRSAPRIVATEKEY-----","type":"PRIVATE"}],"cloudProviderName":"exogeni"}' http://localhost:8080/drip-api/configuration
// curl -H "Content-Type: application/json" -X POST -d '{"key":"AKISAKISAKIS","keyIdAlias":"6J76J76J76J76J76J76J7","logineKys":[{"attributes":{"domain_name":"California"},"type":"PUBLIC","key":"-----BEGINRSAPRIVATEKEY-----\nMIIEpQIBAAKCAQEA3Tz2mr7SZiAMfQyuvBjM9Oi..Z1BjP5CE/Wm/Rr500P\nRK+Lh9x5eJPo5CAZ3/ANBE0sTK0ZsDGMak2m1g7..3VHqIxFTz0Ta1d+NAj\nwnLe4nOb7/eEJbDPkk05ShhBrJGBKKxb8n104o/..PdzbFMIyNjJzBM2o5y\n5A13wiLitEO7nco2WfyYkQzaxCw0AwzlkVHiIyC..71pSzkv6sv+4IDMbT/\nXpCo8L6wTarzrywnQsh+etLD6FtTjYbbrvZ8RQM..Hg2qxraAV++HNBYmNW\ns0duEdjUbJK+ZarypXI9TtnS4o1Ckj7POfljiQI..IBAFyidxtqRQyv5KrD\nkbJ+q+rsJxQlaipn2M4lGuQJEfIxELFDyd3XpxP..Un/82NZNXlPmRIopXs\n2T91jiLZEUKQw+n73j26adTbteuEaPGSrTZxBLR..yssO0wWomUyILqVeti\n6AkL0NJAuKcucHGqWVgUIa4g1haE0ilcm6dWUDo..fd+PpzdCJf1s4NdUWK\nYV2GJcutGQb+jqT5DTUqAgST7N8M28rwjK6nVMI..BUpP0xpPnuYDyPOw6x\n4hBt8DZQYyduzIXBXRBKNiNdv8fum68/5klHxp6..4HRkMUL958UVeljUsT\nBFQlO9UCgYEA/VqzXVzlz8K36VSTMPEhB5zBATV..PRiXtYK1YpYV4/jSUj\nvvT4hP8uoYNC+BlEMi98LtnxZIh0V4rqHDsScAq..VyeSLH0loKMZgpwFEm\nbEIDnEOD0nKrfT/9K9sPYgvB43wsLEtUujaYw3W..Liy0WKmB8CgYEA34xn\n1QlOOhHBn9Z8qYjoDYhvcj+a89tD9eMPhesfQFw..rsfGcXIonFmWdVygbe\n6Doihc+GIYIq/QP4jgMksE1ADvczJSke92ZfE2i..fitBpQERNJO0BlabfP\nALs5NssKNmLkWS2U2BHCbv4DzDXwiQB37KPOL1c..kBHfF2/htIs20d1UVL\n+PK+aXKwguI6bxLGZ3of0UH+mGsSl0mkp7kYZCm..OTQtfeRqP8rDSC7DgA\nkHc5ajYqh04AzNFaxjRo+M3IGICUaOdKnXd0Fda..QwfoaX4QlRTgLqb7AN\nZTzM9WbmnYoXrx17kZlT3lsCgYEAm757XI3WJVj..WoLj1+v48WyoxZpcai\nuv9bT4Cj+lXRS+gdKHK+SH7J3x2CRHVS+WH/SVC..DxuybvebDoT0TkKiCj\nBWQaGzCaJqZa+POHK0klvS+9ln0/6k539p95tfX..X4TCzbVG6+gJiX0ysz\nYfehn5MCgYEAkMiKuWHCsVyCab3RUf6XA9gd3qY..fCTIGtS1tR5PgFIV+G\nengiVoWc/hkj8SBHZz1n1xLN7KDf8ySU06MDggB..hJ+gXJKy+gf3mF5Kmj\nDtkpjGHQzPF6vOe907y5NQLvVFGXUq/FIJZxB8k..fJdHEm2M4=\n-----ENDRSAPRIVATEKEY-----"},{"attributes":{"domain_name":"Virginia"},"type":"PUBLIC","key":"-----BEGINRSAPRIVATEKEY-----\nMIICXAIBAAKBgQCqGKukO1De7zhZj6+H0qtjTkVxwTCpvKe4eCZ0FPqri0cb2JZfXJ/DgYSF6vUp\nwmJG8wVQZKjeGcjDOL5UlsuusFncCzWBQ7RKNUSesmQRMSGkVb1/3j+skZ6UtW+5u09lHNsj6tQ5\n1s1SPrCBkedbNf0Tp0GbMJDyR4e9T04ZZwIDAQABAoGAFijko56+qGyN8M0RVyaRAXz++xTqHBLh\n3tx4VgMtrQ+WEgCjhoTwo23KMBAuJGSYnRmoBZM3lMfTKevIkAidPExvYCdm5dYq3XToLkkLv5L2\npIIVOFMDG+KESnAFV7l2c+cnzRMW0+b6f8mR1CJzZuxVLL6Q02fvLi55/mbSYxECQQDeAw6fiIQX\nGukBI4eMZZt4nscy2o12KyYner3VpoeE+Np2q+Z3pvAMd/aNzQ/W9WaI+NRfcxUJrmfPwIGm63il\nAkEAxCL5HQb2bQr4ByorcMWm/hEP2MZzROV73yF41hPsRC9m66KrheO9HPTJuo3/9s5p+sqGxOlF\nL0NDt4SkosjgGwJAFklyR1uZ/wPJjj611cdBcztlPdqoxssQGnh85BzCj/u3WqBpE2vjvyyvyI5k\nX6zk7S0ljKtt2jny2+00VsBerQJBAJGC1Mg5Oydo5NwD6BiROrPxGo2bpTbu/fhrT8ebHkTz2epl\nU9VQQSQzY1oZMVX8i1m5WUTLPz2yLJIBQVdXqhMCQBGoiuSoSjafUhV7i1cEGpb88h5NBYZzWXGZ\n37sJ5QsW+sJyoNde3xH8vdXhzU7eT82D6X/scw9RZz+/6rCJ4p0=\n-----ENDRSAPRIVATEKEY-----"}],"cloudProviderName":"ec2"}'
@RequestMapping(method = RequestMethod.POST)
public @ResponseBody
......@@ -49,12 +49,12 @@ public class CloudConfigurationController {
return cc.getId();
}
@RequestMapping(value = "/cloud/{id}", method = RequestMethod.GET)
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
public CloudCredentials get(@PathVariable("id") String id) {
return cloudCredentialsDao.findOne(id);
}
@RequestMapping(value = "/cloud/ids")
@RequestMapping(value = "/ids")
public @ResponseBody
List<String> getIds() {
List<CloudCredentials> all = cloudCredentialsDao.findAll();
......
......@@ -49,7 +49,7 @@ import nl.uva.sne.drip.api.dao.ToscaDao;
* @author S. Koulouzis
*/
@RestController
@RequestMapping("/rest/planner")
@RequestMapping("/planner")
@Component
public class PlannerController {
......
......@@ -42,7 +42,7 @@ import nl.uva.sne.drip.api.dao.ToscaDao;
* @author S. Koulouzis
*/
@RestController
@RequestMapping("/rest/tosca")
@RequestMapping("/tosca")
@Component
public class ToscaController {
......@@ -51,7 +51,7 @@ public class ToscaController {
@Autowired
private ToscaDao dao;
// curl -X POST -F "file=@DRIP/input.yaml" localhost:8080/drip-api/rest/upload
// curl -X POST -F "file=@DRIP/input.yaml" localhost:8080/drip-api/upload
@RequestMapping(value = "/upload", method = RequestMethod.POST)
public @ResponseBody
String toscaUpload(@RequestParam("file") MultipartFile file) {
......@@ -87,7 +87,7 @@ public class ToscaController {
return null;
}
// curl http://localhost:8080/drip-api/rest/tosca/589e1160d9925f9dc127e882/?fromat=yaml
// curl http://localhost:8080/drip-api/tosca/589e1160d9925f9dc127e882/?fromat=yaml
@RequestMapping(value = "/{id}", method = RequestMethod.GET, params = {"fromat"})
public @ResponseBody
String get(@PathVariable("id") String id, @RequestParam(value = "fromat") String fromat) {
......@@ -112,7 +112,7 @@ public class ToscaController {
return null;
}
// http://localhost:8080/drip-api/rest/tosca/ids
// http://localhost:8080/drip-api/tosca/ids
@RequestMapping(value = "/ids")
public @ResponseBody
List<String> getIds() {
......
......@@ -17,6 +17,7 @@ package nl.uva.sne.drip.api.rest;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.security.RolesAllowed;
import nl.uva.sne.drip.commons.types.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
......@@ -25,32 +26,35 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import nl.uva.sne.drip.api.dao.UserDao;
import nl.uva.sne.drip.api.service.UserService;
/**
*
* @author S. Koulouzis
*/
//@CrossOrigin(origins = "http://domain2.com", maxAge = 3600)
@RestController
@RequestMapping("/user/")
@Component
public class UserController {
@Autowired
private UserDao userRepository;
private UserService service;
@RequestMapping(value = "/register", method = RequestMethod.POST)
@RolesAllowed({UserService.ADMIN})
public @ResponseBody
String register(User user) {
userRepository.save(user);
return "registration";
service.getDao().save(user);
return user.getId();
}
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
@RolesAllowed({UserService.ADMIN})
public @ResponseBody
User get(@PathVariable("id") String id) {
try {
return userRepository.findOne(id);
return service.getDao().findOne(id);
} catch (Exception ex) {
Logger.getLogger(UserController.class.getName()).log(Level.SEVERE, null, ex);
}
......
......@@ -38,14 +38,14 @@ import org.springframework.web.bind.annotation.PathVariable;
* @author S. Koulouzis
*/
@RestController
@RequestMapping("/rest/user_key")
@RequestMapping("/user_key")
@Component
public class UserPublicKeysController {
@Autowired
private UserKeyDao dao;
// curl -v -X POST -F "file=@.ssh/id_dsa.pub" localhost:8080/drip-api/rest/user_key/upload
// curl -v -X POST -F "file=@.ssh/id_dsa.pub" localhost:8080/drip-api/user_key/upload
@RequestMapping(value = "/upload", method = RequestMethod.POST)
public @ResponseBody
String uploadUserPublicKeys(@RequestParam("file") MultipartFile file) {
......@@ -70,7 +70,7 @@ public class UserPublicKeysController {
}
// curl -H "Content-Type: application/json" -X POST -d '{"key":"ssh-rsa AAAAB3NzaDWBqs75i849MytgwgQcRYMcsXIki0yeYTKABH6JqoiyFBHtYlyh/EV1t6cujb9LyNP4J5EN4fPbtwKYvxecd0LojSPxl4wjQlfrHyg6iKUYB7hVzGqACMvgYZHrtHPfrdEmOGPplPVPpoaX2j+u0BZ0yYhrWMKjzyYZKa68yy5N18+Gq+1p83HfUDwIU9wWaUYdgEvDujqF6b8p3z6LDx9Ob+RanSMZSt+b8eZRcd+F2Oy/gieJEJ8kc152VIOv8UY1xB3hVEwVnSRGgrAsa+9PChfF6efXUGWiKf8KBlWgBOYsSTsOY4ks9zkXMnbcTdC+o7xspOkyIcWjv us@u\n","name":"id_rsa.pub"}' localhost:8080/drip-api/rest/user_key/
// curl -H "Content-Type: application/json" -X POST -d '{"key":"ssh-rsa AAAAB3NzaDWBqs75i849MytgwgQcRYMcsXIki0yeYTKABH6JqoiyFBHtYlyh/EV1t6cujb9LyNP4J5EN4fPbtwKYvxecd0LojSPxl4wjQlfrHyg6iKUYB7hVzGqACMvgYZHrtHPfrdEmOGPplPVPpoaX2j+u0BZ0yYhrWMKjzyYZKa68yy5N18+Gq+1p83HfUDwIU9wWaUYdgEvDujqF6b8p3z6LDx9Ob+RanSMZSt+b8eZRcd+F2Oy/gieJEJ8kc152VIOv8UY1xB3hVEwVnSRGgrAsa+9PChfF6efXUGWiKf8KBlWgBOYsSTsOY4ks9zkXMnbcTdC+o7xspOkyIcWjv us@u\n","name":"id_rsa.pub"}' localhost:8080/drip-api/user_key/
@RequestMapping(method = RequestMethod.POST)
public @ResponseBody
String postConf(UserPublicKey uk) throws JSONException {
......@@ -80,13 +80,13 @@ public class UserPublicKeysController {
return uk.getId();
}
//curl localhost:8080/drip-api/rest/user_key/58a20be263d4a5898835676e
//curl localhost:8080/drip-api/user_key/58a20be263d4a5898835676e
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
public UserPublicKey get(@PathVariable("id") String id) {
return dao.findOne(id);
}
// localhost:8080/drip-api/rest/user_key/ids
// localhost:8080/drip-api/user_key/ids
@RequestMapping(value = "/ids")
public @ResponseBody
List<String> getIds() {
......
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.uva.sne.drip.api.service;
import java.util.logging.Level;
import java.util.logging.Logger;
import nl.uva.sne.drip.api.dao.UserDao;
import nl.uva.sne.drip.commons.types.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
/**
*
* @author S. Koulouzis
*/
@Service
public class UserService implements UserDetailsService {
public static final String ADMIN = "ADMIN";
@Autowired
UserDao dao;
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
try {
// dao.deleteAll();
// User u = new User();
// u.setAccountNonExpired(true);
// u.setAccountNonLocked(true);
// Collection<GrantedAuthority> athorities = new HashSet<>();
// GrantedAuthority ga = new SimpleGrantedAuthority("ROLE_USER");
// athorities.add(ga);
// u.setAthorities(athorities);
// u.setCredentialsNonExpired(true);
// u.setEnabled(true);
// u.setPassword(new BCryptPasswordEncoder().encode("123"));
// u.setUsername(username);
// dao.save(u);
//
// User u2 = new User();
// u2.setAccountNonExpired(true);
// u2.setAccountNonLocked(true);
// athorities = new HashSet<>();
// ga = new SimpleGrantedAuthority("ROLE_ADMIN");
// athorities.add(ga);
// u2.setAthorities(athorities);
// u2.setCredentialsNonExpired(true);
// u2.setEnabled(true);
// u2.setPassword(new BCryptPasswordEncoder().encode("admin"));
// u2.setUsername("admin");
// dao.save(u2);
User user = dao.findByUsername(username);
return user;
} catch (Exception ex) {
Logger.getLogger(UserService.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
public UserDao getDao() {
return dao;
}
}
......@@ -49,7 +49,7 @@ public class RESTTest {
@BeforeClass
public static void setUpClass() throws URISyntaxException {
url = new URI("http://localhost:8080/drip-api/rest/upload");
url = new URI("http://localhost:8080/drip-api/upload");
toscaFile = new File("./etc/input.yaml");
}
......
......@@ -15,11 +15,8 @@
*/
package nl.uva.sne.drip.commons.types;
import nl.uva.sne.drip.commons.utils.PasswordUtil;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import java.util.Collection;
import java.util.List;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.security.core.GrantedAuthority;
......@@ -32,52 +29,39 @@ import org.springframework.security.core.userdetails.UserDetails;
@JsonIgnoreProperties({"password"})
@Document
public class User implements UserDetails {
@Id
private String id;
private String username;
@JsonIgnore
private Collection<? extends GrantedAuthority> athorities;
private String password;
private List<String> roles;
private boolean expired;
private boolean nonLocked;
private String username;
private boolean accountNonExpired;
private boolean accountNonLocked;
private boolean credentialsNonExpired;
private boolean enabled;
private Collection<? extends GrantedAuthority> authorities;
public void setPassword(String password) throws Exception {
this.password = PasswordUtil.hash(password);
}
public boolean isValide(String password) throws Exception {
if (this.password != null && password != null) {
return PasswordUtil.validate(this.password, password);
}
return false;
}
public List<String> getRoles() {
return roles;
}
public void setRoles(List<String> roles) {
this.roles = roles;
}
/**
* @return the id
*/
public String getId() {
return id;
}
/**
* @param id the id to set
*/
public void setId(String id) {
this.id = id;
}
@Override
public Collection<? extends GrantedAuthority> getAuthorities() {
return this.authorities;
return this.athorities;
}
@Override
public String getPassword() {
return this.password;
}
@Override
......@@ -87,12 +71,12 @@ public class User implements UserDetails {
@Override
public boolean isAccountNonExpired() {
return this.expired;
return this.accountNonExpired;
}
@Override
public boolean isAccountNonLocked() {
return this.nonLocked;
return this.accountNonLocked;
}
@Override
......@@ -105,8 +89,53 @@ public class User implements UserDetails {
return this.enabled;
}
@Override
public String getPassword() {
return this.password;
/**
* @param athorities the athorities to set
*/
public void setAthorities(Collection<? extends GrantedAuthority> athorities) {
this.athorities = athorities;
}
/**
* @param password the password to set
*/
public void setPassword(String password) {
this.password = password;
}
/**
* @param username the username to set
*/
public void setUsername(String username) {
this.username = username;
}
/**
* @param accountNonExpired the accountNonExpired to set
*/
public void setAccountNonExpired(boolean accountNonExpired) {
this.accountNonExpired = accountNonExpired;
}
/**
* @param accountNonLocked the accountNonLocked to set
*/
public void setAccountNonLocked(boolean accountNonLocked) {
this.accountNonLocked = accountNonLocked;
}
/**
* @param credentialsNonExpired the credentialsNonExpired to set
*/
public void setCredentialsNonExpired(boolean credentialsNonExpired) {
this.credentialsNonExpired = credentialsNonExpired;
}
/**
* @param enabled the enabled to set
*/
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
}
......@@ -13,30 +13,46 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.uva.sne.drip.api.rest;
package nl.uva.sne.drip.commons.types;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import nl.uva.sne.drip.api.dao.UserDao;
import org.springframework.data.mongodb.core.mapping.Document;
/**
*
* @author S. Koulouzis
*/
@Service
public class UserService implements UserDetailsService {
@Document
public class UserRole {
@Autowired
private UserDao userRepository;
private Integer userRoleId;
private String role;
@Override
public UserDetails loadUserByUsername(String string) throws UsernameNotFoundException {
return null;
/**
* @return the userRoleId
*/
public Integer getUserRoleId() {
return userRoleId;
}
/**
* @param userRoleId the userRoleId to set
*/
public void setUserRoleId(Integer userRoleId) {
this.userRoleId = userRoleId;
}
/**
* @return the role
*/
public String getRole() {
return role;
}
/**
* @param role the role to set
*/
public void setRole(String role) {
this.role = role;
}
}
/*
* Copyright 2017 S. Koulouzis, Wang Junchao, Huan Zhou, Yang Hu
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.uva.sne.drip.commons.utils;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
/**
*
* @author S. Koulouzis
*/
public class PasswordUtil {
public static String hash(String password) throws NoSuchAlgorithmException {
MessageDigest messageDigest = MessageDigest.getInstance("SHA-256");
messageDigest.update(password.getBytes());
return new String(messageDigest.digest());
}
public static boolean validate(String password, String password0) throws NoSuchAlgorithmException {
MessageDigest messageDigest = MessageDigest.getInstance("SHA-256");
messageDigest.update(password.getBytes());
String h1 = new String(messageDigest.digest());
messageDigest.update(password0.getBytes());
String h2 = new String(messageDigest.digest());
return h1.equals(h2);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment