use of org.pac4j.couch.profile.CouchProfile in project pac4j by pac4j.
the class CouchProfileServiceTests method setUp.
@BeforeClass
public static void setUp() {
final String password = PASSWORD_ENCODER.encode(PASSWORD);
final CouchProfileService couchProfileService = new CouchProfileService(couchDbConnector);
couchProfileService.setPasswordEncoder(PASSWORD_ENCODER);
// insert sample data
final Map<String, Object> properties1 = new HashMap<>();
properties1.put(USERNAME, GOOD_USERNAME);
properties1.put(FIRSTNAME, FIRSTNAME_VALUE);
CouchProfile couchProfile = new CouchProfile();
couchProfile.build(IDPERSON1, properties1);
couchProfileService.create(couchProfile, PASSWORD);
// second person,
final Map<String, Object> properties2 = new HashMap<>();
properties2.put(USERNAME, MULTIPLE_USERNAME);
couchProfile = new CouchProfile();
couchProfile.build(IDPERSON2, properties2);
couchProfileService.create(couchProfile, PASSWORD);
final Map<String, Object> properties3 = new HashMap<>();
properties3.put(USERNAME, MULTIPLE_USERNAME);
properties3.put(PASSWORD, password);
couchProfile = new CouchProfile();
couchProfile.build(IDPERSON3, properties3);
couchProfileService.create(couchProfile, PASSWORD);
}
use of org.pac4j.couch.profile.CouchProfile in project pac4j by pac4j.
the class CouchProfileServiceTests method authentSuccessSingleAttribute.
@Test
public void authentSuccessSingleAttribute() {
final CouchProfileService couchProfileService = new CouchProfileService(couchDbConnector);
couchProfileService.setPasswordEncoder(PASSWORD_ENCODER);
final UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(GOOD_USERNAME, PASSWORD);
couchProfileService.validate(credentials, null);
final CommonProfile profile = credentials.getUserProfile();
assertNotNull(profile);
assertTrue(profile instanceof CouchProfile);
final CouchProfile couchProfile = (CouchProfile) profile;
assertEquals(GOOD_USERNAME, couchProfile.getUsername());
assertEquals(2, couchProfile.getAttributes().size());
assertEquals(FIRSTNAME_VALUE, couchProfile.getAttribute(FIRSTNAME));
}
use of org.pac4j.couch.profile.CouchProfile in project pac4j by pac4j.
the class CouchProfileServiceTests method testCreateUpdateFindDelete.
@Test
public void testCreateUpdateFindDelete() {
final CouchProfile profile = new CouchProfile();
profile.setId(COUCH_ID);
profile.setLinkedId(COUCH_LINKED_ID);
profile.addAttribute(USERNAME, COUCH_USER);
final CouchProfileService couchProfileService = new CouchProfileService(couchDbConnector);
couchProfileService.setPasswordEncoder(PASSWORD_ENCODER);
// create
couchProfileService.create(profile, COUCH_PASS);
// check credentials
final UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(COUCH_USER, COUCH_PASS);
couchProfileService.validate(credentials, null);
final CommonProfile profile1 = credentials.getUserProfile();
assertNotNull(profile1);
// check data
final List<Map<String, Object>> results = getData(couchProfileService, COUCH_ID);
assertEquals(1, results.size());
final Map<String, Object> result = results.get(0);
assertEquals(5, result.size());
assertEquals(COUCH_ID, result.get(COUCH_ID_FIELD));
assertEquals(COUCH_LINKED_ID, result.get(AbstractProfileService.LINKEDID));
assertNotNull(result.get(AbstractProfileService.SERIALIZED_PROFILE));
assertEquals(COUCH_USER, result.get(USERNAME));
// findById
final CouchProfile profile2 = couchProfileService.findById(COUCH_ID);
assertEquals(COUCH_ID, profile2.getId());
assertEquals(COUCH_LINKED_ID, profile2.getLinkedId());
assertEquals(COUCH_USER, profile2.getUsername());
assertEquals(1, profile2.getAttributes().size());
// update with password
profile.addAttribute(USERNAME, COUCH_USER2);
couchProfileService.update(profile, COUCH_PASS2);
List<Map<String, Object>> results2 = getData(couchProfileService, COUCH_ID);
assertEquals(1, results2.size());
Map<String, Object> result2 = results2.get(0);
assertEquals(5, result2.size());
assertEquals(COUCH_ID, result2.get(COUCH_ID_FIELD));
assertEquals(COUCH_LINKED_ID, result2.get(AbstractProfileService.LINKEDID));
assertNotNull(result2.get(AbstractProfileService.SERIALIZED_PROFILE));
assertEquals(COUCH_USER2, result2.get(USERNAME));
// check credentials
final UsernamePasswordCredentials credentials2 = new UsernamePasswordCredentials(COUCH_USER2, COUCH_PASS2);
couchProfileService.validate(credentials2, null);
CommonProfile profile3 = credentials.getUserProfile();
assertNotNull(profile3);
// update with no password update
couchProfileService.update(profile, null);
results2 = getData(couchProfileService, COUCH_ID);
assertEquals(1, results2.size());
result2 = results2.get(0);
assertEquals(5, result2.size());
assertEquals(COUCH_USER2, result2.get(USERNAME));
// check credentials
couchProfileService.validate(credentials2, null);
profile3 = credentials.getUserProfile();
assertNotNull(profile3);
// remove
couchProfileService.remove(profile);
final List<Map<String, Object>> results3 = getData(couchProfileService, COUCH_ID);
assertEquals(0, results3.size());
}
Aggregations