implemented simple static configuration services
parent
f44c704472
commit
1251082c6d
|
@ -0,0 +1,61 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.mitre.openid.connect.client.service.impl;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.mitre.openid.connect.client.service.ClientConfigurationService;
|
||||||
|
import org.springframework.beans.factory.InitializingBean;
|
||||||
|
import org.springframework.security.oauth2.provider.ClientDetails;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Client configuration service that holds a static map from issuer URL to a ClientDetails object to use at that issuer.
|
||||||
|
*
|
||||||
|
* Designed to be configured as a bean.
|
||||||
|
*
|
||||||
|
* @author jricher
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class StaticClientConfigurationService implements ClientConfigurationService, InitializingBean {
|
||||||
|
|
||||||
|
// Map of issuer URL -> client configuration information
|
||||||
|
private Map<String, ClientDetails> clients;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the clients
|
||||||
|
*/
|
||||||
|
public Map<String, ClientDetails> getClients() {
|
||||||
|
return clients;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param clients the clients to set
|
||||||
|
*/
|
||||||
|
public void setClients(Map<String, ClientDetails> clients) {
|
||||||
|
this.clients = clients;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the client configured for this issuer
|
||||||
|
*
|
||||||
|
* @see org.mitre.openid.connect.client.service.ClientConfigurationService#getClientConfiguration(java.lang.String)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public ClientDetails getClientConfiguration(String issuer) {
|
||||||
|
|
||||||
|
return clients.get(issuer);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void afterPropertiesSet() throws Exception {
|
||||||
|
if (clients == null || clients.isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("Clients map cannot be null or empty");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,56 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.mitre.openid.connect.client.service.impl;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.mitre.openid.connect.client.service.ServerConfigurationService;
|
||||||
|
import org.mitre.openid.connect.config.ServerConfiguration;
|
||||||
|
import org.springframework.beans.factory.InitializingBean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Statically configured server configuration service that maps issuer URLs to server configurations to use at that issuer.
|
||||||
|
*
|
||||||
|
* @author jricher
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class StaticServerConfigurationService implements ServerConfigurationService, InitializingBean {
|
||||||
|
|
||||||
|
// map of issuer url -> server configuration information
|
||||||
|
private Map<String, ServerConfiguration> servers;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the servers
|
||||||
|
*/
|
||||||
|
public Map<String, ServerConfiguration> getServers() {
|
||||||
|
return servers;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param servers the servers to set
|
||||||
|
*/
|
||||||
|
public void setServers(Map<String, ServerConfiguration> servers) {
|
||||||
|
this.servers = servers;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.mitre.openid.connect.client.service.ServerConfigurationService#getServerConfiguration(java.lang.String)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public ServerConfiguration getServerConfiguration(String issuer) {
|
||||||
|
return servers.get(issuer);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void afterPropertiesSet() throws Exception {
|
||||||
|
if (servers == null || servers.isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("Servers map cannot be null or empty.");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,57 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.mitre.openid.connect.client.service.impl;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
|
import org.mitre.openid.connect.client.service.IssuerService;
|
||||||
|
import org.springframework.beans.factory.InitializingBean;
|
||||||
|
|
||||||
|
import com.google.common.base.Strings;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author jricher
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class StaticSingleIssuerService implements IssuerService, InitializingBean {
|
||||||
|
|
||||||
|
private String issuer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the issuer
|
||||||
|
*/
|
||||||
|
public String getIssuer() {
|
||||||
|
return issuer;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param issuer the issuer to set
|
||||||
|
*/
|
||||||
|
public void setIssuer(String issuer) {
|
||||||
|
this.issuer = issuer;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Always returns the configured issuer URL
|
||||||
|
*
|
||||||
|
* @see org.mitre.openid.connect.client.service.IssuerService#getIssuer(javax.servlet.http.HttpServletRequest)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getIssuer(HttpServletRequest request) {
|
||||||
|
return getIssuer();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void afterPropertiesSet() throws Exception {
|
||||||
|
|
||||||
|
if (Strings.isNullOrEmpty(issuer)) {
|
||||||
|
throw new IllegalArgumentException("Issuer must not be null or empty.");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue