小编Pow*_*tat的帖子

141
推荐指数
3
解决办法
5万
查看次数

AccessController用法

我正在尝试了解java安全性和AccessController.doPrivileged()用法的基础知识我从一个示例程序开始

import java.security.AccessController;
import java.security.PrivilegedAction;
public class AccessSystemProperty {
   public static void main(String[] args) {
     System.out.println(System.getSecurityManager());
       AccessController.doPrivileged(
        new PrivilegedAction<Boolean>(){
           public Boolean run(){
               System.out.println(System.getProperty("java.home"));
               return Boolean.TRUE;
           }
        }
       );
   }
}
Run Code Online (Sandbox Code Playgroud)

如果我尝试使用默认安全管理运行上面的代码我得到AccessControlException我的stacktrace是

C:\>java -Djava.security.manager AccessSystemProperty
java.lang.SecurityManager@923e30
Exception in thread "main" java.security.AccessControlException: access denied (
java.util.PropertyPermission java.home read)
        at java.security.AccessControlContext.checkPermission(Unknown Source)
        at java.security.AccessController.checkPermission(Unknown Source)
        at java.lang.SecurityManager.checkPermission(Unknown Source)
        at java.lang.SecurityManager.checkPropertyAccess(Unknown Source)
        at java.lang.System.getProperty(Unknown Source)
        at AccessSystemProperty$1.run(AccessSystemProperty.java:9)
        at AccessSystemProperty$1.run(AccessSystemProperty.java:8)
        at java.security.AccessController.doPrivileged(Native Method)
        at AccessSystemProperty.main(AccessSystemProperty.java:6)
Run Code Online (Sandbox Code Playgroud)

请帮助我清楚地了解一下

1)什么时候需要使用AccessController.doPrivileged()?(如果存在SecurityManager,我们使用AccessController.doPrivileged - 为什么这在上面的示例中失败)

2)使用AccessController和PrivilegedAction获得的真正优势是什么?

3)我们是否需要上述示例的自定义策略文件才能工作?

谢谢,

保罗

java security

25
推荐指数
1
解决办法
1万
查看次数

带有maven的Java 11/12 Javadoc无法生成用于测试的Javadocs

我有一个具有以下结构的小项目:

pom.xml

src/main/java/
  module-info.java
  de.ps.pl.te/
    package-info.java
    TE.java

src/test/java/
   de.ps.pl.te.test/
     package-info.java
     TETests.java
Run Code Online (Sandbox Code Playgroud)

同样在我的maven pom中,我定义了javadoc插件,如下所示:

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-javadoc-plugin</artifactId>
        <version>3.1.0</version>
        <configuration>
          <show>protected</show>
          <failOnError>false</failOnError>
        </configuration>
      </plugin>
Run Code Online (Sandbox Code Playgroud)

现在我在跑步过程中得到了一些奇怪的输出

mvn clean install site
Run Code Online (Sandbox Code Playgroud)

[INFO]生成“ Javadoc”报告--- maven-javadoc-plugin:3.1.0:aggregate-no-fork [错误]提取链接时出错:D:\ work \ eclipse \ java \ FritzBox \ phplib \ target \ javadoc-捆绑选项。忽略它。

[...]

[INFO]生成“ Test Javadoc”报告--- maven-javadoc-plugin:3.1.0:test-aggregate-no-fork

[错误]提取链接时出错:D:\ work \ eclipse \ java \ FritzBox \ phplib \ target \ javadoc-bundle-options。忽略它。

正在加载软件包de.ps.pl.te.test的源文件...

1个错误

[错误]创建javadoc报告时出错:

退出代码:2-Javadoc:错误-软件包de.powerstat.phplib.templateengine.test没有源文件

命令行为:[...] javadoc.exe @options @packages

请参考“ [...]”目录中生成的Javadoc文件。

org.apache.maven.reporting.MavenReportException:

退出代码:2-javadoc:错误-没有软件包de.ps.pl.te.test的源文件

命令行为:[...] javadoc.exe @options @packages

请参考“ …

java javadoc maven java-11 java-12

11
推荐指数
1
解决办法
1607
查看次数

如何在 React Native 的 React Tab Navigation 中设置默认屏幕路由

我想将仪表板加载为 react Native 底部选项卡中的活动选项卡。每当仪表板加载时导航,但每当我移动到仪表板时,它都会移动到收件箱屏幕,这是我的反应底部选项卡导航中的第一个元素。有没有办法在使用屏幕底部选项卡时创建默认屏幕?

我用于底部导航的代码是

 dashboard: {
        screen: createBottomTabNavigator({
            inbox: {
                screen: Chat,
                navigationOptions: ({ navigation }) => ({
                    title: 'Inbox',
                }),
            },
            favourite: {
                screen: Favourite,
                navigationOptions: ({ navigation }) => ({
                    title: 'Favourite',
                }),
            },
            dashboard: {
                screen: Dashboard,
                navigationOptions: ({ navigation }) => ({
                    title: 'Home',
                    initialRouteName: 'dashboard'
                }),
            },
            setting: {
                screen: SettingScreen,
                navigationOptions: ({ navigation }) => ({
                    title: 'Setting',
                }),
            },
            survey: {
                screen: NutritionistSurvey,
                navigationOptions: ({ navigation }) => ({
                    title: 'Survey',
                }), …
Run Code Online (Sandbox Code Playgroud)

native react-native react-navigation react-navigation-stack

9
推荐指数
2
解决办法
9793
查看次数

如何使用groovy for Jenkins自动化Maven和Java JDK8安装?

我正在构建一个Jenkins Docker映像,我想自动化最后一个JDK的Maven 3和Java 8的安装。但是不幸的是,我使用这两个groovy文件定位到groovy文件夹中:

groovy / java.groovy

import jenkins.model.*
import hudson.model.*
import hudson.tools.*

def inst = Jenkins.getInstance()

def desc = inst.getDescriptor("hudson.model.JDK")

def versions = [ "jdk8": "jdk-8u202"]
def installations = [];

for (v in versions) {
  def installer = new JDKInstaller(v.value, true)
  def installerProps = new InstallSourceProperty([installer])
  def installation = new JDK(v.key, "", [installerProps])
  installations.push(installation)
}

desc.setInstallations(installations.toArray(new JDK[0]))

desc.save()
Run Code Online (Sandbox Code Playgroud)

groovy / maven.groovy

import jenkins.*;
import jenkins.model.*;
import hudson.*;
import hudson.model.*;

mavenName = "maven3"
mavenVersion = "3.6.0"
println("Checking Maven …
Run Code Online (Sandbox Code Playgroud)

java groovy maven jenkins docker

8
推荐指数
1
解决办法
393
查看次数

如何只生成API的接口?

我试图仅使用 OpenApi 及其 maven 插件openapi-generator-maven-plugin生成接口,但它也生成我不想要/不需要的完整服务。

现在我找到了withInterfaces属性,但当设置为 true 时,它​​还会生成 API 服务。因此它会生成我想要的服务,但也会生成我不想要的服务。

这是我的 pom 配置:

<plugin>
    <groupId>org.openapitools</groupId>
    <artifactId>openapi-generator-maven-plugin</artifactId>
    <version>3.3.4</version>
    <executions>
        <execution>
            <goals>
                <goal>generate</goal>
            </goals>
            <configuration>
                <inputSpec>${openAPIContractsDirectory}/swagger.json</inputSpec>
                <generatorName>typescript-angular</generatorName>
                <output>${openAPIOutputDirectory}</output>
                <configOptions>
                    <ngVersion>7.2.11</ngVersion>
                    <withInterfaces>true</withInterfaces>
                </configOptions>
                <generateApiTests>false</generateApiTests>
                <generateApiDocumentation>false</generateApiDocumentation>
                <generateModelTests>false</generateModelTests>
                <generateModelDocumentation>false</generateModelDocumentation>
                <supportingFilesToGenerate>variables.ts,configuration.ts,encoder.ts</supportingFilesToGenerate>
            </configuration>
        </execution>
    </executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)

我想要的是模型、pom 中描述的一些支持文件,以及API 接口(不是完整的服务)

有人知道如何做到这一点吗?

typescript openapi angular openapi-generator

8
推荐指数
1
解决办法
7608
查看次数

Spring Boot,Tomcat和Gradle:找不到xalan和serializer jar

昨天我尝试将一些弹簧启动项目合并到一个新项目中,从那时起,我在启动项目时在ide控制台中遇到以下错误:

Ignoring Class-Path entry xercesImpl.jar found in/home/test/.gradle/caches/modules-2/files-2.1/xalan/xalan/2.7.2/d55d3f02a56ec4c25695fe67e1334ff8c2ecea23/xalan-2.7.2.jar as /home/test/.gradle/caches/modules-2/files-2.1/xalan/xalan/2.7.2/d55d3f02a56ec4c25695fe67e1334ff8c2ecea23/xercesImpl.jar does not exist
Ignoring Class-Path entry xml-apis.jar found in/home/test/.gradle/caches/modules-2/files-2.1/xalan/xalan/2.7.2/d55d3f02a56ec4c25695fe67e1334ff8c2ecea23/xalan-2.7.2.jar as /home/test/.gradle/caches/modules-2/files-2.1/xalan/xalan/2.7.2/d55d3f02a56ec4c25695fe67e1334ff8c2ecea23/xml-apis.jar does not exist
Ignoring Class-Path entry serializer.jar found in/home/test/.gradle/caches/modules-2/files-2.1/xalan/xalan/2.7.2/d55d3f02a56ec4c25695fe67e1334ff8c2ecea23/xalan-2.7.2.jar as /home/test/.gradle/caches/modules-2/files-2.1/xalan/xalan/2.7.2/d55d3f02a56ec4c25695fe67e1334ff8c2ecea23/serializer.jar does not exist
Ignoring Class-Path entry xml-apis.jar found in/home/test/.gradle/caches/modules-2/files-2.1/xalan/serializer/2.7.2/24247f3bb052ee068971393bdb83e04512bb1c3c/serializer-2.7.2.jar as /home/test/.gradle/caches/modules-2/files-2.1/xalan/serializer/2.7.2/24247f3bb052ee068971393bdb83e04512bb1c3c/xml-apis.jar does not exist
Run Code Online (Sandbox Code Playgroud)

这些消息作为System.err消息打印.

检查路径会显示以下图片:

test@localhost ~/.gradle/caches/modules-2/files-2.1/xalan $ ls -lRt
.:
total 8
drwxr-xr-x 3 test test 4096 Jul  6 07:54 serializer
drwxr-xr-x 3 test test 4096 Jul  6 07:54 xalan

./serializer:
total 4
drwxr-xr-x 5 test test …
Run Code Online (Sandbox Code Playgroud)

gradle spring-boot

7
推荐指数
0
解决办法
1163
查看次数

Jenkins管道中的Maven生命周期-如何最好地分离职责?

在使用jenkins 2(声明性)管道和Maven时,我始终对如何组织管道中的事物以使其可重用和灵活存在问题。

一方面,我想将管道分成逻辑阶段,例如:

pipeline
 {
  stages
   {
    stage('Clean') {}
    stage('Build') {}
    stage('Test') {}
    stage('Sanity check') {}
    stage('Documentation') {}
    stage('Deploy - Test') {}
    stage('Selenium tests') {}
    stage('Deploy - Production') {}
    stage('Deliver') {}
   }
 }
Run Code Online (Sandbox Code Playgroud)

另一方面,我有与

mvn clean deploy site
Run Code Online (Sandbox Code Playgroud)

我可以简单地将Maven拆分为

mvn clean
mvn deploy
mvn site
Run Code Online (Sandbox Code Playgroud)

但是,“部署”包括以下所有生命周期阶段

  • 验证
  • 编译
  • 测试
  • 校验
  • 安装
  • 部署

所以我看了很多例子,例如

sh 'mvn clean compile'
Run Code Online (Sandbox Code Playgroud)

sh 'mvn test'
Run Code Online (Sandbox Code Playgroud)

这导致第二次重复验证和编译步骤,并以此方式浪费“时间/资源”。这可以通过做一个解决

sh 'mvn surefire:test'
Run Code Online (Sandbox Code Playgroud)

而不是再次运行整个生命周期。

所以我的问题是-在詹金斯油耗阶段和Maven生命周期之间取得最佳平衡的最佳方法是什么?对我来说,我看到两种方式:

  1. 将Maven生命周期划分为尽可能多的流水线阶段-这将产生更好的詹金斯用户反馈(请参阅哪个阶段失败等)。
  2. 让maven做所有事情,只使用jenkins管道处理maven的结果(即分析单元测试结果等)。

还是我误解了CI / CD实践中的某些内容?

maven-3 maven jenkins maven-lifecycle jenkins-pipeline

7
推荐指数
1
解决办法
1069
查看次数

PiTest“改变条件边界突变幸存”无缘无故?

我有一个带有 JUnit 5 测试的小型 Java 11 示例,结果是:

改变条件边界 ? 幸存下来

主要类:

public final class CheckerUtils
 {
  private CheckerUtils()
   {
    super();
   }


  public static int checkPort(final int port)
   {
    if (port < 0)
     {
      throw new IndexOutOfBoundsException("Port number out of range!");
     }
    return port;
   }

 }
Run Code Online (Sandbox Code Playgroud)

测试类:

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

import org.junit.jupiter.api.Test;

import de.powerstat.security.CheckerUtils;


public final class CheckerUtilsTests
 {
  @Test
  public void checkPortOk()
   {
    final int port = 1023;
    final int resultPort = CheckerUtils.checkPort(port);
    assertEquals(port, resultPort, "Port not …
Run Code Online (Sandbox Code Playgroud)

pitest junit5 java-11

7
推荐指数
1
解决办法
4568
查看次数

Spring JPA ColumnTransformer 从 application.properties 文件中读取值

我正在使用 hibernate 注释@ColumnTransformer来利用 MySQL 数据加密,但是,我不想(实际上我不能)将密码硬编码到代码中,相反,我想从application.properties文件中加载密码, 样例如下:

@NotBlank
@Column(name = "phone_numbers", columnDefinition = "LONGBLOB")
@ColumnTransformer(
        read="AES_DECRYPT(phone_numbers, '${mms.encryption.key}')",
        write="AES_ENCRYPT(?, '${mms.encryption.key}')")
private String phoneNumbers;```
Run Code Online (Sandbox Code Playgroud)

mms.encryption.key是在进入application.properties

mms.encryption.key=mypassword

但似乎这个行不通。做这个的最好方式是什么?

我在这里找到了类似的帖子,但我不确定 2018 年是否有人有更好的解决方案。

java spring hibernate spring-data-jpa spring-boot

6
推荐指数
0
解决办法
1376
查看次数