AnsweredAssumed Answered

Create users and groups using alfresco service java api maven dependencies

Question asked by justind on Apr 2, 2018
Latest reply on Apr 11, 2018 by justind

Hello, I am trying to create users and groups in my web application using the alfresco java api. The problem is that even though I've tried the code but I do not have the right maven dependencies that would import the libraries that would make the code implementable.

Here's my code, Please tell me what I'm doing wrong, thanks:

public class UserManagement {

    AlfrescoClient client = new AlfrescoClient.Builder().connect("http://localhost:8080/alfresco", "admin", "admin").build();
    PeopleAPI peopleAPI = client.getPeopleAPI();

    public UserManagement(String userName, String password) {
        if (authenticationService.authenticationExists(userName) == false)
        {
            authenticationService.createAuthentication(userName, password.toCharArray());

            Map user = new Map();
            user.put(ContentModel.PROP_USERNAME, userName);
            user.put(ContentModel.PROP_FIRSTNAME, "firstName");
            user.put(ContentModel.PROP_LASTNAME, "lastName");
            user.put(ContentModel.PROP_EMAIL, userName+"@example.com");
            user.put(ContentModel.PROP_JOBTITLE, "jobTitle");

            NodeRef person = personService.createPerson(user);

            // ...
        }
    }


if (!personService.personExists("tuser1")) {
        personService.createPerson(createDefaultProperties("tuser1", "Test", "User1", "tuser1@localhost", "password"));
        if (logger.isDebugEnabled()) logger.debug("Created tuser1 person");
    }

    if (!personService.personExists("tuser1")) {
        personService.createPerson(createDefaultProperties("tuser1", "Test", "User1", "tuser1@localhost", "password"));
        if (logger.isDebugEnabled()) logger.debug("Created tuser1 person");
    }
}

and my pom dependencies:

<dependencies>
<dependency>
    <groupId>org.apache.chemistry.opencmis</groupId>
    <artifactId>chemistry-opencmis-client-impl</artifactId>
    <version>1.1.0</version>
</dependency>
<dependency>
    <groupId>commons-logging</groupId>
    <artifactId>commons-logging</artifactId>
    <version>1.2</version>
</dependency>
<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.12</version>
    <scope>test</scope>
</dependency>

    <dependency>
        <groupId>joda-time</groupId>
        <artifactId>joda-time</artifactId>
        <version>2.3</version>
    </dependency>
    <dependency>
        <groupId>org.alfresco.cmis.client</groupId>
        <artifactId>alfresco-opencmis-extension</artifactId>
        <version>0.3</version>
        <type>jar</type>
    </dependency>

    <!--<dependency>-->
        <!--<groupId>org.alfresco</groupId>-->
        <!--<artifactId>alfresco-web-client</artifactId>-->
        <!--<version>4.2.e</version>-->
    <!--</dependency>-->
    <!--<dependency>-->
        <!--<groupId>org.alfresco</groupId>-->
        <!--<artifactId>alfresco-repository</artifactId>-->
        <!--<version>4.2.e</version>-->
    <!--</dependency>-->

    <!-- https://mvnrepository.com/artifact/org.alfresco/alfresco-web-service-client -->
    <dependency>
        <groupId>org.alfresco</groupId>
        <artifactId>alfresco-web-service-client</artifactId>
        <version>5.0.a</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.alfresco/share -->
    <dependency>
        <groupId>org.alfresco</groupId>
        <artifactId>share</artifactId>
        <version>5.2.f</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.alfresco/alfresco-core -->
    <dependency>
        <groupId>org.alfresco</groupId>
        <artifactId>alfresco-core</artifactId>
        <version>7.0</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.alfresco.maven/alfresco-sdk-aggregator -->
    <dependency>
        <groupId>org.alfresco.maven</groupId>
        <artifactId>alfresco-sdk-aggregator</artifactId>
        <version>3.0.1</version>
        <type>pom</type>
    </dependency>
    <dependency>
        <groupId>org.alfresco.client</groupId>
        <artifactId>alfresco-java-client</artifactId>
        <version>1.0.0-</version>
    </dependency>

</dependencies>

<repositories>
    <repository>
        <id>ossrh</id>
        <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
    <repository>
        <id>mavencentral</id>
        <name>Maven Central</name>
        <url>https://repo1.maven.org/maven2/</url>
        <layout>default</layout>
    </repository>
    <repository>
        <id>osssonatype</id>
        <name>OSS Sonatype</name>
        <url>https://repo1.maven.org/maven2/</url>
        <layout>default</layout>
    </repository>
    <repository>
        <id>sonatype-snapshots</id>
        <name>Sonatype Snapshot Repository</name>
        <url>https://oss.sonatype.org/content/repositories/snapshots</url>
        <releases>
            <enabled>true</enabled>
        </releases>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
    <repository>
        <id>maven.alfresco.com</id>
        <name>Alfresco Maven Repository</name>
        <url>http://maven.alfresco.com/nexus/content/groups/public/</url>
    </repository>
    <repository>
        <id>maven.alfresco.com</id>
        <name>Alfresco Maven Repository</name>
        <url>http://maven.alfresco.com/nexus/content/groups/public/</url>
    </repository>
</repositories>

Outcomes