Search in sources :

Example 1 with ILocalAccountDao

use of org.apereo.portal.persondir.ILocalAccountDao in project uPortal by Jasig.

the class LocalAccountDaoLocator method getLocalAccountDao.

public static ILocalAccountDao getLocalAccountDao() {
    AbstractBeanLocator<ILocalAccountDao> locator = locatorInstance;
    if (locator == null) {
        LOG.info("Looking up bean '" + BEAN_NAME + "' in ApplicationContext due to context not yet being initialized");
        final ApplicationContext applicationContext = PortalApplicationContextLocator.getApplicationContext();
        applicationContext.getBean(LocalAccountDaoLocator.class.getName());
        locator = locatorInstance;
        if (locator == null) {
            LOG.warn("Instance of '" + BEAN_NAME + "' still null after portal application context has been initialized");
            return applicationContext.getBean(BEAN_NAME, ILocalAccountDao.class);
        }
    }
    return locator.getInstance();
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) ILocalAccountDao(org.apereo.portal.persondir.ILocalAccountDao)

Example 2 with ILocalAccountDao

use of org.apereo.portal.persondir.ILocalAccountDao in project uPortal by Jasig.

the class SimpleSecurityContext method authenticate.

/**
 * Authenticate user.
 *
 * @exception PortalSecurityException
 */
@Override
public synchronized void authenticate() throws PortalSecurityException {
    this.isauth = false;
    if (this.myPrincipal.UID != null && this.myOpaqueCredentials.credentialstring != null) {
        // Logs if an attempt is made to log into a local account
        if (log.isWarnEnabled())
            log.warn("An attempt to log into the local login has occurred. user=" + this.myPrincipal.UID);
        try {
            ILocalAccountDao accountStore = LocalAccountDaoLocator.getLocalAccountDao();
            IPortalPasswordService passwordService = PortalPasswordServiceLocator.getPortalPasswordService();
            // retrieve the account from the local user store
            ILocalAccountPerson account = accountStore.getPerson(this.myPrincipal.UID);
            if (account != null) {
                // get the account password as an ASCII string
                String loginPassword = new String(this.myOpaqueCredentials.credentialstring, UTF_8);
                // account password, authenticate the user
                if (passwordService.validatePassword(loginPassword, account.getPassword())) {
                    // set the full name for this user
                    String fullName = (String) account.getAttributeValue("displayName");
                    this.myPrincipal.FullName = fullName;
                    if (log.isInfoEnabled())
                        log.info("User " + this.myPrincipal.UID + " is authenticated");
                    this.isauth = true;
                } else {
                    log.info("Password Invalid");
                }
            } else {
                if (log.isInfoEnabled())
                    log.info("No such user: " + this.myPrincipal.UID);
            }
        } catch (Exception e) {
            log.error("Error authenticating user", e);
            throw new RuntimeException("Error authenticating user", e);
        }
    } else // If the principal and/or credential are missing, the context authentication
    // simply fails. It should not be construed that this is an error. It happens for guest
    // access.
    {
        log.info("Principal or OpaqueCredentials not initialized prior to authenticate");
    }
    // Ok...we are now ready to authenticate all of our subcontexts.
    super.authenticate();
    return;
}
Also used : IPortalPasswordService(org.apereo.portal.security.IPortalPasswordService) ILocalAccountDao(org.apereo.portal.persondir.ILocalAccountDao) ILocalAccountPerson(org.apereo.portal.persondir.ILocalAccountPerson) PortalSecurityException(org.apereo.portal.security.PortalSecurityException)

Example 3 with ILocalAccountDao

use of org.apereo.portal.persondir.ILocalAccountDao 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)

Aggregations

ILocalAccountDao (org.apereo.portal.persondir.ILocalAccountDao)3 ILocalAccountPerson (org.apereo.portal.persondir.ILocalAccountPerson)2 PortalSecurityException (org.apereo.portal.security.PortalSecurityException)2 IPortalPasswordService (org.apereo.portal.security.IPortalPasswordService)1 ApplicationContext (org.springframework.context.ApplicationContext)1