GVKun编程网logo

Eclipse中的Glassfish 3.1 CREDENTIAL_ERROR(eclipse中的快捷键)

6

对于想了解Eclipse中的Glassfish3.1CREDENTIAL_ERROR的读者,本文将提供新的信息,我们将详细介绍eclipse中的快捷键,并且为您提供关于Centos安装Eclipse报

对于想了解Eclipse中的Glassfish 3.1 CREDENTIAL_ERROR的读者,本文将提供新的信息,我们将详细介绍eclipse中的快捷键,并且为您提供关于Centos 安装Eclipse报错java.lang.UnsatisfiedLinkError: Could not load SWT library、com.amazonaws.auth.ClasspathPropertiesFileCredentialsProvider的实例源码、CORE 3.1 Visual Studio 2019 上 IdentityServer4 ClientCredentials 的 swashbuckle 的正确配置、Eclipse 3.3 + GlassFish + Java EE 5 的集成的有价值信息。

本文目录一览:

Eclipse中的Glassfish 3.1 CREDENTIAL_ERROR(eclipse中的快捷键)

Eclipse中的Glassfish 3.1 CREDENTIAL_ERROR(eclipse中的快捷键)

我无法使用Windows 7上的“ Oracle Glassfish服务器工具”插件在Eclipse Indigo上启动Glassfish
3.1。安装该插件后,我在服务器视图中选择了“新建”->“服务器”,并单击了GlassFish 3.1并下载了该文件。通过Eclipse安装。

每次尝试启动它时,都会显示以下消息:

The Eclipse plugin cannot communicate with the GlassFish server, status is :CREDENTIAL_ERROR

我发现初始密码是“ changeit”,并在命令行上将其更改为自己的密码:

bin/asadmin change-master-password  domain1Enter the current master password>Enter the new master password>Enter the new master password again>Command change-master-password executed successfully.

我已经在Eclipse的GlasshFish 3.1配置屏幕的“应用程序服务器(管理员密码)”部分中进行了相应的更改。

列出的端口(8080,4848)似乎与domain.xml配置兼容:

<network-listeners>    <network-listener port="8080" protocol="http-listener-1" transport="tcp" name="http-listener-1" thread-pool="http-thread-pool"></network-listener>    <network-listener port="8181" protocol="http-listener-2" transport="tcp" name="http-listener-2" thread-pool="http-thread-pool"></network-listener>    <network-listener port="4848" protocol="admin-listener" transport="tcp" name="admin-listener" thread-pool="admin-thread-pool"></network-listener></network-listeners>

但是,在我的.log文件中,我发现以下内容:

!ENTRY oracle.eclipse.tools.glassfish 4 1 2011-08-04 11:38:43.925!MESSAGE GlassFish: error !STACK 0java.net.ConnectException: Connection refused: connect    at java.net.PlainSocketImpl.socketConnect(Native Method)    at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)    at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)    at java.net.Socket.connect(Socket.java:525)    at java.net.Socket.connect(Socket.java:475)    at sun.net.NetworkClient.doConnect(NetworkClient.java:163)    at sun.net.www.http.HttpClient.openServer(HttpClient.java:394)    at sun.net.www.http.HttpClient.openServer(HttpClient.java:529)    at sun.net.www.http.HttpClient.<init>(HttpClient.java:233)    at sun.net.www.http.HttpClient.New(HttpClient.java:306)    at sun.net.www.http.HttpClient.New(HttpClient.java:323)    at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:860)    at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:801)    at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:726)    at com.sun.enterprise.jst.server.sunappsrv.commands.CommandRunner.call(CommandRunner.java:607)    at com.sun.enterprise.jst.server.sunappsrv.commands.CommandRunner.call(CommandRunner.java:1)    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)    at java.util.concurrent.FutureTask.run(FutureTask.java:138)    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)    at java.lang.Thread.run(Thread.java:619)!ENTRY oracle.eclipse.tools.glassfish 4 150 2011-08-04 11:38:43.928!MESSAGE The Eclipse plugin cannot communicate with the GlassFish server, status is :CREDENTIAL_ERROR!STACK 0java.lang.RuntimeException: The Eclipse plugin cannot communicate with the GlassFish server.Status is :CREDENTIAL_ERROR    at com.sun.enterprise.jst.server.sunappsrv.SunAppServerLaunch.launch(SunAppServerLaunch.java:163)    at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:854)    at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:703)    at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:696)    at org.eclipse.wst.server.core.internal.Server.startImpl2(Server.java:3404)    at org.eclipse.wst.server.core.internal.Server.startImpl(Server.java:3342)    at org.eclipse.wst.server.core.internal.Server$StartJob.run(Server.java:363)    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)

因此,据我所知,似乎界面中显示的错误消息具有误导性,应该是连接问题,而不是密码问题。有人知道如何解决这个问题吗?

答案1

小编典典

禁用ZoneAlarm防火墙后,我可以在Windows上成功启动GlassFish。但是,然后我开始遇到许多不相关且烦人的问题,并且如Mico所建议的那样,我转而使用Linux(这是我通常的开发平台),一切正常。

要记录该过程:

  1. 对于Eclipse Indigo,默认情况下不存在GlassFish连接器。在WTP的服务器选项卡中,右键单击并选择新建->服务器,然后单击链接“下载其他服务器适配器”,选择GlassFish并按下一步,接受许可并单击完成。

  2. 这次我自己从http://glassfish.java.net/下载了GlassFish,并选择了.sh文件格式的Unix开源版本完整平台。

  3. 在命令行上,我将归档文件移到了我要安装归档文件的父文件夹中,并命名为“ sh glassfish-3.1.1-unix.sh”,这将显示一个图形配置。我选择典型配置。

  4. 如果选择自动升级选项,请准备等待几分钟。自3.0.1以来,这是一个已知的错误,似乎他们更喜欢记录文档,而不是修复它。不必遵循建议来取消安装,只需喝杯咖啡或阅读一些新闻,它就会成功。

  5. 安装GlassFish后,在Eclipse服务器选项卡中,选择“新建”->“服务器”,然后选择“ GlassFish”->““ GlassFish Server开源版本4(Java EE 6)””,浏览Glassfish的domain1目录,将管理密码保留为空白。

此时,可以像在Tomcat中一样在Glassfish上部署项目。在我的第一天经验中,热重新部署是一种工作,但并非总是如此,但经常需要服务器停止+启动。

Centos 安装Eclipse报错java.lang.UnsatisfiedLinkError: Could not load SWT library

Centos 安装Eclipse报错java.lang.UnsatisfiedLinkError: Could not load SWT library

在CentOs上安装Eclipse时报错:

!ENTRY org.eclipse.osgi 4 0 2017-08-15 00:22:12.612
!MESSAGE Application error
!STACK 1
java.lang.UnsatisfiedLinkError: Could not load SWT library. Reasons: 
    /home/badou/app/eclipse/configuration/org.eclipse.osgi/744/0/.cp/libswt-pi-gtk-4527.so: libgtk-x11-2.0.so.0: cannot open shared object file: No such file or directory
    no swt-pi-gtk in java.library.path
    Can't load library: /home/badou/.swt/lib/linux/x86/libswt-pi-gtk-4527.so
    Can't load library: /home/badou/.swt/lib/linux/x86/libswt-pi-gtk.so
    /home/badou/.swt/lib/linux/x86/libswt-pi-gtk-4527.so: libgtk-x11-2.0.so.0: cannot open shared object file: No such file or directory

    at org.eclipse.swt.internal.Library.loadLibrary(Library.java:327)
    at org.eclipse.swt.internal.Library.loadLibrary(Library.java:236)
    at org.eclipse.swt.internal.gtk.OS.<clinit>(OS.java:38)
    at org.eclipse.swt.internal.Converter.wcsToMbcs(Converter.java:63)
    at org.eclipse.swt.internal.Converter.wcsToMbcs(Converter.java:54)
    at org.eclipse.swt.widgets.display.<clinit>(display.java:134)
    at org.eclipse.ui.internal.Workbench.createdisplay(Workbench.java:734)
    at org.eclipse.ui.PlatformUI.createdisplay(PlatformUI.java:162)
    at org.eclipse.ui.internal.ide.application.IDEApplication.createdisplay(IDEApplication.java:169)
    at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:111)
    at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:380)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:235)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:669)
    at org.eclipse.equinox.launcher.Main.basicRun(Main.java:608)
    at org.eclipse.equinox.launcher.Main.run(Main.java:1515)

原因是缺少SWT library,在联网的情况下执行一下命令:

yum install gtk2.i686 gtk2-engines.i686 PackageKit-gtk-module.i686 PackageKit-gtk-module.x86_64 libcanberra-gtk2.x86_64 libcanberra-gtk2.i686

重启Eclipse,就可以了

com.amazonaws.auth.ClasspathPropertiesFileCredentialsProvider的实例源码

com.amazonaws.auth.ClasspathPropertiesFileCredentialsProvider的实例源码

项目:tweetamo    文件:PersistentStore.java   
/**
 * The only information needed to create a client are security credentials
 * consisting of the AWS Access Key ID and Secret Access Key. All other
 * configuration,such as the service endpoints,are performed
 * automatically. Client parameters,such as proxies,can be specified in an
 * optional ClientConfiguration object when constructing a client.
 * 
 * @see com.amazonaws.auth.BasicAWSCredentials
 * @see com.amazonaws.auth.PropertiesCredentials
 * @see com.amazonaws.ClientConfiguration
 */
private PersistentStore(Region region,long readCapacity,long writeCapacity)
        throws Exception {
    /*
     * This credentials provider implementation loads your AWS credentials
     * from a properties file at the root of your classpath.
     */
    dynamoDB = new AmazonDynamoDBClient(
            new ClasspathPropertiesFileCredentialsProvider());
    dynamoDB.setRegion(region);

    try {
        if (!tablesExist()) {
            createTables(readCapacity,writeCapacity);
        }
        waitForTabletoBecomeAvailable(TABLE_NAME);
    } catch (Exception e) {
        handleException(e);
    }
}
项目:aws-iot-mqtt-load-generator    文件:MyCredentialsProvider.java   
MyCredentialsProvider() {
    super(new EnvironmentvariableCredentialsProvider(),new SystemPropertiesCredentialsProvider(),// Removed due to ElasticBeanstalk environment not being setup with a profile dir
            // new ProfileCredentialsProvider(),new InstanceProfileCredentialsProvider(),new ClasspathPropertiesFileCredentialsProvider());
}
项目:duckdns    文件:AmazonDynamoDBDAO.java   
protected AmazonDynamoDBDAO() {
    dynamoDB = new AmazonDynamoDBClient(new ClasspathPropertiesFileCredentialsProvider());
       Region usWest2 = Region.getRegion(Regions.US_WEST_2);

       String local_db = EnvironmentUtils.getInstance().getLocal_db();
       if (local_db != null && local_db.trim().length() > 0) {
        // LOCAL
        dynamoDB.setEndpoint(local_db,"local","us-west-2"); 
       } else {
        // PROD
        dynamoDB.setRegion(usWest2);
       }
       mapper = new DynamoDBMapper(dynamoDB);
}
项目:duckdns    文件:AccountTools.java   
private static void updateApp() {

    System.out.println("Downloading file (duckdns-dist) duckdns.war  --->  /var/tmp/duckdns.war");
    ClientConfiguration clientConfig = new ClientConfiguration();
    clientConfig.setProtocol(Protocol.HTTP);

    AmazonS3 conn = new AmazonS3Client(new ClasspathPropertiesFileCredentialsProvider(),clientConfig);

    conn.getobject(new GetobjectRequest("duckdns-dist","duckdns.war"),new File("/var/tmp/duckdns.war"));
    System.out.println("Done");
}
项目:milton-aws    文件:AmazonS3ManagerImpl.java   
/**
 * You can choose the geographical region where Amazon S3 will store the
 * buckets you create. You might choose a region to optimize latency,* minimize costs,or address regulator requirements.
 * 
 * @param region
 */
public AmazonS3ManagerImpl(Region region) {
    LOG.info("Create an instance of the AmazonS3Client class by providing your "
            + "AWS Account or IAM user credentials (Access Key ID,Secret Access Key)");

    // Create an instance of the AmazonS3Client class by providing your AWS
    // Account or IAM user credentials (Access Key ID,Secret Access Key)
    amazonS3Client = new AmazonS3Client(new ClasspathPropertiesFileCredentialsProvider());
    amazonS3Client.setRegion(region);
}
项目:aws-cloudtrail-processing-library    文件:PropertiesFileConfiguration.java   
/**
 * Creates a {@link PropertiesFileConfiguration} from values provided in a classpath properties file.
 *
 * @param propertiesFile the classpath properties file to load.
 */
public PropertiesFileConfiguration(String propertiesFile) {
    //load properties from configuration properties file
    Properties prop = loadProperty(propertiesFile);

    sqsUrl = prop.getProperty(SQS_URL);
    LibraryUtils.checkArgumentNotNull(sqsUrl,"Cannot find SQS URL in properties file.");

    String accessKey = prop.getProperty(ACCESS_KEY);
    String secretKey = prop.getProperty(SECRET_KEY);

    if (accessKey != null && secretKey != null) {
        awsCredentialsProvider = new ClasspathPropertiesFileCredentialsProvider(propertiesFile);
    }

    s3Region = prop.getProperty(S3_REGION);
    visibilityTimeout = getIntProperty(prop,VISIBILITY_TIMEOUT);

    sqsRegion = prop.getProperty(SQS_REGION);

    threadCount = getIntProperty(prop,THREAD_COUNT);
    threadTerminationDelaySeconds = getIntProperty(prop,THREAD_TERMINATION_DELAY_SECONDS);

    maxEventsPerEmit = getIntProperty(prop,MAX_EVENTS_PER_EMIT);
    enableRawEventInfo = getBooleanProperty(prop,ENABLE_RAW_EVENT_INFO);

    deleteMessageUponFailure  = getBooleanProperty(prop,DELETE_MESSAGE_UPON_FAILURE);
}
项目:Fancraft    文件:FandomDAO.java   
public FandomDAO() {
    client = new AmazonDynamoDBClient(
            new ClasspathPropertiesFileCredentialsProvider());
    mapper = new DynamoDBMapper(client);

    Fandom test = mapper.load(Fandom.class,"fandoms");
    if (test == null) {
        test = new Fandom();
        test.setId("fandoms");
        mapper.save(test);
    }
}
项目:Fancraft    文件:CraftDAO.java   
public CraftDAO(){
    client = new AmazonDynamoDBClient(new ClasspathPropertiesFileCredentialsProvider());
    mapper = new DynamoDBMapper(client);

    Craft test = mapper.load(Craft.class,"crafts");
    if(test == null){
        test = new Craft();
        test.setId("crafts");
        mapper.save(test);
    }
}
项目:geoprism    文件:AmazonEndpoint.java   
@Override
public void copyFiles(File directory,List<String> keys,boolean preserveDirectories)
{
  try
  {
    List<File> files = new LinkedList<File>();

    AmazonS3 client = new AmazonS3Client(new ClasspathPropertiesFileCredentialsProvider());

    for (String key : keys)
    {
      GetobjectRequest request = new GetobjectRequest("geodashboarddata",key);

      S3Object object = client.getobject(request);

      InputStream istream = object.getobjectContent();

      try
      {
        String targetPath = this.getTargetPath(preserveDirectories,key);

        File file = new File(directory,targetPath);

        FileUtils.copyInputStreamToFile(istream,file);

        files.add(file);
      }
      finally
      {
        // Process the objectData stream.
        istream.close();
      }
    }
  }
  catch (IOException e)
  {
    throw new ProgrammingErrorException(e);
  }
}
项目:geoprism    文件:AmazonEndpoint.java   
private List<String> listFiles(String prefix)
{
  List<String> files = new LinkedList<String>();

  try
  {
    AmazonS3 s3Client = new AmazonS3Client(new ClasspathPropertiesFileCredentialsProvider());

    ListObjectsRequest request = new ListObjectsRequest();
    request = request.withBucketName("geodashboarddata");
    request = request.withPrefix(prefix);

    ObjectListing listing;

    do
    {
      listing = s3Client.listObjects(request);

      List<S3ObjectSummary> summaries = listing.getobjectSummaries();

      for (S3ObjectSummary summary : summaries)
      {
        String key = summary.getKey();

        if (key.endsWith(".xml.gz"))
        {
          files.add(key);
        }
      }

      request.setMarker(listing.getNextMarker());
    } while (listing != null && listing.isTruncated());
  }
  catch (Exception e)
  {
    logger.error("Unable to retrieve files",e);
  }

  return files;
}
项目:kinesis-logback-appender    文件:CustomCredentialsProviderChain.java   
public CustomCredentialsProviderChain() {
  super(new ClasspathPropertiesFileCredentialsProvider(),new EnvironmentvariableCredentialsProvider(),new ProfileCredentialsProvider());
}
项目:transcoder    文件:ApplicationConfig.java   
@Bean
AWSCredentialsProvider awsCredentials()
{
    return new ClasspathPropertiesFileCredentialsProvider( "aws-credentials.properties" );
}
项目:ivona-speechcloud-sdk-java    文件:SampleIvonaSpeechCloudVoiceList.java   
private static void init() {
    speechCloud = new IvonaSpeechCloudClient(
            new ClasspathPropertiesFileCredentialsProvider("resources/IvonaCredentials.properties"));
    speechCloud.setEndpoint("https://tts.eu-west-1.ivonacloud.com");
}
项目:ivona-speechcloud-sdk-java    文件:SampleIvonaSpeechCloudGetVoiceListURL.java   
private static void init() {
    speechCloud = new IvonaSpeechCloudClient(
            new ClasspathPropertiesFileCredentialsProvider("resources/IvonaCredentials.properties"));
    speechCloud.setEndpoint("https://tts.eu-west-1.ivonacloud.com");
}
项目:ivona-speechcloud-sdk-java    文件:SampleIvonaSpeechCloudGetCreateSpeechURL.java   
private static void init() {
    speechCloud = new IvonaSpeechCloudClient(
            new ClasspathPropertiesFileCredentialsProvider("resources/IvonaCredentials.properties"));
    speechCloud.setEndpoint("https://tts.eu-west-1.ivonacloud.com");
}
项目:ivona-speechcloud-sdk-java    文件:SampleIvonaSpeechCloudCreateSpeech.java   
private static void init() {
    speechCloud = new IvonaSpeechCloudClient(
            new ClasspathPropertiesFileCredentialsProvider("resources/IvonaCredentials.properties"));
    speechCloud.setEndpoint("https://tts.eu-west-1.ivonacloud.com");
}
项目:ivona-speechcloud-sdk-java    文件:SampleIvonaSpeechCloudPutLexicon.java   
private static void init() {
    speechCloud = new IvonaSpeechCloudClient(
            new ClasspathPropertiesFileCredentialsProvider("resources/IvonaCredentials.properties"));
    speechCloud.setEndpoint("https://tts.eu-west-1.ivonacloud.com");
}
项目:ivona-speechcloud-sdk-java    文件:SampleIvonaSpeechCloudGetLexicon.java   
private static void init() {
    speechCloud = new IvonaSpeechCloudClient(
            new ClasspathPropertiesFileCredentialsProvider("resources/IvonaCredentials.properties"));
    speechCloud.setEndpoint("https://tts.eu-west-1.ivonacloud.com");
}
项目:ivona-speechcloud-sdk-java    文件:SampleIvonaSpeechCloudDeleteLexicon.java   
private static void init() {
    speechCloud = new IvonaSpeechCloudClient(
            new ClasspathPropertiesFileCredentialsProvider("resources/IvonaCredentials.properties"));
    speechCloud.setEndpoint("https://tts.eu-west-1.ivonacloud.com");
}
项目:ivona-speechcloud-sdk-java    文件:SampleIvonaSpeechCloudListLexicons.java   
private static void init() {
    speechCloud = new IvonaSpeechCloudClient(
            new ClasspathPropertiesFileCredentialsProvider("resources/IvonaCredentials.properties"));
    speechCloud.setEndpoint("https://tts.eu-west-1.ivonacloud.com");
}
项目:kinesis-log4j-appender    文件:CustomCredentialsProviderChain.java   
public CustomCredentialsProviderChain() {
  super(new ClasspathPropertiesFileCredentialsProvider(),new EnvironmentvariableCredentialsProvider());
}
项目:aws-big-data-blog    文件:CustomCredentialsProviderChain.java   
public CustomCredentialsProviderChain() {
    super(new EnvironmentvariableCredentialsProvider(),new ClasspathPropertiesFileCredentialsProvider(),new InstanceProfileCredentialsProvider());
}
项目:Fancraft    文件:UserDAO.java   
public UserDAO() {
    client = new AmazonDynamoDBClient(
            new ClasspathPropertiesFileCredentialsProvider());
    mapper = new DynamoDBMapper(client);
}
项目:Fancraft    文件:CommentDAO.java   
public CommentDAO() {
    client = new AmazonDynamoDBClient(
            new ClasspathPropertiesFileCredentialsProvider());
    mapper = new DynamoDBMapper(client);
}
项目:Fancraft    文件:PostDAO.java   
public PostDAO() {
    client = new AmazonDynamoDBClient(
            new ClasspathPropertiesFileCredentialsProvider());
    mapper = new DynamoDBMapper(client);
}
项目:milton-aws    文件:DynamoDBServiceImpl.java   
/**
 * The only information needed to create a client are security credentials
 * consisting of the AWS Access Key ID and Secret Access Key. All other
 * configuration,can be specified in an
 * optional ClientConfiguration object when constructing a client.
 *
 * @see com.amazonaws.auth.ClasspathPropertiesFileCredentialsProvider
 * @see com.amazonaws.regions.Region
 */
public DynamoDBServiceImpl(Region region) {
    LOG.info("Initialize Amazon DynamoDB environment...!!!");

    dynamoDBClient = new AmazonDynamoDBClient(new ClasspathPropertiesFileCredentialsProvider());
    dynamoDBClient.setRegion(region);
}
项目:sumologic-kinesis-connector    文件:KinesisConnectorExecutor.java   
/**
 * Returns an {@link AWSCredentialsProvider} with the permissions necessary to accomplish all specified
 * tasks. At the minimum it will require read permissions for Amazon Kinesis. Additional read permissions
 * and write permissions may be required based on the Pipeline used.
 * 
 * @return
 */
public AWSCredentialsProvider getAWSCredentialsProvider() {
    return new ClasspathPropertiesFileCredentialsProvider("SumologicConnector.properties");
}

CORE 3.1 Visual Studio 2019 上 IdentityServer4 ClientCredentials 的 swashbuckle 的正确配置

CORE 3.1 Visual Studio 2019 上 IdentityServer4 ClientCredentials 的 swashbuckle 的正确配置

如何解决CORE 3.1 Visual Studio 2019 上 IdentityServer4 ClientCredentials 的 swashbuckle 的正确配置?

我有一个需要授权的 API(使用属性 [Authorize]) 使用生成的数据库配置的身份服务器 4,包括表 Clients、Scope、ClientScope、Client Secrets。

我有一个带有秘密 InternalClientSecret 的客户端 InternalClient,如果从代码授权,它可以完美运行。

但我不知道如何配置正确的 swashbuckle 来使 swagger 发出授权请求

enter image description here

enter image description here

按下授权按钮后:

enter image description here

API 列表也改变外观:

enter image description here

如果我到达 API,我会得到 401,如果我按下锁定按钮,我会看到:

enter image description here

背后的代码:

services.AddSwaggerGen(c =>
        {
            c.SwaggerDoc("v1.0",new OpenApiInfo { Title = "Main API v1.0",Version = "v1.0" });

            if(configuration != null)
            {
                c.AddSecurityDeFinition("Bearer",new OpenApiSecurityScheme
                {
                    Type = SecuritySchemeType.OAuth2,Flows = new OpenApiOAuthFlows()
                    {
                        ClientCredentials = new OpenApiOAuthFlow()
                        {
                            TokenUrl = new Uri("https://localhost:44339/connect/token"),Scopes = new Dictionary<string,string>()
                            {
                                { "LookupsApi","LookupsApi" }
                            }
                        }
                    },});

                c.AddSecurityRequirement(new OpenApiSecurityRequirement
                {
                    {
                        new OpenApiSecurityScheme
                        {
                            Name = "Bearer",Scheme = "oauth2",Type = SecuritySchemeType.OAuth2,In = ParameterLocation.Header,Reference = new OpenApiReference
                            {
                                Type = ReferenceType.SecurityScheme,Id = "Bearer"
                            }
                        },new List<string>()
                    }
                });

            }

            c.OperationFilter<AuthorizeCheckOperationFilter>();
        });

        return services;
    }

    public static IApplicationBuilder UseSwaggerDocumentation(this IApplicationBuilder app)
    {
        app.UseSwagger();
        app.UseSwaggerUI(c =>
        {
            c.SwaggerEndpoint("/swagger/v1.0/swagger.json","Versioned API v1.0");
            c.SwaggerEndpoint("/swagger/v1/swagger.json","Our Awesome API V1");
            c.OAuthClientId("InternalClient");
            c.OAuthClientSecret("InternalClientSecret");
        });

        return app;
    }
internal class AuthorizeCheckOperationFilter : Swashbuckle.AspNetCore.SwaggerGen.IOperationFilter
{
    public void Apply(OpenApiOperation operation,OperationFilterContext context)
    {
        var hasAuthorize = context.ApiDescription.CustomAttributes().OfType<AuthorizeAttribute>().Any();

        if (hasAuthorize)
        {
            operation.Responses.Add("401",new OpenApiResponse { Description = "Unauthorized" });
            operation.Responses.Add("403",new OpenApiResponse { Description = "Forbidden" });

            operation.Security ??= new List<OpenApiSecurityRequirement>(); //new List<IDictionary<string,IEnumerable<string>>>();
            var openApiSecurityRequirement = new OpenApiSecurityRequirement();
            openApiSecurityRequirement.Add(new OpenApiSecurityScheme { Type = SecuritySchemeType.OAuth2 },new List<string> {
                    "LookupsApi"
                });
            operation.Security.Add(openApiSecurityRequirement);
        }
    }
}

我做错了什么,有什么想法吗?或者也许有人有一个可行的例子?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

Eclipse 3.3 + GlassFish + Java EE 5 的集成

Eclipse 3.3 + GlassFish + Java EE 5 的集成

【源创会预告】1024 程序员节(的前两天),相约开源中国办公室,我们一起聊 AI!>>>

http://www.cnblogs.com/huqingyu/archive/2008/04/24/1169600.html

今天的关于Eclipse中的Glassfish 3.1 CREDENTIAL_ERROReclipse中的快捷键的分享已经结束,谢谢您的关注,如果想了解更多关于Centos 安装Eclipse报错java.lang.UnsatisfiedLinkError: Could not load SWT library、com.amazonaws.auth.ClasspathPropertiesFileCredentialsProvider的实例源码、CORE 3.1 Visual Studio 2019 上 IdentityServer4 ClientCredentials 的 swashbuckle 的正确配置、Eclipse 3.3 + GlassFish + Java EE 5 的集成的相关知识,请在本站进行查询。

本文标签: