Search in sources :

Example 21 with Client

use of io.jans.as.common.model.registration.Client in project jans by JanssenProject.

the class AuthenticationService method configureSessionClient.

public Client configureSessionClient() {
    String clientInum = credentials.getUsername();
    log.debug("ConfigureSessionClient: username: '{}', credentials: '{}'", clientInum, System.identityHashCode(credentials));
    Client client = clientService.getClient(clientInum);
    configureSessionClient(client);
    return client;
}
Also used : Client(io.jans.as.common.model.registration.Client) SessionClient(io.jans.as.server.model.session.SessionClient)

Example 22 with Client

use of io.jans.as.common.model.registration.Client in project jans by JanssenProject.

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);
        if (client == null) {
            log.debug("Failed to find client = {}", clientId);
            return authenticated;
        }
        String decryptedClientSecret = decryptSecret(client.getClientSecret());
        authenticated = decryptedClientSecret != null && decryptedClientSecret.equals(password);
    } catch (StringEncrypter.EncryptionException e) {
        log.error(e.getMessage(), e);
    }
    return authenticated;
}
Also used : EncryptionException(io.jans.util.security.StringEncrypter.EncryptionException) Client(io.jans.as.common.model.registration.Client) StringEncrypter(io.jans.util.security.StringEncrypter)

Example 23 with Client

use of io.jans.as.common.model.registration.Client in project jans by JanssenProject.

the class ClientsResource method patchClient.

@PATCH
@Consumes(MediaType.APPLICATION_JSON_PATCH_JSON)
@ProtectedApi(scopes = { ApiAccessConstants.OPENID_CLIENTS_WRITE_ACCESS })
@Path(ApiConstants.INUM_PATH)
public Response patchClient(@PathParam(ApiConstants.INUM) @NotNull String inum, @NotNull String pathString) throws JsonPatchException, IOException {
    if (logger.isDebugEnabled()) {
        logger.debug("Client details to be patched - inum:{}, pathString:{}", escapeLog(inum), escapeLog(pathString));
    }
    Client existingClient = clientService.getClientByInum(inum);
    checkResourceNotNull(existingClient, OPENID_CONNECT_CLIENT);
    existingClient = Jackson.applyPatch(pathString, existingClient);
    clientService.updateClient(existingClient);
    return Response.ok(existingClient).build();
}
Also used : Client(io.jans.as.common.model.registration.Client) ProtectedApi(io.jans.configapi.core.rest.ProtectedApi)

Example 24 with Client

use of io.jans.as.common.model.registration.Client in project jans by JanssenProject.

the class ClientsResource method getOpenIdClientByInum.

@GET
@ProtectedApi(scopes = { ApiAccessConstants.OPENID_CLIENTS_READ_ACCESS })
@Path(ApiConstants.INUM_PATH)
public Response getOpenIdClientByInum(@PathParam(ApiConstants.INUM) @NotNull String inum) {
    if (logger.isDebugEnabled()) {
        logger.debug("Client serach by inum:{}", escapeLog(inum));
    }
    Client client = clientService.getClientByInum(inum);
    checkResourceNotNull(client, OPENID_CONNECT_CLIENT);
    return Response.ok(client).build();
}
Also used : Client(io.jans.as.common.model.registration.Client) ProtectedApi(io.jans.configapi.core.rest.ProtectedApi)

Example 25 with Client

use of io.jans.as.common.model.registration.Client in project jans by JanssenProject.

the class ClientsResource method createOpenIdConnect.

@POST
@ProtectedApi(scopes = { ApiAccessConstants.OPENID_CLIENTS_WRITE_ACCESS })
public Response createOpenIdConnect(@Valid Client client) throws NoSuchAlgorithmException, EncryptionException {
    if (logger.isDebugEnabled()) {
        logger.debug("Client details to be added - client:{}", escapeLog(client));
    }
    String inum = client.getClientId();
    if (inum == null || inum.isEmpty() || inum.isBlank()) {
        inum = inumService.generateClientInum();
        client.setClientId(inum);
    }
    checkNotNull(client.getClientName(), AttributeNames.DISPLAY_NAME);
    String clientSecret = client.getClientSecret();
    if (StringHelper.isEmpty(clientSecret)) {
        clientSecret = generatePassword();
    }
    client.setClientSecret(encryptionService.encrypt(clientSecret));
    client.setDn(clientService.getDnForClient(inum));
    client.setDeletable(client.getClientSecretExpiresAt() != null);
    clientService.addClient(client);
    Client result = clientService.getClientByInum(inum);
    result.setClientSecret(encryptionService.decrypt(result.getClientSecret()));
    return Response.status(Response.Status.CREATED).entity(result).build();
}
Also used : Client(io.jans.as.common.model.registration.Client) ProtectedApi(io.jans.configapi.core.rest.ProtectedApi)

Aggregations

Client (io.jans.as.common.model.registration.Client)70 WebApplicationException (javax.ws.rs.WebApplicationException)20 InvalidJwtException (io.jans.as.model.exception.InvalidJwtException)12 JSONObject (org.json.JSONObject)12 Test (org.testng.annotations.Test)12 User (io.jans.as.common.model.common.User)11 BaseComponentTest (io.jans.as.server.BaseComponentTest)10 Calendar (java.util.Calendar)10 GregorianCalendar (java.util.GregorianCalendar)10 IOException (java.io.IOException)9 OAuth2AuditLog (io.jans.as.server.model.audit.OAuth2AuditLog)8 AuthorizationGrant (io.jans.as.server.model.common.AuthorizationGrant)8 ExecutionContext (io.jans.as.server.model.common.ExecutionContext)8 JSONException (org.json.JSONException)8 Jwt (io.jans.as.model.jwt.Jwt)7 Response (javax.ws.rs.core.Response)7 SessionClient (io.jans.as.server.model.session.SessionClient)6 ProtectedApi (io.jans.configapi.core.rest.ProtectedApi)6 ServletException (javax.servlet.ServletException)6 SignatureAlgorithm (io.jans.as.model.crypto.signature.SignatureAlgorithm)5