Commit c690c225 authored by Matija Obreza's avatar Matija Obreza
Browse files

Merge branch 'oauth_clientid_suffix' into 'main'

OAuth clientIdSuffix from base url

See merge request genesys-pgr/application-blocks!111
parents 052b5e6a e82c2be1
......@@ -15,6 +15,7 @@
*/
package org.genesys.blocks.oauth.service;
import java.net.URL;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
......@@ -30,6 +31,7 @@ import org.genesys.blocks.oauth.persistence.OAuthClientRepository;
import org.genesys.blocks.security.service.impl.CustomAclServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.Cache;
......@@ -55,14 +57,18 @@ import com.querydsl.core.types.Predicate;
*/
@Service
@Transactional(readOnly = true)
public class OAuthServiceImpl implements OAuthClientDetailsService {
public class OAuthServiceImpl implements OAuthClientDetailsService, InitializingBean {
/** The Constant LOG. */
private static final Logger LOG = LoggerFactory.getLogger(OAuthServiceImpl.class);
/** The site URL. */
@Value("${base.url:#{null}}")
private String baseUrl;
/** The hostname. */
@Value("${host.name}")
private String hostname;
@Value("${oauth.clientId.suffix:#{null}}")
private String clientIdSuffix;
/** The oauth client repository. */
@Autowired
......@@ -76,6 +82,18 @@ public class OAuthServiceImpl implements OAuthClientDetailsService {
@Autowired(required = false)
private CacheManager cacheManager;
@Override
public void afterPropertiesSet() throws Exception {
if (StringUtils.isEmpty(clientIdSuffix)) {
if (StringUtils.isNotEmpty(baseUrl)) {
var siteUrl = new URL(baseUrl);
clientIdSuffix = siteUrl.getHost();
} else {
clientIdSuffix = "localhost";
}
}
}
/*
* (non-Javadoc)
* @see org.springframework.security.oauth2.provider.ClientDetailsService#
......@@ -153,7 +171,7 @@ public class OAuthServiceImpl implements OAuthClientDetailsService {
@Override
@Transactional
public OAuthClient addClient(OAuthClient client) {
final String clientId = RandomStringUtils.randomAlphanumeric(5).toLowerCase() + "." + RandomStringUtils.randomAlphanumeric(20).toLowerCase() + "@" + hostname;
final String clientId = RandomStringUtils.randomAlphanumeric(5).toLowerCase() + "." + RandomStringUtils.randomAlphanumeric(20).toLowerCase() + "@" + clientIdSuffix;
final String clientSecret = RandomStringUtils.randomAlphanumeric(32);
final OAuthClient newClient = new OAuthClient();
......
host.name=localhost:8080
oauth.clientId.suffix=junit
# Database connection
db.url=jdbc:hsqldb:mem:test;sql.syntax_mys=true;sql.ignore_case=true
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment