use of org.pac4j.core.client.Client in project pac4j by pac4j.
the class DefaultCallbackClientFinder method find.
public List<Client> find(final Clients clients, final WebContext context, final String clientNames) {
final List<Client> result = new ArrayList<>();
final List<Client> indirectClients = new ArrayList<>();
for (final Client client : clients.findAllClients()) {
if (client instanceof IndirectClient) {
final IndirectClient indirectClient = (IndirectClient) client;
indirectClients.add(client);
indirectClient.init();
if (indirectClient.getCallbackUrlResolver().matches(indirectClient.getName(), context)) {
result.add(indirectClient);
}
}
}
logger.debug("result: {}", result.stream().map(c -> c.getName()).collect(Collectors.toList()));
// fallback: we didn't find any client on the URL
if (result.isEmpty()) {
// we have a default client, use it
if (CommonHelper.isNotBlank(clientNames)) {
final Client defaultClient = clients.findClient(clientNames);
logger.debug("Defaulting to the configured client: {}", defaultClient);
result.add(defaultClient);
// or we only have one indirect client, use it
} else if (indirectClients.size() == 1) {
logger.debug("Defaulting to the only client: {}", indirectClients.get(0));
result.addAll(indirectClients);
}
}
return result;
}
use of org.pac4j.core.client.Client in project pac4j by pac4j.
the class DefaultSecurityClientFinder method find.
public List<Client> find(final Clients clients, final WebContext context, final String clientNames) {
final List<Client> result = new ArrayList<>();
String securityClientNames = clientNames;
// we don't have defined clients to secure the URL, use the general default security ones from the Clients if they exist
// we check the nullity and not the blankness to allow the blank string to mean no client
// so no clients parameter -> use the default security ones; clients=blank string -> no clients defined
logger.debug("Provided clientNames: {}", securityClientNames);
if (clientNames == null) {
securityClientNames = clients.getDefaultSecurityClients();
logger.debug("Default security clients: {}", securityClientNames);
// still no clients defined and we only have one client, use it
if (securityClientNames == null && clients.findAllClients().size() == 1) {
securityClientNames = clients.getClients().get(0).getName();
logger.debug("Only client: {}", securityClientNames);
}
}
if (CommonHelper.isNotBlank(securityClientNames)) {
final List<String> names = Arrays.asList(securityClientNames.split(Pac4jConstants.ELEMENT_SEPRATOR));
// if a "client_name" parameter is provided on the request, get the client
// and check if it is allowed (defined in the list of the clients)
final String clientNameOnRequest = context.getRequestParameter(clientNameParameter);
logger.debug("clientNameOnRequest: {}", clientNameOnRequest);
if (clientNameOnRequest != null) {
// from the request
final Client client = clients.findClient(clientNameOnRequest);
final String nameFound = client.getName();
// if allowed -> return it
boolean found = false;
for (final String name : names) {
if (CommonHelper.areEqualsIgnoreCaseAndTrim(name, nameFound)) {
result.add(client);
found = true;
break;
}
}
if (!found) {
throw new TechnicalException("Client not allowed: " + nameFound);
}
} else {
// no client provided, return all
for (final String name : names) {
// from its name
final Client client = clients.findClient(name);
result.add(client);
}
}
}
logger.debug("result: {}", result.stream().map(c -> c.getName()).collect(Collectors.toList()));
return result;
}
use of org.pac4j.core.client.Client in project pac4j by pac4j.
the class DefaultCallbackLogic method renewSession.
protected void renewSession(final C context, final Config config) {
final SessionStore<C> sessionStore = context.getSessionStore();
if (sessionStore != null) {
final String oldSessionId = sessionStore.getOrCreateSessionId(context);
final boolean renewed = sessionStore.renewSession(context);
if (renewed) {
final String newSessionId = sessionStore.getOrCreateSessionId(context);
logger.debug("Renewing session: {} -> {}", oldSessionId, newSessionId);
final Clients clients = config.getClients();
if (clients != null) {
final List<Client> clientList = clients.getClients();
for (final Client client : clientList) {
final BaseClient baseClient = (BaseClient) client;
baseClient.notifySessionRenewal(oldSessionId, context);
}
}
} else {
logger.error("Unable to renew the session. The session store may not support this feature");
}
} else {
logger.error("No session store available for this web context");
}
}
use of org.pac4j.core.client.Client in project pac4j by pac4j.
the class DefaultSecurityClientFinderTests method internalTestNoClientOnRequestList.
private void internalTestNoClientOnRequestList(final String names) {
final MockIndirectClient client1 = new MockIndirectClient(NAME, RedirectAction.redirect(LOGIN_URL), (Credentials) null, new CommonProfile());
final MockIndirectClient client2 = new MockIndirectClient(CLIENT_NAME, RedirectAction.redirect(LOGIN_URL), (Credentials) null, new CommonProfile());
final Clients clients = new Clients(client1, client2);
final WebContext context = MockWebContext.create();
final List<Client> currentClients = finder.find(clients, context, names);
assertEquals(2, currentClients.size());
assertEquals(client2, currentClients.get(0));
assertEquals(client1, currentClients.get(1));
}
use of org.pac4j.core.client.Client in project pac4j by pac4j.
the class DefaultSecurityClientFinderTests method testBlankClientName.
@Test
public void testBlankClientName() {
final List<Client> currentClients = finder.find(new Clients(), MockWebContext.create(), " ");
assertEquals(0, currentClients.size());
}
Aggregations