Skip to content

Commit e0d934e

Browse files
committed
1 parent 4ebfd7a commit e0d934e

26 files changed

Lines changed: 296 additions & 15 deletions

src/main/java/act/Act.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
import act.app.*;
2424
import act.app.event.AppEventId;
25-
import act.app.util.AppCrypto;
25+
import act.crypto.AppCrypto;
2626
import act.app.util.NamedPort;
2727
import act.boot.BootstrapClassLoader;
2828
import act.boot.PluginClassProvider;

src/main/java/act/app/App.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import act.app.data.BinderManager;
2727
import act.app.data.StringValueResolverManager;
2828
import act.app.event.AppEventId;
29-
import act.app.util.AppCrypto;
29+
import act.crypto.AppCrypto;
3030
import act.app.util.NamedPort;
3131
import act.boot.BootstrapClassLoader;
3232
import act.boot.app.BlockIssueSignal;

src/main/java/act/conf/Config.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,11 @@ public <T> T getIgnoreCase(String key) {
200200
return null;
201201
}
202202

203-
public Map rawConfiguration() {
203+
public Map<String, Object> rawConfiguration() {
204204
return raw;
205205
}
206206

207-
public Map subSet(String prefix) {
207+
public Map<String, Object> subSet(String prefix) {
208208
String prefix2 = "act." + prefix;
209209
Map<String, Object> subset = C.newMap();
210210
for (String key : raw.keySet()) {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package act.app.util;
1+
package act.crypto;
22

33
/*-
44
* #%L

src/main/java/act/crypto/HMAC.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package act.crypto;
2+
3+
/*-
4+
* #%L
5+
* ACT Framework
6+
* %%
7+
* Copyright (C) 2014 - 2017 ActFramework
8+
* %%
9+
* Licensed under the Apache License, Version 2.0 (the "License");
10+
* you may not use this file except in compliance with the License.
11+
* You may obtain a copy of the License at
12+
*
13+
* http://www.apache.org/licenses/LICENSE-2.0
14+
*
15+
* Unless required by applicable law or agreed to in writing, software
16+
* distributed under the License is distributed on an "AS IS" BASIS,
17+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
* See the License for the specific language governing permissions and
19+
* limitations under the License.
20+
* #L%
21+
*/
22+
23+
public class HMAC {
24+
}

src/main/java/act/data/SObjectResolver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public SObject resolve(String value) {
8080
try {
8181
return resolveFromBase64(value);
8282
} catch (Exception e) {
83-
Act.LOGGER.warn(S.concat("Cannot resolve SObject from value", value));
83+
Act.LOGGER.warn(S.concat("Cannot resolve SObject from value: ", value));
8484
return null;
8585
}
8686
}

src/main/java/act/inject/ActProviders.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import act.Act;
2424
import act.app.ActionContext;
2525
import act.app.App;
26-
import act.app.util.AppCrypto;
26+
import act.crypto.AppCrypto;
2727
import act.cli.CliContext;
2828
import act.cli.CliOverHttpContext;
2929
import act.cli.CliSession;

src/main/java/act/inject/genie/GenieProviders.java

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,28 @@
2020
* #L%
2121
*/
2222

23+
import act.Act;
2324
import act.app.App;
2425
import act.app.AppClassLoader;
26+
import act.conf.AppConfig;
27+
import act.inject.DependencyInjector;
2528
import act.util.ClassNode;
2629
import org.osgl.$;
2730
import org.osgl.Osgl;
31+
import org.osgl.inject.BeanSpec;
32+
import org.osgl.inject.InjectException;
2833
import org.osgl.inject.loader.AnnotatedElementLoader;
2934
import org.osgl.inject.loader.ConfigurationValueLoader;
3035
import org.osgl.inject.loader.TypedElementLoader;
3136
import org.osgl.util.C;
37+
import org.osgl.util.S;
3238

3339
import javax.inject.Provider;
3440
import java.lang.annotation.Annotation;
41+
import java.lang.reflect.Type;
42+
import java.util.Collection;
3543
import java.util.List;
44+
import java.util.Map;
3645

3746
/**
3847
* Integrate Genie with ActFramework
@@ -80,10 +89,74 @@ private GenieProviders() {
8089
@Override
8190
public ConfigurationValueLoader get() {
8291
return new ConfigurationValueLoader() {
92+
93+
@Override
94+
public Object get() {
95+
final AppConfig appConfig = app().config();
96+
DependencyInjector injector = Act.injector();
97+
final String confKey = value().toString();
98+
boolean isImpl = confKey.endsWith(".impl");
99+
if (this.spec.isInstanceOf(Map.class)) {
100+
String prefix = confKey.toString();
101+
Map<String, Object> confMap = appConfig.subSet(prefix);
102+
Map retVal = (Map) injector.get(spec.rawType());
103+
List<Type> typeParams = spec.typeParams();
104+
Type valType = null != typeParams && typeParams.size() > 1 ? typeParams.get(1) : Object.class;
105+
BeanSpec valSpec = BeanSpec.of(valType, injector);
106+
int pos = prefix.length() + 1;
107+
for (String key : confMap.keySet()) {
108+
Object val = confMap.get(key);
109+
retVal.put(key.substring(pos), null == val ? null : cast(S.string(val), valSpec, isImpl));
110+
}
111+
return retVal;
112+
} else if (this.spec.isInstanceOf(Collection.class)) {
113+
Object val;
114+
try {
115+
val = appConfig.get(confKey);
116+
} catch (Exception e) {
117+
val = appConfig.rawConfiguration().get(confKey);
118+
}
119+
if (spec.isInstance(val)) {
120+
return val;
121+
}
122+
return cast(null == val ? null : val.toString(), spec, isImpl);
123+
}
124+
return super.get();
125+
}
126+
83127
@Override
84128
protected Object conf(String s) {
85129
return app().config().get(s);
86130
}
131+
132+
private Object cast(String val, BeanSpec spec, boolean isImpl) {
133+
if (null == val) {
134+
return null;
135+
}
136+
if (spec.isInstanceOf(Collection.class)) {
137+
Collection retVal = (Collection<?>) Act.getInstance(spec.rawType());
138+
List<Type> typeParams = spec.typeParams();
139+
Type itemType = (null != typeParams && typeParams.size() > 0) ? typeParams.get(0) : Object.class;
140+
BeanSpec itemSpec = BeanSpec.of(itemType, Act.injector());
141+
for (String itemVal : S.fastSplit(S.string(val), ",")) {
142+
retVal.add(cast(itemVal, itemSpec, isImpl));
143+
}
144+
return retVal;
145+
} else {
146+
Class<?> type = spec.rawType();
147+
if (type.isInstance(val)) {
148+
return val;
149+
}
150+
if (isImpl) {
151+
return $.newInstance(val, Act.app().classLoader());
152+
}
153+
if ($.isSimpleType(type)) {
154+
return Act.app().resolverManager().resolve(val, type);
155+
}
156+
}
157+
throw new InjectException("Cannot cast value type[%s] to required type[%]", val.getClass(), spec);
158+
}
159+
87160
};
88161
}
89162
};

src/main/java/act/internal/util/ResourceChecksumManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*/
2222

2323
import act.Act;
24-
import act.app.util.AppCrypto;
24+
import act.crypto.AppCrypto;
2525
import act.util.DestroyableBase;
2626
import org.osgl.$;
2727
import org.osgl.util.E;

src/main/java/act/security/CSRFProtector.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import act.Act;
2424
import act.app.ActionContext;
2525
import act.app.App;
26-
import act.app.util.AppCrypto;
26+
import act.crypto.AppCrypto;
2727
import org.osgl.http.H;
2828
import org.osgl.util.S;
2929

0 commit comments

Comments
 (0)