Search in sources :

Example 41 with KeycloakDeployment

use of org.keycloak.adapters.KeycloakDeployment in project keycloak by keycloak.

the class KeycloakPreAuthActionsFilter method doFilter.

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    HttpFacade facade = new SimpleHttpFacade((HttpServletRequest) request, (HttpServletResponse) response);
    KeycloakDeployment deployment = deploymentContext.resolveDeployment(facade);
    if (deployment == null) {
        return;
    }
    if (deployment.isConfigured()) {
        nodesRegistrationManagement.tryRegister(deploymentContext.resolveDeployment(facade));
    }
    PreAuthActionsHandler handler = preAuthActionsHandlerFactory.createPreAuthActionsHandler(facade);
    if (handler.handleRequest()) {
        log.debug("Pre-auth filter handled request: {}", ((HttpServletRequest) request).getRequestURI());
    } else {
        chain.doFilter(request, response);
    }
}
Also used : HttpFacade(org.keycloak.adapters.spi.HttpFacade) SimpleHttpFacade(org.keycloak.adapters.springsecurity.facade.SimpleHttpFacade) KeycloakDeployment(org.keycloak.adapters.KeycloakDeployment) SimpleHttpFacade(org.keycloak.adapters.springsecurity.facade.SimpleHttpFacade) PreAuthActionsHandler(org.keycloak.adapters.PreAuthActionsHandler)

Example 42 with KeycloakDeployment

use of org.keycloak.adapters.KeycloakDeployment in project keycloak by keycloak.

the class PathBasedKeycloakConfigResolver method getOrCreateDeployment.

/**
 * {@code pathFragment} is a key for {@link KeycloakDeployment deployments}. The key is used to construct
 * a path relative to {@code keycloak.config} or {@code karaf.etc} system properties.
 * For given key, {@code <key>-keycloak.json} file is checked.
 * @param pathFragment
 * @return
 */
protected synchronized KeycloakDeployment getOrCreateDeployment(String pathFragment) {
    KeycloakDeployment deployment = getCachedDeployment(pathFragment);
    if (null == deployment) {
        // not found on the simple cache, try to load it from the file system
        if (keycloakConfigLocation == null) {
            throw new IllegalStateException("Neither \"keycloak.config\" nor \"karaf.etc\" java properties are set." + " Please set one of them.");
        }
        File configuration = new File(keycloakConfigLocation, pathFragment + ("".equals(pathFragment) ? "" : "-") + "keycloak.json");
        if (!cacheConfiguration(pathFragment, configuration)) {
            throw new IllegalStateException("Not able to read the file " + configuration);
        }
        deployment = getCachedDeployment(pathFragment);
    }
    return deployment;
}
Also used : KeycloakDeployment(org.keycloak.adapters.KeycloakDeployment) File(java.io.File)

Example 43 with KeycloakDeployment

use of org.keycloak.adapters.KeycloakDeployment in project keycloak by keycloak.

the class HierarchicalPathBasedKeycloakConfigResolverTest method newKeycloakDeployment.

private KeycloakDeployment newKeycloakDeployment(String realm) {
    KeycloakDeployment deployment = new KeycloakDeployment();
    deployment.setRealm(realm);
    return deployment;
}
Also used : KeycloakDeployment(org.keycloak.adapters.KeycloakDeployment)

Example 44 with KeycloakDeployment

use of org.keycloak.adapters.KeycloakDeployment in project keycloak by keycloak.

the class AbstractKeycloakAuthenticatorValve method checkKeycloakSession.

/**
 * Checks that access token is still valid.  Will attempt refresh of token if it is not.
 *
 * @param request
 */
protected void checkKeycloakSession(Request request, HttpFacade facade) {
    KeycloakDeployment deployment = deploymentContext.resolveDeployment(facade);
    AdapterTokenStore tokenStore = getTokenStore(request, facade, deployment);
    tokenStore.checkCurrentToken();
}
Also used : KeycloakDeployment(org.keycloak.adapters.KeycloakDeployment) AdapterTokenStore(org.keycloak.adapters.AdapterTokenStore)

Example 45 with KeycloakDeployment

use of org.keycloak.adapters.KeycloakDeployment in project keycloak by keycloak.

the class AbstractKeycloakAuthenticatorValve method authenticateInternal.

protected boolean authenticateInternal(Request request, HttpServletResponse response, Object loginConfig) throws IOException {
    CatalinaHttpFacade facade = new OIDCCatalinaHttpFacade(request, response);
    KeycloakDeployment deployment = deploymentContext.resolveDeployment(facade);
    if (deployment == null || !deployment.isConfigured()) {
        // needed for the EAP6/AS7 adapter relying on the tomcat core adapter
        facade.getResponse().sendError(401);
        return false;
    }
    AdapterTokenStore tokenStore = getTokenStore(request, facade, deployment);
    nodesRegistrationManagement.tryRegister(deployment);
    CatalinaRequestAuthenticator authenticator = createRequestAuthenticator(request, facade, deployment, tokenStore);
    AuthOutcome outcome = authenticator.authenticate();
    if (outcome == AuthOutcome.AUTHENTICATED) {
        if (facade.isEnded()) {
            return false;
        }
        return true;
    }
    AuthChallenge challenge = authenticator.getChallenge();
    if (challenge != null) {
        challenge.challenge(facade);
    }
    return false;
}
Also used : AuthChallenge(org.keycloak.adapters.spi.AuthChallenge) KeycloakDeployment(org.keycloak.adapters.KeycloakDeployment) AuthOutcome(org.keycloak.adapters.spi.AuthOutcome) AdapterTokenStore(org.keycloak.adapters.AdapterTokenStore)

Aggregations

KeycloakDeployment (org.keycloak.adapters.KeycloakDeployment)69 Test (org.junit.Test)21 AbstractKeycloakTest (org.keycloak.testsuite.AbstractKeycloakTest)21 PolicyEnforcer (org.keycloak.adapters.authorization.PolicyEnforcer)20 AuthorizationContext (org.keycloak.AuthorizationContext)16 OIDCHttpFacade (org.keycloak.adapters.OIDCHttpFacade)14 RefreshableKeycloakSecurityContext (org.keycloak.adapters.RefreshableKeycloakSecurityContext)12 AdapterDeploymentContext (org.keycloak.adapters.AdapterDeploymentContext)11 OAuthClient (org.keycloak.testsuite.util.OAuthClient)11 AdapterTokenStore (org.keycloak.adapters.AdapterTokenStore)10 InputStream (java.io.InputStream)9 KeycloakSecurityContext (org.keycloak.KeycloakSecurityContext)9 AuthenticatedActionsHandler (org.keycloak.adapters.AuthenticatedActionsHandler)9 FileInputStream (java.io.FileInputStream)7 FileNotFoundException (java.io.FileNotFoundException)7 HashMap (java.util.HashMap)7 KeycloakConfigResolver (org.keycloak.adapters.KeycloakConfigResolver)6 AuthChallenge (org.keycloak.adapters.spi.AuthChallenge)6 AuthOutcome (org.keycloak.adapters.spi.AuthOutcome)6 List (java.util.List)5