Search in sources :

Example 1 with User

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);
    }
}
Also used : User(alien4cloud.security.model.User) StringWriter(java.io.StringWriter) Application(alien4cloud.model.application.Application)

Example 2 with User

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;
}
Also used : Set(java.util.Set) User(alien4cloud.security.model.User) HashMap(java.util.HashMap) Subject(alien4cloud.security.Subject)

Example 3 with User

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);
}
Also used : Path(java.nio.file.Path) User(alien4cloud.security.model.User) Authentication(org.springframework.security.core.Authentication)

Example 4 with User

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);
}
Also used : User(alien4cloud.security.model.User) FacetedSearchResult(alien4cloud.dao.model.FacetedSearchResult)

Example 5 with User

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());
}
Also used : User(alien4cloud.security.model.User) CreateUserRequest(alien4cloud.security.users.rest.CreateUserRequest) Test(org.junit.Test)

Aggregations

User (alien4cloud.security.model.User)51 Authentication (org.springframework.security.core.Authentication)9 Group (alien4cloud.security.model.Group)8 Then (cucumber.api.java.en.Then)8 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)8 ApiOperation (io.swagger.annotations.ApiOperation)7 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)7 Audit (alien4cloud.audit.annotation.Audit)5 GetMultipleDataResult (alien4cloud.dao.model.GetMultipleDataResult)4 Application (alien4cloud.model.application.Application)4 Location (alien4cloud.model.orchestrators.locations.Location)4 RestResponse (alien4cloud.rest.model.RestResponse)4 Subject (alien4cloud.security.Subject)4 List (java.util.List)4 Set (java.util.Set)4 IdsFilterBuilder (org.elasticsearch.index.query.IdsFilterBuilder)4 ApplicationEnvironmentService (alien4cloud.application.ApplicationEnvironmentService)3 ResourcePermissionService (alien4cloud.authorization.ResourcePermissionService)3 IGenericSearchDAO (alien4cloud.dao.IGenericSearchDAO)3 ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)3