Revision 50321
Added by Panagiotis Kanakakis over 6 years ago
UserServiceImpl.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.repo.manager.server.services; |
2 | 2 |
|
3 |
import com.google.gwt.user.client.Cookies; |
|
3 | 4 |
import eu.dnetlib.domain.functionality.UserProfile; |
4 | 5 |
import eu.dnetlib.gwt.server.service.SpringGwtRemoteServiceServlet; |
5 | 6 |
import eu.dnetlib.repo.manager.client.services.UserService; |
... | ... | |
8 | 9 |
import eu.dnetlib.repo.manager.shared.UserAccessException; |
9 | 10 |
import eu.dnetlib.users.UserApi; |
10 | 11 |
import org.apache.log4j.Logger; |
12 |
import org.eclipse.jetty.server.Authentication; |
|
13 |
import org.mitre.openid.connect.model.OIDCAuthenticationToken; |
|
11 | 14 |
import org.springframework.beans.factory.annotation.Autowired; |
15 |
import org.springframework.security.core.context.SecurityContextHolder; |
|
12 | 16 |
import org.springframework.stereotype.Service; |
13 | 17 |
|
14 | 18 |
import javax.servlet.ServletConfig; |
15 | 19 |
import javax.servlet.ServletException; |
20 |
import javax.servlet.http.Cookie; |
|
21 |
import javax.servlet.http.HttpSession; |
|
16 | 22 |
import java.util.ArrayList; |
17 | 23 |
import java.util.Arrays; |
18 | 24 |
import java.util.List; |
... | ... | |
243 | 249 |
|
244 | 250 |
} |
245 | 251 |
|
252 |
@Override |
|
253 |
public Tuple<UserProfile, String> checkCookie() throws Exception { |
|
254 |
OIDCAuthenticationToken authentication; |
|
255 |
try { |
|
256 |
authentication = (OIDCAuthenticationToken) SecurityContextHolder.getContext().getAuthentication(); |
|
257 |
UserProfile userProfile = new UserProfile(); |
|
258 |
userProfile.setFirstname(authentication.getUserInfo().getGivenName()); |
|
259 |
userProfile.setLastname(authentication.getUserInfo().getFamilyName()); |
|
260 |
userProfile.setEmail(authentication.getUserInfo().getEmail()); |
|
261 |
|
|
262 |
LOGGER.debug("User email -> " + userProfile.getEmail()); |
|
263 |
|
|
264 |
|
|
265 |
String role = ""; |
|
266 |
String[] adminEmails = new String[] {"stefania.martziou@gmail.com" , "antleb@di.uoa.gr", "ant.lebesis@gmail.com", "natalia@di.uoa.gr", "pedroprincipe@sdum.uminho.pt", "dpierrakos@gmail.com", "jochen.schirrwagen@uni-bielefeld.de", "aenne.loehden@uni-bielefeld.de"}; |
|
267 |
if(Arrays.asList(adminEmails).contains(userProfile.getEmail())) |
|
268 |
role = "admin"; |
|
269 |
return new Tuple<>(userProfile, role); |
|
270 |
|
|
271 |
} catch (Exception e) { |
|
272 |
LOGGER.debug("Error on security context holder",e); |
|
273 |
LOGGER.debug(Cookies.getCookie("currentUser")); |
|
274 |
throw e; |
|
275 |
} |
|
276 |
} |
|
277 |
|
|
278 |
@Override |
|
279 |
public void clearCookie(){ |
|
280 |
SecurityContextHolder.clearContext(); |
|
281 |
Cookies.getCookie("currentUser"); |
|
282 |
} |
|
283 |
|
|
246 | 284 |
} |
Also available in: Unified diff
1. Modify web.xml file
2. Add check cookie methods on user service. Delete code for login/register/activate profile
3. Disable #login/#register uri's