Search in sources :

Example 6 with ILocalAccountPerson

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;
}
Also used : Calendar(java.util.Calendar) ILocalAccountPerson(org.apereo.portal.persondir.ILocalAccountPerson) Date(java.util.Date) List(java.util.List) Map(java.util.Map)

Example 7 with ILocalAccountPerson

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;
}
Also used : ILocalAccountDao(org.apereo.portal.persondir.ILocalAccountDao) ILocalAccountPerson(org.apereo.portal.persondir.ILocalAccountPerson) PortalSecurityException(org.apereo.portal.security.PortalSecurityException) PortalSecurityException(org.apereo.portal.security.PortalSecurityException)

Example 8 with ILocalAccountPerson

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));
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) Multipart(javax.mail.Multipart) MimeMessage(javax.mail.internet.MimeMessage) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ILocalAccountPerson(org.apereo.portal.persondir.ILocalAccountPerson) URL(java.net.URL) Test(org.junit.Test)

Example 9 with ILocalAccountPerson

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);
}
Also used : EntityManager(javax.persistence.EntityManager) ILocalAccountPerson(org.apereo.portal.persondir.ILocalAccountPerson)

Example 10 with ILocalAccountPerson

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;
}
Also used : ILocalAccountPerson(org.apereo.portal.persondir.ILocalAccountPerson)

Aggregations

ILocalAccountPerson (org.apereo.portal.persondir.ILocalAccountPerson)14 Date (java.util.Date)3 Calendar (java.util.Calendar)2 List (java.util.List)2 Map (java.util.Map)2 ILocalAccountDao (org.apereo.portal.persondir.ILocalAccountDao)2 PortalSecurityException (org.apereo.portal.security.PortalSecurityException)2 Test (org.junit.Test)2 Transactional (org.springframework.transaction.annotation.Transactional)2 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 Multipart (javax.mail.Multipart)1 InternetAddress (javax.mail.internet.InternetAddress)1 MimeMessage (javax.mail.internet.MimeMessage)1 EntityManager (javax.persistence.EntityManager)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 EntityIdentifier (org.apereo.portal.EntityIdentifier)1 LocalAccountQuery (org.apereo.portal.persondir.LocalAccountQuery)1 Preference (org.apereo.portal.portletpublishing.xml.Preference)1 StringListAttribute (org.apereo.portal.portlets.StringListAttribute)1