小编Coe*_*men的帖子

身份验证后以编程方式添加角色

我有以下JSF 2.1登录表单,在Glassfish 3.1中运行

<h:form id="loginForm">
        <h:panelGrid columns="2" cellspacing="5">
            <h:outputText value="Username" />
            <h:inputText value="#{loginHandler.username}" />
            <h:outputText value="Password:" />
            <h:inputText value="#{loginHandler.password}" />
            <h:outputLabel value="" />
            <h:commandButton value="Login" action="#{loginHandler.login}" />
        </h:panelGrid>
    </h:form>
Run Code Online (Sandbox Code Playgroud)

以及支持bean.

public String login() throws IOException, LoginException {

    log.debug("Trying to login with username " + username);

    HttpSession session = getRequest().getSession(true);

    try {
        getRequest().login(username, password);

        // if OK, add Roles
                    ????????
                    ...................

    } catch (ServletException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }


    log.debug("USER principal === " + getRequest().getUserPrincipal());

    return "home"; …
Run Code Online (Sandbox Code Playgroud)

java authentication jsf glassfish-3

6
推荐指数
2
解决办法
2万
查看次数

如何从read_committed Kafka Consumer获得最后一次提交的偏移量

我正在使用事务性KafkaProducer向主题发送消息.这很好用.我使用具有read_committed隔离级别的KafkaConsumer,我遇到了seek和seekToEnd方法的问题.根据文档,seek和seekToEnd方法给了我LSO(Last Stable Offset).但这有点令人困惑.因为它给我总是相同的值,主题的结尾.无论最后一个条目是由提交者提交还是由中止事务的一部分提交.例如,在我中止最后5次尝试插入20_000条消息后,消费者不应读取最后100_000条记录.但是在seekToEnd期间,它会移动到主题的末尾(包括100_000条消息).但是poll()并没有返回它们.

我正在寻找一种方法来检索Last Committed Offset(生成器最后一次成功提交的消息).似乎没有适当的API方法.所以我需要自己动手吗?

选项是返回并轮询直到不再检索到记录,这将导致最后提交的消息.但我认为卡夫卡提供了这种方法.

我们使用Kafka 1.0.0.

apache-kafka kafka-consumer-api kafka-producer-api

5
推荐指数
1
解决办法
2325
查看次数

PrimeFaces 面板在更新时崩溃

我不知道仅使用 primefaces 和 JSF 是否可行,但我有一个面板,该面板在视图条目上折叠。我可以打开面板,其中有一个触发面板更新的复选框。

问题是,当通过 Ajax 更新面板时,面板会再次折叠。但我想保留面板当前的打开状态。它不应该关闭更新。这可能吗?

我使用 PF 3.2 和 JSF2.1

<p:fieldset style="width:200px;height:300px;overflow:auto;">

        <h:outputLabel value="Available Applications"
    style="font-weight: bold;font-size: 14px;" />
                <br />
                <br />
                <h:panelGroup>

                    <ui:repeat var="category"
                        value="#{epsEditController.subscriptionCategoryVOs}">

                        <p:panel header="#{category.applicationCategory.name}"
                            id="panell" toggleable="true" closable="false" toggleSpeed="500"
                            collapsed="true"
                            widgetVar="panel_#{category.applicationCategory.name}">

                            <h:panelGrid columns="2" border="0">
                                <h:outputLabel value="Select all"
                                    style="font-weight: bold;float:left;" />
                                <p:selectBooleanCheckbox value="#{category.allSelected}">
                                    <p:ajax event="change"
                                        listener="#{epsEditController.selectionChanged(category)}"
                                        update="panell" />
                                </p:selectBooleanCheckbox>
                            </h:panelGrid>

                            <ui:repeat var="subcat"
                                value="#{category.applicationSubcategoryVOs}">

                                <p:selectBooleanCheckbox value="#{subcat.selected}"
                                    title="#{subcat.applicationSubcategory.name}"
                                    itemLabel="#{subcat.applicationSubcategory.name}" />

                </ui:repeat>

                </p:panel>
            </ui:repeat>
        </h:panelGroup>
    </p:fieldset>
Run Code Online (Sandbox Code Playgroud)

jsf primefaces jsf-2

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

调整大小后,Google地图也不会居中

好的,所以我有一个Jquery对话框和Google Maps v3画布.单击链接时将打开该对话框,并且地图以与链接关联的标记为中心.现在,第一次一切正常.显示地图并以标记的位置为中心.当我关闭对话框,然后单击另一个链接.地图显示但标记位于地图区域外,众所周知的左上角.我需要拖动地图以使标记出现.好的,所以我在代码中添加了多个resizes和setCenter,但它仍然不起作用.

怎么了?

这是代码var map;

        $(document).ready(function() {

            $("#map_container").dialog({
                autoOpen : false,
                resizable : false,
                resizeStop : function(event, ui) {
                    google.maps.event.trigger(map, 'resize')
                },
                open : function(event, ui) {
                    google.maps.event.trigger(map, 'resize');
                },
                close : function(event, ui) {
                    map = null;
                }
            });

            $(".show_on_map").click(function(e) {

                alert("click");

                var lat = $(this).attr('lat');
                var lng = $(this).attr('lng');
                var placeName = $(this).attr('placeName');
                var placeAddress = $(this).attr('placeAddress');

                initialize(lat, lng);
                plotPoint(lat, lng, placeName, '<span class="gBubble"><b>' + placeName + '</b><br>' + placeAddress + '</span>');

                $("#map_container").dialog("open");

            });

        function plotPoint(srcLat, srcLon, …
Run Code Online (Sandbox Code Playgroud)

jquery google-maps

4
推荐指数
1
解决办法
7285
查看次数

java邮件Base64编码字符串到图像附件

我有一个base64编码的字符串,使用JSON发布到Spring表单中.

data:image/png;base64,iVBORw0KGg......etc
Run Code Online (Sandbox Code Playgroud)

我想将此图像添加为电子邮件的附件.附加文件工作正常,但它只是添加base64字符串作为附件.

我使用以下代码来创建附件部分.

private MimeBodyPart addAttachment(final String fileName, final String fileContent) throws MessagingException {

    if (fileName == null || fileContent == null) {
        return null;
    }

    LOG.debug("addAttachment()");

    MimeBodyPart filePart = new MimeBodyPart();

    String data = fileContent;
    DataSource ds;
    ds = new ByteArrayDataSource(data.getBytes(), "image/*");

    // "image/*"
    filePart.setDataHandler(new DataHandler(ds));
    filePart.setFileName(fileName);

    LOG.debug("addAttachment success !");

    return filePart;

}
Run Code Online (Sandbox Code Playgroud)

我也试过了

 ds = new ByteArrayDataSource(data, "image/*");
Run Code Online (Sandbox Code Playgroud)

如何使用ByteArrayDataSource将base64字符串转换为正确的图像文件?

java jakarta-mail

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

Spring Boot 2 Actuator 端点在 GET 请求时返回 405

我正在配置 spring Boot 执行器,但 /actuator 和 /health 端点在每个 GET 请求中返回 405。

我打开了整个安全机制,但它不起作用:

management.endpoints.jmx.exposure.exclude=*
management.endpoints.web.exposure.include=health,info,beans,env
management.endpoint.health.enabled=true
management.security.enabled=false
management.endpoint.beans.cache.time-to-live=10s
management.endpoints.web.cors.allowed-origins=*
management.endpoints.web.cors.allowed-methods=GET,POST
Run Code Online (Sandbox Code Playgroud)

我添加了以下配置

@Configuration(proxyBeanMethods = false)
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

@Override
public void configure(HttpSecurity http) throws Exception {
    http.authorizeRequests().antMatchers("/health", "/actuator").permitAll().and().csrf().disable();
    super.configure(http);
}
Run Code Online (Sandbox Code Playgroud)

}

因此,我按照教程进行操作,看起来非常简单,我不明白为什么在默认 GET 请求上收到此 405。当我使用 cURL 调用端点时:

 curl http://localhost:8080/sm-integration/health -v --> 405
 curl -X POST http://localhost:8080/sm-integration/health -v --> 400
Run Code Online (Sandbox Code Playgroud)

我不明白在执行 POST 时出现 400 Bad Request。文档指出 /health 是最基本和开放的端点,应该作为 GET 调用来调用。那么为什么是405呢?

更新 收到几个答案后,我设置了如下配置:

@Override
public void configure(HttpSecurity http) throws Exception …
Run Code Online (Sandbox Code Playgroud)

java spring spring-security spring-boot spring-boot-actuator

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