KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > properties > impl > profile > ProfilePropertyKey


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

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 JavaDoc username;
34     private int realm;
35
36     public ProfilePropertyKey(String JavaDoc 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 JavaDoc username, String JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc getUsername() {
79         return username;
80     }
81
82     public int getRealm() {
83         return realm;
84     }
85     
86     public boolean equals(Object JavaDoc o) {
87         ProfilePropertyKey k = (ProfilePropertyKey)o;
88         return super.equals(o) && getProfile() == k.getProfile() && getUsername().equals(k.getUsername());
89     }
90
91 }
92
Popular Tags