Skip to content
Snippets Groups Projects
Commit 6eb2d395 authored by Daniel Gerhardt's avatar Daniel Gerhardt
Browse files

Merge branch '2.x'

parents 6f825c10 46fc6996
Branches
No related merge requests found
......@@ -257,7 +257,12 @@
<dependency>
<groupId>org.pac4j</groupId>
<artifactId>pac4j-oauth</artifactId>
<version>3.4.0</version>
<version>3.5.0</version>
</dependency>
<dependency>
<groupId>org.pac4j</groupId>
<artifactId>pac4j-oidc</artifactId>
<version>3.5.0</version>
</dependency>
<dependency>
<groupId>com.corundumstudio.socketio</groupId>
......
......@@ -31,8 +31,9 @@ import org.jasig.cas.client.validation.Cas20ProxyTicketValidator;
import org.pac4j.core.client.Client;
import org.pac4j.core.config.Config;
import org.pac4j.oauth.client.FacebookClient;
import org.pac4j.oauth.client.Google2Client;
import org.pac4j.oauth.client.TwitterClient;
import org.pac4j.oidc.client.GoogleOidcClient;
import org.pac4j.oidc.config.OidcConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -473,9 +474,13 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
}
@Bean
public Google2Client googleClient() {
final Google2Client client = new Google2Client(googleKey, googleSecret);
client.setCallbackUrl(rootUrl + apiPath + OAUTH_CALLBACK_PATH_SUFFIX + "?client_name=Google2Client");
public GoogleOidcClient googleClient() {
OidcConfiguration config = new OidcConfiguration();
config.setClientId(googleKey);
config.setSecret(googleSecret);
config.setScope("openid email");
final GoogleOidcClient client = new GoogleOidcClient(config);
client.setCallbackUrl(rootUrl + apiPath + OAUTH_CALLBACK_PATH_SUFFIX + "?client_name=GoogleOidcClient");
return client;
}
......
......@@ -28,8 +28,8 @@ import de.thm.arsnova.web.exceptions.UnauthorizedException;
import org.pac4j.core.context.J2EContext;
import org.pac4j.core.exception.HttpAction;
import org.pac4j.oauth.client.FacebookClient;
import org.pac4j.oauth.client.Google2Client;
import org.pac4j.oauth.client.TwitterClient;
import org.pac4j.oidc.client.GoogleOidcClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -123,7 +123,7 @@ public class AuthenticationController extends AbstractController {
private TwitterClient twitterClient;
@Autowired(required = false)
private Google2Client google2Client;
private GoogleOidcClient googleOidcClient;
@Autowired(required = false)
private FacebookClient facebookClient;
......@@ -238,9 +238,8 @@ public class AuthenticationController extends AbstractController {
result = new RedirectView(
facebookClient.getRedirectAction(new J2EContext(request, response)).getLocation());
} else if (googleEnabled && "google".equals(type)) {
google2Client.setScope(Google2Client.Google2Scope.EMAIL);
result = new RedirectView(
google2Client.getRedirectAction(new J2EContext(request, response)).getLocation());
googleOidcClient.getRedirectAction(new J2EContext(request, response)).getLocation());
} else {
response.setStatus(HttpStatus.BAD_REQUEST.value());
}
......
......@@ -21,8 +21,8 @@ import de.thm.arsnova.model.UserProfile;
import de.thm.arsnova.security.User;
import de.thm.arsnova.service.UserService;
import org.pac4j.oauth.profile.facebook.FacebookProfile;
import org.pac4j.oauth.profile.google2.Google2Profile;
import org.pac4j.oauth.profile.twitter.TwitterProfile;
import org.pac4j.oidc.profile.google.GoogleOidcProfile;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.AuthenticationUserDetailsService;
......@@ -53,8 +53,8 @@ public class OauthUserDetailsService implements AuthenticationUserDetailsService
public User loadUserDetails(final OAuthToken token)
throws UsernameNotFoundException {
User user;
if (token.getDetails() instanceof Google2Profile) {
final Google2Profile profile = (Google2Profile) token.getDetails();
if (token.getDetails() instanceof GoogleOidcProfile) {
final GoogleOidcProfile profile = (GoogleOidcProfile) token.getDetails();
user = userService.loadUser(UserProfile.AuthProvider.GOOGLE, profile.getEmail(),
grantedAuthorities, true);
} else if (token.getDetails() instanceof TwitterProfile) {
......
......@@ -20,8 +20,8 @@ package de.thm.arsnova.config;
import de.thm.arsnova.security.CasUserDetailsService;
import org.jasig.cas.client.validation.Cas20ProxyTicketValidator;
import org.pac4j.oauth.client.FacebookClient;
import org.pac4j.oauth.client.Google2Client;
import org.pac4j.oauth.client.TwitterClient;
import org.pac4j.oidc.client.GoogleOidcClient;
import org.springframework.context.annotation.AdviceMode;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
......@@ -89,7 +89,7 @@ public class TestSecurityConfig extends SecurityConfig {
}
@Override
public Google2Client googleClient() {
public GoogleOidcClient googleClient() {
return null;
}
......
......@@ -27,9 +27,8 @@ import de.thm.arsnova.security.User;
import de.thm.arsnova.security.pac4j.OAuthToken;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.pac4j.oauth.profile.google2.Google2Email;
import org.pac4j.oauth.profile.google2.Google2Profile;
import org.pac4j.oauth.profile.google2.Google2ProfileDefinition;
import org.pac4j.core.profile.definition.CommonProfileDefinition;
import org.pac4j.oidc.profile.google.GoogleOidcProfile;
import org.springframework.security.authentication.AnonymousAuthenticationToken;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
......@@ -66,13 +65,10 @@ public class UserServiceTest {
//socketid2user.put(UUID.randomUUID(), new ClientAuthentication(new UsernamePasswordAuthenticationToken("ptsr00", UUID.randomUUID())));
//socketid2user.put(UUID.randomUUID(), new ClientAuthentication(new AttributePrincipalImpl("ptstr0")));
Google2Email email = new Google2Email();
email.setEmail("mail@host.com");
ArrayList<Google2Email> emails = new ArrayList<>();
emails.add(email);
Google2Profile profile = new Google2Profile();
profile.addAttribute(Google2ProfileDefinition.DISPLAY_NAME, "ptsr00");
profile.addAttribute(Google2ProfileDefinition.EMAILS, emails);
GoogleOidcProfile profile = new GoogleOidcProfile();
profile.addAttribute(CommonProfileDefinition.DISPLAY_NAME, "ptsr00");
profile.addAttribute(CommonProfileDefinition.EMAIL, "mail@host.com");
profile.addAttribute("email_verified", true);
UserProfile userProfile = new UserProfile(UserProfile.AuthProvider.GOOGLE, "ptsr00");
userProfile.setId(UUID.randomUUID().toString());
User user = new User(userProfile, Collections.emptyList());
......
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