Package org.dspace.eperson

Examples of org.dspace.eperson.EPerson


        // Find the EPerson, assign to context
        try
        {
            if (line.hasOption('e'))
            {
                EPerson eperson;
                String e = line.getOptionValue('e');
                if (e.indexOf('@') != -1)
                {
                    eperson = EPerson.findByEmail(c, e);
                }
View Full Code Here


        }

        // No email address, perhaps the eperson has been setup, better check it
        if (email == null)
        {
            EPerson p = context.getCurrentUser();
            if (p != null)
                email = p.getEmail();
        }

        if (email == null)
        {
            log
                    .error("No email is given, you're denied access by Shib, please release email address");
            return AuthenticationMethod.BAD_ARGS;
        }

        email = email.toLowerCase();

        if (fnameHeader != null)
        {
            // try to grab name from the header
            fname = request.getHeader(fnameHeader);

            // fail, try lower case
            if (fname == null)
                fname = request.getHeader(fnameHeader.toLowerCase());
        }
        if (lnameHeader != null)
        {
            // try to grab name from the header
            lname = request.getHeader(lnameHeader);

            // fail, try lower case
            if (lname == null)
                lname = request.getHeader(lnameHeader.toLowerCase());
        }

        // future version can offer auto-update feature, this needs testing
        // before inclusion to core code

        EPerson eperson = null;
        try
        {
            eperson = EPerson.findByEmail(context, email);
            context.setCurrentUser(eperson);
        }
        catch (AuthorizeException e)
        {
            log.warn("Fail to locate user with email:" + email, e);
            eperson = null;
        }

        // auto create user if needed
        if (eperson == null
                && ConfigurationManager
                        .getBooleanProperty("authentication.shib.autoregister"))
        {
            log.info(LogManager.getHeader(context, "autoregister", "email="
                    + email));

            // TEMPORARILY turn off authorisation
            context.setIgnoreAuthorization(true);
            try
            {
                eperson = EPerson.create(context);
                eperson.setEmail(email);
                if (fname != null)
                    eperson.setFirstName(fname);
                if (lname != null)
                    eperson.setLastName(lname);
                eperson.setCanLogIn(true);
                AuthenticationManager.initEPerson(context, request, eperson);
                eperson.update();
                context.commit();
                context.setCurrentUser(eperson);
            }
            catch (AuthorizeException e)
            {
View Full Code Here

    protected void doDSPost(Context context, HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException,
            SQLException, AuthorizeException
    {
        // Get the user - authentication should have happened
        EPerson eperson = context.getCurrentUser();

        // Find out if they're trying to set a new password
        boolean settingPassword = false;

        if ((eperson.getRequireCertificate() == false)
                && (request.getParameter("password") != null)
                && !request.getParameter("password").equals(""))
        {
            settingPassword = true;
        }

        // Set the user profile info
        boolean ok = updateUserProfile(eperson, request);

        if (!ok)
        {
            request.setAttribute("missing.fields", new Boolean(true));
        }

        String passwordProblem = null;

        if (ok && settingPassword)
        {
            // They want to set a new password.
            ok = confirmAndSetPassword(eperson, request);

            if (!ok)
            {
                request.setAttribute("password.problem", new Boolean(true));
            }
        }

        if (ok)
        {
            // Update the DB
            log.info(LogManager.getHeader(context, "edit_profile",
                    "password_changed=" + settingPassword));
            eperson.update();

            // Show confirmation
            request.setAttribute("password.updated", new Boolean(
                    settingPassword));
            JSPManager.showJSP(request, response,
View Full Code Here

        // Skip out when no netid or password is given.
        if (netid == null || password == null)
          return BAD_ARGS;

        // Locate the eperson
        EPerson eperson = null;
        try
        {
            eperson = EPerson.findByNetid(context, netid.toLowerCase());
        }
        catch (SQLException e)
        {
        }
        SpeakerToLDAP ldap = new SpeakerToLDAP(log);

    // Get the DN of the user
    String adminUser = ConfigurationManager.getProperty("ldap.search.user");
    String adminPassword = ConfigurationManager.getProperty("ldap.search.password");
    String dn = ldap.getDNOfUser(adminUser, adminPassword, context, netid);

    // Check a DN was found
    if ((dn == null) || (dn.trim().equals("")))
    {
      log.info(LogManager
        .getHeader(context, "failed_login", "no DN found for user " + netid));
      return BAD_CREDENTIALS;
    }

    // if they entered a netid that matches an eperson
        if (eperson != null)
        {
            // e-mail address corresponds to active account
            if (eperson.getRequireCertificate())
                return CERT_REQUIRED;
            else if (!eperson.canLogIn())
                return BAD_ARGS;
            {
                if (ldap.ldapAuthenticate(dn, password, context))
                {
                    context.setCurrentUser(eperson);
                    log.info(LogManager
                        .getHeader(context, "authenticate", "type=ldap"));
                    return SUCCESS;
                }
                else
                   return BAD_CREDENTIALS;
            }
        }

        // the user does not already exist so try and authenticate them
        // with ldap and create an eperson for them
        else
        {
            if (ldap.ldapAuthenticate(dn, password, context))
            {
                // Register the new user automatically
                log.info(LogManager.getHeader(context,
                                "autoregister", "netid=" + netid));

        if ((ldap.ldapEmail!=null)&&(!ldap.ldapEmail.equals("")))
        {
          try
          {
            eperson = EPerson.findByEmail(context, ldap.ldapEmail);
            if (eperson!=null)
            {
              log.info(LogManager.getHeader(context,
                  "type=ldap-login", "type=ldap_but_already_email"));
              context.setIgnoreAuthorization(true);
              eperson.setNetid(netid.toLowerCase());
              eperson.update();
              context.commit();
              context.setIgnoreAuthorization(false);
              context.setCurrentUser(eperson);
              return SUCCESS;
            }
            else
            {
              if (canSelfRegister(context, request, netid))
              {
                // TEMPORARILY turn off authorisation
                try
                {
                  context.setIgnoreAuthorization(true);
                  eperson = EPerson.create(context);
                  if ((ldap.ldapEmail != null) && (!ldap.ldapEmail.equals("")))
                  {
                    eperson.setEmail(ldap.ldapEmail);
                  }
                  else
                  {
                    eperson.setEmail(netid + ConfigurationManager.getProperty("ldap.netid_email_domain"));
                  }
                  if ((ldap.ldapGivenName!=null) && (!ldap.ldapGivenName.equals("")))
                  {
                    eperson.setFirstName(ldap.ldapGivenName);
                  }
                  if ((ldap.ldapSurname!=null) && (!ldap.ldapSurname.equals("")))
                  {
                    eperson.setLastName(ldap.ldapSurname);
                  }
                  if ((ldap.ldapPhone!=null)&&(!ldap.ldapPhone.equals("")))
                  {
                    eperson.setMetadata("phone", ldap.ldapPhone);
                  }
                  eperson.setNetid(netid.toLowerCase());
                  eperson.setCanLogIn(true);
                  AuthenticationManager.initEPerson(context, request, eperson);
                  eperson.update();
                  context.commit();
                  context.setCurrentUser(eperson);
                }
                catch (AuthorizeException e)
                {
View Full Code Here

   
    try
    {
      // attempt to authenticate the primary user
      SWORDContext sc = new SWORDContext();
      EPerson ep = null;
      boolean authenticated = false;
      if (this.authenticates(context, un, pw))
      {
        // if authenticated, obtain the eperson object
        ep = context.getCurrentUser();

        if (ep != null)
        {
          authenticated = true;
          sc.setAuthenticated(ep);
           // Set any special groups - invoke the authentication mgr.
                int[] groupIDs = AuthenticationManager.getSpecialGroups(context, null);

                for (int i = 0; i < groupIDs.length; i++)
                {
                    context.setSpecialGroup(groupIDs[i]);
                    log.debug("Adding Special Group id="+String.valueOf(groupIDs[i]));
                }
         
          sc.setAuthenticatorContext(context);
          sc.setContext(context);
        }

        // if there is an onBehalfOfuser, then find their eperson
        // record, and if it exists set it.  If not, then the
        // authentication process fails
        EPerson epObo = null;
        if (obo != null)
        {
          epObo = EPerson.findByEmail(context, obo);
          if (epObo == null)
          {
View Full Code Here

    throws DSpaceSWORDException
  {
    try
    {
      Context context = swordContext.getContext();
      EPerson authenticated = swordContext.getAuthenticated();
      if (authenticated != null)
      {
        return AuthorizeManager.isAdmin(swordContext.getAuthenticatorContext());
      }
      return false;
View Full Code Here

        {
            pr("Error - an eperson to do the importing must be specified");
            pr(" (run with -h flag for details)");
            throw new Exception("EPerson not specified.");        }

        EPerson myEPerson = null;

        if (eperson.indexOf('@') != -1)
        {
            // @ sign, must be an email
            myEPerson = EPerson.findByEmail(context, eperson);
View Full Code Here

   */
  public boolean isOnBehalfOfAdmin(SWORDContext swordContext)
    throws DSpaceSWORDException
  {
    Context context = swordContext.getContext();
    EPerson onBehalfOf = swordContext.getOnBehalfOf();
    try
    {
      if (onBehalfOf != null)
      {
        return AuthorizeManager.isAdmin(swordContext.getOnBehalfOfContext());
View Full Code Here

   * @param group
   * @return
   */
  public boolean isUserInGroup(SWORDContext swordContext, Group group)
  {
    EPerson authenticated = swordContext.getAuthenticated();
    if (authenticated != null)
    {
      return isInGroup(group, authenticated);
    }
    return false;
View Full Code Here

   * @param group
   * @return
   */
  public boolean isOnBehalfOfInGroup(SWORDContext swordContext, Group group)
  {
    EPerson onBehalfOf = swordContext.getOnBehalfOf();
    if (onBehalfOf != null)
    {
      return isInGroup(group, onBehalfOf);
    }
    return false;
View Full Code Here

TOP

Related Classes of org.dspace.eperson.EPerson

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.