Beispiel #1
0
  public void deleteGroup(PerunSession sess, Vo vo, Group group)
      throws InternalErrorException, GroupAlreadyRemovedException {
    Utils.notNull(group.getName(), "group.getName()");

    try {
      // Delete group's members
      jdbc.update("delete from groups_members where source_group_id=?", group.getId());

      // Delete authz entries for this group
      AuthzResolverBlImpl.removeAllAuthzForGroup(sess, group);

      int rowAffected = jdbc.update("delete from groups where id=?", group.getId());
      if (rowAffected == 0)
        throw new GroupAlreadyRemovedException("Group: " + group + " , Vo: " + vo);
    } catch (RuntimeException err) {
      throw new InternalErrorException(err);
    }
  }
  @Override
  public List<UserExtSource> consolidateIdentityUsingToken(PerunSession sess, String token)
      throws PerunException {

    Map<String, Object> originalIdentity = requestCache.get(token);

    if (originalIdentity == null) {
      throw new InvalidTokenException(
          "Your token for joining identities is no longer valid. Please retry from the start.");
    }

    User originalUser = (User) originalIdentity.get("user");
    User currentUser = sess.getPerunPrincipal().getUser();

    if (originalUser == null && currentUser == null) {
      IdentityUnknownException ex =
          new IdentityUnknownException(
              "Neither original or current identity is know to Perun. Please use at least one identity known to Perun.");
      ex.setLogin((String) originalIdentity.get("actor"));
      ex.setSource2((String) originalIdentity.get("extSourceName"));
      ex.setSourceType2((String) originalIdentity.get("extSourceType"));
      ex.setLogin2(sess.getPerunPrincipal().getActor());
      ex.setSource2(sess.getPerunPrincipal().getExtSourceName());
      ex.setSourceType2(sess.getPerunPrincipal().getExtSourceType());
      throw ex;
    }

    if (originalIdentity.get("extSourceName").equals(sess.getPerunPrincipal().getExtSourceName())
        && originalIdentity.get("actor").equals(sess.getPerunPrincipal().getActor())
        && originalIdentity
            .get("extSourceType")
            .equals(sess.getPerunPrincipal().getExtSourceType())) {
      IdentityIsSameException ex =
          new IdentityIsSameException(
              "You tried to join same identity with itself. Please try again but select different identity.");
      ex.setLogin(sess.getPerunPrincipal().getActor());
      ex.setSource(sess.getPerunPrincipal().getExtSourceName());
      ex.setSourceType(sess.getPerunPrincipal().getExtSourceType());
      throw ex;
    }

    if (originalUser != null && currentUser != null && originalUser.equals(currentUser)) {
      throw new IdentitiesAlreadyJoinedException("You already have both identities joined.");
    }

    if (originalUser != null && currentUser != null && !originalUser.equals(currentUser)) {
      throw new IdentityAlreadyInUseException(
          "Your identity is already associated with a different user. If you are really the same person, please contact support to help you.",
          originalUser,
          currentUser);
    }

    // merge original identity into current user
    if (originalUser == null) {
      createExtSourceAndUserExtSource(
          currentUser,
          (String) originalIdentity.get("actor"),
          (String) originalIdentity.get("extSourceName"),
          (String) originalIdentity.get("extSourceType"),
          (Integer) originalIdentity.get("extSourceLoa"));
    }

    // merge current identity into original user
    if (currentUser == null) {
      createExtSourceAndUserExtSource(
          originalUser,
          sess.getPerunPrincipal().getActor(),
          sess.getPerunPrincipal().getExtSourceName(),
          sess.getPerunPrincipal().getExtSourceType(),
          sess.getPerunPrincipal().getExtSourceLoa());
    }

    AuthzResolverBlImpl.refreshSession(sess);

    requestCache.remove(token);

    return perun.getUsersManager().getUserExtSources(sess, sess.getPerunPrincipal().getUser());
  }