Example usage for com.google.gson.stream JsonReader hasNext

List of usage examples for com.google.gson.stream JsonReader hasNext

Introduction

In this page you can find the example usage for com.google.gson.stream JsonReader hasNext.

Prototype

public boolean hasNext() throws IOException 

Source Link

Document

Returns true if the current array or object has another element.

Usage

From source file:org.mitre.openid.connect.service.impl.MITREidDataService_1_2.java

License:Apache License

/**
 * @param reader/*from  w  ww .  jav a2  s.c  o  m*/
 * @throws IOException
 */
private void readAuthenticationHolders(JsonReader reader) throws IOException {
    reader.beginArray();
    while (reader.hasNext()) {
        AuthenticationHolderEntity ahe = new AuthenticationHolderEntity();
        reader.beginObject();
        Long currentId = null;
        while (reader.hasNext()) {
            switch (reader.peek()) {
            case END_OBJECT:
                continue;
            case NAME:
                String name = reader.nextName();
                if (reader.peek() == JsonToken.NULL) {
                    reader.skipValue();
                } else if (name.equals(ID)) {
                    currentId = reader.nextLong();
                } else if (name.equals(REQUEST_PARAMETERS)) {
                    ahe.setRequestParameters(readMap(reader));
                } else if (name.equals(CLIENT_ID)) {
                    ahe.setClientId(reader.nextString());
                } else if (name.equals(SCOPE)) {
                    ahe.setScope(readSet(reader));
                } else if (name.equals(RESOURCE_IDS)) {
                    ahe.setResourceIds(readSet(reader));
                } else if (name.equals(AUTHORITIES)) {
                    Set<String> authorityStrs = readSet(reader);
                    Set<GrantedAuthority> authorities = new HashSet<GrantedAuthority>();
                    for (String s : authorityStrs) {
                        GrantedAuthority ga = new SimpleGrantedAuthority(s);
                        authorities.add(ga);
                    }
                    ahe.setAuthorities(authorities);
                } else if (name.equals(APPROVED)) {
                    ahe.setApproved(reader.nextBoolean());
                } else if (name.equals(REDIRECT_URI)) {
                    ahe.setRedirectUri(reader.nextString());
                } else if (name.equals(RESPONSE_TYPES)) {
                    ahe.setResponseTypes(readSet(reader));
                } else if (name.equals(EXTENSIONS)) {
                    ahe.setExtensions(readMap(reader));
                } else if (name.equals(SAVED_USER_AUTHENTICATION)) {
                    ahe.setUserAuth(readSavedUserAuthentication(reader));
                } else {
                    logger.debug("Found unexpected entry");
                    reader.skipValue();
                }
                break;
            default:
                logger.debug("Found unexpected entry");
                reader.skipValue();
                continue;
            }
        }
        reader.endObject();
        Long newId = authHolderRepository.save(ahe).getId();
        maps.getAuthHolderOldToNewIdMap().put(currentId, newId);
        logger.debug("Read authentication holder {}", currentId);
    }
    reader.endArray();
    logger.info("Done reading authentication holders");
}

From source file:org.mitre.openid.connect.service.impl.MITREidDataService_1_2.java

License:Apache License

/**
 * @param reader/*from w  ww  .  ja  v a2 s. com*/
 * @return
 * @throws IOException
 */
private SavedUserAuthentication readSavedUserAuthentication(JsonReader reader) throws IOException {
    SavedUserAuthentication savedUserAuth = new SavedUserAuthentication();
    reader.beginObject();

    while (reader.hasNext()) {
        switch (reader.peek()) {
        case END_OBJECT:
            continue;
        case NAME:
            String name = reader.nextName();
            if (reader.peek() == JsonToken.NULL) {
                reader.skipValue();
            } else if (name.equals(NAME)) {
                savedUserAuth.setName(reader.nextString());
            } else if (name.equals(SOURCE_CLASS)) {
                savedUserAuth.setSourceClass(reader.nextString());
            } else if (name.equals(AUTHENTICATED)) {
                savedUserAuth.setAuthenticated(reader.nextBoolean());
            } else if (name.equals(AUTHORITIES)) {
                Set<String> authorityStrs = readSet(reader);
                Set<GrantedAuthority> authorities = new HashSet<GrantedAuthority>();
                for (String s : authorityStrs) {
                    GrantedAuthority ga = new SimpleGrantedAuthority(s);
                    authorities.add(ga);
                }
                savedUserAuth.setAuthorities(authorities);
            } else {
                logger.debug("Found unexpected entry");
                reader.skipValue();
            }
            break;
        default:
            logger.debug("Found unexpected entry");
            reader.skipValue();
            continue;
        }
    }

    reader.endObject();
    return savedUserAuth;
}

From source file:org.mitre.openid.connect.service.impl.MITREidDataService_1_2.java

License:Apache License

/**
 * @param reader/*  ww w  .  jav a2 s  . c om*/
 * @throws IOException
 */
private void readGrants(JsonReader reader) throws IOException {
    reader.beginArray();
    while (reader.hasNext()) {
        ApprovedSite site = new ApprovedSite();
        Long currentId = null;
        Set<Long> tokenIds = null;
        reader.beginObject();
        while (reader.hasNext()) {
            switch (reader.peek()) {
            case END_OBJECT:
                continue;
            case NAME:
                String name = reader.nextName();
                if (reader.peek() == JsonToken.NULL) {
                    reader.skipValue();
                } else if (name.equals(ID)) {
                    currentId = reader.nextLong();
                } else if (name.equals(ACCESS_DATE)) {
                    Date date = utcToDate(reader.nextString());
                    site.setAccessDate(date);
                } else if (name.equals(CLIENT_ID)) {
                    site.setClientId(reader.nextString());
                } else if (name.equals(CREATION_DATE)) {
                    Date date = utcToDate(reader.nextString());
                    site.setCreationDate(date);
                } else if (name.equals(TIMEOUT_DATE)) {
                    Date date = utcToDate(reader.nextString());
                    site.setTimeoutDate(date);
                } else if (name.equals(USER_ID)) {
                    site.setUserId(reader.nextString());
                } else if (name.equals(ALLOWED_SCOPES)) {
                    Set<String> allowedScopes = readSet(reader);
                    site.setAllowedScopes(allowedScopes);
                } else if (name.equals(APPROVED_ACCESS_TOKENS)) {
                    tokenIds = readSet(reader);
                } else {
                    logger.debug("Found unexpected entry");
                    reader.skipValue();
                }
                break;
            default:
                logger.debug("Found unexpected entry");
                reader.skipValue();
                continue;
            }
        }
        reader.endObject();
        Long newId = approvedSiteRepository.save(site).getId();
        maps.getGrantOldToNewIdMap().put(currentId, newId);
        if (tokenIds != null) {
            maps.getGrantToAccessTokensRefs().put(currentId, tokenIds);
        }
        logger.debug("Read grant {}", currentId);
    }
    reader.endArray();
    logger.info("Done reading grants");
}

From source file:org.mitre.openid.connect.service.impl.MITREidDataService_1_2.java

License:Apache License

/**
 * @param reader/*from ww w. ja va 2s  .  c o m*/
 * @throws IOException
 */
private void readWhitelistedSites(JsonReader reader) throws IOException {
    reader.beginArray();
    while (reader.hasNext()) {
        WhitelistedSite wlSite = new WhitelistedSite();
        Long currentId = null;
        reader.beginObject();
        while (reader.hasNext()) {
            switch (reader.peek()) {
            case END_OBJECT:
                continue;
            case NAME:
                String name = reader.nextName();
                if (name.equals(ID)) {
                    currentId = reader.nextLong();
                } else if (name.equals(CLIENT_ID)) {
                    wlSite.setClientId(reader.nextString());
                } else if (name.equals(CREATOR_USER_ID)) {
                    wlSite.setCreatorUserId(reader.nextString());
                } else if (name.equals(ALLOWED_SCOPES)) {
                    Set<String> allowedScopes = readSet(reader);
                    wlSite.setAllowedScopes(allowedScopes);
                } else {
                    logger.debug("Found unexpected entry");
                    reader.skipValue();
                }
                break;
            default:
                logger.debug("Found unexpected entry");
                reader.skipValue();
                continue;
            }
        }
        reader.endObject();
        Long newId = wlSiteRepository.save(wlSite).getId();
        maps.getWhitelistedSiteOldToNewIdMap().put(currentId, newId);
    }
    reader.endArray();
    logger.info("Done reading whitelisted sites");
}

From source file:org.mitre.openid.connect.service.impl.MITREidDataService_1_2.java

License:Apache License

/**
 * @param reader//from  w w  w.j ava 2  s  . c o  m
 * @throws IOException
 */
private void readBlacklistedSites(JsonReader reader) throws IOException {
    reader.beginArray();
    while (reader.hasNext()) {
        BlacklistedSite blSite = new BlacklistedSite();
        reader.beginObject();
        while (reader.hasNext()) {
            switch (reader.peek()) {
            case END_OBJECT:
                continue;
            case NAME:
                String name = reader.nextName();
                if (name.equals(ID)) {
                    reader.skipValue();
                } else if (name.equals(URI)) {
                    blSite.setUri(reader.nextString());
                } else {
                    logger.debug("Found unexpected entry");
                    reader.skipValue();
                }
                break;
            default:
                logger.debug("Found unexpected entry");
                reader.skipValue();
                continue;
            }
        }
        reader.endObject();
        blSiteRepository.save(blSite);
    }
    reader.endArray();
    logger.info("Done reading blacklisted sites");
}

From source file:org.mitre.openid.connect.service.impl.MITREidDataService_1_2.java

License:Apache License

/**
 * @param reader//ww  w .  j a  v  a2 s .c  o  m
 * @throws IOException
 */
private void readClients(JsonReader reader) throws IOException {
    reader.beginArray();
    while (reader.hasNext()) {
        ClientDetailsEntity client = new ClientDetailsEntity();
        reader.beginObject();
        while (reader.hasNext()) {
            switch (reader.peek()) {
            case END_OBJECT:
                continue;
            case NAME:
                String name = reader.nextName();
                if (reader.peek() == JsonToken.NULL) {
                    reader.skipValue();
                } else if (name.equals(CLIENT_ID)) {
                    client.setClientId(reader.nextString());
                } else if (name.equals(RESOURCE_IDS)) {
                    Set<String> resourceIds = readSet(reader);
                    client.setResourceIds(resourceIds);
                } else if (name.equals(SECRET)) {
                    client.setClientSecret(reader.nextString());
                } else if (name.equals(SCOPE)) {
                    Set<String> scope = readSet(reader);
                    client.setScope(scope);
                } else if (name.equals(AUTHORITIES)) {
                    Set<String> authorityStrs = readSet(reader);
                    Set<GrantedAuthority> authorities = new HashSet<GrantedAuthority>();
                    for (String s : authorityStrs) {
                        GrantedAuthority ga = new SimpleGrantedAuthority(s);
                        authorities.add(ga);
                    }
                    client.setAuthorities(authorities);
                } else if (name.equals(ACCESS_TOKEN_VALIDITY_SECONDS)) {
                    client.setAccessTokenValiditySeconds(reader.nextInt());
                } else if (name.equals(REFRESH_TOKEN_VALIDITY_SECONDS)) {
                    client.setRefreshTokenValiditySeconds(reader.nextInt());
                } else if (name.equals(REDIRECT_URIS)) {
                    Set<String> redirectUris = readSet(reader);
                    client.setRedirectUris(redirectUris);
                } else if (name.equals(CLAIMS_REDIRECT_URIS)) {
                    Set<String> claimsRedirectUris = readSet(reader);
                    client.setClaimsRedirectUris(claimsRedirectUris);
                } else if (name.equals(NAME)) {
                    client.setClientName(reader.nextString());
                } else if (name.equals(URI)) {
                    client.setClientUri(reader.nextString());
                } else if (name.equals(LOGO_URI)) {
                    client.setLogoUri(reader.nextString());
                } else if (name.equals(CONTACTS)) {
                    Set<String> contacts = readSet(reader);
                    client.setContacts(contacts);
                } else if (name.equals(TOS_URI)) {
                    client.setTosUri(reader.nextString());
                } else if (name.equals(TOKEN_ENDPOINT_AUTH_METHOD)) {
                    AuthMethod am = AuthMethod.getByValue(reader.nextString());
                    client.setTokenEndpointAuthMethod(am);
                } else if (name.equals(GRANT_TYPES)) {
                    Set<String> grantTypes = readSet(reader);
                    client.setGrantTypes(grantTypes);
                } else if (name.equals(RESPONSE_TYPES)) {
                    Set<String> responseTypes = readSet(reader);
                    client.setResponseTypes(responseTypes);
                } else if (name.equals(POLICY_URI)) {
                    client.setPolicyUri(reader.nextString());
                } else if (name.equals(APPLICATION_TYPE)) {
                    AppType appType = AppType.getByValue(reader.nextString());
                    client.setApplicationType(appType);
                } else if (name.equals(SECTOR_IDENTIFIER_URI)) {
                    client.setSectorIdentifierUri(reader.nextString());
                } else if (name.equals(SUBJECT_TYPE)) {
                    SubjectType st = SubjectType.getByValue(reader.nextString());
                    client.setSubjectType(st);
                } else if (name.equals(JWKS_URI)) {
                    client.setJwksUri(reader.nextString());
                } else if (name.equals(JWKS)) {
                    try {
                        client.setJwks(JWKSet.parse(reader.nextString()));
                    } catch (ParseException e) {
                        logger.error("Couldn't parse JWK Set", e);
                    }
                } else if (name.equals(REQUEST_OBJECT_SIGNING_ALG)) {
                    JWSAlgorithm alg = JWSAlgorithm.parse(reader.nextString());
                    client.setRequestObjectSigningAlg(alg);
                } else if (name.equals(USER_INFO_ENCRYPTED_RESPONSE_ALG)) {
                    JWEAlgorithm alg = JWEAlgorithm.parse(reader.nextString());
                    client.setUserInfoEncryptedResponseAlg(alg);
                } else if (name.equals(USER_INFO_ENCRYPTED_RESPONSE_ENC)) {
                    EncryptionMethod alg = EncryptionMethod.parse(reader.nextString());
                    client.setUserInfoEncryptedResponseEnc(alg);
                } else if (name.equals(USER_INFO_SIGNED_RESPONSE_ALG)) {
                    JWSAlgorithm alg = JWSAlgorithm.parse(reader.nextString());
                    client.setUserInfoSignedResponseAlg(alg);
                } else if (name.equals(ID_TOKEN_SIGNED_RESPONSE_ALG)) {
                    JWSAlgorithm alg = JWSAlgorithm.parse(reader.nextString());
                    client.setIdTokenSignedResponseAlg(alg);
                } else if (name.equals(ID_TOKEN_ENCRYPTED_RESPONSE_ALG)) {
                    JWEAlgorithm alg = JWEAlgorithm.parse(reader.nextString());
                    client.setIdTokenEncryptedResponseAlg(alg);
                } else if (name.equals(ID_TOKEN_ENCRYPTED_RESPONSE_ENC)) {
                    EncryptionMethod alg = EncryptionMethod.parse(reader.nextString());
                    client.setIdTokenEncryptedResponseEnc(alg);
                } else if (name.equals(TOKEN_ENDPOINT_AUTH_SIGNING_ALG)) {
                    JWSAlgorithm alg = JWSAlgorithm.parse(reader.nextString());
                    client.setTokenEndpointAuthSigningAlg(alg);
                } else if (name.equals(DEFAULT_MAX_AGE)) {
                    client.setDefaultMaxAge(reader.nextInt());
                } else if (name.equals(REQUIRE_AUTH_TIME)) {
                    client.setRequireAuthTime(reader.nextBoolean());
                } else if (name.equals(DEFAULT_ACR_VALUES)) {
                    Set<String> defaultACRvalues = readSet(reader);
                    client.setDefaultACRvalues(defaultACRvalues);
                } else if (name.equals("initiateLoginUri")) {
                    client.setInitiateLoginUri(reader.nextString());
                } else if (name.equals(POST_LOGOUT_REDIRECT_URI)) {
                    Set<String> postLogoutUris = readSet(reader);
                    client.setPostLogoutRedirectUris(postLogoutUris);
                } else if (name.equals(REQUEST_URIS)) {
                    Set<String> requestUris = readSet(reader);
                    client.setRequestUris(requestUris);
                } else if (name.equals(DESCRIPTION)) {
                    client.setClientDescription(reader.nextString());
                } else if (name.equals(ALLOW_INTROSPECTION)) {
                    client.setAllowIntrospection(reader.nextBoolean());
                } else if (name.equals(REUSE_REFRESH_TOKEN)) {
                    client.setReuseRefreshToken(reader.nextBoolean());
                } else if (name.equals(CLEAR_ACCESS_TOKENS_ON_REFRESH)) {
                    client.setClearAccessTokensOnRefresh(reader.nextBoolean());
                } else if (name.equals(DYNAMICALLY_REGISTERED)) {
                    client.setDynamicallyRegistered(reader.nextBoolean());
                } else {
                    logger.debug("Found unexpected entry");
                    reader.skipValue();
                }
                break;
            default:
                logger.debug("Found unexpected entry");
                reader.skipValue();
                continue;
            }
        }
        reader.endObject();
        clientRepository.saveClient(client);
    }
    reader.endArray();
    logger.info("Done reading clients");
}

From source file:org.mitre.openid.connect.service.impl.MITREidDataService_1_2.java

License:Apache License

/**
 * Read the list of system scopes from the reader and insert them into the
 * scope repository.//from   w  w w.j a  v a  2s .c o m
 *
 * @param reader
 * @throws IOException
 */
private void readSystemScopes(JsonReader reader) throws IOException {
    reader.beginArray();
    while (reader.hasNext()) {
        SystemScope scope = new SystemScope();
        reader.beginObject();
        while (reader.hasNext()) {
            switch (reader.peek()) {
            case END_OBJECT:
                continue;
            case NAME:
                String name = reader.nextName();
                if (reader.peek() == JsonToken.NULL) {
                    reader.skipValue();
                } else if (name.equals(VALUE)) {
                    scope.setValue(reader.nextString());
                } else if (name.equals(DESCRIPTION)) {
                    scope.setDescription(reader.nextString());
                } else if (name.equals(RESTRICTED)) {
                    scope.setRestricted(reader.nextBoolean());
                } else if (name.equals(DEFAULT_SCOPE)) {
                    scope.setDefaultScope(reader.nextBoolean());
                } else if (name.equals(ICON)) {
                    scope.setIcon(reader.nextString());
                } else if (name.equals(STRUCTURED)) {
                    logger.warn("Found a structured scope, ignoring structure");
                } else if (name.equals(STRUCTURED_PARAMETER)) {
                    logger.warn("Found a structured scope, ignoring structure");
                } else {
                    logger.debug("found unexpected entry");
                    reader.skipValue();
                }
                break;
            default:
                logger.debug("Found unexpected entry");
                reader.skipValue();
                continue;
            }
        }
        reader.endObject();
        sysScopeRepository.save(scope);
    }
    reader.endArray();
    logger.info("Done reading system scopes");
}

From source file:org.mitre.openid.connect.service.impl.MITREidDataService_1_3.java

License:Apache License

@Override
public void importData(JsonReader reader) throws IOException {

    logger.info("Reading configuration for 1.3");

    // this *HAS* to start as an object
    reader.beginObject();//from  w w  w  . j a  v  a  2s .c o  m

    while (reader.hasNext()) {
        JsonToken tok = reader.peek();
        switch (tok) {
        case NAME:
            String name = reader.nextName();
            // find out which member it is
            if (name.equals(CLIENTS)) {
                readClients(reader);
            } else if (name.equals(GRANTS)) {
                readGrants(reader);
            } else if (name.equals(WHITELISTEDSITES)) {
                readWhitelistedSites(reader);
            } else if (name.equals(BLACKLISTEDSITES)) {
                readBlacklistedSites(reader);
            } else if (name.equals(AUTHENTICATIONHOLDERS)) {
                readAuthenticationHolders(reader);
            } else if (name.equals(ACCESSTOKENS)) {
                readAccessTokens(reader);
            } else if (name.equals(REFRESHTOKENS)) {
                readRefreshTokens(reader);
            } else if (name.equals(SYSTEMSCOPES)) {
                readSystemScopes(reader);
            } else {
                boolean processed = false;
                for (MITREidDataServiceExtension extension : extensions) {
                    if (extension.supportsVersion(THIS_VERSION)) {
                        processed = extension.importExtensionData(name, reader);
                        if (processed) {
                            // if the extension processed data, break out of this inner loop
                            // (only the first extension to claim an extension point gets it)
                            break;
                        }
                    }
                }
                if (!processed) {
                    // unknown token, skip it
                    reader.skipValue();
                }
            }
            break;
        case END_OBJECT:
            // the object ended, we're done here
            reader.endObject();
            continue;
        default:
            logger.debug("Found unexpected entry");
            reader.skipValue();
            continue;
        }
    }
    fixObjectReferences();
    for (MITREidDataServiceExtension extension : extensions) {
        if (extension.supportsVersion(THIS_VERSION)) {
            extension.fixExtensionObjectReferences(maps);
            break;
        }
    }
    maps.clearAll();
}

From source file:org.mitre.openid.connect.service.impl.MITREidDataService_1_3.java

License:Apache License

/**
 * @param reader/*from w w w  .  ja  va 2 s  .  com*/
 * @throws IOException
 */
private void readClients(JsonReader reader) throws IOException {
    reader.beginArray();
    while (reader.hasNext()) {
        ClientDetailsEntity client = new ClientDetailsEntity();
        reader.beginObject();
        while (reader.hasNext()) {
            switch (reader.peek()) {
            case END_OBJECT:
                continue;
            case NAME:
                String name = reader.nextName();
                if (reader.peek() == JsonToken.NULL) {
                    reader.skipValue();
                } else if (name.equals(CLIENT_ID)) {
                    client.setClientId(reader.nextString());
                } else if (name.equals(RESOURCE_IDS)) {
                    Set<String> resourceIds = readSet(reader);
                    client.setResourceIds(resourceIds);
                } else if (name.equals(SECRET)) {
                    client.setClientSecret(reader.nextString());
                } else if (name.equals(SCOPE)) {
                    Set<String> scope = readSet(reader);
                    client.setScope(scope);
                } else if (name.equals(AUTHORITIES)) {
                    Set<String> authorityStrs = readSet(reader);
                    Set<GrantedAuthority> authorities = new HashSet<GrantedAuthority>();
                    for (String s : authorityStrs) {
                        GrantedAuthority ga = new SimpleGrantedAuthority(s);
                        authorities.add(ga);
                    }
                    client.setAuthorities(authorities);
                } else if (name.equals(ACCESS_TOKEN_VALIDITY_SECONDS)) {
                    client.setAccessTokenValiditySeconds(reader.nextInt());
                } else if (name.equals(REFRESH_TOKEN_VALIDITY_SECONDS)) {
                    client.setRefreshTokenValiditySeconds(reader.nextInt());
                } else if (name.equals(ID_TOKEN_VALIDITY_SECONDS)) {
                    client.setIdTokenValiditySeconds(reader.nextInt());
                } else if (name.equals(DEVICE_CODE_VALIDITY_SECONDS)) {
                    client.setDeviceCodeValiditySeconds(reader.nextInt());
                } else if (name.equals(REDIRECT_URIS)) {
                    Set<String> redirectUris = readSet(reader);
                    client.setRedirectUris(redirectUris);
                } else if (name.equals(CLAIMS_REDIRECT_URIS)) {
                    Set<String> claimsRedirectUris = readSet(reader);
                    client.setClaimsRedirectUris(claimsRedirectUris);
                } else if (name.equals(NAME)) {
                    client.setClientName(reader.nextString());
                } else if (name.equals(URI)) {
                    client.setClientUri(reader.nextString());
                } else if (name.equals(LOGO_URI)) {
                    client.setLogoUri(reader.nextString());
                } else if (name.equals(CONTACTS)) {
                    Set<String> contacts = readSet(reader);
                    client.setContacts(contacts);
                } else if (name.equals(TOS_URI)) {
                    client.setTosUri(reader.nextString());
                } else if (name.equals(TOKEN_ENDPOINT_AUTH_METHOD)) {
                    AuthMethod am = AuthMethod.getByValue(reader.nextString());
                    client.setTokenEndpointAuthMethod(am);
                } else if (name.equals(GRANT_TYPES)) {
                    Set<String> grantTypes = readSet(reader);
                    client.setGrantTypes(grantTypes);
                } else if (name.equals(RESPONSE_TYPES)) {
                    Set<String> responseTypes = readSet(reader);
                    client.setResponseTypes(responseTypes);
                } else if (name.equals(POLICY_URI)) {
                    client.setPolicyUri(reader.nextString());
                } else if (name.equals(APPLICATION_TYPE)) {
                    AppType appType = AppType.getByValue(reader.nextString());
                    client.setApplicationType(appType);
                } else if (name.equals(SECTOR_IDENTIFIER_URI)) {
                    client.setSectorIdentifierUri(reader.nextString());
                } else if (name.equals(SUBJECT_TYPE)) {
                    SubjectType st = SubjectType.getByValue(reader.nextString());
                    client.setSubjectType(st);
                } else if (name.equals(JWKS_URI)) {
                    client.setJwksUri(reader.nextString());
                } else if (name.equals(JWKS)) {
                    try {
                        client.setJwks(JWKSet.parse(reader.nextString()));
                    } catch (ParseException e) {
                        logger.error("Couldn't parse JWK Set", e);
                    }
                } else if (name.equals(REQUEST_OBJECT_SIGNING_ALG)) {
                    JWSAlgorithm alg = JWSAlgorithm.parse(reader.nextString());
                    client.setRequestObjectSigningAlg(alg);
                } else if (name.equals(USER_INFO_ENCRYPTED_RESPONSE_ALG)) {
                    JWEAlgorithm alg = JWEAlgorithm.parse(reader.nextString());
                    client.setUserInfoEncryptedResponseAlg(alg);
                } else if (name.equals(USER_INFO_ENCRYPTED_RESPONSE_ENC)) {
                    EncryptionMethod alg = EncryptionMethod.parse(reader.nextString());
                    client.setUserInfoEncryptedResponseEnc(alg);
                } else if (name.equals(USER_INFO_SIGNED_RESPONSE_ALG)) {
                    JWSAlgorithm alg = JWSAlgorithm.parse(reader.nextString());
                    client.setUserInfoSignedResponseAlg(alg);
                } else if (name.equals(ID_TOKEN_SIGNED_RESPONSE_ALG)) {
                    JWSAlgorithm alg = JWSAlgorithm.parse(reader.nextString());
                    client.setIdTokenSignedResponseAlg(alg);
                } else if (name.equals(ID_TOKEN_ENCRYPTED_RESPONSE_ALG)) {
                    JWEAlgorithm alg = JWEAlgorithm.parse(reader.nextString());
                    client.setIdTokenEncryptedResponseAlg(alg);
                } else if (name.equals(ID_TOKEN_ENCRYPTED_RESPONSE_ENC)) {
                    EncryptionMethod alg = EncryptionMethod.parse(reader.nextString());
                    client.setIdTokenEncryptedResponseEnc(alg);
                } else if (name.equals(TOKEN_ENDPOINT_AUTH_SIGNING_ALG)) {
                    JWSAlgorithm alg = JWSAlgorithm.parse(reader.nextString());
                    client.setTokenEndpointAuthSigningAlg(alg);
                } else if (name.equals(DEFAULT_MAX_AGE)) {
                    client.setDefaultMaxAge(reader.nextInt());
                } else if (name.equals(REQUIRE_AUTH_TIME)) {
                    client.setRequireAuthTime(reader.nextBoolean());
                } else if (name.equals(DEFAULT_ACR_VALUES)) {
                    Set<String> defaultACRvalues = readSet(reader);
                    client.setDefaultACRvalues(defaultACRvalues);
                } else if (name.equals("initiateLoginUri")) {
                    client.setInitiateLoginUri(reader.nextString());
                } else if (name.equals(POST_LOGOUT_REDIRECT_URI)) {
                    Set<String> postLogoutUris = readSet(reader);
                    client.setPostLogoutRedirectUris(postLogoutUris);
                } else if (name.equals(REQUEST_URIS)) {
                    Set<String> requestUris = readSet(reader);
                    client.setRequestUris(requestUris);
                } else if (name.equals(DESCRIPTION)) {
                    client.setClientDescription(reader.nextString());
                } else if (name.equals(ALLOW_INTROSPECTION)) {
                    client.setAllowIntrospection(reader.nextBoolean());
                } else if (name.equals(REUSE_REFRESH_TOKEN)) {
                    client.setReuseRefreshToken(reader.nextBoolean());
                } else if (name.equals(CLEAR_ACCESS_TOKENS_ON_REFRESH)) {
                    client.setClearAccessTokensOnRefresh(reader.nextBoolean());
                } else if (name.equals(DYNAMICALLY_REGISTERED)) {
                    client.setDynamicallyRegistered(reader.nextBoolean());
                } else if (name.equals(CODE_CHALLENGE_METHOD)) {
                    client.setCodeChallengeMethod(PKCEAlgorithm.parse(reader.nextString()));
                } else if (name.equals(SOFTWARE_ID)) {
                    client.setSoftwareId(reader.nextString());
                } else if (name.equals(SOFTWARE_VERSION)) {
                    client.setSoftwareVersion(reader.nextString());
                } else if (name.equals(SOFTWARE_STATEMENT)) {
                    try {
                        client.setSoftwareStatement(JWTParser.parse(reader.nextString()));
                    } catch (ParseException e) {
                        logger.error("Couldn't parse software statement", e);
                    }
                } else if (name.equals(CREATION_DATE)) {
                    Date date = utcToDate(reader.nextString());
                    client.setCreatedAt(date);
                } else {
                    logger.debug("Found unexpected entry");
                    reader.skipValue();
                }
                break;
            default:
                logger.debug("Found unexpected entry");
                reader.skipValue();
                continue;
            }
        }
        reader.endObject();
        clientRepository.saveClient(client);
    }
    reader.endArray();
    logger.info("Done reading clients");
}

From source file:org.mitre.openid.connect.service.impl.MITREidDataService_1_3.java

License:Apache License

/**
 * Read the list of system scopes from the reader and insert them into the
 * scope repository.//from ww w .  j a  v a 2  s .co  m
 *
 * @param reader
 * @throws IOException
 */
private void readSystemScopes(JsonReader reader) throws IOException {
    reader.beginArray();
    while (reader.hasNext()) {
        SystemScope scope = new SystemScope();
        reader.beginObject();
        while (reader.hasNext()) {
            switch (reader.peek()) {
            case END_OBJECT:
                continue;
            case NAME:
                String name = reader.nextName();
                if (reader.peek() == JsonToken.NULL) {
                    reader.skipValue();
                } else if (name.equals(VALUE)) {
                    scope.setValue(reader.nextString());
                } else if (name.equals(DESCRIPTION)) {
                    scope.setDescription(reader.nextString());
                } else if (name.equals(RESTRICTED)) {
                    scope.setRestricted(reader.nextBoolean());
                } else if (name.equals(DEFAULT_SCOPE)) {
                    scope.setDefaultScope(reader.nextBoolean());
                } else if (name.equals(ICON)) {
                    scope.setIcon(reader.nextString());
                } else {
                    logger.debug("found unexpected entry");
                    reader.skipValue();
                }
                break;
            default:
                logger.debug("Found unexpected entry");
                reader.skipValue();
                continue;
            }
        }
        reader.endObject();
        sysScopeRepository.save(scope);
    }
    reader.endArray();
    logger.info("Done reading system scopes");
}