Unverified Commit f6b63765 authored by aiwenmo's avatar aiwenmo Committed by GitHub

[Fix-1418] [web] Fix users without tenants are not prompted when logging in (#1419)

parent c2795d67
...@@ -110,18 +110,17 @@ public final class ExtractionUtils { ...@@ -110,18 +110,17 @@ public final class ExtractionUtils {
final Class<?> param = executable.getParameterTypes()[currentParam]; final Class<?> param = executable.getParameterTypes()[currentParam];
// last parameter is a vararg that needs to consume remaining classes // last parameter is a vararg that needs to consume remaining classes
if (currentParam == paramCount - 1 && executable.isVarArgs()) { if (currentParam == paramCount - 1 && executable.isVarArgs()) {
final Class<?> paramComponent = final Class<?> paramComponent = executable.getParameterTypes()[currentParam].getComponentType();
executable.getParameterTypes()[currentParam].getComponentType();
// we have more than 1 classes left so the vararg needs to consume them all // we have more than 1 classes left so the vararg needs to consume them all
if (classCount - currentClass > 1) { if (classCount - currentClass > 1) {
while (currentClass < classCount while (currentClass < classCount
&& ExtractionUtils.isAssignable( && ExtractionUtils.isAssignable(
classes[currentClass], paramComponent, true)) { classes[currentClass], paramComponent, true)) {
currentClass++; currentClass++;
} }
} else if (currentClass < classCount } else if (currentClass < classCount
&& (parameterMatches(classes[currentClass], param) && (parameterMatches(classes[currentClass], param)
|| parameterMatches(classes[currentClass], paramComponent))) { || parameterMatches(classes[currentClass], paramComponent))) {
currentClass++; currentClass++;
} }
} }
...@@ -214,10 +213,9 @@ public final class ExtractionUtils { ...@@ -214,10 +213,9 @@ public final class ExtractionUtils {
// is<Name>() // is<Name>()
// <Name>() for Scala // <Name>() for Scala
final String normalizedMethodName = normalizeAccessorName(method.getName()); final String normalizedMethodName = normalizeAccessorName(method.getName());
final boolean hasName = final boolean hasName = normalizedMethodName.equals("GET" + normalizedFieldName)
normalizedMethodName.equals("GET" + normalizedFieldName) || normalizedMethodName.equals("IS" + normalizedFieldName)
|| normalizedMethodName.equals("IS" + normalizedFieldName) || normalizedMethodName.equals(normalizedFieldName);
|| normalizedMethodName.equals(normalizedFieldName);
if (!hasName) { if (!hasName) {
continue; continue;
} }
...@@ -260,10 +258,9 @@ public final class ExtractionUtils { ...@@ -260,10 +258,9 @@ public final class ExtractionUtils {
// <Name>(type) // <Name>(type)
// <Name>_$eq(type) for Scala // <Name>_$eq(type) for Scala
final String normalizedMethodName = normalizeAccessorName(method.getName()); final String normalizedMethodName = normalizeAccessorName(method.getName());
final boolean hasName = final boolean hasName = normalizedMethodName.equals("SET" + normalizedFieldName)
normalizedMethodName.equals("SET" + normalizedFieldName) || normalizedMethodName.equals(normalizedFieldName)
|| normalizedMethodName.equals(normalizedFieldName) || normalizedMethodName.equals(normalizedFieldName + "$EQ");
|| normalizedMethodName.equals(normalizedFieldName + "$EQ");
if (!hasName) { if (!hasName) {
continue; continue;
} }
...@@ -278,11 +275,10 @@ public final class ExtractionUtils { ...@@ -278,11 +275,10 @@ public final class ExtractionUtils {
// check parameters: // check parameters:
// one parameter that has the same (or primitive) type of the field // one parameter that has the same (or primitive) type of the field
final boolean hasParameter = final boolean hasParameter = method.getParameterCount() == 1
method.getParameterCount() == 1 && (method.getGenericParameterTypes()[0].equals(field.getGenericType())
&& (method.getGenericParameterTypes()[0].equals(field.getGenericType())
|| primitiveToWrapper(method.getGenericParameterTypes()[0]) || primitiveToWrapper(method.getGenericParameterTypes()[0])
.equals(field.getGenericType())); .equals(field.getGenericType()));
if (!hasParameter) { if (!hasParameter) {
continue; continue;
} }
...@@ -351,9 +347,8 @@ public final class ExtractionUtils { ...@@ -351,9 +347,8 @@ public final class ExtractionUtils {
if (clazz.getSuperclass() != baseClass) { if (clazz.getSuperclass() != baseClass) {
return Optional.empty(); return Optional.empty();
} }
final Type t = final Type t = ((ParameterizedType) clazz.getGenericSuperclass())
((ParameterizedType) clazz.getGenericSuperclass()) .getActualTypeArguments()[pos];
.getActualTypeArguments()[pos];
return Optional.ofNullable(toClass(t)); return Optional.ofNullable(toClass(t));
} catch (Exception unused) { } catch (Exception unused) {
return Optional.empty(); return Optional.empty();
...@@ -462,9 +457,8 @@ public final class ExtractionUtils { ...@@ -462,9 +457,8 @@ public final class ExtractionUtils {
final Type currentType = typeHierarchy.get(i); final Type currentType = typeHierarchy.get(i);
if (currentType instanceof ParameterizedType) { if (currentType instanceof ParameterizedType) {
final Type resolvedType = final Type resolvedType = resolveVariableInParameterizedType(
resolveVariableInParameterizedType( variable, (ParameterizedType) currentType);
variable, (ParameterizedType) currentType);
if (resolvedType instanceof TypeVariable) { if (resolvedType instanceof TypeVariable) {
// follow type variables transitively // follow type variables transitively
variable = (TypeVariable<?>) resolvedType; variable = (TypeVariable<?>) resolvedType;
...@@ -646,6 +640,7 @@ public final class ExtractionUtils { ...@@ -646,6 +640,7 @@ public final class ExtractionUtils {
* Result of the extraction in {@link #extractAssigningConstructor(Class, List)}. * Result of the extraction in {@link #extractAssigningConstructor(Class, List)}.
*/ */
public static class AssigningConstructor { public static class AssigningConstructor {
public final Constructor<?> constructor; public final Constructor<?> constructor;
public final List<String> parameterNames; public final List<String> parameterNames;
...@@ -663,14 +658,12 @@ public final class ExtractionUtils { ...@@ -663,14 +658,12 @@ public final class ExtractionUtils {
Class<?> clazz, List<Field> fields) { Class<?> clazz, List<Field> fields) {
AssigningConstructor foundConstructor = null; AssigningConstructor foundConstructor = null;
for (Constructor<?> constructor : clazz.getDeclaredConstructors()) { for (Constructor<?> constructor : clazz.getDeclaredConstructors()) {
final boolean qualifyingConstructor = final boolean qualifyingConstructor = Modifier.isPublic(constructor.getModifiers())
Modifier.isPublic(constructor.getModifiers()) && constructor.getParameterTypes().length == fields.size();
&& constructor.getParameterTypes().length == fields.size();
if (!qualifyingConstructor) { if (!qualifyingConstructor) {
continue; continue;
} }
final List<String> parameterNames = final List<String> parameterNames = extractConstructorParameterNames(constructor, fields);
extractConstructorParameterNames(constructor, fields);
if (parameterNames != null) { if (parameterNames != null) {
if (foundConstructor != null) { if (foundConstructor != null) {
throw extractionError( throw extractionError(
...@@ -703,12 +696,11 @@ public final class ExtractionUtils { ...@@ -703,12 +696,11 @@ public final class ExtractionUtils {
return null; return null;
} }
final Map<String, Field> fieldMap = final Map<String, Field> fieldMap = fields.stream()
fields.stream() .collect(
.collect( Collectors.toMap(
Collectors.toMap( f -> normalizeAccessorName(f.getName()),
f -> normalizeAccessorName(f.getName()), Function.identity()));
Function.identity()));
// check that all fields are represented in the parameters of the constructor // check that all fields are represented in the parameters of the constructor
final List<String> fieldNames = new ArrayList<>(); final List<String> fieldNames = new ArrayList<>();
...@@ -741,10 +733,9 @@ public final class ExtractionUtils { ...@@ -741,10 +733,9 @@ public final class ExtractionUtils {
} }
// by default parameter names are "arg0, arg1, arg2, ..." if compiler flag is not set // by default parameter names are "arg0, arg1, arg2, ..." if compiler flag is not set
// so we need to extract them manually if possible // so we need to extract them manually if possible
List<String> parameterNames = List<String> parameterNames = Stream.of(executable.getParameters())
Stream.of(executable.getParameters()) .map(Parameter::getName)
.map(Parameter::getName) .collect(Collectors.toList());
.collect(Collectors.toList());
if (parameterNames.stream().allMatch(n -> n.startsWith("arg"))) { if (parameterNames.stream().allMatch(n -> n.startsWith("arg"))) {
final ParameterExtractor extractor; final ParameterExtractor extractor;
if (executable instanceof Constructor) { if (executable instanceof Constructor) {
...@@ -752,7 +743,6 @@ public final class ExtractionUtils { ...@@ -752,7 +743,6 @@ public final class ExtractionUtils {
} else { } else {
extractor = new ParameterExtractor((Method) executable); extractor = new ParameterExtractor((Method) executable);
} }
// getClassReader(executable.getDeclaringClass()).accept(extractor, 0);
final List<String> extractedNames = extractor.getParameterNames(); final List<String> extractedNames = extractor.getParameterNames();
if (extractedNames.size() == 0) { if (extractedNames.size() == 0) {
...@@ -760,12 +750,11 @@ public final class ExtractionUtils { ...@@ -760,12 +750,11 @@ public final class ExtractionUtils {
} }
// remove "this" and additional local variables // remove "this" and additional local variables
// select less names if class file has not the required information // select less names if class file has not the required information
parameterNames = parameterNames = extractedNames.subList(
extractedNames.subList( offset,
offset, Math.min(
Math.min( executable.getParameterCount() + offset,
executable.getParameterCount() + offset, extractedNames.size()));
extractedNames.size()));
} }
if (parameterNames.size() != executable.getParameterCount()) { if (parameterNames.size() != executable.getParameterCount()) {
...@@ -830,6 +819,7 @@ public final class ExtractionUtils { ...@@ -830,6 +819,7 @@ public final class ExtractionUtils {
int access, String name, String descriptor, String signature, String[] exceptions) { int access, String name, String descriptor, String signature, String[] exceptions) {
if (descriptor.equals(methodDescriptor)) { if (descriptor.equals(methodDescriptor)) {
return new MethodVisitor(OPCODE) { return new MethodVisitor(OPCODE) {
@Override @Override
public void visitLocalVariable( public void visitLocalVariable(
String name, String name,
......
...@@ -211,6 +211,10 @@ const Login: React.FC = () => { ...@@ -211,6 +211,10 @@ const Login: React.FC = () => {
onFinish={async (values: API.LoginParams) => { onFinish={async (values: API.LoginParams) => {
setType("password") setType("password")
let res: TenantTableListItem[] = await getData("/api/geTenants", {username: values.username}).then(result => { let res: TenantTableListItem[] = await getData("/api/geTenants", {username: values.username}).then(result => {
if(!result?.datas){
message.error(result?.msg);
return;
}
setTenant(result?.datas); setTenant(result?.datas);
return result?.datas return result?.datas
}) })
......
Markdown is supported
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