Package org.keycloak.models

Examples of org.keycloak.models.ApplicationModel


        String adminRealmId = Config.getAdminRealm();
        if (adminRealmId.equals(realm.getId())) {
            // We just imported master realm. All 'masterAdminApps' need to be refreshed
            RealmModel adminRealm = realm;
            for (RealmModel currentRealm : model.getRealms()) {
                ApplicationModel masterApp = adminRealm.getApplicationByName(KeycloakModelUtils.getMasterRealmAdminApplicationName(currentRealm));
                if (masterApp != null) {
                    currentRealm.setMasterAdminApp(masterApp);
                else {
                    setupMasterAdminManagement(model, currentRealm);
                }
            }
        } else {
            // Need to refresh masterApp for current realm
            RealmModel adminRealm = model.getRealm(adminRealmId);
            ApplicationModel masterApp = adminRealm.getApplicationByName(KeycloakModelUtils.getMasterRealmAdminApplicationName(realm));
            if (masterApp != null) {
                realm.setMasterAdminApp(masterApp);
            else {
                setupMasterAdminManagement(model, realm);
            }
View Full Code Here


        } else {
            adminRealm = model.getRealmByName(Config.getAdminRealm());
            adminRole = adminRealm.getRole(AdminRoles.ADMIN);
        }

        ApplicationModel realmAdminApp = KeycloakModelUtils.createApplication(adminRealm, KeycloakModelUtils.getMasterRealmAdminApplicationName(realm));
        realmAdminApp.setBearerOnly(true);
        realm.setMasterAdminApp(realmAdminApp);

        for (String r : AdminRoles.ALL_REALM_ROLES) {
            RoleModel role = realmAdminApp.addRole(r);
            adminRole.addCompositeRole(role);
        }
    }
View Full Code Here

                    if (scopeMappingRep == null) {
                        scopeMappingRep = rep.scopeMapping(client.getClientId());
                    }
                    scopeMappingRep.role(scope.getName());
                } else {
                    ApplicationModel app = (ApplicationModel)scope.getContainer();
                    String appName = app.getName();
                    List<ScopeMappingRepresentation> currentAppScopes = appScopeReps.get(appName);
                    if (currentAppScopes == null) {
                        currentAppScopes = new ArrayList<ScopeMappingRepresentation>();
                        appScopeReps.put(appName, currentAppScopes);
                    }
View Full Code Here

                } else {
                    if (compositeAppRoles == null) {
                        compositeAppRoles = new HashMap<String, List<String>>();
                    }

                    ApplicationModel app = (ApplicationModel)crContainer;
                    String appName = app.getName();
                    List<String> currentAppComposites = compositeAppRoles.get(appName);
                    if (currentAppComposites == null) {
                        currentAppComposites = new ArrayList<String>();
                        compositeAppRoles.put(appName, currentAppComposites);
                    }
View Full Code Here

        Map<String, List<String>> appRoleNames = new HashMap<String, List<String>>();
        for (RoleModel role : roles) {
            if (role.getContainer() instanceof RealmModel) {
                realmRoleNames.add(role.getName());
            } else {
                ApplicationModel app = (ApplicationModel)role.getContainer();
                String appName = app.getName();
                List<String> currentAppRoles = appRoleNames.get(appName);
                if (currentAppRoles == null) {
                    currentAppRoles = new ArrayList<String>();
                    appRoleNames.put(appName, currentAppRoles);
                }
View Full Code Here

        if (!realm.isEnabled()) {
            event.error(Errors.REALM_DISABLED);
            throw new UnauthorizedException("Realm not enabled");
        }

        ApplicationModel application = authorizeApplication(authorizationHeader, formData);
        String nodeHost = getApplicationClusterHost(formData);

        event.client(application).detail(Details.NODE_HOST, nodeHost);
        logger.debugf("Registering cluster host '%s' for client '%s'", nodeHost, application.getName());

        application.registerNode(nodeHost, Time.currentTime());

        event.success();

        return Response.noContent().build();
    }
View Full Code Here

        if (!realm.isEnabled()) {
            event.error(Errors.REALM_DISABLED);
            throw new UnauthorizedException("Realm not enabled");
        }

        ApplicationModel application = authorizeApplication(authorizationHeader, formData);
        String nodeHost = getApplicationClusterHost(formData);

        event.client(application).detail(Details.NODE_HOST, nodeHost);
        logger.debugf("Unregistering cluster host '%s' for client '%s'", nodeHost, application.getName());

        application.unregisterNode(nodeHost);

        event.success();

        return Response.noContent().build();
    }
View Full Code Here

        Set<RoleModel> appRoles = new HashSet<RoleModel>();
        for (RoleModel role : roleMappings) {
            RoleContainerModel container = role.getContainer();
            if (container instanceof RealmModel) {
            } else {
                ApplicationModel app = (ApplicationModel)container;
                if (app.getId().equals(getId())) {
                    appRoles.add(role);
                }
            }
        }
View Full Code Here

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || !(o instanceof ApplicationModel)) return false;

        ApplicationModel that = (ApplicationModel) o;
        return that.getId().equals(getId());
    }
View Full Code Here

        {   // test bearer-only

            {
                KeycloakSession session = keycloakRule.startSession();
                RealmModel realm = session.realms().getRealmByName("test");
                ApplicationModel clientModel = realm.getApplicationByName("test-app");
                clientModel.setBearerOnly(true);
                session.getTransaction().commit();
                session.close();
            }


            Response response = executeGrantAccessTokenRequest(grantTarget);
            Assert.assertEquals(400, response.getStatus());
            response.close();

            {
                KeycloakSession session = keycloakRule.startSession();
                RealmModel realm = session.realms().getRealmByName("test");
                ApplicationModel clientModel = realm.getApplicationByName("test-app");
                clientModel.setBearerOnly(false);
                session.getTransaction().commit();
                session.close();
            }

        }

        {   // test realm disabled
            {
                KeycloakSession session = keycloakRule.startSession();
                RealmModel realm = session.realms().getRealmByName("test");
                realm.setEnabled(false);
                session.getTransaction().commit();
                session.close();
            }

            Response response = executeGrantAccessTokenRequest(grantTarget);
            Assert.assertEquals(401, response.getStatus());
            response.close();

            {
                KeycloakSession session = keycloakRule.startSession();
                RealmModel realm = session.realms().getRealmByName("test");
                realm.setEnabled(true);
                session.getTransaction().commit();
                session.close();
            }

        }

        {   // test application disabled

            {
                KeycloakSession session = keycloakRule.startSession();
                RealmModel realm = session.realms().getRealmByName("test");
                ClientModel clientModel = realm.findClient("test-app");
                clientModel.setEnabled(false);
                session.getTransaction().commit();
                session.close();
            }


            Response response = executeGrantAccessTokenRequest(grantTarget);
            Assert.assertEquals(400, response.getStatus());
            response.close();

            {
                KeycloakSession session = keycloakRule.startSession();
                RealmModel realm = session.realms().getRealmByName("test");
                ClientModel clientModel = realm.findClient("test-app");
                clientModel.setEnabled(true);
                session.getTransaction().commit();
                session.close();
            }

        }
View Full Code Here

TOP

Related Classes of org.keycloak.models.ApplicationModel

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.