Java Azure Adal与Dropwizard

Java Azure Adal与Dropwizard,java,azure,dropwizard,adal,azure-active-directory,Java,Azure,Dropwizard,Adal,Azure Active Directory,我试图找到一个使用Dropwizard的Azure Adal(Oauth2)示例,但似乎找不到任何东西 dropwizard网站上的Oauth2示例非常模糊,我似乎不明白在哪里提供ClientId和令牌端点 任何人都有关于如何将Oauth2(Azure AD)与Dropwizard一起使用的示例我对Dropwizard没有任何经验,但我确实找到了一些可能对您有所帮助的示例代码 我想指出我在自述部分注意到的一个小免责声明 此项目仅用于CommerceHub的内部项目。您应该熟悉DropWizard

我试图找到一个使用Dropwizard的Azure Adal(Oauth2)示例,但似乎找不到任何东西

dropwizard网站上的Oauth2示例非常模糊,我似乎不明白在哪里提供ClientId和令牌端点


任何人都有关于如何将Oauth2(Azure AD)与Dropwizard一起使用的示例

我对Dropwizard没有任何经验,但我确实找到了一些可能对您有所帮助的示例代码

我想指出我在自述部分注意到的一个小免责声明

此项目仅用于CommerceHub的内部项目。您应该熟悉DropWizard手册的auth部分

也就是说,作为一个样本,它对我来说是相当可行的,希望这能帮助你。以下是他们发布的示例配置,以供参考

    ad:
    domain: my.company.example.com  # No Default
    domainController: my-fav-dc.my.company.example.com # Default: <domain>
    sslEnabled: true  # Default: true
    usernameFilterTemplate: (&((&(objectCategory=Person)(objectClass=User)))(sAMAccountName=%s)) # Default: <As shown> %s replaced with the sAMAccountName
    attributeNames: # Default: <As Shown>. first two are required. Will be fetched as String.
        - sAMAccountName
        - memberOf
        - mail
    binaryAttributeNames: # Default: empty. Will be fetched as byte[]. Need for the ones below.
        - objectGUID
        - objectSid
    connectionTimeout: 1000 # Default: as shown in millseconds
    readTimeout: 1000 # Default: as shown in millseconds
    requiredGroups: # Default: <empty>
        - All
        - Of
        - These
        - Are
        - Required
        - Or
        - You
        - Get
        - A
        - 401
ad:
域:my.company.example.com#无默认值
domainController:my-fav-dc.my.company.example.com#默认值:
sslEnabled:true#默认值:true
usernameFilterTemplate:(&(&(&(objectCategory=Person)(objectClass=User))(sAMAccountName=%s))#默认值:%s替换为sAMAccountName
AttributeName:#默认值:。前两个是必需的。将作为字符串获取。
-sAMAccountName
-成员
-邮寄
BinaryAttributeName:#默认值:空。将作为字节[]获取。需要下面这些。
-对象GUID
-对象SID
connectionTimeout:1000#默认值:以毫秒为单位
readTimeout:1000#默认值:以毫秒为单位
requiredGroups:#默认值:
-全部
-的
-这些
-是
-必需的
-或
-你
-得到
-A
- 401
我还包括了页面中的示例:

@Override
public void run(HelloWorldConfiguration configuration, Environment environment) throws ClassNotFoundException {
...
// dropwizard 0.9.x
environment.jersey().register(new AuthDynamicFeature(
        new BasicCredentialAuthFilter.Builder<AdPrincipal>()
            .setAuthenticator(AdAuthenticator.createDefault(configuration.getAdConfiguration()))
            .setRealm("MSAD")
            .buildAuthFilter()));
environment.jersey().register(RolesAllowedDynamicFeature.class);
environment.jersey().register(new AuthValueFactoryProvider.Binder<>(AdPrincipal.class));

// dropwizard 0.7.x
environment.jersey().register(new BasicAuthProvider<>(AdAuthenticator.createDefault(configuration.getAdConfiguration()), "MSAD"));
...
environment.jersey().register(new ProtectedResource());
}
@覆盖
公共void运行(HelloWorldConfiguration配置,环境)引发ClassNotFoundException{
...
//dropwizard 0.9.x
environment.jersey().register(新AuthDynamicFeature)(
新建BasicCredentialAuthFilter.Builder()
.setAuthenticator(AdAuthenticator.createDefault(configuration.getAdConfiguration()))
.setRealm(“MSAD”)
.buildAuthFilter());
environment.jersey().register(RolesAllowedDynamicFeature.class);
register(新的AuthValueFactoryProvider.Binder(AdPrincipal.class));
//dropwizard 0.7.x
environment.jersey().register(新BasicAuthenticator.createDefault(configuration.getAdConfiguration()),“MSAD”);
...
environment.jersey().register(newprotectedResource());
}

我没有Dropwizard方面的经验,但我认为您可能希望将Azure AD与您的应用程序集成,以调用某些Azure服务或实现类似SSO的身份验证

我用Dropwizard在用户手册中搜索OAuth2。它似乎通过将相关的REST服务注册到应用程序容器中作为Spring框架的过滤器来进行身份验证和授权

Azure官方网站上有一个示例演示了如何使用。我认为了解这些步骤对你很有帮助


如果有任何问题,请随时告诉我。

嘿,我尝试运行示例java web应用程序,但出现错误,说它缺少主应用程序method@user3711455您是如何运行样本的?它应该部署在Tomcat或Jetty.Ops上。对不起,我只是想独自运行这场战争(这里是noob)。和泽西一起运行,它工作正常。现在我们需要弄清楚如何使用它Dropwizard@user3711455请尝试通过将war文件复制到Tomcat路径中的目录
webapps
来在Tomcat上部署war。如果可行,您只需要使用FTP或Kudu控制台将war文件上载到Azure上路径“D:\home\site\wwwroot”的同一目录中。