Package ch.entwine.weblounge.common.site

Examples of ch.entwine.weblounge.common.site.Site


    // Check the parameters
    if (siteId == null)
      throw new WebApplicationException(Status.BAD_REQUEST);

    // Load the site
    Site site = sites.findSiteByIdentifier(siteId);
    if (site == null) {
      throw new WebApplicationException(Status.NOT_FOUND);
    }

    // Create the response
    String siteXml = site.toXml();
    siteXml = siteXml.replaceAll("<password.*</password>", "");
    siteXml = siteXml.replaceAll("( xmlns.*?>)", ">");
    siteXml = ConfigurationUtils.processTemplate(siteXml, site, environment);
    ResponseBuilder response = Response.ok(siteXml);
    return response.build();
View Full Code Here


    // Check the parameters
    if (siteId == null)
      throw new WebApplicationException(Status.BAD_REQUEST);

    // Extract the site
    Site site = sites.findSiteByIdentifier(siteId);
    if (site == null) {
      throw new WebApplicationException(Status.NOT_FOUND);
    }

    // Process changes in site
    if (StringUtils.isNotBlank(status)) {
      if (!site.isOnline() && ConfigurationUtils.isEnabled(status)) {
        try {
          site.start();
        } catch (IllegalStateException e) {
          throw new WebApplicationException(Status.PRECONDITION_FAILED);
        } catch (SiteException e) {
          throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR);
        }
      } else if (site.isOnline() && ConfigurationUtils.isDisabled(status)) {
        site.stop();
      } else {
        throw new WebApplicationException(Status.BAD_REQUEST);
      }
    }
View Full Code Here

    // Check the parameters
    if (siteId == null)
      throw new WebApplicationException(Status.BAD_REQUEST);

    // Load the site
    Site site = sites.findSiteByIdentifier(siteId);
    if (site == null)
      throw new WebApplicationException(Status.NOT_FOUND);

    StringBuffer buf = new StringBuffer();
    buf.append("<modules>");
    for (Module m : site.getModules()) {
      String moduleXml = m.toXml();
      moduleXml = moduleXml.replaceAll("<actions.*</actions>", "");
      moduleXml = moduleXml.replaceAll("<jobs.*</jobs>", "");
      moduleXml = moduleXml.replaceAll("<imagestyles.*</imagestyles>", "");
      moduleXml = moduleXml.replaceAll("<options.*</options>", "");
View Full Code Here

    // Check the parameters
    if (moduleId == null)
      throw new WebApplicationException(Status.BAD_REQUEST);

    // Load the site
    Site site = sites.findSiteByIdentifier(siteId);
    if (site == null) {
      throw new WebApplicationException(Status.NOT_FOUND);
    }

    Module m = site.getModule(moduleId);
    if (m == null)
      throw new WebApplicationException(Status.NOT_FOUND);

    // Create the response
    String moduleXml = m.toXml();
View Full Code Here

      }
    } else if (args.length > 1) {
      String id = args[0];

      // Look up the site
      Site site = getSite(id);
      if (site == null) {
        try {
          site = getSite(Integer.parseInt(id));
          if (site == null) {
            System.out.println("Unknown site: " + id);
View Full Code Here

        format.append("#");
      DecimalFormat formatter = new DecimalFormat(format.toString());

      // Display the site list
      for (int i = 0; i < sites.size(); i++) {
        Site site = sites.get(i);
        StringBuffer buf = new StringBuffer();
        buf.append("[ ").append(formatter.format(i + 1)).append(" ] ");
        while (buf.length() < 8)
          buf.append(" ");
        buf.append(site.getName() != null ? site.getName() : site.getIdentifier());
        buf.append(" ");
        int descriptionLength = buf.length();
        for (int j = 0; j < 64 - descriptionLength; j++)
          buf.append(".");
        buf.append(site.isOnline() ? " STARTED " : " STOPPED");
        while (buf.length() < 22)
          buf.append(" ");
        System.out.println(buf.toString());
      }
    }
View Full Code Here

   * {@inheritDoc}
   *
   * @see ch.entwine.weblounge.common.security.DirectoryService#getRoles()
   */
  public Role[] getRoles() throws IllegalStateException {
    Site site = securityService.getSite();

    if (site == null)
      throw new IllegalStateException("No site set in security context");

    List<DirectoryProvider> providers = new ArrayList<DirectoryProvider>();

    // Assemble a list of all possible directories
    List<DirectoryProvider> siteProviders = this.siteDirectories.get(site.getIdentifier());
    if (siteProviders != null)
      providers.addAll(siteProviders);
    providers.addAll(systemDirectories);

    // Collect roles from all directories registered for this site
View Full Code Here

   * @see org.springframework.security.core.userdetails.UserDetailsService#loadUserByUsername(java.lang.String)
   */
  public UserDetails loadUserByUsername(String name)
      throws UsernameNotFoundException, DataAccessException {

    Site site = securityService.getSite();
    if (site == null) {
      logger.error("Site context not available during user lookup");
      throw new UsernameNotFoundException("No site context available");
    }

    User user = loadUser(name, site);
    if (user == null) {
      throw new UsernameNotFoundException(name);
    } else {

      // By default, add the anonymous role so the user is able to access
      // publicly available resources
      user.addPublicCredentials(SystemRole.GUEST);

      // Collect the set of roles (granted authorities) for this users
      Set<GrantedAuthority> authorities = new HashSet<GrantedAuthority>();
      for (Object o : user.getPublicCredentials(Role.class)) {
        Role masterRole = (Role) o;
        for (Role r : masterRole.getClosure()) {
          authorities.add(new SimpleGrantedAuthority(r.getContext() + ":" + r.getIdentifier()));

          // Every role may or may not be a system role or - in case of non-
          // system roles, may or may not be including one or more of those
          // roles. Let's ask for a translation and then add those roles
          // to the set of granted authorities
          Role[] systemEquivalents = getSystemRoles(r);
          for (Role systemRole : systemEquivalents) {
            authorities.add(new SimpleGrantedAuthority(systemRole.getContext() + ":" + systemRole.getIdentifier()));
            user.addPublicCredentials(systemRole);
          }
        }
      }

      // Make sure there is no ambiguous information with regards to passwords
      Set<Object> passwords = user.getPrivateCredentials(Password.class);
      if (passwords.size() > 1) {
        logger.warn("User '{}@{}' has more than one password'", name, site.getIdentifier());
        throw new DataRetrievalFailureException("User '" + user + "' has more than one password");
      } else if (passwords.size() == 0) {
        logger.warn("User '{}@{}' has no password", name, site.getIdentifier());
        throw new DataRetrievalFailureException("User '" + user + "' has no password");
      }

      // Create the password according to the site's and Spring Security's
      // digest policy
      Password p = (Password) passwords.iterator().next();
      String password = null;
      switch (site.getDigestType()) {
        case md5:
          if (!DigestType.md5.equals(p.getDigestType())) {
            logger.debug("Creating digest password for '{}@{}'", name, site.getIdentifier());
            password = PasswordEncoder.encode(p.getPassword());
          } else {
            password = p.getPassword();
          }
          break;
        case plain:
          if (!DigestType.plain.equals(p.getDigestType())) {
            logger.warn("User '{}@{}' does not have a plain text password'", name, site.getIdentifier());
            return null;
          }
          password = p.getPassword();
          break;
        default:
          throw new IllegalStateException("Unknown digest type '" + site.getDigestType() + "'");
      }

      // Notifiy login listeners of the initiated login attempt
      for (LoginListener listener : loginListeners) {
        try {
View Full Code Here

   * {@inheritDoc}
   *
   * @see ch.entwine.weblounge.common.security.DirectoryService#getLocalRole(ch.entwine.weblounge.common.security.Role)
   */
  public Role getLocalRole(Role role) {
    Site site = securityService.getSite();

    if (site == null)
      throw new IllegalStateException("No site set in security context");

    List<DirectoryProvider> providers = new ArrayList<DirectoryProvider>();

    // Assemble a list of all possible directories
    List<DirectoryProvider> siteProviders = this.siteDirectories.get(site.getIdentifier());
    if (siteProviders != null)
      providers.addAll(siteProviders);
    providers.addAll(systemDirectories);

    for (DirectoryProvider directory : providers) {
View Full Code Here

   * {@inheritDoc}
   *
   * @see ch.entwine.weblounge.common.security.DirectoryService#getSystemRoles(ch.entwine.weblounge.common.security.Role)
   */
  public Role[] getSystemRoles(Role role) {
    Site site = securityService.getSite();

    if (site == null)
      throw new IllegalStateException("No site set in security context");

    List<DirectoryProvider> providers = new ArrayList<DirectoryProvider>();

    // Assemble a list of all possible directories
    List<DirectoryProvider> siteProviders = this.siteDirectories.get(site.getIdentifier());
    if (siteProviders != null)
      providers.addAll(siteProviders);
    providers.addAll(systemDirectories);

    Set<Role> systemRoles = new HashSet<Role>();
View Full Code Here

TOP

Related Classes of ch.entwine.weblounge.common.site.Site

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.