use of org.apereo.portal.persondir.ILocalAccountPerson in project uPortal by Jasig.
the class UserImporterExporter method exportData.
@Override
public UserType exportData(String userName) {
final UserType userType = new ExternalUser();
userType.setUsername(userName);
final ILocalAccountPerson localAccountPerson = this.localAccountDao.getPerson(userName);
if (localAccountPerson != null) {
userType.setPassword(localAccountPerson.getPassword());
final Date lastPasswordChange = localAccountPerson.getLastPasswordChange();
if (lastPasswordChange != null) {
final Calendar lastPasswordChangeCal = Calendar.getInstance();
lastPasswordChangeCal.setTime(lastPasswordChange);
userType.setLastPasswordChange(lastPasswordChangeCal);
}
final List<Attribute> externalAttributes = userType.getAttributes();
for (final Map.Entry<String, List<Object>> attributeEntry : localAccountPerson.getAttributes().entrySet()) {
final String name = attributeEntry.getKey();
final List<Object> values = attributeEntry.getValue();
final Attribute externalAttribute = new Attribute();
externalAttribute.setName(name);
final List<String> externalValues = externalAttribute.getValues();
for (final Object value : values) {
if (value != null) {
externalValues.add(value.toString());
} else {
externalValues.add(null);
}
}
externalAttributes.add(externalAttribute);
}
Collections.sort(externalAttributes, AttributeComparator.INSTANCE);
}
return userType;
}
use of org.apereo.portal.persondir.ILocalAccountPerson in project uPortal by Jasig.
the class TrustSecurityContext method authenticate.
@Override
public synchronized void authenticate() throws PortalSecurityException {
this.isauth = true;
if (this.myPrincipal.UID != null) {
try {
String first_name, last_name;
ILocalAccountDao accountStore = LocalAccountDaoLocator.getLocalAccountDao();
ILocalAccountPerson account = accountStore.getPerson(this.myPrincipal.UID);
if (account != null) {
first_name = (String) account.getAttributeValue("given");
last_name = (String) account.getAttributeValue("sn");
this.myPrincipal.FullName = first_name + " " + last_name;
if (log.isInfoEnabled())
log.info("User " + this.myPrincipal.UID + " is authenticated");
this.isauth = true;
} else {
if (log.isInfoEnabled())
log.info("No such user: " + this.myPrincipal.UID);
}
} catch (Exception e) {
PortalSecurityException ep = new PortalSecurityException("SQL Database Error");
log.error(e, e);
throw (ep);
}
} else {
log.error("Principal not initialized prior to authenticate");
}
// Ok...we are now ready to authenticate all of our subcontexts.
super.authenticate();
return;
}
use of org.apereo.portal.persondir.ILocalAccountPerson in project uPortal by Jasig.
the class EmailPasswordResetNotificationImplTest method testNotification.
@Test
public void testNotification() throws Exception {
final String fromAddress = "portal@test.com";
final String toAddress = "to@test.com";
final String subject = "i18nSubject";
final String resetUrl = "http://localhost/testing";
final String displayName = "displayName";
ILocalAccountPerson person = mock(ILocalAccountPerson.class);
when(person.getAttributeValue(eq(ILocalAccountPerson.ATTR_DISPLAY_NAME))).thenReturn(displayName);
when(person.getAttributeValue(eq(ILocalAccountPerson.ATTR_MAIL))).thenReturn(toAddress);
MimeMessage mockedMimeMessage = mock(MimeMessage.class);
when(mailSender.createMimeMessage()).thenReturn(mockedMimeMessage);
URL url = new URL(resetUrl);
service.setSubjectMessageKey(subject);
service.setPortalEmailAddress(fromAddress);
service.sendNotification(url, person, Locale.getDefault());
// verify send request was made...
verify(mailSender).send(mimeMessageCaptor.capture());
// verify basic email contents...
ArgumentCaptor<InternetAddress> fromCaptor = ArgumentCaptor.forClass(InternetAddress.class);
ArgumentCaptor<InternetAddress> toCaptor = ArgumentCaptor.forClass(InternetAddress.class);
ArgumentCaptor<Multipart> bodyCaptor = ArgumentCaptor.forClass(Multipart.class);
verify(mockedMimeMessage).setFrom(fromCaptor.capture());
verify(mockedMimeMessage).addRecipient(eq(RecipientType.TO), toCaptor.capture());
verify(mockedMimeMessage).setSubject(eq(subject));
verify(mockedMimeMessage).setContent(bodyCaptor.capture());
assertThat(fromCaptor.getValue().getAddress(), equalTo(fromAddress));
assertThat(toCaptor.getValue().getAddress(), equalTo(toAddress));
assertThat(getBodyHtml(bodyCaptor.getValue()), containsString(resetUrl));
}
use of org.apereo.portal.persondir.ILocalAccountPerson in project uPortal by Jasig.
the class JpaLocalAccountDaoImpl method deleteAccount.
@Override
@PortalTransactional
public void deleteAccount(ILocalAccountPerson account) {
Validate.notNull(account, "definition can not be null");
final EntityManager entityManager = this.getEntityManager();
final ILocalAccountPerson persistentAccount;
if (entityManager.contains(account)) {
persistentAccount = account;
} else {
persistentAccount = entityManager.merge(account);
}
entityManager.remove(persistentAccount);
}
use of org.apereo.portal.persondir.ILocalAccountPerson in project uPortal by Jasig.
the class JpaLocalAccountDaoImpl method createPerson.
@Override
@PortalTransactional
public ILocalAccountPerson createPerson(String username) {
final ILocalAccountPerson person = new LocalAccountPersonImpl(username);
this.getEntityManager().persist(person);
return person;
}
Aggregations