Package org.structr.core.entity

Examples of org.structr.core.entity.Principal


   * @throws AuthenticationException
   */
  public static Principal getPrincipalForPassword(final PropertyKey<String> key, final String value, final String password) throws AuthenticationException {

    String errorMsg = null;
    Principal principal  = null;

    // FIXME: this might be slow, because the the property file needs to be read each time
    final String superuserName = StructrApp.getConfigurationValue(Services.SUPERUSER_USERNAME);
    final String superUserPwd  = StructrApp.getConfigurationValue(Services.SUPERUSER_PASSWORD);

    if (superuserName.equals(value) && superUserPwd.equals(password)) {

      logger.log(Level.INFO, "############# Authenticated as superadmin! ############");

      principal = new SuperUser();

    } else {

      try {

        principal = StructrApp.getInstance().nodeQuery(Principal.class).and().or(key, value).or(AbstractUser.name, value).getFirst();

        if (principal == null) {

          logger.log(Level.INFO, "No principal found for {0} {1}", new Object[]{ key.dbName(), value });

          errorMsg = STANDARD_ERROR_MSG;

        } else {

          if (principal.getProperty(Principal.blocked)) {

            logger.log(Level.INFO, "Principal {0} is blocked", principal);

            errorMsg = STANDARD_ERROR_MSG;

          }

          if (StringUtils.isEmpty(password)) {

            logger.log(Level.INFO, "Empty password for principal {0}", principal);

            errorMsg = "Empty password, should never happen here!";

          } else {

            String salt      = principal.getProperty(Principal.salt);
            String encryptedPasswordValue;

            if (salt != null) {

              encryptedPasswordValue  = getHash(password, salt);
            } else {

              encryptedPasswordValue  = getSimpleHash(password);

            }

            String pw      = principal.getEncryptedPassword();

            if (pw == null || !encryptedPasswordValue.equals(pw)) {

              logger.log(Level.INFO, "Wrong password for principal {0}", principal);

View Full Code Here


  }

  public boolean isSuperUser() {

    Principal user = getUser(false);

    return ((user != null) && (user instanceof SuperUser || user.getProperty(Principal.isAdmin)));

  }
View Full Code Here

    if (isSuperUser()) {

      return true;
    }

    Principal user = getUser(false);

    if (user == null) {

      return false;
    }

    Principal owner = node.getOwnerNode();

    // owner is always allowed to do anything with its nodes
    if (user.equals(node) || user.equals(owner) || user.getParents().contains(owner)) {

      return true;
View Full Code Here

      return false;
    }

    // fetch user
    Principal user = getUser(false);

    // anonymous users may not see any nodes in backend
    if (user == null) {

      return false;
View Full Code Here

      return false;
    }

    // Fetch already logged-in user, if present (don't try to login)
    Principal user = getUser(false);

    if (user != null) {

      Principal owner = node.getOwnerNode();

      // owner is always allowed to do anything with its nodes
      if (user.equals(node) || user.equals(owner) || user.getParents().contains(owner)) {

        return true;
View Full Code Here

TOP

Related Classes of org.structr.core.entity.Principal

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.