Search in sources :

Example 16 with Client

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

the class EndSessionRestWebServiceImpl method getRpFrontchannelLogoutUris.

private Set<String> getRpFrontchannelLogoutUris(Pair<SessionState, AuthorizationGrant> pair) {
    final Set<String> result = Sets.newHashSet();
    SessionState sessionState = pair.getFirst();
    AuthorizationGrant authorizationGrant = pair.getSecond();
    if (sessionState == null) {
        log.error("session_state is not passed to endpoint (as cookie or manually). Therefore unable to match clients for session_state." + "Http based html will contain no iframes.");
        return result;
    }
    final Set<Client> clientsByDns = sessionState.getPermissionGrantedMap() != null ? clientService.getClient(sessionState.getPermissionGrantedMap().getClientIds(true), true) : Sets.<Client>newHashSet();
    if (authorizationGrant != null) {
        clientsByDns.add(authorizationGrant.getClient());
    }
    for (Client client : clientsByDns) {
        String[] logoutUris = client.getFrontChannelLogoutUri();
        if (logoutUris == null) {
            continue;
        }
        for (String logoutUri : logoutUris) {
            if (Util.isNullOrEmpty(logoutUri)) {
                // skip client if logout_uri is blank
                continue;
            }
            if (client.getFrontChannelLogoutSessionRequired() != null && client.getFrontChannelLogoutSessionRequired()) {
                if (logoutUri.contains("?")) {
                    logoutUri = logoutUri + "&sid=" + sessionState.getId();
                } else {
                    logoutUri = logoutUri + "?sid=" + sessionState.getId();
                }
            }
            result.add(logoutUri);
        }
    }
    return result;
}
Also used : SessionState(org.xdi.oxauth.model.common.SessionState) Client(org.xdi.oxauth.model.registration.Client) AuthorizationGrant(org.xdi.oxauth.model.common.AuthorizationGrant)

Example 17 with Client

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

the class CleanUpClientTest method cleanUpClient.

@Test
@Parameters(value = "usedClients")
public void cleanUpClient(String usedClients) {
    Assert.assertNotNull(usedClients);
    List<String> usedClientsList = Arrays.asList(StringHelper.split(usedClients, ",", true, false));
    output("Used clients: " + usedClientsList);
    int clientsResultSetSize = 50;
    int countResults = 0;
    int countRemoved = 0;
    boolean existsMoreClients = true;
    while (existsMoreClients && countResults < 10000) {
        List<Client> clients = clientService.getAllClients(new String[] { "inum" }, clientsResultSetSize);
        existsMoreClients = clients.size() == clientsResultSetSize;
        countResults += clients.size();
        Assert.assertNotNull(clients);
        output("Found clients: " + clients.size());
        output("Total clients: " + countResults);
        for (Client client : clients) {
            String clientId = client.getClientId();
            if (!usedClientsList.contains(clientId)) {
                try {
                    clientService.remove(client);
                } catch (EntryPersistenceException ex) {
                    output("Failed to remove client: " + ex.getMessage());
                }
                countRemoved++;
            }
        }
    }
    output("Removed clients: " + countRemoved);
}
Also used : EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) Client(org.xdi.oxauth.model.registration.Client) Parameters(org.testng.annotations.Parameters) BaseComponentTest(org.xdi.oxauth.BaseComponentTest) Test(org.testng.annotations.Test)

Example 18 with Client

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

the class AuthenticationService method configureSessionClient.

public void configureSessionClient() {
    String clientInum = credentials.getUsername();
    log.debug("ConfigureSessionClient: username: '{}', credentials: '{}'", clientInum, System.identityHashCode(credentials));
    Client client = clientService.getClient(clientInum);
    configureSessionClient(client);
}
Also used : Client(org.xdi.oxauth.model.registration.Client) SessionClient(org.xdi.oxauth.model.session.SessionClient)

Example 19 with Client

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

the class CleanerTimer method processRegisteredClients.

private void processRegisteredClients() {
    log.debug("Start Client clean up");
    BatchOperation<Client> clientBatchService = new BatchOperation<Client>(ldapEntryManager) {

        @Override
        protected List<Client> getChunkOrNull(int chunkSize) {
            return clientService.getClientsWithExpirationDate(this, chunkSize, chunkSize);
        }

        @Override
        protected void performAction(List<Client> entries) {
            for (Client client : entries) {
                try {
                    GregorianCalendar now = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
                    GregorianCalendar expirationDate = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
                    expirationDate.setTime(client.getClientSecretExpiresAt());
                    if (expirationDate.before(now)) {
                        List<AuthorizationGrant> toRemove = authorizationGrantList.getAuthorizationGrant(client.getClientId());
                        authorizationGrantList.removeAuthorizationGrants(toRemove);
                        log.debug("Removing Client: {}, Expiration date: {}", client.getClientId(), client.getClientSecretExpiresAt());
                        clientService.remove(client);
                    }
                } catch (Exception e) {
                    log.error("Failed to remove entry", e);
                }
            }
        }
    };
    clientBatchService.iterateAllByChunks(BATCH_SIZE);
    log.debug("End Client clean up");
}
Also used : AuthorizationGrantList(org.xdi.oxauth.model.common.AuthorizationGrantList) BatchOperation(org.gluu.site.ldap.persistence.BatchOperation) Client(org.xdi.oxauth.model.registration.Client) AuthorizationGrant(org.xdi.oxauth.model.common.AuthorizationGrant)

Example 20 with Client

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

the class ClientService method authenticate.

/**
     * Authenticate client.
     *
     * @param clientId Client inum.
     * @param password Client password.
     * @return <code>true</code> if success, otherwise <code>false</code>.
     */
public boolean authenticate(String clientId, String password) {
    log.debug("Authenticating Client with LDAP: clientId = {}", clientId);
    boolean authenticated = false;
    try {
        Client client = getClient(clientId);
        String decryptedClientSecret = decryptSecret(client.getClientSecret());
        authenticated = client != null && decryptedClientSecret != null && decryptedClientSecret.equals(password);
    } catch (StringEncrypter.EncryptionException e) {
        log.error(e.getMessage(), e);
    }
    return authenticated;
}
Also used : EncryptionException(org.xdi.util.security.StringEncrypter.EncryptionException) Client(org.xdi.oxauth.model.registration.Client) StringEncrypter(org.xdi.util.security.StringEncrypter)

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