Skip to content
Snippets Groups Projects
Commit d6c72aec authored by Paul-Christian Volkmer's avatar Paul-Christian Volkmer
Browse files

Explicit handling of OAuth accounts

parent f9288e34
No related merge requests found
......@@ -2,13 +2,19 @@ package de.thm.arsnova.security;
import java.io.Serializable;
import org.scribe.up.profile.facebook.FacebookProfile;
import org.scribe.up.profile.google.Google2Profile;
import org.scribe.up.profile.twitter.TwitterProfile;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.PermissionEvaluator;
import org.springframework.security.authentication.AnonymousAuthenticationToken;
import org.springframework.security.core.Authentication;
import com.github.leleuj.ss.oauth.client.authentication.OAuthAuthenticationToken;
import de.thm.arsnova.dao.IDatabaseDao;
import de.thm.arsnova.entities.Session;
import de.thm.arsnova.entities.User;
import de.thm.arsnova.exceptions.ForbiddenException;
import de.thm.arsnova.exceptions.UnauthorizedException;
......@@ -52,6 +58,26 @@ public class ApplicationPermissionEvaluator implements PermissionEvaluator {
throw new UnauthorizedException();
}
if (authentication instanceof OAuthAuthenticationToken) {
User user = null;
OAuthAuthenticationToken token = (OAuthAuthenticationToken) authentication;
if (token.getUserProfile() instanceof Google2Profile) {
Google2Profile profile = (Google2Profile) token.getUserProfile();
user = new User(profile);
} else if (token.getUserProfile() instanceof TwitterProfile) {
TwitterProfile profile = (TwitterProfile) token.getUserProfile();
user = new User(profile);
} else if (token.getUserProfile() instanceof FacebookProfile) {
FacebookProfile profile = (FacebookProfile) token.getUserProfile();
user = new User(profile);
}
if (user != null) {
return user.getUsername();
}
}
return authentication.getName();
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment