1 19 20 package com.sslexplorer.properties.impl.profile; 21 22 import com.sslexplorer.boot.AbstractPropertyKey; 23 import com.sslexplorer.boot.Util; 24 import com.sslexplorer.core.UserDatabaseManager; 25 import com.sslexplorer.properties.PropertyProfile; 26 import com.sslexplorer.security.Constants; 27 import com.sslexplorer.security.SessionInfo; 28 import com.sslexplorer.security.User; 29 30 public class ProfilePropertyKey extends AbstractPropertyKey { 31 32 private int profile; 33 private String username; 34 private int realm; 35 36 public ProfilePropertyKey(String name, SessionInfo session) { 37 super(name, ProfileProperties.NAME); 38 if(session != null && session.getHttpSession() != null && 39 session.getHttpSession().getAttribute(Constants.SELECTED_PROFILE) != null) { 40 this.profile = ((PropertyProfile)session.getHttpSession().getAttribute(Constants.SELECTED_PROFILE)).getResourceId(); 41 this.username = session.getUser().getPrincipalName(); 42 this.realm = session.getRealmId(); 43 } 44 else { 45 this.profile = 0; 46 this.username = null; 47 this.realm = UserDatabaseManager.getInstance().getDefaultUserDatabase().getRealm().getResourceId(); 48 } 49 } 50 51 public ProfilePropertyKey(int profile, String username, String name, int realm) { 52 super(name, ProfileProperties.NAME); 53 this.profile = profile; 54 this.username = username; 55 this.realm = realm; 56 } 57 58 public ProfilePropertyKey(int profile, User user, String name) { 59 this(profile, user.getPrincipalName(), name, user.getRealm().getResourceId()); 60 } 61 62 public boolean isUserSpecific() { 63 return !Util.isNullOrTrimmedBlank(username); 64 } 65 66 public ProfilePropertyKey(String name) { 67 this(0, null, name, UserDatabaseManager.getInstance().getDefaultUserDatabase().getRealm().getResourceId()); 68 } 69 70 public int getProfile() { 71 return profile; 72 } 73 74 public int hashCode() { 75 return getName().hashCode() + getProfile() + ( getUsername() != null ? getUsername().hashCode() : "".hashCode() ); 76 } 77 78 public String getUsername() { 79 return username; 80 } 81 82 public int getRealm() { 83 return realm; 84 } 85 86 public boolean equals(Object o) { 87 ProfilePropertyKey k = (ProfilePropertyKey)o; 88 return super.equals(o) && getProfile() == k.getProfile() && getUsername().equals(k.getUsername()); 89 } 90 91 } 92 | Popular Tags |