Skip to content

Commit

Permalink
spring social rm
Browse files Browse the repository at this point in the history
  • Loading branch information
ao508 committed Feb 8, 2019
1 parent d1e470d commit 114f1cc
Show file tree
Hide file tree
Showing 9 changed files with 262 additions and 35 deletions.
35 changes: 35 additions & 0 deletions security/security-spring/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,41 @@
<artifactId>spring-security-web</artifactId>
<version>${spring.security.version}</version>
</dependency>
<!-- Spring boot oauth2 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
<version>2.1.2.RELEASE</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.springframework.security.oauth</groupId>
<artifactId>spring-security-oauth2</artifactId>
<version>2.3.0.RC1</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.springframework.security.oauth.boot</groupId>
<artifactId>spring-security-oauth2-autoconfigure</artifactId>
<version>2.1.2.RELEASE</version>
</dependency>
<!-- Google OAuth2 -->
<dependency>
<groupId>com.google.api-client</groupId>
<artifactId>google-api-client</artifactId>
<version>1.19.0</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>com.google.oauth-client</groupId>
<artifactId>google-oauth-client</artifactId>
<version>1.23.0</version>
</dependency>
<dependency>
<groupId>com.google.oauth-client</groupId>
<artifactId>google-oauth-client-servlet</artifactId>
<version>1.23.0</version>
</dependency>
<!-- Spring Social -->
<dependency>
<groupId>org.springframework.social</groupId>
Expand Down
129 changes: 129 additions & 0 deletions security/security-spring/pom.xml.new-version
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.mskcc.cbio</groupId>
<artifactId>security</artifactId>
<version>2.0.0-31-gefc5979c1-dirty-SNAPSHOT</version>
</parent>
<artifactId>security-spring</artifactId>
<version>2.0.0-31-gefc5979c1-dirty-SNAPSHOT</version>
<properties>
<org.springframework.social.google-version>1.1.3</org.springframework.social.google-version>
<spring.social.version>1.1.6.RELEASE</spring.social.version>
</properties>
<dependencies>
<dependency>
<groupId>org.mskcc.cbio</groupId>
<artifactId>web</artifactId>
<version>2.0.0-31-gefc5979c1-dirty-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-acl</artifactId>
<version>${spring.security.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>${spring.security.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
<version>${spring.security.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-ldap</artifactId>
<version>${spring.security.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-openid</artifactId>
<version>${spring.security.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.security.extensions</groupId>
<artifactId>spring-security-saml2-core</artifactId>
<version>${spring.security.saml.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-taglibs</artifactId>
<version>${spring.security.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>${spring.security.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
<version>2.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security.oauth.boot</groupId>
<artifactId>spring-security-oauth2-autoconfigure</artifactId>
<version>2.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>com.google.api-client</groupId>
<artifactId>google-api-client</artifactId>
<version>1.19.0</version>
</dependency>
<dependency>
<groupId>com.google.oauth-client</groupId>
<artifactId>google-oauth-client</artifactId>
<version>1.23.0</version>
</dependency>
<dependency>
<groupId>com.google.oauth-client</groupId>
<artifactId>google-oauth-client-servlet</artifactId>
<version>1.23.0</version>
</dependency>
<dependency>
<groupId>org.springframework.social</groupId>
<artifactId>spring-social-config</artifactId>
<version>${spring.social.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.social</groupId>
<artifactId>spring-social-core</artifactId>
<version>${spring.social.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.social</groupId>
<artifactId>spring-social-security</artifactId>
<version>${spring.social.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.social</groupId>
<artifactId>spring-social-web</artifactId>
<version>${spring.social.version}</version>
</dependency>
<dependency>
<groupId>com.github.spring-social</groupId>
<artifactId>spring-social-google</artifactId>
<version>${org.springframework.social.google-version}</version>
</dependency>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.security.oauth</groupId>
<artifactId>spring-security-oauth2</artifactId>
<version>2.3.0.RC1</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package org.cbioportal.security.spring.authentication.googleplus;
package org.cbioportal.security.spring.authentication.google;

import java.util.ArrayList;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.social.security.SocialUser;
import org.springframework.social.security.SocialUserDetailsService;

import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;

public class CustomUserDetailsService implements SocialUserDetailsService {
public class CustomUserDetailsService implements UserDetailsService {

private static final Logger LOGGER = LoggerFactory.getLogger(CustomUserDetailsService.class);

Expand All @@ -22,11 +23,9 @@ public class CustomUserDetailsService implements SocialUserDetailsService {
*/

@Override
public org.springframework.social.security.SocialUserDetails loadUserByUserId(String userId) {
public UserDetails loadUserByUsername(String userId) {
Preconditions.checkArgument(!Strings.isNullOrEmpty(userId), "A userid is required");
LOGGER.debug("Loading user by user id: {}", userId);

return new SocialUser(userId, "unused", new ArrayList<GrantedAuthority>());

return new User(userId, "unused", new ArrayList<GrantedAuthority>());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,31 +30,24 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package org.cbioportal.security.spring.authentication.googleplus;
package org.cbioportal.security.spring.authentication.google;

import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.dao.DataAccessException;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.social.security.SocialUser;
import org.springframework.social.security.SocialUserDetailsService;

public class GoogleUserDetailsService implements UserDetailsService {





public class GoogleplusUserDetailsService implements SocialUserDetailsService {

private static final Logger LOGGER = LoggerFactory.getLogger(GoogleplusUserDetailsService.class);

private static final Logger LOGGER = LoggerFactory.getLogger(GoogleUserDetailsService.class);
private UserDetailsService userDetailsService;

public GoogleplusUserDetailsService(UserDetailsService userDetailsService) {
public GoogleUserDetailsService(UserDetailsService userDetailsService) {
this.userDetailsService = userDetailsService;

}
Expand All @@ -66,29 +59,20 @@ public GoogleplusUserDetailsService(UserDetailsService userDetailsService) {
* @throws UsernameNotFoundException Thrown if no user is found.
* @throws DataAccessException
*/


@Override
public org.springframework.social.security.SocialUserDetails loadUserByUserId(String userId) throws UsernameNotFoundException, DataAccessException {
public UserDetails loadUserByUsername(String userId) throws UsernameNotFoundException {
Preconditions.checkArgument(!Strings.isNullOrEmpty(userId), "A userid is required");
LOGGER.debug("Loading user by user id: {}", userId);

UserDetails ud = userDetailsService.loadUserByUsername(userId);
LOGGER.debug("Found user details: " +ud.getUsername());
/**
* Map Spring Security UserDetails implementation to a Spring Social SocialUser instance
*/
return new SocialUser(ud.getUsername(),
return new User(ud.getUsername(),
ud.getPassword(),
ud.isEnabled(),
ud.isAccountNonExpired(),
ud.isCredentialsNonExpired(),
ud.isAccountNonLocked(),
ud.getAuthorities());


}


}

Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package org.cbioportal.security.spring.authentication.googleplus;
package org.cbioportal.security.spring.authentication.google;

import org.springframework.social.connect.support.OAuth2ConnectionFactory;
import org.springframework.social.google.api.Google;
Expand All @@ -43,7 +43,7 @@
*
*/
public class GoogleplusConnectionFactory extends OAuth2ConnectionFactory<Google> {

public GoogleplusConnectionFactory(String clientId, String clientSecret) {
super("google", new GoogleServiceProvider(clientId, clientSecret),
new GoogleAdapter());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package org.cbioportal.security.spring.authentication.googleplus;
package org.cbioportal.security.spring.authentication.google;

import org.springframework.social.connect.Connection;
import org.springframework.social.connect.ConnectionSignUp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package org.cbioportal.security.spring.authentication.googleplus;
package org.cbioportal.security.spring.authentication.google;

import org.cbioportal.model.User;
import org.cbioportal.model.UserAuthorities;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration;
import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer;
import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter;
import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer;

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

/**
*
* @author ochoaa
*/
public class CustomAuthorizationServerConfigurer extends AuthorizationServerConfigurerAdapter {
private AuthenticationManager authenticationManager;

public CustomAuthorizationServerConfigurer(AuthenticationConfiguration authenticationConfiguration) throws Exception {
this.authenticationManager = authenticationConfiguration.getAuthenticationManager();
}

@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
clients.inMemory()
.withClient("client")
.authorizedGrantTypes("password")
.secret("{noop}secret")
.scopes("all");
}

@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
endpoints.authenticationManager(authenticationManager);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.cbioportal.security.spring.authentication.google.oauth2;

//import java.util.Set;
//import java.util.HashSet;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.security.oauth2.config.annotation.builders.ClientDetailsServiceBuilder;
import org.springframework.security.oauth2.config.annotation.builders.ClientDetailsServiceBuilder.ClientBuilder;
import org.springframework.security.oauth2.provider.ClientDetailsService;
import org.springframework.security.oauth2.provider.request.DefaultOAuth2RequestFactory;

/**
*
* @author ochoaa
*/
public class GenericOAuth2ConnectionFactory extends DefaultOAuth2RequestFactory {
@Value("${google.client}")
private String clientId;
@Value("${google.client.secret}")
private String clientSecret;

public GenericOAuth2ConnectionFactory(ClientDetailsService clientDetailsService) {
super(clientDetailsService);
}

@Bean
public GenericOAuth2ConnectionFactory genericOAuth2ConnectionFactory() throws Exception {
// Set<String> redirectUris = new HashSet<>();
// redirectUris.add("https://accounts.google.com/o/oauth2/auth");
// redirectUris.add("https://accounts.google.com/o/oauth2/token");
ClientBuilder builder = new ClientDetailsServiceBuilder()
.withClient(clientId)
.secret(clientSecret);
builder.redirectUris("https://www.googleapis.com/oauth2/v2/userinfo");
return new GenericOAuth2ConnectionFactory(builder.and().build());
}
}

0 comments on commit 114f1cc

Please sign in to comment.