Revision 118:8309b5636cde

View differences:

src/main/java/my/com/upass/MinimalConstants.java
52 52
	public static final int ERR_SYSTEM_NOT_READY = 98;
53 53
	public static final int ERR_ALREADY_EXIST = 11;
54 54
	public static final int ERR_LDAP = 80;
55
	public static final int ERR_TOO_MANY_MATCHES = 90;
55 56
	/**
56 57
	 * defaultDateFormat = "dd-MM-yyyy HH:mm:ss";
57 58
	 */
......
98 99
		map.put("25", "ERR_REQINVALID");
99 100
		map.put("26", "ERR_AUTH_MODE");
100 101

  
102
		map.put("90", "ERR_TOO_MANY_MATCHES");
101 103
		map.put("96", "ERR_PASSWD_WEAK");
102 104
		map.put("97", "ERR_INVALID_INPUT");
103 105
		map.put("98", "ERR_SYSTEM_NOT_READY");
src/main/java/my/com/upass/dao/hibernate/UserDAOHibernate.java
23 23

  
24 24
import my.com.upass.ConfigBean;
25 25
import my.com.upass.MinimalConstants;
26
import my.com.upass.UPassException;
26 27
import my.com.upass.dao.UserDAO;
27 28
import my.com.upass.generic.hibernate.GenericDAOHibernate;
28 29
import my.com.upass.maybank.entities.Im2uUser;
......
43 44
import org.hibernate.Hibernate;
44 45
import org.hibernate.Query;
45 46
import org.hibernate.Session;
47
import org.hibernate.criterion.CriteriaSpecification;
46 48
import org.hibernate.criterion.Criterion;
47 49
import org.hibernate.criterion.Example;
50
import org.hibernate.criterion.Projections;
48 51
import org.hibernate.criterion.Restrictions;
49 52

  
50 53
/**
......
57 60
		extends GenericDAOHibernate
58 61
		implements UserDAO {
59 62

  
63
	private static final int MAX_QUERY_RESULT_SIZE = 1000;
60 64
	private static Logger logger = Logger.getLogger(UserDAOHibernate.class);
61 65

  
62 66
	//
......
570 574
		Session session = null;
571 575
		try {
572 576
			session = txSession != null ? txSession : getSession();
577
			long totalRows = 0;
573 578

  
574 579
			for (Iterator iter = exampleProfiles.iterator(); iter.hasNext();) {
575 580
				UserProfile example = (UserProfile) iter.next();
......
588 593
						c.createAlias("minUser", MU);
589 594
					}
590 595
					c.add(Restrictions.ilike(MU + ".userAlias", username));
596

  
597
					checkQueryResultSize(c);
591 598
				}
592 599
				profiles.addAll(c.list());
593 600
				if (txSession == null)
......
610 617
		try {
611 618
			session = txSession != null ? txSession : getSession();
612 619

  
620
			long totalRows = 0;
613 621
			perProfileLoop: for (Iterator iter = exampleProfiles.iterator(); iter.hasNext();) {
614 622
				UserProfile example = (UserProfile) iter.next();
615 623

  
......
662 670
				if (toDate != null)
663 671
					c.add(Restrictions.le(MU + ".udateCreated", toDate));
664 672

  
673
				checkQueryResultSize(c);
674
				
665 675
				profiles.addAll(c.list());
666 676

  
667 677
				if (txSession == null)
......
674 684
		return profiles;
675 685
	}
676 686

  
687
	private Object checkQueryResultSize(Criteria c) throws UPassException {
688
		long totalRows;
689
		Object rowCount = c.setProjection(Projections.rowCount()).uniqueResult();
690
		if (rowCount instanceof Number) {
691
			totalRows = ((Number) rowCount).longValue();
692
			if (totalRows > MAX_QUERY_RESULT_SIZE )
693
				throw new UPassException(MinimalConstants.ERR_TOO_MANY_MATCHES);
694
		}
695
		c.setProjection(null);
696
		c.setResultTransformer(CriteriaSpecification.ROOT_ENTITY);
697
		return rowCount;
698
	}
699

  
677 700
	public boolean deleteProfile(String username, Class profileClass, Session txSession) throws Exception {
678 701

  
679 702
		boolean isSuccessful = false;

Also available in: Unified diff