CCM NG: Repository and Manager class for Groups. Repository is finished, Manager not yet

git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@3530 8810af33-2d31-482b-a856-94f89814c4df
pull/2/head
jensp 2015-07-24 19:48:44 +00:00
parent 91cb6dddb0
commit 7c43e82068
28 changed files with 914 additions and 208 deletions

View File

@ -33,24 +33,24 @@ public class CcmSessionContext implements Serializable {
private static final long serialVersionUID = 6110177865273823685L;
private Subject currentParty;
private Subject effectiveParty;
private Subject currentSubject;
private Subject effectiveSubject;
public Subject getCurrentParty() {
return currentParty;
public Subject getCurrentSubject() {
return currentSubject;
}
public void setCurrentParty(final Subject currentParty) {
this.currentParty = currentParty;
this.effectiveParty = currentParty;
public void setCurrentSubject(final Subject currentSubject) {
this.currentSubject = currentSubject;
this.effectiveSubject = currentSubject;
}
public Subject getEffectiveParty() {
return effectiveParty;
public Subject getEffectiveSubject() {
return effectiveSubject;
}
protected void setEffectiveParty(final Subject effectiveParty) {
this.effectiveParty = effectiveParty;
protected void setEffectiveSubject(final Subject effectiveSubject) {
this.effectiveSubject = effectiveSubject;
}
/**
@ -60,15 +60,15 @@ public class CcmSessionContext implements Serializable {
* The there is a current user the method will check if the current user
* has the permission to use the {@code sudo} method.
*
* @param party The party with which permissions the code is executed.
* @param subject The party with which permissions the code is executed.
* @param runnable The code to execute.
*/
public void sudo(final Subject party, final Runnable runnable) {
public void sudo(final Subject subject, final Runnable runnable) {
//ToDo: Check if current user is permitted to use sudo.
effectiveParty = party;
effectiveSubject = subject;
runnable.run();
effectiveParty = currentParty;
effectiveSubject = currentSubject;
}
}

View File

@ -34,6 +34,8 @@ import javax.persistence.Table;
import org.hibernate.validator.constraints.NotBlank;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
@ -44,12 +46,16 @@ import javax.xml.bind.annotation.XmlRootElement;
*/
@Entity
@Table(name = "ccm_groups")
@NamedQueries({
@NamedQuery(name = "findGroupByName",
query = "SELECT g FROM Group g WHERE g.name = :groupName")
})
@XmlRootElement(name = "user-group", namespace = CORE_XML_NS)
public class Group extends Subject implements Serializable {
private static final long serialVersionUID = -5555063356689597270L;
@Column(name = "name", length = 512, nullable = false)
@Column(name = "name", length = 512, unique = true, nullable = false)
@NotBlank
@XmlElement(name = "name", namespace = CORE_XML_NS)
private String name;

View File

@ -0,0 +1,74 @@
/*
* Copyright (C) 2015 LibreCCM Foundation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package org.libreccm.core;
import javax.enterprise.context.RequestScoped;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@RequestScoped
public class GroupManager {
/**
* Add a user to a group. If the user is already a member of the group, this
* method will do nothing.
*
* @param user The user to add to the group
* @param group The group to add the user to.
*/
public void addUserToGroup(final User user, final Group group) {
}
/**
* Remove a user from a group. If the user is not member of the group this
* method will do nothing.
*
* @param user The user to remove from the group.
* @param group The group to remove the user from.
*/
public void removeUserFromGroup(final User user, final Group group) {
}
/**
* Determines if a user is member of a group.
*
* @param user The user to check
* @param group The group to check
*
* @return {@code true} if the provided user is a member of the provided
* group, {@code false} otherwise.
*/
public boolean isMemberOfGroup(final User user, final Group group) {
boolean result = false;
for (final GroupMembership membership : user.getGroupMemberships()) {
if (group.equals(membership.getGroup())) {
result = true;
break;
}
}
return result;
}
}

View File

@ -0,0 +1,69 @@
/*
* Copyright (C) 2015 LibreCCM Foundation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package org.libreccm.core;
import java.util.List;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.persistence.TypedQuery;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@RequestScoped
public class GroupRepository extends AbstractEntityRepository<Long, Group> {
@Inject
private transient EntityManager entityManager;
@Override
public Class<Group> getEntityClass() {
return Group.class;
}
@Override
public boolean isNew(final Group entity) {
if (entity == null) {
throw new IllegalArgumentException("Can't save null.");
}
return entity.getSubjectId() == 0;
}
public Group findByGroupName(final String groupName) {
final TypedQuery<Group> query = entityManager.createNamedQuery(
"findGroupByName", Group.class);
query.setParameter("groupName", groupName);
final List<Group> result = query.getResultList();
//Check if result list is empty and if not return the first element.
//If their ist a result than there can only be one because the
//name column of group has a unique constraint.
if (result.isEmpty()) {
return null;
} else {
return result.get(0);
}
}
}

View File

@ -63,15 +63,6 @@ public class Subject implements Serializable {
@GeneratedValue(strategy = GenerationType.AUTO)
private long subjectId;
@ElementCollection(fetch = FetchType.EAGER)
@CollectionTable(name = "subject_email_addresses",
joinColumns = {
@JoinColumn(name = "subject_id")})
@Size(min = 1)
@XmlElementWrapper(name = "email-addresses", namespace = CORE_XML_NS)
@XmlElement(name = "email-address", namespace = CORE_XML_NS)
private List<EmailAddress> emailAddresses;
@OneToMany(mappedBy = "grantee")
//Can't shorten this variable name without reducing descriptiveness
@SuppressWarnings("PMD.LongVariable")
@ -82,7 +73,6 @@ public class Subject implements Serializable {
public Subject() {
super();
emailAddresses = new ArrayList<>();
grantedPermissions = new ArrayList<>();
}
@ -94,26 +84,6 @@ public class Subject implements Serializable {
this.subjectId = subjectId;
}
public List<EmailAddress> getEmailAddresses() {
if (emailAddresses == null) {
return null;
} else {
return Collections.unmodifiableList(emailAddresses);
}
}
protected void setEmailAddresses(final List<EmailAddress> eMailAddresses) {
this.emailAddresses = eMailAddresses;
}
protected void addEmailAddress(final EmailAddress emailAddress) {
emailAddresses.add(emailAddress);
}
protected void removeEmailAddress(final EmailAddress emailAddress) {
emailAddresses.remove(emailAddress);
}
public List<Permission> getGrantedPermissions() {
return Collections.unmodifiableList(grantedPermissions);
}
@ -172,12 +142,10 @@ public class Subject implements Serializable {
public String toString(final String data) {
return String.format("%s{ "
+ "subjectId = %d, "
+ "emailAddresses = %s"
+ "%s"
+ " }",
super.toString(),
subjectId,
Objects.toString(emailAddresses),
data);
}

View File

@ -38,9 +38,13 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javax.persistence.CollectionTable;
import javax.persistence.ElementCollection;
import javax.persistence.FetchType;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
@ -95,6 +99,15 @@ public class User extends Subject implements Serializable {
@XmlElement(name = "screen-name", namespace = CORE_XML_NS)
private String screenName;
@ElementCollection(fetch = FetchType.EAGER)
@CollectionTable(name = "user_email_addresses",
joinColumns = {
@JoinColumn(name = "user_id")})
@Size(min = 1)
@XmlElementWrapper(name = "email-addresses", namespace = CORE_XML_NS)
@XmlElement(name = "email-address", namespace = CORE_XML_NS)
private List<EmailAddress> emailAddresses;
/**
* A user can be banned which means that he or she can't login into the
* system anymore.
@ -171,6 +184,7 @@ public class User extends Subject implements Serializable {
super();
name = new PersonName();
emailAddresses = new ArrayList<>();
this.groupMemberships = new ArrayList<>();
}
@ -190,6 +204,26 @@ public class User extends Subject implements Serializable {
this.screenName = screenName;
}
public List<EmailAddress> getEmailAddresses() {
if (emailAddresses == null) {
return null;
} else {
return Collections.unmodifiableList(emailAddresses);
}
}
protected void setEmailAddresses(final List<EmailAddress> eMailAddresses) {
this.emailAddresses = eMailAddresses;
}
protected void addEmailAddress(final EmailAddress emailAddress) {
emailAddresses.add(emailAddress);
}
protected void removeEmailAddress(final EmailAddress emailAddress) {
emailAddresses.remove(emailAddress);
}
public boolean isBanned() {
return banned;
}
@ -353,12 +387,14 @@ public class User extends Subject implements Serializable {
public String toString(final String data) {
return super.toString(String.format(", name = %s, "
+ "screenName = \"%s\", "
+ "emailAddress = { %s }"
+ "banned = %b, "
+ "ssoLogin = \"%s\" "
+ "hashAlgorithm = \"%s\" "
+ "passwordResetRequired = %b%s",
Objects.toString(name),
screenName,
Objects.toString(emailAddresses),
banned,
ssoLogin,
hashAlgorithm,

View File

@ -80,7 +80,7 @@ public class LoginManager {
final UserPrincipal principal = iterator.next();
final User user = principal.getUser();
sessionContext.setCurrentParty(user);
sessionContext.setCurrentSubject(user);
}
}

View File

@ -42,10 +42,17 @@ public class DatasetsTest extends DatasetsVerifier {
@Parameterized.Parameters(name = "Dataset {0}")
public static Collection<String> data() {
return Arrays.asList(new String[]{
"/datasets/org/libreccm/core/authentication/LoginManagerTest/data.json",
"/datasets/org/libreccm/core/CcmObjectRepositoryTest/data.json",
"/datasets/org/libreccm/core/CcmObjectRepositoryTest/after-delete.json",
"/datasets/org/libreccm/core/CcmObjectRepositoryTest/after-save-changed.json",
"/datasets/org/libreccm/core/CcmObjectRepositoryTest/after-save-new.json",
"/datasets/org/libreccm/core/GroupManagerTest/users-groups.json",
"/datasets/org/libreccm/core/GroupRepositoryTest/data.json",
"/datasets/org/libreccm/core/GroupRepositoryTest/after-delete.json",
"/datasets/org/libreccm/core/GroupRepositoryTest/after-save-changed.json",
"/datasets/org/libreccm/core/GroupRepositoryTest/after-save-new.json",
"/datasets/org/libreccm/core/UserManagerTest/verify-password.json",
"/datasets/org/libreccm/core/UserRepositoryTest/data.json",
"/datasets/org/libreccm/core/UserRepositoryTest/after-delete.json",
"/datasets/org/libreccm/core/UserRepositoryTest/after-save-changed.json",

View File

@ -0,0 +1,139 @@
/*
* Copyright (C) 2015 LibreCCM Foundation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package org.libreccm.core;
import static org.hamcrest.Matchers.*;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.junit.InSequence;
import org.jboss.arquillian.persistence.PersistenceTest;
import org.jboss.arquillian.persistence.UsingDataSet;
import org.jboss.arquillian.transaction.api.annotation.TransactionMode;
import org.jboss.arquillian.transaction.api.annotation.Transactional;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.jboss.shrinkwrap.resolver.api.maven.Maven;
import org.jboss.shrinkwrap.resolver.api.maven.PomEquippedResolveStage;
import org.junit.After;
import org.junit.AfterClass;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
import org.libreccm.tests.categories.IntegrationTest;
import java.io.File;
import javax.inject.Inject;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@Category(IntegrationTest.class)
@RunWith(Arquillian.class)
@PersistenceTest
@Transactional(TransactionMode.COMMIT)
public class GroupManagerTest {
@Inject
private transient GroupManager groupManager;
@Inject
private transient UserRepository userRepository;
@Inject
private transient GroupRepository groupRepository;
public GroupManagerTest() {
}
@BeforeClass
public static void setUpClass() {
}
@AfterClass
public static void tearDownClass() {
}
@Before
public void setUp() {
}
@After
public void tearDown() {
}
@Deployment
public static WebArchive createDeployment() {
final PomEquippedResolveStage pom = Maven
.resolver()
.loadPomFromFile("pom.xml");
final PomEquippedResolveStage dependencies = pom.
importCompileAndRuntimeDependencies();
final File[] libs = dependencies.resolve().withTransitivity().asFile();
for (File lib : libs) {
System.err.printf("Adding file '%s' to test archive...%n",
lib.getName());
}
return ShrinkWrap
.create(WebArchive.class,
"LibreCCM-org.libreccm.core.GroupManagerTest.war")
.addPackage(User.class.getPackage())
.addPackage(org.libreccm.web.Application.class.getPackage())
.addPackage(org.libreccm.categorization.Category.class.
getPackage())
.addPackage(org.libreccm.l10n.LocalizedString.class.getPackage()).
addPackage(org.libreccm.jpa.EntityManagerProducer.class
.getPackage())
.addPackage(org.libreccm.jpa.utils.MimeTypeConverter.class
.getPackage())
.addPackage(org.libreccm.testutils.EqualsVerifier.class.
getPackage())
.addPackage(org.libreccm.tests.categories.IntegrationTest.class
.getPackage())
.addAsLibraries(libs)
.addAsResource("test-persistence.xml",
"META-INF/persistence.xml")
.addAsWebInfResource("test-web.xml", "WEB-INF/web.xml")
.addAsWebInfResource(EmptyAsset.INSTANCE, "WEB-INF/beans.xml");
}
@Test
@InSequence(10)
@UsingDataSet("datasets/org/libreccm/core/GroupManagerTest/users-groups.json")
public void verifyIsMemberOfGroup() {
final User jdoe = userRepository.findByScreenName("jdoe");
final Group admins = groupRepository.findByGroupName("admins");
final Group users = groupRepository.findByGroupName("users");
final Group authors = groupRepository.findByGroupName("authors");
assertThat(groupManager.isMemberOfGroup(jdoe, admins), is(false));
assertThat(groupManager.isMemberOfGroup(jdoe, users), is(true));
assertThat(groupManager.isMemberOfGroup(jdoe, authors), is(true));
}
}

View File

@ -0,0 +1,207 @@
/*
* Copyright (C) 2015 LibreCCM Foundation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package org.libreccm.core;
import static org.hamcrest.Matchers.*;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.ShouldThrowException;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.junit.InSequence;
import org.jboss.arquillian.persistence.PersistenceTest;
import org.jboss.arquillian.persistence.ShouldMatchDataSet;
import org.jboss.arquillian.persistence.UsingDataSet;
import org.jboss.arquillian.transaction.api.annotation.TransactionMode;
import org.jboss.arquillian.transaction.api.annotation.Transactional;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.jboss.shrinkwrap.resolver.api.maven.Maven;
import org.jboss.shrinkwrap.resolver.api.maven.PomEquippedResolveStage;
import org.junit.After;
import org.junit.AfterClass;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
import org.libreccm.tests.categories.IntegrationTest;
import java.io.File;
import javax.inject.Inject;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@Category(IntegrationTest.class)
@RunWith(Arquillian.class)
@PersistenceTest
@Transactional(TransactionMode.COMMIT)
public class GroupRepositoryTest {
@Inject
private transient GroupRepository groupRepository;
public GroupRepositoryTest() {
}
@BeforeClass
public static void setUpClass() {
}
@AfterClass
public static void tearDownClass() {
}
@Before
public void setUp() {
}
@After
public void tearDown() {
}
@Deployment
public static WebArchive createDeployment() {
final PomEquippedResolveStage pom = Maven
.resolver()
.loadPomFromFile("pom.xml");
final PomEquippedResolveStage dependencies = pom.
importCompileAndRuntimeDependencies();
final File[] libs = dependencies.resolve().withTransitivity().asFile();
for (File lib : libs) {
System.err.printf("Adding file '%s' to test archive...%n",
lib.getName());
}
return ShrinkWrap
.create(WebArchive.class,
"LibreCCM-org.libreccm.core.UserRepositoryTest.war")
.addPackage(User.class.getPackage())
.addPackage(org.libreccm.web.Application.class.getPackage())
.addPackage(org.libreccm.categorization.Category.class.
getPackage())
.addPackage(org.libreccm.l10n.LocalizedString.class.getPackage()).
addPackage(org.libreccm.jpa.EntityManagerProducer.class
.getPackage())
.addPackage(org.libreccm.jpa.utils.MimeTypeConverter.class
.getPackage())
.addPackage(org.libreccm.testutils.EqualsVerifier.class.
getPackage())
.addPackage(org.libreccm.tests.categories.IntegrationTest.class
.getPackage())
.addAsLibraries(libs)
.addAsResource("test-persistence.xml",
"META-INF/persistence.xml")
.addAsWebInfResource("test-web.xml", "WEB-INF/web.xml")
.addAsWebInfResource(EmptyAsset.INSTANCE, "WEB-INF/beans.xml");
}
private void verifyGroups(final Group admins,
final Group users,
final Group authors,
final Group none) {
assertThat(admins, is(not(nullValue())));
assertThat(admins.getName(), is(equalTo("admins")));
assertThat(users, is(not(nullValue())));
assertThat(users.getName(), is(equalTo("users")));
assertThat(authors, is(not(nullValue())));
assertThat(authors.getName(), is(equalTo("authors")));
assertThat(none, is(nullValue()));
}
@Test
@InSequence
@UsingDataSet("datasets/org/libreccm/core/GroupRepositoryTest/data.json")
public void findGroupById() {
final Group admins = groupRepository.findById(-10L);
final Group users = groupRepository.findById(-20L);
final Group authors = groupRepository.findById(-30L);
final Group none = groupRepository.findById(-999L);
verifyGroups(admins, users, authors, none);
}
@Test
@InSequence(20)
@UsingDataSet("datasets/org/libreccm/core/GroupRepositoryTest/data.json")
public void findGroupByName() {
final Group admins = groupRepository.findByGroupName("admins");
final Group users = groupRepository.findByGroupName("users");
final Group authors = groupRepository.findByGroupName("authors");
final Group none = groupRepository.findByGroupName("none");
verifyGroups(admins, users, authors, none);
}
@Test
@InSequence(30)
@UsingDataSet("datasets/org/libreccm/core/GroupRepositoryTest/data.json")
@ShouldMatchDataSet(value
= "datasets/org/libreccm/core/GroupRepositoryTest/after-save-new.json",
excludeColumns = "subject_id")
public void saveNewGroup() {
final Group publishers = new Group();
publishers.setName("publishers");
groupRepository.save(publishers);
}
@Test
@InSequence(40)
@UsingDataSet("datasets/org/libreccm/core/GroupRepositoryTest/data.json")
@ShouldMatchDataSet(value
= "datasets/org/libreccm/core/GroupRepositoryTest/after-save-changed.json",
excludeColumns = {"subject_id"})
public void saveChangedGroup() {
final Group group = groupRepository.findByGroupName("authors");
group.setName("editors");
groupRepository.save(group);
}
@Test(expected = IllegalArgumentException.class)
@ShouldThrowException(IllegalArgumentException.class)
@InSequence(50)
public void saveNullValue() {
groupRepository.save(null);
}
@Test
@InSequence(60)
@UsingDataSet("datasets/org/libreccm/core/GroupRepositoryTest/data.json")
@ShouldMatchDataSet(
"datasets/org/libreccm/core/GroupRepositoryTest/after-delete.json")
public void deleteGroup() {
final Group group = groupRepository.findByGroupName("users");
groupRepository.delete(group);
}
}

View File

@ -40,7 +40,6 @@ import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
import static org.libreccm.core.CoreConstants.*;
import org.apache.commons.codec.binary.Base64;
import org.jboss.arquillian.container.test.api.ShouldThrowException;

View File

@ -55,7 +55,6 @@ import org.libreccm.tests.categories.IntegrationTest;
import java.util.List;
import javax.persistence.Query;
/**
*
@ -252,7 +251,7 @@ public class UserRepositoryTest {
@UsingDataSet("datasets/org/libreccm/core/UserRepositoryTest/data.json")
@ShouldMatchDataSet(value
= "datasets/org/libreccm/core/UserRepositoryTest/after-save-new.json",
excludeColumns = {"subject_id"})
excludeColumns = {"subject_id", "user_id"})
@InSequence(500)
public void saveNewUser() {
final User user = new User();

View File

@ -45,6 +45,8 @@ import org.junit.runner.RunWith;
import org.libreccm.core.CcmObject;
import org.libreccm.core.CcmSessionContext;
import org.libreccm.core.EmailAddress;
import org.libreccm.core.Subject;
import org.libreccm.core.User;
import org.libreccm.tests.categories.IntegrationTest;
import java.io.File;
@ -175,13 +177,17 @@ public class LoginManagerTest {
public void loginValidCredentials() throws LoginException {
loginManager.login("jdoe@example.com", "foobar");
assertThat(ccmSessionContext.getCurrentParty(), is(not(nullValue())));
assertThat(ccmSessionContext.getCurrentSubject(), is(not(nullValue())));
final EmailAddress emailAddress = new EmailAddress();
emailAddress.setAddress("jdoe@example.com");
emailAddress.setBouncing(false);
emailAddress.setVerified(true);
assertThat(ccmSessionContext.getCurrentParty().getEmailAddresses(),
contains(equalTo(emailAddress)));
final Subject subject = ccmSessionContext.getCurrentSubject();
assertThat(subject, is(instanceOf(User.class)));
final User user = (User) subject;
assertThat(user.getEmailAddresses(), contains(equalTo(emailAddress)));
}
@Test
@ -192,7 +198,7 @@ public class LoginManagerTest {
try {
loginManager.login("jdoe@example.com", "wrong-pw");
} catch (LoginException ex) {
assertThat(ccmSessionContext.getCurrentParty(), is(nullValue()));
assertThat(ccmSessionContext.getCurrentSubject(), is(nullValue()));
return;
}
@ -207,7 +213,7 @@ public class LoginManagerTest {
try {
loginManager.login("jdoe@example.com", "");
} catch (LoginException ex) {
assertThat(ccmSessionContext.getCurrentParty(), is(nullValue()));
assertThat(ccmSessionContext.getCurrentSubject(), is(nullValue()));
return;
}
@ -222,7 +228,7 @@ public class LoginManagerTest {
try {
loginManager.login("", "correct-pw");
} catch (LoginException ex) {
assertThat(ccmSessionContext.getCurrentParty(), is(nullValue()));
assertThat(ccmSessionContext.getCurrentSubject(), is(nullValue()));
return;
}
@ -237,7 +243,7 @@ public class LoginManagerTest {
try {
loginManager.login("jdoe@example.com", null);
} catch (LoginException ex) {
assertThat(ccmSessionContext.getCurrentParty(), is(nullValue()));
assertThat(ccmSessionContext.getCurrentSubject(), is(nullValue()));
return;
}
@ -252,7 +258,7 @@ public class LoginManagerTest {
try {
loginManager.login(null, "correct-pw");
} catch (LoginException ex) {
assertThat(ccmSessionContext.getCurrentParty(), is(nullValue()));
assertThat(ccmSessionContext.getCurrentSubject(), is(nullValue()));
return;
}

View File

@ -0,0 +1,68 @@
{
"subjects":
[
{
"subject_id": -10
},
{
"subject_id": -20
},
{
"subject_id": -30
},
{
"subject_id": -40
}
],
"ccm_users":
[
{
"banned": false,
"hash_algorithm": "SHA-512",
"family_name": "Doe",
"given_name": "John",
"password": "C+o2w6mp+eLrbluMEgKMVSdP50A9BMethXN8R3yihtkbzt7WfWsde2nmq/t5gq6im3J8i3jw4Y3YrKHou8JQ2A==",
"password_reset_required": false,
"salt": "Fu8FPgqAal4GZp1hDjkOB+t6ITRCcO7HBoN5Xqf29UnVj5NUdUFZRTyKYMBEx6JmZGmHcMDG9OGVCKcEM9oyScSRreJs4B51wM44NM6KeRwbCf+VhBn14DkBrl40ygraNf+AJacKpMyCpFI0O/Am7mMDWL4flskBsylkxaQn3vKfzgN5MVG2szW//I6Q6YEH9AuL8LauS6fKaVynMzzu3xzD8Hjqvvlnzym898eom2lqScPfg5g4e8Ww13HCHAYe6twupAW/BjUNax5HSioEisZN/P1UGrde8uFEj+hbbavrWYZuilPuEu25+/98jyXx6542agqrWN8j0SFYcIyOgA==",
"screen_name": "jdoe",
"subject_id": -10
}
],
"ccm_groups":
[
{
"name": "admins",
"subject_id": -20
},
{
"name": "users",
"subject_id": -30
},
{
"name": "authors",
"subject_id": -40
}
],
"user_email_addresses":
[
{
"user_id": -10,
"email_address": "john.doe@example.com",
"bouncing": false,
"verified": true
}
],
"group_memberships":
[
{
"membership_id": -10,
"group_subject_id": -30,
"user_subject_id": -10
},
{
"membership_id": -20,
"group_subject_id": -40,
"user_subject_id": -10
}
]
}

View File

@ -0,0 +1,22 @@
{
"subjects":
[
{
"subject_id": -10
},
{
"subject_id": -30
}
],
"ccm_groups":
[
{
"name": "admins",
"subject_id": -10
},
{
"name": "authors",
"subject_id": -30
}
]
}

View File

@ -0,0 +1,29 @@
{
"subjects":
[
{
"subject_id": -10
},
{
"subject_id": -20
},
{
"subject_id": -30
}
],
"ccm_groups":
[
{
"name": "admins",
"subject_id": -10
},
{
"name": "users",
"subject_id": -20
},
{
"name": "editors",
"subject_id": -30
}
]
}

View File

@ -0,0 +1,36 @@
{
"subjects":
[
{
"subject_id": -10
},
{
"subject_id": -20
},
{
"subject_id": -30
},
{
"subject_id": -40
}
],
"ccm_groups":
[
{
"name": "admins",
"subject_id": -10
},
{
"name": "users",
"subject_id": -20
},
{
"name": "authors",
"subject_id": -30
},
{
"name": "publishers",
"subject_id": -40
}
]
}

View File

@ -0,0 +1,29 @@
{
"subjects":
[
{
"subject_id": -10
},
{
"subject_id": -20
},
{
"subject_id": -30
}
],
"ccm_groups":
[
{
"name": "admins",
"subject_id": -10
},
{
"name": "users",
"subject_id": -20
},
{
"name": "authors",
"subject_id": -30
}
]
}

View File

@ -5,15 +5,6 @@
"subject_id": -10
}
],
"subject_email_addresses":
[
{
"subject_id": -10,
"email_address": "john.doe@example.com",
"bouncing": false,
"verified": true
}
],
"ccm_users":
[
{
@ -27,5 +18,14 @@
"screen_name": "jdoe",
"subject_id": -10
}
],
"user_email_addresses":
[
{
"user_id": -10,
"email_address": "john.doe@example.com",
"bouncing": false,
"verified": true
}
]
}

View File

@ -8,21 +8,6 @@
"subject_id": -30
}
],
"subject_email_addresses":
[
{
"subject_id": -10,
"email_address": "john.doe@example.com",
"bouncing": false,
"verified": true
},
{
"subject_id": -30,
"email_address": "joe.public@example.com",
"bouncing": true,
"verified": false
}
],
"ccm_users":
[
{
@ -47,5 +32,20 @@
"screen_name": "joe",
"subject_id": -30
}
],
"user_email_addresses":
[
{
"user_id": -10,
"email_address": "john.doe@example.com",
"bouncing": false,
"verified": true
},
{
"user_id": -30,
"email_address": "joe.public@example.com",
"bouncing": true,
"verified": false
}
]
}

View File

@ -11,33 +11,6 @@
"subject_id": -30
}
],
"subject_email_addresses":
[
{
"subject_id": -10,
"email_address": "jd@example.com",
"bouncing": false,
"verified": true
},
{
"subject_id": -20,
"email_address": "max.mustermann@example.org",
"bouncing": false,
"verified": true
},
{
"subject_id": -20,
"email_address": "mm@example.com",
"bouncing": false,
"verified": true
},
{
"subject_id": -30,
"email_address": "joe.public@example.com",
"bouncing": true,
"verified": false
}
],
"ccm_users":
[
{
@ -74,5 +47,32 @@
"screen_name": "joe",
"subject_id": -30
}
],
"user_email_addresses":
[
{
"user_id": -10,
"email_address": "jd@example.com",
"bouncing": false,
"verified": true
},
{
"user_id": -20,
"email_address": "max.mustermann@example.org",
"bouncing": false,
"verified": true
},
{
"user_id": -20,
"email_address": "mm@example.com",
"bouncing": false,
"verified": true
},
{
"user_id": -30,
"email_address": "joe.public@example.com",
"bouncing": true,
"verified": false
}
]
}

View File

@ -14,39 +14,6 @@
"subject_id": -40
}
],
"subject_email_addresses":
[
{
"subject_id": -10,
"email_address": "john.doe@example.com",
"bouncing": false,
"verified": true
},
{
"subject_id": -20,
"email_address": "max.mustermann@example.org",
"bouncing": false,
"verified": true
},
{
"subject_id": -20,
"email_address": "mm@example.com",
"bouncing": false,
"verified": true
},
{
"subject_id": -30,
"email_address": "joe.public@example.com",
"bouncing": true,
"verified": false
},
{
"subject_id": -40,
"email_address": "jane.doe@example.org",
"bouncing": false,
"verified": false
}
],
"ccm_users":
[
{
@ -95,5 +62,38 @@
"screen_name": "jane",
"subject_id": -40
}
],
"user_email_addresses":
[
{
"user_id": -10,
"email_address": "john.doe@example.com",
"bouncing": false,
"verified": true
},
{
"user_id": -20,
"email_address": "max.mustermann@example.org",
"bouncing": false,
"verified": true
},
{
"user_id": -20,
"email_address": "mm@example.com",
"bouncing": false,
"verified": true
},
{
"user_id": -30,
"email_address": "joe.public@example.com",
"bouncing": true,
"verified": false
},
{
"user_id": -40,
"email_address": "jane.doe@example.org",
"bouncing": false,
"verified": false
}
]
}

View File

@ -11,33 +11,6 @@
"subject_id": -30
}
],
"subject_email_addresses":
[
{
"subject_id": -10,
"email_address": "john.doe@example.com",
"bouncing": false,
"verified": true
},
{
"subject_id": -20,
"email_address": "max.mustermann@example.org",
"bouncing": false,
"verified": true
},
{
"subject_id": -20,
"email_address": "mm@example.com",
"bouncing": false,
"verified": true
},
{
"subject_id": -30,
"email_address": "max.mustermann@example.org",
"bouncing": true,
"verified": false
}
],
"ccm_users":
[
{
@ -73,5 +46,32 @@
"screen_name": "joe",
"subject_id": -30
}
],
"user_email_addresses":
[
{
"user_id": -10,
"email_address": "john.doe@example.com",
"bouncing": false,
"verified": true
},
{
"user_id": -20,
"email_address": "max.mustermann@example.org",
"bouncing": false,
"verified": true
},
{
"user_id": -20,
"email_address": "mm@example.com",
"bouncing": false,
"verified": true
},
{
"user_id": -30,
"email_address": "max.mustermann@example.org",
"bouncing": true,
"verified": false
}
]
}

View File

@ -11,33 +11,6 @@
"subject_id": -30
}
],
"subject_email_addresses":
[
{
"subject_id": -10,
"email_address": "john.doe@example.com",
"bouncing": false,
"verified": true
},
{
"subject_id": -20,
"email_address": "max.mustermann@example.org",
"bouncing": false,
"verified": true
},
{
"subject_id": -20,
"email_address": "mm@example.com",
"bouncing": false,
"verified": true
},
{
"subject_id": -30,
"email_address": "joe.public@example.com",
"bouncing": true,
"verified": false
}
],
"ccm_users":
[
{
@ -73,5 +46,32 @@
"screen_name": "joe",
"subject_id": -30
}
],
"user_email_addresses":
[
{
"user_id": -10,
"email_address": "john.doe@example.com",
"bouncing": false,
"verified": true
},
{
"user_id": -20,
"email_address": "max.mustermann@example.org",
"bouncing": false,
"verified": true
},
{
"user_id": -20,
"email_address": "mm@example.com",
"bouncing": false,
"verified": true
},
{
"user_id": -30,
"email_address": "joe.public@example.com",
"bouncing": true,
"verified": false
}
]
}

View File

@ -5,15 +5,6 @@
"subject_id": -10
}
],
"subject_email_addresses":
[
{
"subject_id": -10,
"email_address": "jdoe@example.com",
"bouncing": false,
"verified": true
}
],
"ccm_users":
[
{
@ -27,5 +18,14 @@
"screen_name": "jdoe",
"subject_id": -10
}
],
"user_email_addresses":
[
{
"user_id": -10,
"email_address": "jdoe@example.com",
"bouncing": false,
"verified": true
}
]
}

View File

@ -1,6 +1,10 @@
DELETE FROM ccm_objects;
DELETE FROM subject_email_addresses;
DELETE FROM group_memberships;
DELETE FROM ccm_groups;
DELETE FROM user_email_addresses;
DELETE FROM ccm_users;

View File

@ -2,6 +2,10 @@ DELETE FROM ccm_objects;
DELETE FROM subject_email_addresses;
DELETE FROM group_memberships;
DELETE FROM ccm_groups;
DELETE FROM ccm_users;
DELETE FROM subjects;

View File

@ -2,6 +2,10 @@ DELETE FROM ccm_objects;
DELETE FROM subject_email_addresses;
DELETE FROM group_memberships;
DELETE FROM ccm_groups;
DELETE FROM ccm_users;
DELETE FROM subjects;