2323import net .ymate .platform .core .lang .BlurObject ;
2424import net .ymate .platform .core .support .IPasswordProcessor ;
2525import net .ymate .platform .core .util .ClassUtils ;
26+ import net .ymate .platform .core .util .RuntimeUtils ;
2627import org .apache .commons .lang .StringUtils ;
2728
29+ import java .util .HashMap ;
2830import java .util .Map ;
31+ import java .util .concurrent .ConcurrentHashMap ;
2932
3033/**
3134 * @author 刘镇 (suninformation@163.com) on 2017/03/27 上午 01:31
@@ -43,6 +46,8 @@ public class DefaultModuleCfg implements IOAuthConnectorModuleCfg {
4346
4447 private IPasswordProcessor __password ;
4548
49+ private Map <String , IOAuthConnectProcessor .ConnectInitCfg > __connectInitCfgs = new ConcurrentHashMap <String , IOAuthConnectProcessor .ConnectInitCfg >();
50+
4651 public DefaultModuleCfg (YMP owner ) {
4752 __moduleCfgs = owner .getConfig ().getModuleConfigs (IOAuthConnector .MODULE_NAME );
4853 //
@@ -68,14 +73,35 @@ public String getCacheNamePrefix() {
6873
6974 @ Override
7075 public IOAuthConnectProcessor .ConnectInitCfg getConnectInitCfg (String name ) throws Exception {
71- String _clientId = __moduleCfgs .get (name + ".client_id" );
72- String _clientSecret = __moduleCfgs .get (name + ".client_secret" );
73- if (StringUtils .isBlank (_clientId ) || StringUtils .isBlank (_clientSecret )) {
74- return null ;
75- } else if (__isPasswordEncrypted && __password != null ) {
76- _clientSecret = __password .decrypt (_clientSecret );
76+ IOAuthConnectProcessor .ConnectInitCfg _initCfg = __connectInitCfgs .get (name );
77+ if (_initCfg == null ) {
78+ String _clientId = null ;
79+ String _clientSecret = null ;
80+ String _redirectUrl = null ;
81+ //
82+ Map <String , String > _attributes = new HashMap <String , String >();
83+ Map <String , String > _cfgMap = RuntimeUtils .keyStartsWith (__moduleCfgs , name + "." );
84+ for (Map .Entry <String , String > _entry : _cfgMap .entrySet ()) {
85+ if ("client_id" .equalsIgnoreCase (_entry .getKey ())) {
86+ _clientId = _entry .getValue ();
87+ } else if ("client_secret" .equalsIgnoreCase (_entry .getValue ())) {
88+ _clientSecret = _entry .getValue ();
89+ } else if ("redirect_uri" .equalsIgnoreCase (_entry .getValue ())) {
90+ _redirectUrl = _entry .getValue ();
91+ } else {
92+ _attributes .put (_entry .getKey (), _entry .getValue ());
93+ }
94+ }
95+ if (StringUtils .isBlank (_clientId ) && StringUtils .isBlank (_clientSecret )) {
96+ if (__isPasswordEncrypted && __password != null ) {
97+ _clientSecret = __password .decrypt (_clientSecret );
98+ }
99+ _initCfg = new IOAuthConnectProcessor .ConnectInitCfg (name , _clientId , _clientSecret , _redirectUrl , _attributes );
100+ //
101+ __connectInitCfgs .put (name , _initCfg );
102+ }
77103 }
78- return new IOAuthConnectProcessor . ConnectInitCfg ( name , _clientId , _clientSecret , __moduleCfgs . get ( name + ".redirect_uri" )) ;
104+ return _initCfg ;
79105 }
80106
81107 @ Override
0 commit comments