Search in sources :

Example 1 with MultivaluedHashMap

use of org.keycloak.common.util.MultivaluedHashMap in project keycloak by keycloak.

the class FilterSessionStore method parseForm.

public static MultivaluedHashMap<String, String> parseForm(InputStream entityStream) throws IOException {
    char[] buffer = new char[100];
    StringBuffer buf = new StringBuffer();
    BufferedReader reader = new BufferedReader(new InputStreamReader(entityStream));
    int wasRead = 0;
    do {
        wasRead = reader.read(buffer, 0, 100);
        if (wasRead > 0)
            buf.append(buffer, 0, wasRead);
    } while (wasRead > -1);
    String form = buf.toString();
    MultivaluedHashMap<String, String> formData = new MultivaluedHashMap<String, String>();
    if ("".equals(form))
        return formData;
    String[] params = form.split("&");
    for (String param : params) {
        if (param.indexOf('=') >= 0) {
            String[] nv = param.split("=");
            String val = nv.length > 1 ? nv[1] : "";
            formData.add(Encode.decode(nv[0]), Encode.decode(val));
        } else {
            formData.add(Encode.decode(param), "");
        }
    }
    return formData;
}
Also used : MultivaluedHashMap(org.keycloak.common.util.MultivaluedHashMap) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader)

Example 2 with MultivaluedHashMap

use of org.keycloak.common.util.MultivaluedHashMap in project keycloak by keycloak.

the class SAMLServletAdapterTest method createKeys.

private PublicKey createKeys(String priority) throws Exception {
    PublicKey publicKey = NEW_KEY_PAIR.getPublic();
    ComponentRepresentation rep = new ComponentRepresentation();
    rep.setName("mycomponent");
    rep.setParentId("demo");
    rep.setProviderId(ImportedRsaKeyProviderFactory.ID);
    rep.setProviderType(KeyProvider.class.getName());
    MultivaluedHashMap<String, String> config = new MultivaluedHashMap<>();
    config.addFirst("priority", priority);
    config.addFirst(Attributes.PRIVATE_KEY_KEY, NEW_KEY_PRIVATE_KEY_PEM);
    rep.setConfig(config);
    testRealmResource().components().add(rep);
    return publicKey;
}
Also used : ComponentRepresentation(org.keycloak.representations.idm.ComponentRepresentation) KeyProvider(org.keycloak.keys.KeyProvider) MultivaluedHashMap(org.keycloak.common.util.MultivaluedHashMap) PublicKey(java.security.PublicKey)

Example 3 with MultivaluedHashMap

use of org.keycloak.common.util.MultivaluedHashMap in project keycloak by keycloak.

the class ExportUtils method exportComponents.

public static MultivaluedHashMap<String, ComponentExportRepresentation> exportComponents(RealmModel realm, String parentId) {
    MultivaluedHashMap<String, ComponentExportRepresentation> components = new MultivaluedHashMap<>();
    realm.getComponentsStream(parentId).forEach(component -> {
        ComponentExportRepresentation compRep = new ComponentExportRepresentation();
        compRep.setId(component.getId());
        compRep.setProviderId(component.getProviderId());
        compRep.setConfig(component.getConfig());
        compRep.setName(component.getName());
        compRep.setSubType(component.getSubType());
        compRep.setSubComponents(exportComponents(realm, component.getId()));
        components.add(component.getProviderType(), compRep);
    });
    return components;
}
Also used : MultivaluedHashMap(org.keycloak.common.util.MultivaluedHashMap) ComponentExportRepresentation(org.keycloak.representations.idm.ComponentExportRepresentation)

Example 4 with MultivaluedHashMap

use of org.keycloak.common.util.MultivaluedHashMap in project keycloak by keycloak.

the class ApplicationsBean method toApplicationEntry.

/**
 * Constructs a {@link ApplicationEntry} from the specified parameters.
 *
 * @param session a reference to the {@code Keycloak} session.
 * @param realm a reference to the realm.
 * @param user a reference to the user.
 * @param client a reference to the client that contains the applications.
 * @param offlineClients a {@link Set} containing the offline clients.
 * @return the constructed {@link ApplicationEntry} instance or {@code null} if the user can't access the applications
 * in the specified client.
 */
private ApplicationEntry toApplicationEntry(final KeycloakSession session, final RealmModel realm, final UserModel user, final ClientModel client, final Set<ClientModel> offlineClients) {
    // Construct scope parameter with all optional scopes to see all potentially available roles
    Stream<ClientScopeModel> allClientScopes = Stream.concat(client.getClientScopes(true).values().stream(), client.getClientScopes(false).values().stream());
    allClientScopes = Stream.concat(allClientScopes, Stream.of(client)).distinct();
    Set<RoleModel> availableRoles = TokenManager.getAccess(user, client, allClientScopes);
    // unless this is can be changed by approving/revoking consent
    if (!isAdminClient(client) && availableRoles.isEmpty() && !client.isConsentRequired()) {
        return null;
    }
    List<RoleModel> realmRolesAvailable = new LinkedList<>();
    MultivaluedHashMap<String, ClientRoleEntry> resourceRolesAvailable = new MultivaluedHashMap<>();
    processRoles(availableRoles, realmRolesAvailable, resourceRolesAvailable);
    List<ClientScopeModel> orderedScopes = new LinkedList<>();
    if (client.isConsentRequired()) {
        UserConsentModel consent = session.users().getConsentByClient(realm, user.getId(), client.getId());
        if (consent != null) {
            orderedScopes.addAll(consent.getGrantedClientScopes());
        }
    }
    List<String> clientScopesGranted = orderedScopes.stream().sorted(OrderedModel.OrderedModelComparator.getInstance()).map(ClientScopeModel::getConsentScreenText).collect(Collectors.toList());
    List<String> additionalGrants = new ArrayList<>();
    if (offlineClients.contains(client)) {
        additionalGrants.add("${offlineToken}");
    }
    return new ApplicationEntry(session, realmRolesAvailable, resourceRolesAvailable, client, clientScopesGranted, additionalGrants);
}
Also used : ArrayList(java.util.ArrayList) ClientScopeModel(org.keycloak.models.ClientScopeModel) RoleModel(org.keycloak.models.RoleModel) LinkedList(java.util.LinkedList) UserConsentModel(org.keycloak.models.UserConsentModel) MultivaluedHashMap(org.keycloak.common.util.MultivaluedHashMap)

Example 5 with MultivaluedHashMap

use of org.keycloak.common.util.MultivaluedHashMap in project keycloak by keycloak.

the class GeneratedEcdsaKeyProviderFactory method createFallbackKeys.

@Override
public boolean createFallbackKeys(KeycloakSession session, KeyUse keyUse, String algorithm) {
    if (keyUse.equals(KeyUse.SIG) && (algorithm.equals(Algorithm.ES256) || algorithm.equals(Algorithm.ES384) || algorithm.equals(Algorithm.ES512))) {
        RealmModel realm = session.getContext().getRealm();
        ComponentModel generated = new ComponentModel();
        generated.setName("fallback-" + algorithm);
        generated.setParentId(realm.getId());
        generated.setProviderId(ID);
        generated.setProviderType(KeyProvider.class.getName());
        MultivaluedHashMap<String, String> config = new MultivaluedHashMap<>();
        config.putSingle(Attributes.PRIORITY_KEY, "-100");
        config.putSingle(ECDSA_ELLIPTIC_CURVE_KEY, convertAlgorithmToECDomainParmNistRep(algorithm));
        generated.setConfig(config);
        realm.addComponentModel(generated);
        return true;
    } else {
        return false;
    }
}
Also used : RealmModel(org.keycloak.models.RealmModel) MultivaluedHashMap(org.keycloak.common.util.MultivaluedHashMap) ComponentModel(org.keycloak.component.ComponentModel)

Aggregations

MultivaluedHashMap (org.keycloak.common.util.MultivaluedHashMap)44 ComponentModel (org.keycloak.component.ComponentModel)15 List (java.util.List)9 LinkedList (java.util.LinkedList)8 Map (java.util.Map)8 KeyProvider (org.keycloak.keys.KeyProvider)8 RealmModel (org.keycloak.models.RealmModel)7 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 ComponentExportRepresentation (org.keycloak.representations.idm.ComponentExportRepresentation)6 IOException (java.io.IOException)5 HttpSession (javax.servlet.http.HttpSession)5 ComponentRepresentation (org.keycloak.representations.idm.ComponentRepresentation)5 UserRepresentation (org.keycloak.representations.idm.UserRepresentation)5 RoleModel (org.keycloak.models.RoleModel)4 HashSet (java.util.HashSet)3 Test (org.junit.Test)3 ClientModel (org.keycloak.models.ClientModel)3 ClientScopeModel (org.keycloak.models.ClientScopeModel)3 BufferedReader (java.io.BufferedReader)2