Skip to content

Update dependecies and Sonar review #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>lutece-global-pom</artifactId>
<groupId>fr.paris.lutece.tools</groupId>
<version>5.2.0</version>
<version>5.2.1</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down Expand Up @@ -40,12 +40,12 @@
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>0.5</version>
<version>0.9.1</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.11.0</version>
<version>2.13.1</version>
</dependency>

</dependencies>
Expand Down
23 changes: 3 additions & 20 deletions src/java/fr/paris/lutece/plugins/oauth2/jwt/JjwtJWTParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
*/
package fr.paris.lutece.plugins.oauth2.jwt;

import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;

import org.apache.log4j.Logger;

Expand Down Expand Up @@ -67,7 +67,7 @@ public void parseJWT( Token token, AuthClientConf clientConfig, AuthServerConf s
try
{
JwtParser parser = Jwts.parser( );
parser.setSigningKey( clientConfig.getClientSecret( ).getBytes( "UTF-8" ) );
parser.setSigningKey( clientConfig.getClientSecret( ).getBytes( StandardCharsets.UTF_8 ) );

Jwt jwt = parser.parse( strCompactJwt );
Claims claims = (Claims) jwt.getBody( );
Expand All @@ -90,27 +90,10 @@ public void parseJWT( Token token, AuthClientConf clientConfig, AuthServerConf s

token.setIdToken( idToken );
}
catch( SignatureException ex )
catch( SignatureException | ExpiredJwtException | IllegalArgumentException | MalformedJwtException ex )
{
throw new TokenValidationException( ex.getMessage( ), ex );
}
catch( ExpiredJwtException ex )
{
throw new TokenValidationException( ex.getMessage( ), ex );
}
catch( UnsupportedEncodingException ex )
{
throw new TokenValidationException( ex.getMessage( ), ex );
}
catch( IllegalArgumentException ex )
{
throw new TokenValidationException( ex.getMessage( ), ex );
}
catch( MalformedJwtException ex )
{
throw new TokenValidationException( ex.getMessage( ), ex );
}

}

/**
Expand Down
14 changes: 1 addition & 13 deletions src/java/fr/paris/lutece/plugins/oauth2/web/CallbackHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -246,19 +246,7 @@ private void handleAuthorizationCodeResponse( HttpServletRequest request, HttpSe
Token token = getToken( strRedirectUri, strCode, session );
dataClient.handleToken( token, request, response );
}
catch( IOException ex )
{
String strError = "Error retrieving token : " + ex.getMessage( );
_logger.error( strError, ex );
handleError( request, response, strError );
}
catch( HttpAccessException ex )
{
String strError = "Error retrieving token : " + ex.getMessage( );
_logger.error( strError, ex );
handleError( request, response, strError );
}
catch( TokenValidationException ex )
catch( IOException | HttpAccessException | TokenValidationException ex )
{
String strError = "Error retrieving token : " + ex.getMessage( );
_logger.error( strError, ex );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
package fr.paris.lutece.plugins.oauth2.web;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
Expand All @@ -44,7 +43,6 @@
import org.apache.commons.lang3.StringUtils;

import fr.paris.lutece.plugins.oauth2.service.CallbackHandlerService;
import fr.paris.lutece.portal.service.spring.SpringContextService;

/**
* AuthLoginServlet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@
package fr.paris.lutece.plugins.oauth2.service;

import fr.paris.lutece.plugins.oauth2.business.Token;
import fr.paris.lutece.plugins.oauth2.service.TokenService;
import static org.junit.Assert.*;
import fr.paris.lutece.test.LuteceTestCase;

import org.junit.Test;

Expand All @@ -44,9 +43,9 @@
/**
* TokenService Test
*/
public class TokenServiceTest
public class TokenServiceTest extends LuteceTestCase
{
private static final String JSON_TOKEN = "{\"access_token\":\"608c2c4c250f9dcd118dc087cb23b2c4db2a848161044b03\",\"token_type\":\"Bearer\",\"expires_in\":3600,\"id_token\":\"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOi8vZmNwLmludGVnMDEuZGV2LWZyYW5jZWNvbm5lY3QuZnIiLCJzdWIiOiIwMTI2MzIzNDM2MjFjMjYwMGY0M2I1YWIxOTM2NzQzZGZjOGExOTljZWNhODUxYTciLCJhdWQiOiJhOWEyNTg5NWY5ZDc2ZjZjODlhYTIxODMwNTc1YmYzNGIzZjRmNjg0YTcyYTg0YzEzYWIxYzM4MTA2NDNkODU5IiwiZXhwIjoxNDMyOTM1MTM5LCJpYXQiOjE0MzI5MzE1MzksIm5vbmNlIjoiMTNjMWMyMDk5ODlmMSIsImlkcCI6ImRnZmlwIiwiYWNyIjoiZWlkYXMyIn0.RrzwbO0ygvMbFJYYvzsx530IiJpj3iQ44GQPcpTHIKM\"}";
private static final String JSON_TOKEN = "{ \"access_token\" : \"608c2c4c250f9dcd118dc087cb23b2c4db2a848161044b03\", \"token_type\" : \"Bearer\", \"expires_in\" : 3600, \"id_token\" : \"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOi8vZmNwLmludGVnMDEuZGV2LWZyYW5jZWNvbm5lY3QuZnIiLCJzdWIiOiIwMTI2MzIzNDM2MjFjMjYwMGY0M2I1YWIxOTM2NzQzZGZjOGExOTljZWNhODUxYTciLCJhdWQiOiJhOWEyNTg5NWY5ZDc2ZjZjODlhYTIxODMwNTc1YmYzNGIzZjRmNjg0YTcyYTg0YzEzYWIxYzM4MTA2NDNkODU5IiwiZXhwIjoxNDMyOTM1MTM5LCJpYXQiOjE0MzI5MzE1MzksIm5vbmNlIjoiMTNjMWMyMDk5ODlmMSIsImlkcCI6ImRnZmlwIiwiYWNyIjoiZWlkYXMyIn0.RrzwbO0ygvMbFJYYvzsx530IiJpj3iQ44GQPcpTHIKM\" }";

/**
* Test of parse method, of class TokenService.
Expand All @@ -56,10 +55,9 @@ public class TokenServiceTest
@Test
public void testParseToken( ) throws IOException
{
System.out.println( "parse" );
System.out.println( "parseTokenJson" );

String strJson = JSON_TOKEN;
Token token = TokenService.getService( ).parseToken( strJson );
Token token = TokenService.getService( ).parseToken( JSON_TOKEN );

assertEquals( token.getAccessToken( ), "608c2c4c250f9dcd118dc087cb23b2c4db2a848161044b03" );
assertEquals( token.getExpiresIn( ), 3600 );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ private String buildJWT( )

// builder.setIssuedAt( dateIssueAt );
// builder.setExpiration( dateExpiration );
Map<String, Object> mapClaims = new HashMap<String, Object>( );
Map<String, Object> mapClaims = new HashMap<>( );
mapClaims.put( Constants.CLAIM_NONCE, NONCE );
mapClaims.put( Constants.CLAIM_IDP, IDP );
mapClaims.put( Constants.CLAIM_ACR, ACR );
Expand Down
2 changes: 1 addition & 1 deletion webapp/WEB-INF/conf/plugins/oauth2_context.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<property name="tokenEndpointUri" value="https://fcp.integ01.dev-oauth2.fr/api/v1/token"/>
<property name="logoutEndpointUri" value="https://fcp.integ01.dev-oauth2.fr/api/v1/logout"/>
<property name="enableJwtParser" value="true"/>
</bean>
</bean>

<bean id="oauth2.client" class="fr.paris.lutece.plugins.oauth2.business.AuthClientConf">
<property name="clientId" value=""/>
Expand Down