package digital.loom.rhizome.authentication;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;

import com.auth0.authentication.AuthenticationAPIClient;
import com.auth0.jwt.Algorithm;
import com.auth0.spring.security.api.Auth0AuthenticationProvider;
import com.auth0.spring.security.api.authority.AuthorityStrategy;

public class ConfigurableAuth0AuthenticationProvider extends Auth0AuthenticationProvider {

    private final AuthenticationAPIClient auth0Client;

    public ConfigurableAuth0AuthenticationProvider( AuthenticationAPIClient auth0Client ) {
        this.auth0Client = auth0Client;
    }

    @Override
    public Authentication authenticate( Authentication authentication ) throws AuthenticationException {
        return super.authenticate( authentication );
        // TODO: Pretty sure we can skip below, now the we are correctly configuring scope options
        /*
         * final Auth0JWTToken tokenAuth = ( (Auth0JWTToken) authentication ); UserProfile profile =
         * auth0Client.tokenInfo( tokenAuth.getJwt() ).execute();
         * @SuppressWarnings( "unchecked" ) Map<String, Object> decoded = (Map<String, Object>) tokenAuth.getDetails();
         * decoded.putAll( profile.getAppMetadata() ); tokenAuth.setPrincipal( new Auth0UserDetails( decoded,
         * getAuthorityStrategy() ) ); tokenAuth.setDetails( decoded ); return authentication;
         */
    }

    @Override
    public void setAuthorityStrategy( AuthorityStrategy authorityStrategy ) {
        super.setAuthorityStrategy( authorityStrategy );
    }

    @Override
    public void setBase64EncodedSecret( boolean base64EncodedSecret ) {
        super.setBase64EncodedSecret( base64EncodedSecret );
    }

    @Override
    public void setClientId( String clientId ) {
        super.setClientId( clientId );
    }

    @Override
    public void setClientSecret( String clientSecret ) {
        super.setClientSecret( clientSecret );
    }

    @Override
    public void setDomain( String domain ) {
        super.setDomain( domain );
    }

    @Override
    public void setIssuer( String issuer ) {
        super.setIssuer( issuer );
    }

    @Override
    public void setPublicKeyPath( String publicKeyPath ) {
        super.setPublicKeyPath( publicKeyPath );
    }

    @Override
    public void setSecuredRoute( String securedRoute ) {
        super.setSecuredRoute( securedRoute );
    }

    @Override
    public void setSigningAlgorithm( Algorithm signingAlgorithm ) {
        super.setSigningAlgorithm( signingAlgorithm );
    }
}

@@ -35,24 +35,47 @@
 ntication;%0A%0A
+import java.util.Map;%0A%0A
 import org.s
@@ -119,16 +119,16 @@
 cation;%0A
-
 import o
@@ -243,16 +243,68 @@
 Client;%0A
+import com.auth0.authentication.result.UserProfile;%0A
 import c
@@ -393,16 +393,123 @@
 ovider;%0A
+import com.auth0.spring.security.api.Auth0JWTToken;%0Aimport com.auth0.spring.security.api.Auth0UserDetails;%0A
 import c
@@ -981,23 +981,16 @@
         
-return 
 super.au
@@ -1029,17 +1029,16 @@
       //
- 
 TODO: Pr
@@ -1130,20 +1130,100 @@
    /
-*%0A         *
+/Need to verify that front-end code is correctly passing roles before removing this.%0A       
  fin
@@ -1286,16 +1286,24 @@
 ation );
+%0A       
  UserPro
@@ -1316,27 +1316,16 @@
 rofile =
-%0A         *
  auth0Cl
@@ -1379,19 +1379,16 @@
 %0A       
-  *
  @Suppre
@@ -1412,16 +1412,24 @@
 ecked%22 )
+%0A       
  Map%3CStr
@@ -1505,18 +1505,24 @@
         
- *
+%0A       
  decoded
@@ -1553,24 +1553,32 @@
 etadata() );
+%0A       
  tokenAuth.s
@@ -1620,27 +1620,16 @@
 decoded,
-%0A         *
  getAuth
@@ -1648,16 +1648,24 @@
 y() ) );
+%0A       
  tokenAu
@@ -1689,16 +1689,33 @@
 coded );
+%0A        %0A       
  return 
@@ -1734,20 +1734,8 @@
 on;%0A
-         */%0A
     

Revert auth0 change