Search in sources :

Example 1 with ArrayUtils

use of com.loohp.interactivechat.libs.org.apache.commons.lang3.ArrayUtils in project kylo by Teradata.

the class JaasAuthConfig method jaasConfiguration.

@Bean(name = "jaasConfiguration")
public javax.security.auth.login.Configuration jaasConfiguration(Optional<List<LoginConfiguration>> loginModuleEntries) {
    // Generally the entries will be null only in situations like unit/integration tests.
    if (loginModuleEntries.isPresent()) {
        List<LoginConfiguration> sorted = new ArrayList<>(loginModuleEntries.get());
        sorted.sort(new AnnotationAwareOrderComparator());
        Map<String, AppConfigurationEntry[]> merged = sorted.stream().map(c -> c.getAllApplicationEntries().entrySet()).flatMap(s -> s.stream()).collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue(), ArrayUtils::addAll));
        return new InMemoryConfiguration(merged);
    } else {
        return new InMemoryConfiguration(Collections.emptyMap());
    }
}
Also used : AppConfigurationEntry(javax.security.auth.login.AppConfigurationEntry) LoginConfigurationBuilder(com.thinkbiganalytics.auth.jaas.LoginConfigurationBuilder) LoginConfiguration(com.thinkbiganalytics.auth.jaas.LoginConfiguration) ArrayUtils(org.apache.commons.lang3.ArrayUtils) DefaultJaasAuthenticationProvider(org.springframework.security.authentication.jaas.DefaultJaasAuthenticationProvider) Scope(org.springframework.context.annotation.Scope) ArrayList(java.util.ArrayList) AuthorityGranter(org.springframework.security.authentication.jaas.AuthorityGranter) JaasHttpCallbackHandlerFilter(com.thinkbiganalytics.auth.jaas.http.JaasHttpCallbackHandlerFilter) Map(java.util.Map) UserPrincipalAuthorityGranter(com.thinkbiganalytics.auth.UserPrincipalAuthorityGranter) Named(javax.inject.Named) JaasAuthenticationCallbackHandler(org.springframework.security.authentication.jaas.JaasAuthenticationCallbackHandler) Order(org.springframework.core.annotation.Order) InMemoryConfiguration(org.springframework.security.authentication.jaas.memory.InMemoryConfiguration) UsernameJaasAuthenticationProvider(com.thinkbiganalytics.auth.jaas.UsernameJaasAuthenticationProvider) Collectors(java.util.stream.Collectors) DefaultKyloJaasAuthenticationProvider(com.thinkbiganalytics.auth.jaas.DefaultKyloJaasAuthenticationProvider) Configuration(org.springframework.context.annotation.Configuration) List(java.util.List) DefaultPrincipalAuthorityGranter(com.thinkbiganalytics.auth.DefaultPrincipalAuthorityGranter) Optional(java.util.Optional) Bean(org.springframework.context.annotation.Bean) AbstractJaasAuthenticationProvider(org.springframework.security.authentication.jaas.AbstractJaasAuthenticationProvider) GroupPrincipalAuthorityGranter(com.thinkbiganalytics.auth.GroupPrincipalAuthorityGranter) Collections(java.util.Collections) AnnotationAwareOrderComparator(org.springframework.core.annotation.AnnotationAwareOrderComparator) InMemoryConfiguration(org.springframework.security.authentication.jaas.memory.InMemoryConfiguration) ArrayList(java.util.ArrayList) LoginConfiguration(com.thinkbiganalytics.auth.jaas.LoginConfiguration) AnnotationAwareOrderComparator(org.springframework.core.annotation.AnnotationAwareOrderComparator) Bean(org.springframework.context.annotation.Bean)

Example 2 with ArrayUtils

use of com.loohp.interactivechat.libs.org.apache.commons.lang3.ArrayUtils in project so by onap.

the class FluentGenerator method createInterfaceMethods.

protected List<MethodSpec> createInterfaceMethods(ObjectType oType, List<ParameterSpec> typeParams) {
    List<MethodSpec> methods = new ArrayList<>();
    CodeBlock.Builder uriTemplateCodeBlock = CodeBlock.builder();
    if (!oType.getType().equals("top level")) {
        uriTemplateCodeBlock.add("return this.parentObj.uriTemplate() + Info.partialUri");
    } else {
        uriTemplateCodeBlock.add("return Info.partialUri");
    }
    methods.add(MethodSpec.methodBuilder("uriTemplate").returns(String.class).addModifiers(Modifier.PUBLIC).addStatement(uriTemplateCodeBlock.build()).addAnnotation(Override.class).build());
    ClassName arrayUtils = ClassName.get(ArrayUtils.class);
    CodeBlock.Builder valuesReturn = CodeBlock.builder();
    if (oType.getType().equals("top level")) {
        valuesReturn.add("return new Object[0]");
    } else {
        if (!typeParams.isEmpty()) {
            valuesReturn.add("return $T.addAll(this.parentObj.values(), $L)", arrayUtils, String.join(", ", typeParams.stream().map(item -> "this." + item.name).collect(Collectors.toList())));
        } else {
            valuesReturn.add("return this.parentObj.values()");
        }
    }
    methods.add(MethodSpec.methodBuilder("values").returns(Object[].class).addModifiers(Modifier.PUBLIC).addAnnotation(Override.class).addStatement(valuesReturn.build()).build());
    if (!oType.getType().equals("top level")) {
        ClassName returnType = null;
        CodeBlock.Builder block = CodeBlock.builder();
        if (oType.getType().equals("singular")) {
            Pair<String, String> path = splitClasspath(this.singularClass);
            returnType = ClassName.get(path.getLeft(), path.getRight());
            block.add("return new $T(this.parentObj.uriTemplate(), Info.partialUri, Info.name, false)", returnType);
        } else if (oType.getType().equals("plural")) {
            Pair<String, String> path = splitClasspath(this.pluralClass);
            returnType = ClassName.get(path.getLeft(), path.getRight());
            block.add("return new $T(Info.name, this.parentObj.uriTemplate(), Info.partialUri)", returnType);
        }
        methods.add(MethodSpec.methodBuilder("build").returns(returnType).addModifiers(Modifier.PUBLIC).addAnnotation(Override.class).addStatement(block.build()).build());
    }
    return methods;
}
Also used : Arrays(java.util.Arrays) ParameterSpec(com.squareup.javapoet.ParameterSpec) Modifier(javax.lang.model.element.Modifier) CaseFormat(com.google.common.base.CaseFormat) MethodSpec(com.squareup.javapoet.MethodSpec) FieldSpec(com.squareup.javapoet.FieldSpec) ClassName(com.squareup.javapoet.ClassName) IOException(java.io.IOException) ArrayUtils(org.apache.commons.lang3.ArrayUtils) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ParameterizedTypeName(com.squareup.javapoet.ParameterizedTypeName) Log(org.apache.maven.plugin.logging.Log) TypeSpec(com.squareup.javapoet.TypeSpec) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) JavaFile(com.squareup.javapoet.JavaFile) List(java.util.List) Matcher(java.util.regex.Matcher) Pair(org.apache.commons.lang3.tuple.Pair) Paths(java.nio.file.Paths) Map(java.util.Map) Entry(java.util.Map.Entry) Comparator(java.util.Comparator) CodeBlock(com.squareup.javapoet.CodeBlock) MethodSpec(com.squareup.javapoet.MethodSpec) ArrayList(java.util.ArrayList) CodeBlock(com.squareup.javapoet.CodeBlock) ClassName(com.squareup.javapoet.ClassName) Pair(org.apache.commons.lang3.tuple.Pair)

Example 3 with ArrayUtils

use of com.loohp.interactivechat.libs.org.apache.commons.lang3.ArrayUtils in project sduoj-server by SDUOJ.

the class PermissionInitListener method started.

@Override
public void started(ConfigurableApplicationContext context) {
    ConfigurableEnvironment environment = context.getEnvironment();
    String applicationPrefixUrl = Optional.ofNullable(environment.getProperty("server.servlet.context-path")).filter(StringUtils::isNotBlank).orElse("");
    List<PermissionDTO> permissionDTOList = Lists.newArrayList();
    Map<String, Object> beanMap = context.getBeansWithAnnotation(Controller.class);
    for (Entry<String, Object> objectEntry : beanMap.entrySet()) {
        if (ESCAPE_CONTROLLER.contains(objectEntry.getKey())) {
            continue;
        }
        Object value = objectEntry.getValue();
        Class<?> valueClass = value.getClass();
        String classMappingUrl = Optional.ofNullable(valueClass.getAnnotation(RequestMapping.class)).map(RequestMapping::value).filter(ArrayUtils::isNotEmpty).map(values -> values[0]).orElse("");
        Method[] methods = valueClass.getMethods();
        for (Method method : methods) {
            for (Class<? extends Annotation> mappingClass : MAPPING_CLASSES) {
                Annotation mappingAnnotation = method.getAnnotation(mappingClass);
                if (mappingAnnotation != null) {
                    try {
                        Method valueMethod = mappingClass.getDeclaredMethod("value");
                        Method nameMethod = mappingClass.getDeclaredMethod("name");
                        String methodMappingUrl = Optional.ofNullable((String[]) valueMethod.invoke(mappingAnnotation)).filter(ArrayUtils::isNotEmpty).map(values -> values[0]).orElse("");
                        String url = String.format("/%s/%s/%s", applicationPrefixUrl, classMappingUrl, methodMappingUrl).replaceAll("[/]+", "/");
                        String name = (String) nameMethod.invoke(mappingAnnotation);
                        permissionDTOList.add(PermissionDTO.builder().name(name).url(url).build());
                        log.info("syncUrl {} {}", name, url);
                    } catch (Throwable t) {
                        log.error("", t);
                    }
                }
            }
        }
    }
    // 远程调用 auth 微服务同步过去
    if (!permissionDTOList.isEmpty()) {
        try {
            loadBalancerClient = (LoadBalancerClient) context.getBean("loadBalancerClient");
        } catch (Throwable t) {
            log.error("", t);
        }
        syncUrl(permissionDTOList, 0);
    }
}
Also used : PostMapping(org.springframework.web.bind.annotation.PostMapping) java.util(java.util) PermissionApi(cn.edu.sdu.qd.oj.auth.api.PermissionApi) LoadBalancerClient(org.springframework.cloud.client.loadbalancer.LoadBalancerClient) SpringApplicationRunListener(org.springframework.boot.SpringApplicationRunListener) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ArrayUtils(org.apache.commons.lang3.ArrayUtils) Controller(org.springframework.stereotype.Controller) Feign(feign.Feign) StringUtils(org.apache.commons.lang3.StringUtils) PermissionDTO(cn.edu.sdu.qd.oj.auth.dto.PermissionDTO) SpringApplication(org.springframework.boot.SpringApplication) Slf4j(lombok.extern.slf4j.Slf4j) ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) PutMapping(org.springframework.web.bind.annotation.PutMapping) JacksonEncoder(feign.jackson.JacksonEncoder) Lists(org.assertj.core.util.Lists) ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) Annotation(java.lang.annotation.Annotation) Entry(java.util.Map.Entry) GetMapping(org.springframework.web.bind.annotation.GetMapping) Method(java.lang.reflect.Method) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping) SpringMvcContract(org.springframework.cloud.openfeign.support.SpringMvcContract) Method(java.lang.reflect.Method) Annotation(java.lang.annotation.Annotation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) PermissionDTO(cn.edu.sdu.qd.oj.auth.dto.PermissionDTO) ArrayUtils(org.apache.commons.lang3.ArrayUtils)

Aggregations

ArrayUtils (org.apache.commons.lang3.ArrayUtils)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Map (java.util.Map)2 Entry (java.util.Map.Entry)2 Collectors (java.util.stream.Collectors)2 PermissionApi (cn.edu.sdu.qd.oj.auth.api.PermissionApi)1 PermissionDTO (cn.edu.sdu.qd.oj.auth.dto.PermissionDTO)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 CaseFormat (com.google.common.base.CaseFormat)1 ClassName (com.squareup.javapoet.ClassName)1 CodeBlock (com.squareup.javapoet.CodeBlock)1 FieldSpec (com.squareup.javapoet.FieldSpec)1 JavaFile (com.squareup.javapoet.JavaFile)1 MethodSpec (com.squareup.javapoet.MethodSpec)1 ParameterSpec (com.squareup.javapoet.ParameterSpec)1 ParameterizedTypeName (com.squareup.javapoet.ParameterizedTypeName)1 TypeSpec (com.squareup.javapoet.TypeSpec)1 DefaultPrincipalAuthorityGranter (com.thinkbiganalytics.auth.DefaultPrincipalAuthorityGranter)1 GroupPrincipalAuthorityGranter (com.thinkbiganalytics.auth.GroupPrincipalAuthorityGranter)1