Skip to content

Commit

Permalink
[GEOS-8824] Factoring out a single user authentication converter
Browse files Browse the repository at this point in the history
  • Loading branch information
aaime committed Jul 5, 2018
1 parent 59b30a5 commit bc91f42
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package org.geoserver.security.oauth2.services;

import java.util.Map;
import org.geoserver.security.oauth2.GeoServerAccessTokenConverter;
import org.geoserver.security.oauth2.GeoServerOAuthRemoteTokenServices;

/**
Expand All @@ -15,7 +16,7 @@
public class GeoNodeTokenServices extends GeoServerOAuthRemoteTokenServices {

public GeoNodeTokenServices() {
super(new GeoNodeAccessTokenConverter());
super(new GeoServerAccessTokenConverter());
}

protected void transformNonStandardValuesToStandardValues(Map<String, Object> map) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
*/
package org.geoserver.security.oauth2.services;

import java.util.Map;
import org.geoserver.security.oauth2.GeoServerAccessTokenConverter;
import org.geoserver.security.oauth2.GeoServerOAuthRemoteTokenServices;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpEntity;
Expand All @@ -13,8 +15,6 @@
import org.springframework.security.oauth2.common.exceptions.InvalidTokenException;
import org.springframework.util.MultiValueMap;

import java.util.Map;

/**
* Remote Token Services for GitHub token details.
*
Expand All @@ -23,7 +23,7 @@
public class GitHubTokenServices extends GeoServerOAuthRemoteTokenServices {

public GitHubTokenServices() {
super(new GitHubAccessTokenConverter());
super(new GeoServerAccessTokenConverter());
}

protected void transformNonStandardValuesToStandardValues(Map<String, Object> map) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import org.geoserver.security.oauth2.GeoServerUserAuthenticationConverter;
import org.springframework.security.core.Authentication;
import org.springframework.security.oauth2.provider.OAuth2Authentication;
import org.springframework.security.oauth2.provider.OAuth2Request;
Expand All @@ -28,7 +29,7 @@ public class GoogleAccessTokenConverter extends DefaultAccessTokenConverter {

public GoogleAccessTokenConverter() {
final DefaultUserAuthenticationConverter defaultUserAuthConverter =
new GoogleUserAuthenticationConverter("email");
new GeoServerUserAuthenticationConverter("email");
setUserTokenConverter(defaultUserAuthConverter);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ public GeoServerAccessTokenConverter(UserAuthenticationConverter defaultUserAuth
setUserTokenConverter(defaultUserAuthConverter);
}

/**
* Initializes the class with a default user auth converter
*
* @param defaultUserAuthConverter
*/
public GeoServerAccessTokenConverter() {
setUserTokenConverter(new GeoServerUserAuthenticationConverter());
}

/**
* Converter for the part of the data in the token representing a user.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
/*
* (c) 2018 Open Source Geospatial Foundation - all rights reserved
* This code is licensed under the GPL 2.0 license, available at the root
* application directory.
*
*/

/* (c) 2016 Open Source Geospatial Foundation - all rights reserved
* This code is licensed under the GPL 2.0 license, available at the root
* application directory.
*/
package org.geoserver.security.oauth2.services;
package org.geoserver.security.oauth2;

import java.util.Map;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.oauth2.provider.token.DefaultUserAuthenticationConverter;

/**
* User Authentication Converter for GeoNode token details.
* User Authentication Converter
*
* @author Alessio Fabiani, GeoSolutions S.A.S.
*/
public class GeoNodeUserAuthenticationConverter extends DefaultUserAuthenticationConverter {
public class GeoServerUserAuthenticationConverter extends DefaultUserAuthenticationConverter {

private static Object USERNAME_KEY = USERNAME;

Expand All @@ -23,7 +30,7 @@ public class GeoNodeUserAuthenticationConverter extends DefaultUserAuthenticatio
*
* @param username_key
*/
public GeoNodeUserAuthenticationConverter() {
public GeoServerUserAuthenticationConverter() {
super();
}

Expand All @@ -32,7 +39,7 @@ public GeoNodeUserAuthenticationConverter() {
*
* @param username_key
*/
public GeoNodeUserAuthenticationConverter(final String username_key) {
public GeoServerUserAuthenticationConverter(final String username_key) {
super();

USERNAME_KEY = username_key;
Expand Down

0 comments on commit bc91f42

Please sign in to comment.