Revision 7778
Added by ben leinfelder over 11 years ago
src/edu/ucsb/nceas/metacat/restservice/D1ResourceHandler.java | ||
---|---|---|
69 | 69 |
|
70 | 70 |
import edu.ucsb.nceas.metacat.MetacatHandler; |
71 | 71 |
import edu.ucsb.nceas.metacat.properties.PropertyService; |
72 |
import edu.ucsb.nceas.metacat.service.SessionService; |
|
72 | 73 |
import edu.ucsb.nceas.metacat.util.RequestUtil; |
73 | 74 |
import edu.ucsb.nceas.metacat.util.SessionData; |
74 | 75 |
import edu.ucsb.nceas.utilities.PropertyNotFoundException; |
... | ... | |
149 | 150 |
// #2 |
150 | 151 |
if (session == null) { |
151 | 152 |
// check for session-based certificate from the portal |
152 |
String configurationFileName = servletContext.getInitParameter("oa4mp:client.config.file"); |
|
153 |
String configurationFilePath = servletContext.getRealPath(configurationFileName); |
|
154 |
PortalCertificateManager portalManager = new PortalCertificateManager(configurationFilePath); |
|
155 |
logMetacat.debug("Initialized the PortalCertificateManager using config file: " + configurationFilePath); |
|
156 |
X509Certificate certificate = portalManager.getCertificate(request); |
|
157 |
logMetacat.debug("Retrieved certificate: " + certificate); |
|
158 |
PrivateKey key = portalManager.getPrivateKey(request); |
|
159 |
logMetacat.debug("Retrieved key: " + key); |
|
160 |
if (certificate != null && key != null) { |
|
161 |
request.setAttribute("javax.servlet.request.X509Certificate", certificate); |
|
162 |
logMetacat.debug("Added certificate to the request: " + certificate.toString()); |
|
163 |
} |
|
164 |
|
|
165 |
// reload session from certificate that we jsut set in request |
|
166 |
session = CertificateManager.getInstance().getSession(request); |
|
153 |
try { |
|
154 |
String configurationFileName = servletContext.getInitParameter("oa4mp:client.config.file"); |
|
155 |
String configurationFilePath = servletContext.getRealPath(configurationFileName); |
|
156 |
PortalCertificateManager portalManager = new PortalCertificateManager(configurationFilePath); |
|
157 |
logMetacat.debug("Initialized the PortalCertificateManager using config file: " + configurationFilePath); |
|
158 |
X509Certificate certificate = portalManager.getCertificate(request); |
|
159 |
logMetacat.debug("Retrieved certificate: " + certificate); |
|
160 |
PrivateKey key = portalManager.getPrivateKey(request); |
|
161 |
logMetacat.debug("Retrieved key: " + key); |
|
162 |
if (certificate != null && key != null) { |
|
163 |
request.setAttribute("javax.servlet.request.X509Certificate", certificate); |
|
164 |
logMetacat.debug("Added certificate to the request: " + certificate.toString()); |
|
165 |
} |
|
166 |
|
|
167 |
// reload session from certificate that we jsut set in request |
|
168 |
session = CertificateManager.getInstance().getSession(request); |
|
169 |
} catch (Throwable t) { |
|
170 |
// don't require configured OAuth4MyProxy |
|
171 |
logMetacat.error(t.getMessage(), t); |
|
172 |
} |
|
167 | 173 |
} |
168 | 174 |
|
169 | 175 |
// #3 |
... | ... | |
171 | 177 |
if (session == null) { |
172 | 178 |
SessionData sessionData = RequestUtil.getSessionData(request); |
173 | 179 |
if (sessionData != null) { |
174 |
String userName = sessionData.getUserName(); |
|
175 |
String[] groupNames = sessionData.getGroupNames(); |
|
176 |
Subject userSubject = new Subject(); |
|
177 |
userSubject.setValue(userName); |
|
178 |
session.setSubject(userSubject); |
|
179 |
SubjectInfo subjectInfo = new SubjectInfo(); |
|
180 |
Person person = new Person(); |
|
181 |
person.setSubject(userSubject); |
|
182 |
if (groupNames != null && groupNames.length > 0) { |
|
183 |
for (String groupName: groupNames) { |
|
184 |
Group group = new Group(); |
|
185 |
group.setGroupName(groupName); |
|
186 |
Subject groupSubject = new Subject(); |
|
187 |
groupSubject.setValue(groupName); |
|
188 |
group.setSubject(groupSubject); |
|
189 |
subjectInfo.addGroup(group); |
|
190 |
person.addIsMemberOf(groupSubject); |
|
180 |
// is it not the public session? |
|
181 |
if (!SessionService.getInstance().getPublicSession().getUserName().equals(sessionData.getUserName())) { |
|
182 |
session = new Session(); |
|
183 |
String userName = sessionData.getUserName(); |
|
184 |
String[] groupNames = sessionData.getGroupNames(); |
|
185 |
Subject userSubject = new Subject(); |
|
186 |
userSubject.setValue(userName); |
|
187 |
session.setSubject(userSubject); |
|
188 |
SubjectInfo subjectInfo = new SubjectInfo(); |
|
189 |
Person person = new Person(); |
|
190 |
person.setSubject(userSubject); |
|
191 |
if (groupNames != null && groupNames.length > 0) { |
|
192 |
for (String groupName: groupNames) { |
|
193 |
Group group = new Group(); |
|
194 |
group.setGroupName(groupName); |
|
195 |
Subject groupSubject = new Subject(); |
|
196 |
groupSubject.setValue(groupName); |
|
197 |
group.setSubject(groupSubject); |
|
198 |
subjectInfo.addGroup(group); |
|
199 |
person.addIsMemberOf(groupSubject); |
|
200 |
} |
|
191 | 201 |
} |
202 |
subjectInfo.addPerson(person); |
|
203 |
session.setSubjectInfo(subjectInfo); |
|
192 | 204 |
} |
193 |
subjectInfo.addPerson(person); |
|
194 |
session.setSubjectInfo(subjectInfo); |
|
195 | 205 |
} |
196 | 206 |
} |
197 | 207 |
|
Also available in: Unified diff
do not require PortalCertificateManager be configured. Fix NPE because session was not created when using old sessionid-based authentication. https://projects.ecoinformatics.org/ecoinfo/issues/5942