Revision 64:7875974c045f

View differences:

src/main/java/my/com/upass/MinimalUPassControllerV2.java
384 384

  
385 385
			final Integer invokingAppId = checkResult.invokerAppId;
386 386

  
387
			final Object appIdObj = AppAccessMgtService.profileToAppMap.get(profile.getClass());
388
			final int appIdForProfile = ((Integer) appIdObj).intValue();
387
			final int appIdForProfile = AppAccessMgtService.getAppIdForProfile(profile).intValue();
389 388

  
390 389
			boolean permitted = true;
391 390

  
......
594 593
			for (Iterator profileIter = profiles.iterator(); profileIter.hasNext();) {
595 594
				UserProfile profile = (UserProfile) profileIter.next();
596 595

  
597
				final Integer appIdForProfile = (Integer) AppAccessMgtService
598
						.profileToAppMap.get(profile.getClass());
596
				final Integer appIdForProfile = (Integer) AppAccessMgtService.getAppIdForProfile(profile);
599 597

  
600
				if (targetAppId.equals(appIdForProfile)) {
598
				if (targetAppId.equals(appIdForProfile))
601 599
					return profile;
602
				}
603 600
			}
604 601
			return null;
605 602

  
......
640 637
				for (Iterator iterator = profiles.iterator(); iterator.hasNext();) {
641 638
					UserProfile profile = (UserProfile) iterator.next();
642 639

  
643
					final Integer appIdForProfile = (Integer) AppAccessMgtService
644
							.profileToAppMap.get(profile.getClass());
640
					final Integer appIdForProfile = (Integer) AppAccessMgtService.getAppIdForProfile(profile);
645 641

  
646 642
					if (!targetAppId.equals(appIdForProfile))
647 643
						iterator.remove();
......
674 670
		}
675 671
	}
676 672

  
673
	/**
674
	 * A simple delegate method.
675
	 * 
676
	 * @return a list of {@link ClientApp} objects recognized by this system.
677
	 * 
678
	 * @see AppAccessMgtService#listRecognizedClientApps(Session)
679
	 */
680
	public List/* <ClientApp> */ listRecognizedClientApps(Session txSession) {
681
		return appAccessMgtService.listRecognizedClientApps(txSession);
682
	}
683

  
677 684
	public static MaybankLdapDAO getMaybankLdapDAO() {
678 685
		synchronized (CONFIG_LOCK) {
679 686
			if (maybankLdapDAO == null) {
src/main/java/my/com/upass/dao/UserDAO.java
16 16

  
17 17
import my.com.upass.generic.hibernate.GenericDAO;
18 18
import my.com.upass.maybank.entities.UserProfile;
19
import my.com.upass.pojo.ClientApp;
19 20
import my.com.upass.pojo.MinimalUserBean;
20 21
import my.com.upass.pojo.MinimalUserBeanBackup;
21 22
import my.com.upass.pojo.UserAppAccess;
......
57 58

  
58 59
	boolean insertUserToStore(MinimalUserBean userBean, final Session txSession) throws Exception;
59 60

  
61
	/**
62
	 * @return a list of {@link ClientApp} objects
63
	 * @throws Exception
64
	 */
65
	List listAllClientApps(final Session txSession) throws Exception;
66

  
60 67
	boolean addUserAppAccess(UserAppAccess access, Session txSession) throws Exception;
61 68

  
62 69
	boolean removeUserAppAccess(String username, int appId, Session txSession) throws Exception;
src/main/java/my/com/upass/dao/hibernate/UserDAOHibernate.java
24 24
import my.com.upass.maybank.entities.Im2uUser;
25 25
import my.com.upass.maybank.entities.StockUser;
26 26
import my.com.upass.maybank.entities.UserProfile;
27
import my.com.upass.pojo.ClientApp;
27 28
import my.com.upass.pojo.MinimalUserBean;
28 29
import my.com.upass.pojo.MinimalUserBeanBackup;
29 30
import my.com.upass.pojo.UserAppAccess;
......
340 341
		return accesses;
341 342
	}
342 343

  
344
	
345
	/**
346
	 * @see my.com.upass.dao.UserDAO#listAllClientApps(Session)
347
	 */
348
	public List listAllClientApps(Session txSession) throws Exception {
349
		List apps = null;
350
		Session session = null;
351
		try {
352
			session = txSession != null ? txSession : getSession();
353
			apps = session.createCriteria(ClientApp.class).list();
354

  
355
		} finally {
356
			if (txSession == null)
357
				closeSessionIfAny(session);
358
		}
359
		return apps;
360
	}
361

  
343 362
	/**
344 363
	 * 
345 364
	 * @param username
src/main/java/my/com/upass/services/AppAccessMgtService.java
25 25
import my.com.upass.maybank.entities.M2uUser;
26 26
import my.com.upass.maybank.entities.StockUser;
27 27
import my.com.upass.maybank.entities.TicketingUser;
28
import my.com.upass.maybank.entities.UserProfile;
28 29
import my.com.upass.pojo.ClientApp;
29 30
import my.com.upass.pojo.UserAppAccess;
30 31

  
......
43 44
public class AppAccessMgtService {
44 45

  
45 46
	/* Class<Integer, Class<UserProfile>> */
46
	public static final Map appToProfileMap = createAppToProfileMap();
47
	public static final Map APP_ID_TO_PROFILE_MAP = createAppToProfileMap();
47 48

  
48 49
	/* Map<Class<UserProfile>, Integer> */
49
	public static final Map profileToAppMap = createProfileToAppMap();
50
	private static final Map PROFILE_TO_APP_ID_MAP = createProfileToAppMap();
50 51

  
51 52
	//
52 53

  
......
70 71
		return map;
71 72
	}
72 73

  
74
	public static Integer getAppIdForProfile(UserProfile profile) {
75
		for (Iterator keyIterator = PROFILE_TO_APP_ID_MAP.keySet().iterator(); keyIterator.hasNext();) {
76
			Class profileClass = (Class) keyIterator.next();
77
			if (profileClass.isAssignableFrom(profileClass))
78
				return (Integer) PROFILE_TO_APP_ID_MAP.get(profileClass);
79
		}
80
		return null;
81
	}
82

  
83
	public List/* <ClientApp> */listRecognizedClientApps(Session txSession) {
84
		List apps = new ArrayList(APP_ID_TO_PROFILE_MAP.size());
85
		try {
86
			UserDAO userDao = MinimalDAOFactory.minimalInstance().getUserDAO();
87
			apps = userDao.listAllClientApps(txSession);
88
			for (Iterator appIterator = apps.iterator(); appIterator.hasNext();) {
89
				ClientApp app = (ClientApp) appIterator.next();
90
				final Integer appId = new Integer(app.getAppId());
91
				if (!APP_ID_TO_PROFILE_MAP.keySet().contains(appId))
92
					appIterator.remove();
93
			}
94
		} catch (Exception e) {
95
			e.printStackTrace();
96
		}
97
		return apps;
98
	}
99

  
73 100
	public Integer getAppIdForAdmin(String appAccessId, Session txSession) throws MultipleAppAccessesFound {
74 101

  
75 102
		Integer appId = null;
......
148 175
	public class MultipleAppAccessesFound extends Exception {
149 176
		private static final long serialVersionUID = 1L;
150 177
	}
151

  
152 178
}

Also available in: Unified diff