use of alien4cloud.security.model.User in project alien4cloud by alien4cloud.
the class ArchiveExportService method getYaml.
/**
* Get the yaml string out of a cloud service archive and topology.
*
* @param csar The csar that contains archive meta-data.
* @param topology The topology template within the archive.
* @param generateWorkflow check if we generate the workflow
* @param dslVersion the TOSCA DSL version to use
* @param velocityCtx allows to provide some extra configuration options to velocity
*
* @return The TOSCA yaml file that describe the topology.
*/
public String getYaml(Csar csar, Topology topology, boolean generateWorkflow, String dslVersion, Map<String, Object> velocityCtx) {
if (velocityCtx == null) {
velocityCtx = new HashMap<>();
}
velocityCtx.put("topology", topology);
velocityCtx.put("template_name", csar.getName());
velocityCtx.put("template_version", csar.getVersion());
velocityCtx.put("hasCustomWorkflows", hasCustomWorkflows(topology));
velocityCtx.put("generateWorkflow", generateWorkflow);
if (csar.getDescription() == null) {
velocityCtx.put("template_description", "");
} else {
velocityCtx.put("template_description", csar.getDescription());
}
User loggedUser = AuthorizationUtil.getCurrentUser();
String author = csar.getTemplateAuthor();
if (author == null) {
author = loggedUser != null ? loggedUser.getUsername() : null;
}
velocityCtx.put("template_author", author);
velocityCtx.put("topology_description", topology.getDescription());
if (topology.getDescription() == null && ArchiveDelegateType.APPLICATION.toString().equals(csar.getDelegateType())) {
// if the archive has no description let's use the one of the application
Application application = applicationService.getOrFail(csar.getDelegateId());
velocityCtx.put("topology_description", application.getDescription());
}
try {
StringWriter writer = new StringWriter();
VelocityUtil.generate("org/alien4cloud/tosca/exporter/topology-" + dslVersion + ".yml.vm", writer, velocityCtx);
return writer.toString();
} catch (Exception e) {
log.error("Exception while templating YAML for topology " + topology.getId(), e);
return ExceptionUtils.getFullStackTrace(e);
}
}
use of alien4cloud.security.model.User in project alien4cloud by alien4cloud.
the class LocationSecurityService method getSubjectsFromContext.
/**
* Get subjects from context (current user, current user's groups, current environment, application ...)
*
* @param environment the environment from which the request has been made
* @return a map of subject type to subjects' ids
*/
public Map<Subject, Set<String>> getSubjectsFromContext(ApplicationEnvironment environment) {
Map<Subject, Set<String>> subjectsMap = new HashMap<>();
User user = AuthorizationUtil.getCurrentUser();
if (user != null) {
subjectsMap.put(Subject.USER, Sets.newHashSet(user.getUsername()));
Set<String> userGroups = AuthorizationUtil.getUserGroups(user);
subjectsMap.put(Subject.GROUP, userGroups);
}
if (environment != null) {
subjectsMap.put(Subject.ENVIRONMENT, Sets.newHashSet(environment.getId()));
subjectsMap.put(Subject.ENVIRONMENT_TYPE, Sets.newHashSet(environment.getApplicationId() + ":" + environment.getEnvironmentType().toString()));
subjectsMap.put(Subject.APPLICATION, Sets.newHashSet(environment.getApplicationId()));
}
return subjectsMap;
}
use of alien4cloud.security.model.User in project alien4cloud by alien4cloud.
the class EditorRepositoryService method commit.
/**
* Commit the changes to the repository using the given message as commit message.
*
* @param csar The csar under edition for which to commit changes.
* @param message The message to use for the commit.
*/
public void commit(Csar csar, String message) {
Path archiveGitPath = csarRepositry.getExpandedCSAR(csar.getName(), csar.getVersion());
final Authentication auth = SecurityContextHolder.getContext().getAuthentication();
String username = null;
String useremail = null;
User user = auth == null ? null : (User) auth.getPrincipal();
if (user != null) {
username = user.getUsername();
useremail = user.getEmail();
}
RepositoryManager.commitAll(archiveGitPath, username, useremail, message);
}
use of alien4cloud.security.model.User in project alien4cloud by alien4cloud.
the class InMemoryUserDao method search.
@Override
public FacetedSearchResult search(String searchQuery, String group, int from, int size) {
List<User> userList = Lists.newArrayList();
for (User user : userMap.values()) {
if (user.getUsername().startsWith(searchQuery)) {
userList.add(user);
}
}
User[] users = userList.toArray(new User[userList.size()]);
String[] types = new String[users.length];
for (int i = 0; i < types.length; i++) {
types[i] = User.class.getName();
}
Map<String, FacetedSearchFacet[]> facets = Maps.newHashMap();
return new FacetedSearchResult(0, users.length, 0, users.length, types, users, facets);
}
use of alien4cloud.security.model.User in project alien4cloud by alien4cloud.
the class UserServiceTest method testCreateUser.
@Test
public void testCreateUser() {
CreateUserRequest request = new CreateUserRequest();
request.setUsername("oneguy");
request.setPassword("password");
userService.createUser(request.getUsername(), request.getEmail(), request.getFirstName(), request.getLastName(), request.getRoles(), request.getPassword());
User createdUser = userService.retrieveUser(request.getUsername());
Assert.assertNotNull(createdUser);
Assert.assertEquals(request.getUsername(), createdUser.getUsername());
// Password must be encrypted
Assert.assertNotEquals(request.getPassword(), createdUser.getPassword());
}
Aggregations