Search in sources :

Example 6 with Client

use of org.xdi.oxauth.model.registration.Client in project oxAuth by GluuFederation.

the class MemcacheManual method testClient.

private static Client testClient() {
    Client client = new Client();
    client.setClientId(UUID.randomUUID().toString());
    return client;
}
Also used : MemcachedClient(net.spy.memcached.MemcachedClient) Client(org.xdi.oxauth.model.registration.Client)

Example 7 with Client

use of org.xdi.oxauth.model.registration.Client in project oxAuth by GluuFederation.

the class PermissionService method registerPermission.

private String registerPermission(UmaRPT p_rpt, ResourceSet p_resource, List<RsScopeType> p_scopes) {
    final Date expirationDate = rptExpirationDate();
    final UmaPermission r = new UmaPermission();
    r.setResourceSetId(p_resource.getId());
    r.setExpiresAt(expirationDate);
    final String host = appConfiguration.getIssuer();
    final ResourceSetPermission permission = resourceSetPermissionManager.createResourceSetPermission(host, r, expirationDate);
    // IMPORTANT : set scope dns before persistence
    permission.setScopeDns(umaRsResourceService.getScopeDns(p_scopes));
    final Client client = clientService.getClient(p_rpt.getClientId());
    resourceSetPermissionManager.addResourceSetPermission(permission, client.getDn());
    return permission.getTicket();
}
Also used : UmaPermission(org.xdi.oxauth.model.uma.UmaPermission) ResourceSetPermission(org.xdi.oxauth.model.uma.persistence.ResourceSetPermission) Client(org.xdi.oxauth.model.registration.Client) Date(java.util.Date)

Example 8 with Client

use of org.xdi.oxauth.model.registration.Client in project oxAuth by GluuFederation.

the class RedirectionUriService method validatePostLogoutRedirectUri.

public String validatePostLogoutRedirectUri(SessionState sessionState, String postLogoutRedirectUri) {
    if (Strings.isNullOrEmpty(postLogoutRedirectUri) || (sessionState == null)) {
        errorResponseFactory.throwBadRequestException(EndSessionErrorResponseType.INVALID_REQUEST);
        return null;
    }
    final Set<Client> clientsByDns = sessionState.getPermissionGrantedMap() != null ? clientService.getClient(sessionState.getPermissionGrantedMap().getClientIds(true), true) : Sets.<Client>newHashSet();
    log.trace("Validating post logout redirect URI: postLogoutRedirectUri = {}", postLogoutRedirectUri);
    for (Client client : clientsByDns) {
        String[] postLogoutRedirectUris = client.getPostLogoutRedirectUris();
        if (postLogoutRedirectUris == null) {
            continue;
        }
        for (String uri : postLogoutRedirectUris) {
            log.debug("Comparing {} == {}, clientId: {}", uri, postLogoutRedirectUri, client.getClientId());
            if (uri.equals(postLogoutRedirectUri)) {
                return postLogoutRedirectUri;
            }
        }
    }
    errorResponseFactory.throwBadRequestException(EndSessionErrorResponseType.INVALID_REQUEST);
    return null;
}
Also used : Client(org.xdi.oxauth.model.registration.Client)

Example 9 with Client

use of org.xdi.oxauth.model.registration.Client in project oxAuth by GluuFederation.

the class ClientService method getClient.

public Client getClient(String clientId) {
    if (clientId != null && !clientId.isEmpty()) {
        Client result = getClientByDn(buildClientDn(clientId));
        log.debug("Found {} entries for client id = {}", result != null ? 1 : 0, clientId);
        return result;
    }
    return null;
}
Also used : Client(org.xdi.oxauth.model.registration.Client)

Example 10 with Client

use of org.xdi.oxauth.model.registration.Client in project oxAuth by GluuFederation.

the class AuthenticationFilter method processPostAuth.

private void processPostAuth(ClientService clientService, ClientFilterService clientFilterService, ErrorResponseFactory errorResponseFactory, HttpServletRequest servletRequest, HttpServletResponse servletResponse, FilterChain filterChain) {
    try {
        String clientId = "";
        String clientSecret = "";
        boolean isExistUserPassword = false;
        if (StringHelper.isNotEmpty(servletRequest.getParameter("client_id")) && StringHelper.isNotEmpty(servletRequest.getParameter("client_secret"))) {
            clientId = servletRequest.getParameter("client_id");
            clientSecret = servletRequest.getParameter("client_secret");
            isExistUserPassword = true;
        }
        log.trace("isExistUserPassword: {}", isExistUserPassword);
        boolean requireAuth = !StringHelper.equals(clientId, identity.getCredentials().getUsername()) || !identity.isLoggedIn();
        log.debug("requireAuth: '{}'", requireAuth);
        if (requireAuth) {
            if (isExistUserPassword) {
                Client client = clientService.getClient(clientId);
                if (client != null && AuthenticationMethod.CLIENT_SECRET_POST == client.getAuthenticationMethod()) {
                    // Identity.username and user isn't authenticated
                    if (!clientId.equals(identity.getCredentials().getUsername()) || !identity.isLoggedIn()) {
                        identity.logout();
                        identity.getCredentials().setUsername(clientId);
                        identity.getCredentials().setPassword(clientSecret);
                        requireAuth = !authenticator.authenticateWebService();
                    } else {
                        authenticator.configureSessionClient(client);
                    }
                }
            } else if (Boolean.TRUE.equals(appConfiguration.getClientAuthenticationFiltersEnabled())) {
                String clientDn = clientFilterService.processAuthenticationFilters(servletRequest.getParameterMap());
                if (clientDn != null) {
                    Client client = clientService.getClientByDn(clientDn);
                    identity.logout();
                    identity.getCredentials().setUsername(client.getClientId());
                    identity.getCredentials().setPassword(null);
                    requireAuth = !authenticator.authenticateWebService(true);
                }
            }
        }
        if (!requireAuth) {
            filterChain.doFilter(servletRequest, servletResponse);
            return;
        }
        if (requireAuth && !identity.isLoggedIn()) {
            sendError(servletResponse);
        }
    } catch (ServletException ex) {
        log.error("Post authentication failed: {}", ex);
    } catch (IOException ex) {
        log.error("Post authentication failed: {}", ex);
    } catch (Exception ex) {
        log.error("Post authentication failed: {}", ex);
    }
}
Also used : ServletException(javax.servlet.ServletException) IOException(java.io.IOException) Client(org.xdi.oxauth.model.registration.Client) ServletException(javax.servlet.ServletException) InvalidJwtException(org.xdi.oxauth.model.exception.InvalidJwtException) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

Client (org.xdi.oxauth.model.registration.Client)25 Date (java.util.Date)5 OAuth2AuditLog (org.xdi.oxauth.model.audit.OAuth2AuditLog)5 InvalidJwtException (org.xdi.oxauth.model.exception.InvalidJwtException)5 StringEncrypter (org.xdi.util.security.StringEncrypter)5 JSONException (org.codehaus.jettison.json.JSONException)4 EntryPersistenceException (org.gluu.site.ldap.persistence.exception.EntryPersistenceException)4 AuthorizationGrant (org.xdi.oxauth.model.common.AuthorizationGrant)4 User (org.xdi.oxauth.model.common.User)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 WebApplicationException (javax.ws.rs.WebApplicationException)3 Test (org.testng.annotations.Test)3 Prompt (org.xdi.oxauth.model.common.Prompt)3 SessionState (org.xdi.oxauth.model.common.SessionState)3 IOException (java.io.IOException)2 URI (java.net.URI)2 SignatureException (java.security.SignatureException)2 GregorianCalendar (java.util.GregorianCalendar)2 ServletException (javax.servlet.ServletException)2 Response (javax.ws.rs.core.Response)2