private ServerManager getServerManager() {
    ServerManager manager =
        (ServerManager)
            IWMainApplication.getDefaultIWApplicationContext()
                .getApplicationAttribute(OpenIDConstants.ATTRIBUTE_SERVER_MANAGER);
    if (manager == null) {
      String endPointUrl =
          IWMainApplication.getDefaultIWApplicationContext()
              .getApplicationSettings()
              .getProperty(OpenIDConstants.PROPERTY_END_POINT_URL, "http://localhost:8080/");
      String userSetupUrl =
          IWMainApplication.getDefaultIWApplicationContext()
              .getApplicationSettings()
              .getProperty(
                  OpenIDConstants.PROPERTY_USER_SETUP_URL,
                  "http://localhost:8080/pages/profile/?doRedirect=true");

      manager = new ServerManager();
      manager.setSharedAssociations(new InMemoryServerAssociationStore());
      manager.setPrivateAssociations(new InMemoryServerAssociationStore());

      manager.setOPEndpointUrl(endPointUrl);
      manager.setUserSetupUrl(userSetupUrl);
      IWMainApplication.getDefaultIWApplicationContext()
          .setApplicationAttribute(OpenIDConstants.ATTRIBUTE_SERVER_MANAGER, manager);
    }

    return manager;
  }
  protected void redirectToAuthorisationPage(
      HttpServletRequest req,
      HttpServletResponse resp,
      ParameterList requestParameters,
      OpenIDServerBean serverBean)
      throws IOException {
    String URL =
        req.getScheme()
            + "://"
            + req.getServerName()
            + (req.getServerPort() != 80 ? ":" + req.getServerPort() : "")
            + req.getRequestURI();
    String queryString = req.getQueryString();
    if (queryString != null) {
      URL += "?" + queryString;
    }
    serverBean.setServerUrl(URL);
    serverBean.setParameterList(requestParameters);

    String authenticateURL =
        IWMainApplication.getDefaultIWApplicationContext()
            .getApplicationSettings()
            .getProperty(
                OpenIDConstants.PROPERTY_AUTHENTICATION_URL,
                "http://www.elykill.is/pages/profile/mypage/authenticate/");

    resp.sendRedirect(authenticateURL);
  }
 @SuppressWarnings("unchecked")
 protected <T extends IBOService> T getServiceInstance(
     Class<? extends IBOService> serviceBeanClass) {
   //	Casting is needed to avoid stupid compilation error in Maven 2
   return (T)
       getServiceInstance(IWMainApplication.getDefaultIWApplicationContext(), serviceBeanClass);
 }
 private String getUserSelectedClaimedId(IWContext iwc, User user) {
   String identityFormat =
       IWMainApplication.getDefaultIWApplicationContext()
           .getApplicationSettings()
           .getProperty(OpenIDConstants.PROPERTY_OPENID_IDENTITY_FORMAT, "http://{0}.elykill.is");
   String identity = MessageFormat.format(identityFormat, getUserBusiness(iwc).getUserLogin(user));
   return identity;
 }
  protected String getHost() {
    ICDomain domain = null;
    IWContext iwc = CoreUtil.getIWContext();
    if (iwc == null) {
      domain = IWMainApplication.getDefaultIWApplicationContext().getDomain();
    } else domain = iwc.getDomain();

    int port = domain.getServerPort();
    String host = domain.getServerProtocol().concat("://").concat(domain.getServerName());
    if (port > 0) host = host.concat(":").concat(String.valueOf(port));
    return host;
  }
 public boolean validateTicket(java.lang.String in0, java.lang.String in1)
     throws java.rmi.RemoteException {
   try {
     WSTicketBusiness bus1 =
         (WSTicketBusiness)
             IBOLookup.getServiceInstance(
                 IWMainApplication.getDefaultIWApplicationContext(), WSTicketBusiness.class);
     return bus1.validateTicket(in0, in1);
   } catch (Exception ex) {
     ex.printStackTrace();
     return false;
   }
 }
 @SuppressWarnings("unchecked")
 protected <T extends IBOService> T getServiceInstance(
     IWApplicationContext iwac, Class<? extends IBOService> serviceBeanClass) {
   try {
     //	Casting is needed to avoid stupid compilation error in Maven 2
     return (T)
         IBOLookup.getServiceInstance(
             iwac == null ? IWMainApplication.getDefaultIWApplicationContext() : iwac,
             serviceBeanClass);
   } catch (Exception e) {
     LOGGER.log(Level.WARNING, "Error getting service instance: " + serviceBeanClass);
   }
   return null;
 }
  protected List<User> getUsersHavingHandlerRole() {
    String roleKey = getHandlerRoleKey();
    if (StringUtil.isEmpty(roleKey)) {
      return null;
    }

    IWApplicationContext iwac = IWMainApplication.getDefaultIWApplicationContext();
    AccessController accessControler =
        IWMainApplication.getDefaultIWMainApplication().getAccessController();
    Collection<Group> groupsWithRole = accessControler.getAllGroupsForRoleKey(roleKey, iwac);
    if (ListUtil.isEmpty(groupsWithRole)) {
      return null;
    }

    UserBusiness userBusiness = getUserBusiness();
    if (userBusiness == null) {
      return null;
    }

    List<User> users = new ArrayList<User>();
    for (Group group : groupsWithRole) {
      if (group instanceof User) {
        User user = (User) group;
        if (!users.contains(user)) {
          users.add(user);
        }
      } else {
        Collection<User> usersInGroup = null;
        try {
          usersInGroup = userBusiness.getUsersInGroup(group);
        } catch (Exception e) {
          LOGGER.log(Level.WARNING, "Error getting users in group: " + group, e);
        }
        if (!ListUtil.isEmpty(usersInGroup)) {
          for (User user : usersInGroup) {
            if (!users.contains(user)) {
              users.add(user);
            }
          }
        }
      }
    }

    return users;
  }
Esempio n. 9
0
  /**
   * Method that uses the Java Mail API to send an email message.<br>
   * It is recommended to use the <type>com.idega.core.messaging.EmailMessage</type> class rather
   * than calling this method directly.
   *
   * @param from
   * @param to
   * @param cc
   * @param bcc
   * @param replyTo
   * @param host
   * @param subject
   * @param text
   * @param mailType: plain text, HTML etc.
   * @param attachedFiles
   * @throws MessagingException
   */
  public static void send(
      String from,
      String to,
      String cc,
      String bcc,
      String replyTo,
      String host,
      String subject,
      String text,
      String mailType,
      File... attachedFiles)
      throws MessagingException {

    // Charset usually either "UTF-8" or "ISO-8859-1". If not set the system default set is taken
    IWMainApplicationSettings settings =
        IWMainApplication.getDefaultIWApplicationContext().getApplicationSettings();
    String charset = settings.getCharSetForSendMail();
    boolean useSmtpAuthentication =
        settings.getBoolean(MessagingSettings.PROP_SYSTEM_SMTP_USE_AUTHENTICATION, Boolean.FALSE);
    boolean useSSL = settings.getBoolean(MessagingSettings.PROP_SYSTEM_SMTP_USE_SSL, Boolean.FALSE);
    String username =
        settings.getProperty(MessagingSettings.PROP_SYSTEM_SMTP_USER_NAME, CoreConstants.EMPTY);
    String password =
        settings.getProperty(MessagingSettings.PROP_SYSTEM_SMTP_PASSWORD, CoreConstants.EMPTY);
    String port =
        settings.getProperty(MessagingSettings.PROP_SYSTEM_SMTP_PORT, CoreConstants.EMPTY);
    if (StringUtil.isEmpty(host)) {
      host = settings.getProperty(MessagingSettings.PROP_SYSTEM_SMTP_MAILSERVER);
      if (StringUtil.isEmpty(host)) {
        throw new MessagingException("Mail server is not configured.");
      }
    }

    if (StringUtil.isEmpty(username)) {
      useSmtpAuthentication = false;
    }

    // Set the host smtp address
    Properties props = new Properties();
    props.put("mail.smtp.host", host);

    // Set the smtp server port
    if (!StringUtil.isEmpty(port)) {
      props.put("mail.smtp.port", port);
    }

    // Start a session
    Session session;

    if (useSmtpAuthentication) {
      props.put("mail.smtp.auth", Boolean.TRUE.toString());
      Authenticator auth = new SMTPAuthenticator(username, password);

      if (useSSL) {
        props.put("mail.smtp.ssl.enable", Boolean.TRUE.toString());
      }

      session = Session.getInstance(props, auth);
    } else {
      session = Session.getInstance(props, null);
    }

    // Set debug if needed
    session.setDebug(settings.isDebugActive());

    // Construct a message
    if (StringUtil.isEmpty(from)) {
      throw new MessagingException("From address is null.");
    }
    MimeMessage message = new MimeMessage(session);
    message.setFrom(new InternetAddress(from));

    // Process to, cc and bcc
    addRecipients(message, Message.RecipientType.TO, to);
    addRecipients(message, Message.RecipientType.CC, cc);
    addRecipients(message, Message.RecipientType.BCC, bcc);

    if (!StringUtil.isEmpty(replyTo)) {
      message.setReplyTo(InternetAddress.parse(replyTo));
    }

    message.setSubject(subject, charset);

    if (ArrayUtil.isEmpty(attachedFiles)) {
      setMessageContent(message, text, mailType, charset);
    } else {
      MimeBodyPart body = new MimeBodyPart();
      setMessageContent(body, text, mailType, charset);

      MimeMultipart multipart = new MimeMultipart();
      multipart.addBodyPart(body);

      for (File attachedFile : attachedFiles) {
        if (attachedFile == null) {
          continue;
        }

        BodyPart attachment = new MimeBodyPart();
        DataSource attachmentSource = new FileDataSource(attachedFile);
        DataHandler attachmentHandler = new DataHandler(attachmentSource);
        attachment.setDataHandler(attachmentHandler);
        attachment.setFileName(attachedFile.getName());
        attachment.setDescription("Attached file: " + attachment.getFileName());
        LOGGER.info("Adding attachment " + attachment);
        multipart.addBodyPart(attachment);
      }

      message.setContent(multipart);
    }

    // Send the message and close the connection
    Transport.send(message);
  }