@Test public void parserTest3() { final String input = "{\"sub\":\"0c8463c904e6444fa5c2b4597f816bc2\",\"claims\":[\"value1\",\"value2\"],\"email\":\"testadmin@example.com\"}"; final OAuthSettings oAuthSettings = OAuthSettings.builder().build(); final OAuthMachine oAuthMachine = new OAuthMachine( null, oAuthSettings ); Assert.assertEquals( "value1", oAuthMachine.readAttributeFromBodyMap( input, "claims" ) ); }
public String readAttributeFromBodyMap( final String bodyString, final String attributeNames ) { try { final Map<String, Object> bodyMap = JsonUtil.deserializeMap( bodyString ); final List<String> attributeValues = StringUtil.splitAndTrim( attributeNames, "," ); for ( final String attribute : attributeValues ) { final Object objValue = bodyMap.get( attribute ); if ( objValue != null ) { if ( objValue instanceof Double && JavaHelper.doubleContainsLongValue( (Double) objValue ) ) { final long longValue = ( ( Double ) objValue ).longValue(); return Long.toString( longValue ); } final Object singleObjValue; if ( objValue instanceof Collection ) { if ( ( ( Collection ) objValue ).isEmpty() ) { return null; } singleObjValue = ( ( Collection ) objValue ).iterator().next(); } else { singleObjValue = objValue; } final String strValue = singleObjValue.toString(); if ( !StringUtil.isEmpty( strValue ) ) { return strValue; } } } } catch ( final Exception e ) { LOGGER.debug( sessionLabel, () -> "unexpected error parsing json response: " + e.getMessage() ); } return null; }
OAuthMachine { public String readAttributeFromBodyMap( final String bodyString, final String attributeNames ) { try { final Map<String, Object> bodyMap = JsonUtil.deserializeMap( bodyString ); final List<String> attributeValues = StringUtil.splitAndTrim( attributeNames, "," ); for ( final String attribute : attributeValues ) { final Object objValue = bodyMap.get( attribute ); if ( objValue != null ) { if ( objValue instanceof Double && JavaHelper.doubleContainsLongValue( (Double) objValue ) ) { final long longValue = ( ( Double ) objValue ).longValue(); return Long.toString( longValue ); } final Object singleObjValue; if ( objValue instanceof Collection ) { if ( ( ( Collection ) objValue ).isEmpty() ) { return null; } singleObjValue = ( ( Collection ) objValue ).iterator().next(); } else { singleObjValue = objValue; } final String strValue = singleObjValue.toString(); if ( !StringUtil.isEmpty( strValue ) ) { return strValue; } } } } catch ( final Exception e ) { LOGGER.debug( sessionLabel, () -> "unexpected error parsing json response: " + e.getMessage() ); } return null; } }
OAuthMachine { public String readAttributeFromBodyMap( final String bodyString, final String attributeNames ) { try { final Map<String, Object> bodyMap = JsonUtil.deserializeMap( bodyString ); final List<String> attributeValues = StringUtil.splitAndTrim( attributeNames, "," ); for ( final String attribute : attributeValues ) { final Object objValue = bodyMap.get( attribute ); if ( objValue != null ) { if ( objValue instanceof Double && JavaHelper.doubleContainsLongValue( (Double) objValue ) ) { final long longValue = ( ( Double ) objValue ).longValue(); return Long.toString( longValue ); } final Object singleObjValue; if ( objValue instanceof Collection ) { if ( ( ( Collection ) objValue ).isEmpty() ) { return null; } singleObjValue = ( ( Collection ) objValue ).iterator().next(); } else { singleObjValue = objValue; } final String strValue = singleObjValue.toString(); if ( !StringUtil.isEmpty( strValue ) ) { return strValue; } } } } catch ( final Exception e ) { LOGGER.debug( sessionLabel, () -> "unexpected error parsing json response: " + e.getMessage() ); } return null; } OAuthMachine(
            final SessionLabel sessionLabel,
            final OAuthSettings settings
    ); }
OAuthMachine { public String readAttributeFromBodyMap( final String bodyString, final String attributeNames ) { try { final Map<String, Object> bodyMap = JsonUtil.deserializeMap( bodyString ); final List<String> attributeValues = StringUtil.splitAndTrim( attributeNames, "," ); for ( final String attribute : attributeValues ) { final Object objValue = bodyMap.get( attribute ); if ( objValue != null ) { if ( objValue instanceof Double && JavaHelper.doubleContainsLongValue( (Double) objValue ) ) { final long longValue = ( ( Double ) objValue ).longValue(); return Long.toString( longValue ); } final Object singleObjValue; if ( objValue instanceof Collection ) { if ( ( ( Collection ) objValue ).isEmpty() ) { return null; } singleObjValue = ( ( Collection ) objValue ).iterator().next(); } else { singleObjValue = objValue; } final String strValue = singleObjValue.toString(); if ( !StringUtil.isEmpty( strValue ) ) { return strValue; } } } } catch ( final Exception e ) { LOGGER.debug( sessionLabel, () -> "unexpected error parsing json response: " + e.getMessage() ); } return null; } OAuthMachine(
            final SessionLabel sessionLabel,
            final OAuthSettings settings
    ); void redirectUserToOAuthServer(
            final PwmRequest pwmRequest,
            final String nextUrl,
            final UserIdentity userIdentity,
            final String forgottenPasswordProfile
    ); boolean checkOAuthExpiration(
            final PwmRequest pwmRequest
    ); String readAttributeFromBodyMap(
            final String bodyString,
            final String attributeNames
    ); }
OAuthMachine { public String readAttributeFromBodyMap( final String bodyString, final String attributeNames ) { try { final Map<String, Object> bodyMap = JsonUtil.deserializeMap( bodyString ); final List<String> attributeValues = StringUtil.splitAndTrim( attributeNames, "," ); for ( final String attribute : attributeValues ) { final Object objValue = bodyMap.get( attribute ); if ( objValue != null ) { if ( objValue instanceof Double && JavaHelper.doubleContainsLongValue( (Double) objValue ) ) { final long longValue = ( ( Double ) objValue ).longValue(); return Long.toString( longValue ); } final Object singleObjValue; if ( objValue instanceof Collection ) { if ( ( ( Collection ) objValue ).isEmpty() ) { return null; } singleObjValue = ( ( Collection ) objValue ).iterator().next(); } else { singleObjValue = objValue; } final String strValue = singleObjValue.toString(); if ( !StringUtil.isEmpty( strValue ) ) { return strValue; } } } } catch ( final Exception e ) { LOGGER.debug( sessionLabel, () -> "unexpected error parsing json response: " + e.getMessage() ); } return null; } OAuthMachine(
            final SessionLabel sessionLabel,
            final OAuthSettings settings
    ); void redirectUserToOAuthServer(
            final PwmRequest pwmRequest,
            final String nextUrl,
            final UserIdentity userIdentity,
            final String forgottenPasswordProfile
    ); boolean checkOAuthExpiration(
            final PwmRequest pwmRequest
    ); String readAttributeFromBodyMap(
            final String bodyString,
            final String attributeNames
    );  }