Revision 2679
Added by sgarg over 18 years ago
AuthSession.java | ||
---|---|---|
84 | 84 |
String[][] groupsWithDescription = |
85 | 85 |
authService.getGroups(username,password,username); |
86 | 86 |
String groups[] = new String[groupsWithDescription.length]; |
87 |
|
|
87 |
|
|
88 | 88 |
for(int i=0; i<groupsWithDescription.length; i++){ |
89 | 89 |
groups[i] = groupsWithDescription[i][0]; |
90 | 90 |
} |
... | ... | |
93 | 93 |
{ |
94 | 94 |
groups = new String[0]; |
95 | 95 |
} |
96 |
this.session = createSession(request, username, password, groups); |
|
96 |
|
|
97 |
String[] userInfo = |
|
98 |
authService.getUserInfo(username,password); |
|
99 |
|
|
100 |
|
|
101 |
this.session = createSession(request, username, password, groups, userInfo); |
|
97 | 102 |
String sessionId = session.getId(); |
98 | 103 |
message = "Authentication successful for user: " + username; |
99 |
this.statusMessage = formatOutput("login", message, sessionId); |
|
104 |
this.statusMessage = formatOutput("login", message, sessionId, username, groups, userInfo);
|
|
100 | 105 |
return true; |
101 | 106 |
} else { |
102 | 107 |
message = "Authentication failed for user: " + username; |
... | ... | |
117 | 122 |
/** Get new HttpSession and store username & password in it */ |
118 | 123 |
private HttpSession createSession(HttpServletRequest request, |
119 | 124 |
String username, String password, |
120 |
String[] groups) |
|
125 |
String[] groups, String[] userInfo)
|
|
121 | 126 |
throws IllegalStateException { |
122 | 127 |
|
123 | 128 |
// get the current session object, create one if necessary |
... | ... | |
139 | 144 |
session.setMaxInactiveInterval(-1); |
140 | 145 |
session.setAttribute("username", username); |
141 | 146 |
session.setAttribute("password", password); |
147 |
|
|
148 |
if ( userInfo!=null & userInfo.length == 3 ) { |
|
149 |
session.setAttribute("name", userInfo[0]); |
|
150 |
session.setAttribute("organization", userInfo[1]); |
|
151 |
session.setAttribute("email", userInfo[2]); |
|
152 |
} |
|
153 |
|
|
142 | 154 |
if ( groups.length > 0 ) { |
143 | 155 |
session.setAttribute("groupnames", groups); |
144 | 156 |
} |
... | ... | |
178 | 190 |
*/ |
179 | 191 |
private String formatOutput(String tag, String message) |
180 | 192 |
{ |
181 |
return formatOutput(tag, message, null); |
|
193 |
return formatOutput(tag, message, null, null, null, null);
|
|
182 | 194 |
} |
183 | 195 |
|
184 | 196 |
/* |
... | ... | |
188 | 200 |
* @param message the message content of the root element |
189 | 201 |
* @param sessionId the session identifier for a successful login |
190 | 202 |
*/ |
191 |
private String formatOutput(String tag, String message, String sessionId) |
|
203 |
private String formatOutput(String tag, String message, |
|
204 |
String sessionId, String username, String[] groups, |
|
205 |
String userInfo[]) |
|
192 | 206 |
{ |
193 | 207 |
StringBuffer out = new StringBuffer(); |
194 | 208 |
|
... | ... | |
197 | 211 |
out.append("\n <message>" + message + "</message>\n"); |
198 | 212 |
if (sessionId != null) { |
199 | 213 |
out.append("\n <sessionId>" + sessionId + "</sessionId>\n"); |
214 |
|
|
215 |
if(userInfo != null && userInfo[0]!=null){ |
|
216 |
out.append("\n<name>\n"); |
|
217 |
out.append(userInfo[0]); |
|
218 |
out.append("\n</name>\n"); |
|
219 |
} |
|
220 |
if(MetaCatUtil.isAdministrator(username,groups)){ |
|
221 |
out.append("\n <isAdministrator></isAdministrator>\n"); |
|
222 |
} |
|
223 |
|
|
224 |
if(MetaCatUtil.isModerator(username,groups)){ |
|
225 |
out.append("\n <isModerator></isModerator>\n"); |
|
226 |
} |
|
200 | 227 |
} |
201 | 228 |
out.append("</" + tag + ">"); |
202 | 229 |
|
Also available in: Unified diff
Added a new function - getUserInfo to AuthInterface and AuthLdap
The function returns a string array for a given username. the array contains the name, organization name and email address of the user. In case of ldap, it is cn, o and mail attributes for ldapbase=username
Modified AuthSession to use the above function when a user logs into Metacat and store the name of the user in the session. if needed, the organization information can also be stored in the session.