private HashSet<GroupPolicyRepresentation.GroupDefinition> getGroupsDefinition(Map<String, String> config) throws IOException { return new HashSet<>(Arrays.asList(JsonSerialization.readValue(config.get("groups"), GroupPolicyRepresentation.GroupDefinition[].class))); } }
private <T> T parseToken(String encoded, Class<T> clazz) throws IOException { if (encoded == null) return null; String[] parts = encoded.split("\\."); if (parts.length < 2 || parts.length > 3) throw new IllegalArgumentException("Parsing error"); byte[] bytes = Base64Url.decode(parts[1]); return JsonSerialization.readValue(bytes, clazz); }
JWEHeader getHeader() { if (header == null && base64Header != null) { try { byte[] decodedHeader = Base64Url.decode(base64Header); header = JsonSerialization.readValue(decodedHeader, JWEHeader.class); } catch (IOException ioe) { throw new RuntimeException(ioe); } } return header; }
public <T> T readJsonContent(Class<T> type) throws JWSInputException { try { return JsonSerialization.readValue(content, type); } catch (IOException e) { throw new JWSInputException(e); } }
public ConfigData loadConfig() { // for now just dumb impl ignoring file locks for read File file = new File(configFile); if (!file.isFile() || file.length() == 0) { return new ConfigData(); } try { try (FileInputStream is = new FileInputStream(configFile)) { return JsonSerialization.readValue(is, ConfigData.class); } } catch (IOException e) { throw new RuntimeException("Failed to load " + configFile, e); } }
private Map<String, Object>[] getRoles(Policy policy) { String roles = policy.getConfig().get("roles"); if (roles != null) { try { return JsonSerialization.readValue(roles.getBytes(), Map[].class); } catch (IOException e) { throw new RuntimeException("Could not parse roles [" + roles + "] from policy config [" + policy.getName() + ".", e); } } return new Map[] {}; } }
private String[] getClients(Policy policy) { String clients = policy.getConfig().get("clients"); if (clients != null) { try { return JsonSerialization.readValue(clients.getBytes(), String[].class); } catch (IOException e) { throw new RuntimeException("Could not parse clients [" + clients + "] from policy config [" + policy.getName() + "].", e); } } return new String[]{}; } }
@Override public void onImport(Policy policy, PolicyRepresentation representation, AuthorizationProvider authorization) { try { updateRoles(policy, authorization, new HashSet<>(Arrays.asList(JsonSerialization.readValue(representation.getConfig().get("roles"), RolePolicyRepresentation.RoleDefinition[].class)))); } catch (IOException cause) { throw new RuntimeException("Failed to deserialize roles during import", cause); } }
static String[] getUsers(Policy policy) { String users = policy.getConfig().get("users"); if (users != null) { try { return JsonSerialization.readValue(users.getBytes(), String[].class); } catch (IOException e) { throw new RuntimeException("Could not parse users [" + users + "] from policy config [" + policy.getName() + ".", e); } } return new String[0]; } }
@Override public void onImport(Policy policy, PolicyRepresentation representation, AuthorizationProvider authorization) { try { updateUsers(policy, authorization, JsonSerialization.readValue(representation.getConfig().get("users"), Set.class)); } catch (IOException cause) { throw new RuntimeException("Failed to deserialize users during import", cause); } }
@Override public RolePolicyRepresentation toRepresentation(Policy policy, AuthorizationProvider authorization) { RolePolicyRepresentation representation = new RolePolicyRepresentation(); try { representation.setRoles(new HashSet<>(Arrays.asList(JsonSerialization.readValue(policy.getConfig().get("roles"), RolePolicyRepresentation.RoleDefinition[].class)))); } catch (IOException cause) { throw new RuntimeException("Failed to deserialize roles", cause); } return representation; }
private PersistentUserSessionData getData() { if (data == null) { try { data = JsonSerialization.readValue(model.getData(), PersistentUserSessionData.class); } catch (IOException ioe) { throw new ModelException(ioe); } } return data; }
private PersistentClientSessionData getData() { if (data == null) { try { data = JsonSerialization.readValue(model.getData(), PersistentClientSessionData.class); } catch (IOException ioe) { throw new ModelException(ioe); } } return data; }
public String getAccessToken() { logger.debug("Creating Auth0 Api Token"); try { InputStream inputStream = new ClassPathResource("keycloak.json", this.getClass().getClassLoader()).getInputStream(); AuthzClient authzClient = AuthzClient.create(JsonSerialization.readValue(inputStream, Configuration.class)); AccessTokenResponse accessTokenResponse = authzClient.obtainAccessToken(); if (accessTokenResponse != null) return accessTokenResponse.getToken(); } catch (IOException e) { logger.error("Could not read keycloak.json", e); return null; } return null; }
@Override public UserPolicyRepresentation toRepresentation(Policy policy, AuthorizationProvider authorization) { UserPolicyRepresentation representation = new UserPolicyRepresentation(); try { representation.setUsers(JsonSerialization.readValue(policy.getConfig().get("users"), Set.class)); } catch (IOException cause) { throw new RuntimeException("Failed to deserialize roles", cause); } return representation; }
public MappingsRepresentation clientScopeMappings(String authToken, String realmName, String clientApp) throws Exception { HttpGet get = new HttpGet(clientScopeMappingsEndpoint(realmName, clientApp)); addAuthzHeader(get, authToken); return exec(get, 200, "Unable to retrieve scope mappings from " + clientApp, entity -> { try (InputStream is = entity.getContent()) { return JsonSerialization.readValue(is, MappingsRepresentation.class); } catch (IOException e) { throw new ResourceProcessingException(ErrorType.INTERNAL_ERROR, "Unable to retrieve scope mappings from " + clientApp, e); } }); }
public List<RoleRepresentation> clientScopeRolesForApplication(String authToken, String realmName, String clientApp, String appName) throws Exception { HttpGet get = new HttpGet(clientScopeForApplicationsEndpoint(realmName, clientApp, appName)); addAuthzHeader(get, authToken); return exec(get, 200, "Unable to retrieve roles in client scope for " + clientApp, entity -> { try (InputStream is = entity.getContent()) { return JsonSerialization.readValue(is, TypedRoleList.class); } catch (IOException e) { throw new ResourceProcessingException(ErrorType.INTERNAL_ERROR, "Unable to retrieve roles in client scope for " + clientApp, e); } }); }
public ApplicationRepresentation application(String authToken, String realmName, String appName) throws Exception { HttpGet get = new HttpGet(applicationEndpoint(realmName, appName)); addAuthzHeader(get, authToken); return exec(get, 200, "Unable to retrieve application " + appName, entity -> { try (InputStream is = entity.getContent()) { return JsonSerialization.readValue(is, ApplicationRepresentation.class); } catch (IOException e) { throw new ResourceProcessingException(ErrorType.INTERNAL_ERROR, "Unable to retrieve application " + appName, e); } }); }
public List<RoleRepresentation> applicationRoles(String authToken, String realmName, String appName) throws Exception { HttpGet get = new HttpGet(applicationRolesEndpoint(realmName, appName)); addAuthzHeader(get, authToken); return exec(get, 200, "Unable to retrieve application roles list from " + appName, entity -> { try (InputStream is = entity.getContent()) { return JsonSerialization.readValue(is, TypedRoleList.class); } catch (IOException e) { throw new ResourceProcessingException(ErrorType.INTERNAL_ERROR, "Unable to retrieve application roles list from " + appName, e); } }); }
public static <T extends JsonWebToken> T jweDirectVerifyAndDecode(Key aesKey, Key hmacKey, String jweStr, Class<T> expectedClass) throws JWEException { JWE jwe = new JWE(); jwe.getKeyStorage() .setCEKKey(aesKey, JWEKeyStorage.KeyUse.ENCRYPTION) .setCEKKey(hmacKey, JWEKeyStorage.KeyUse.SIGNATURE); jwe.verifyAndDecodeJwe(jweStr); try { return JsonSerialization.readValue(jwe.getContent(), expectedClass); } catch (IOException ioe) { throw new JWEException(ioe); } }