How can I configure glassfish-resource.xml and web.xml for my payara web app? - glassfish

I have following:
web.xml:
<web-app...>
<servlet>
<servlet-name>Jersey Web Application</servlet-name>
<servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<init-param>
<param-name>listings</param-name>
<param-value>false</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey Web Application</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<resource-ref>
<res-ref-name>datasource.mceAPPDb</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
<resource-ref>
</web-app>
glassfish-resource.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE resources PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Resource Definitions//EN" "http://glassfish.org/dtds/glassfish-resources_1_5.dtd">
<resources>
<jdbc-connection-pool name="app_emailverification"
res-type="javax.sql.DataSource"
datasource-classname="oracle.jdbc.pool.OracleDataSource"
pool-resize-quantity="2"
max-pool-size="32"
steady-pool-size="8">
<property name="URL" value="jdbc:oracle:thin:#localhost:1522:MCE0_D1"/>
<property name="user" value="app_emailverification"/>
<property name="datasourceName" value="OracleDataSource"/>
<property name="serverName" value="localhost"/>
<property name="password" value="app_emailverification"/>
</jdbc-connection-pool>
<jdbc-resource enabled="true" jndi-name="datasource.mceAPPDb" object-type="user" pool-name="app_emailverification">
<description>Test DataSource jdbc/testDS for Connection Pool jdbc/testConnPool</description>
</jdbc-resource>
</resources>
and persistence.xml:
<persistence-unit name="mceapp-app-database-model"
transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>datasource.mceAPPDb</jta-data-source>
...
</persistence-unit>
</persistence>
But when i try to deploy the war in payara server gui....i get an error :
SEVERE: java.lang.RuntimeException: Invalid resource :datasource.mceAPPDb
Whats wrong woth this setup ????

Related

Caused by: java.lang.RuntimeException: java.lang.IllegalStateException: Duplicate Filter registration for 'springSecurityFilterChain'

I'm trying to implemenmt Spring security with Oauth2 for Rest API.
well I have successfully implemented this. and everything was working fine.
but then I put 'jboss-deployement-structure.xml' in WEB-INF folder
and suddenly Im getting this Exception: Caused by: java.lang.RuntimeException: java.lang.IllegalStateException: Duplicate Filter registration for 'springSecurityFilterChain'.
I have done some debugging and found out that 'onStartup()' method of 'AbstractSecurityWebApplicationInitializer' is getting executed twice (after I added 'jboss-deployement-structure.xml')
so this is attempting to add same filter twice. and hence the exception
but I dont know why this is happening and how to solve this.
please help
My web.xml:
<display-name>Restful Web Application</display-name>
<servlet>
<servlet-name>mvc-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>mvc-dispatcher</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value> /WEB-INF/mvc-dispatcher-servlet.xml</param-value>
</context-param>
My mvc-dispatcher-servlet.xml:
<?xml version="1.0" encoding="UTF-8"?>
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">
<mvc:annotation-driven />
<context:annotation-config />
<context:component-scan base-package="com.clickawaiter" />
<bean id="customerPortalController"
class="com.clickawaiter.customerportal.controller.CustomerPortalController">
<property name="merchantServiceImpl" ref="merchantServiceImpl"></property>
</bean>
<bean id="merchantServiceImpl"
class="com.clickawaiter.customerportal.serviceimpl.MerchantServiceImpl"></bean>
<bean id="userService" class="com.clickawaiter.security.UserService">
<property name="dataSource" ref="dataSource"></property>
</bean>
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:jboss/datasources/CAW_DS" /> <!-- value="java:CAW_DS" -->
</bean>
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
My WEbAPplicationInitializer:
public class SecurityWebApplicationInitializer extends AbstractSecurityWebApplicationInitializer{
}

How can I access a JAX-RS resource?

I've created a simple JAX-RS resource class for my Java EE based project. I am trying to get a response back from the server but when I access my url I get an error back. This is the class that I wrote:
#Path("/rest")
public class RestResource {
#GET
#Produces(MediaType.APPLICATION_JSON)
public String create(String name)
{
return "print my string";
}
}
I cannot figure out what I'm doing wrong.
Do I have to define a new servlet in my web.xml? Is there something wrong with my current one?
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
metadata-complete="false">
<session-config>
<session-timeout>30</session-timeout>
</session-config>
<display-name>crud-app</display-name>
<!-- Activate the JSF 2.0 servlet -->
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- Tell the context which URLs to send through JSF -->
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<!-- This is an optional parameter, but it makes troubleshooting errors
much easier -->
<!-- You are advised to remove this context parameter before a production
deployment -->
<context-param>
<param-name>facelets.DEVELOPMENT</param-name>
<param-value>true</param-value>
</context-param>
<!-- Welcome page -->
<welcome-file-list>
<welcome-file>person.jsf</welcome-file>
</welcome-file-list>
<error-page>
<exception-type>java.lang.Throwable</exception-type>
<location>/ui/error/error.jsf</location>
</error-page>
<error-page>
<exception-type>javax.faces.application.ViewExpiredException</exception-type>
<location>/ui/error/viewExpired.jsf</location>
</error-page>
</web-app>
I managed to fix my problem by using RESTEasy. Here is my updated web.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
metadata-complete="false">
<session-config>
<session-timeout>30</session-timeout>
</session-config>
<display-name>crud-app</display-name>
<!-- Activate the JSF 2.0 servlet -->
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- Tell the context which URLs to send through JSF -->
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<!-- Auto scan REST service -->
<context-param>
<param-name>resteasy.scan</param-name>
<param-value>true</param-value>
</context-param>
<!-- this need same with resteasy servlet url-pattern -->
<context-param>
<param-name>resteasy.servlet.mapping.prefix</param-name>
<param-value>/rest</param-value>
</context-param>
<listener>
<listener-class>org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap</listener-class>
</listener>
<servlet>
<servlet-name>resteasy-servlet</servlet-name>
<servlet-class>org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>resteasy-servlet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
<!-- This is an optional parameter, but it makes troubleshooting errors
much easier -->
<!-- You are advised to remove this context parameter before a production
deployment -->
<context-param>
<param-name>facelets.DEVELOPMENT</param-name>
<param-value>true</param-value>
</context-param>
<!-- Welcome page -->
<welcome-file-list>
<welcome-file>person.jsf</welcome-file>
</welcome-file-list>
<error-page>
<exception-type>java.lang.Throwable</exception-type>
<location>/ui/error/error.jsf</location>
</error-page>
<error-page>
<exception-type>javax.faces.application.ViewExpiredException</exception-type>
<location>/ui/error/viewExpired.jsf</location>
</error-page>
</web-app>

Authentication of java melody integration with LDAP

I am using the following filter in the web.xml of my application, with it I am able to get authentication over java melody page.
How can I integrate this authentication with LDAP? When I login at localhost:8080/application/monitoring, it will ask credentials and they should be validated against LDAP.
Is it possible to achieve this?
<filter>
<filter-name>monitoring</filter-name>
<filter-class>net.bull.javamelody.MonitoringFilter</filter-class>
<init-param>
<param-name>allowed-addr-pattern</param-name>
<param-value>10\.10\.10\..*|10\.10\.10\.10|10\.10\.10\..*</param-value>
</init-param>
<init-param>
<param-name>authorized-users</param-name>
<param-value>user1:pwd1, user2:pwd2</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>monitoring</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>net.bull.javamelody.SessionListener</listener-class>
</listener>
The following is the configuration that needs to be done in web.xml and
1.server.xml in case of tomcat
2.jetty.xml in case of jetty
web.xml code:
==============
<filter>
<filter-name>monitoring</filter-name>
<filter-class>net.bull.javamelody.MonitoringFilter</filter-class>
<init-param>
<param-name>allowed-addr-pattern</param-name>
<param-value>127.0.0.1</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>monitoring</filter-name>
<url-pattern>/monitoring</url-pattern>
</filter-mapping>
<listener>
<listener-class>net.bull.javamelody.SessionListener</listener-class>
</listener>
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>Monitoring</realm-name>
</login-config>
<security-role>
<role-name>tomcat</role-name>
</security-role>
<security-constraint>
<web-resource-collection>
<web-resource-name>Monitoring</web-resource-name>
<url-pattern>/monitoring</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>tomcat</role-name>
</auth-constraint>
<!-- if SSL enabled (SSL and certificate must then be configured in the
server) <user-data-constraint> <transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint> -->
</security-constraint>
In Tomcat:
===========
Add the following realm in tomcat_home/conf/server.xml
=======================================================
<Realm className="org.apache.catalina.realm.JNDIRealm" debug="99"
connectionURL="ldap://ldapip:ldapport/" userSubtree="true"
userBase="ou=xyz,dc=abc,dc=com" userSearch="(uid={0})"
roleBase="ou=Group,dc=abc,dc=com" roleName="cn"
roleSearch="(memberUid={0})" roleSubtree="true"/>
In Jetty:
===========
Add this code in jetty.xml
<Configure id='wac' class="org.eclipse.jetty.webapp.WebAppContext">
<Set name="contextPath">/abc</Set>
<Set name="war"><Property name="jetty.webapps" default="."/>/abc.war</Set>
<Set name="extractWAR">true</Set>
<Set name="securityHandler">
<New class="org.eclipse.jetty.security.ConstraintSecurityHandler">
<Set name="loginService">
<New class="org.eclipse.jetty.jaas.JAASLoginService">
<Set name="name">Monitoring</Set>
<Set name="loginModuleName">ldaploginmodule</Set>
</New>
</Set>
</New>
</Set>
</Configure>
create a file login.conf file in etc folder of jetty_base directory:
ldaploginmodule {
org.eclipse.jetty.jaas.spi.LdapLoginModule required
debug="true"
contextFactory="com.sun.jndi.ldap.LdapCtxFactory"
hostname="ldapip"
port="ldapport"
authenticationmenthod="simple"
forceBindingLogin="true"
userBaseDn="ou=People,dc=abc,dc=com"
userRdnAttribute="uid"
userIdAttribute="uid"
userObjectClass="posixAccount"
roleBaseDn="ou=Group,dc=abc,dc=com"
roleNameAttribute="cn"
roleMemberAttribute="memberUid"
roleObjectClass="posixGroup";
};

i try to write login page in Osgi-karaf with ldap but i got this error "Can't connect to the LDAP server: [LDAP: error code 49 - Invalid Credentials]"

i want to write login page in Osgi-karaf.
My login.xhtml is ;
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>JSF 2.0 Hello World_denememememe</title>
</h:head>
<h:body>
<h3>JSF 2.0 Hello World Example - login.xhtml</h3>
<h:form id="formLogin" prependId="false"
onsubmit="document.getElementById('formLogin').action = 'j_security_check';">
<h:panelGrid columns="2">
<f:facet name="header">
Login
</f:facet>
<h:outputLabel for="j_username" value="Username: "/>
<h:inputText id="j_username" required="true" value="#{helloBean.name}" />
<h:outputLabel for="j_password" value="Password: "/>
<h:inputSecret id="j_password" required="true" value="#{helloBean.pass}" />
<f:facet name="footer">
<h:commandButton value="Login" action="#{helloBean.birlestir}"/>
</f:facet>
</h:panelGrid>
</h:form>
</h:body>
</html>
and my web.xml is ;
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>xhtmlDeneme</display-name>
<!-- Change to "Production" when you are ready to deploy -->
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<!-- Welcome page -->
<welcome-file-list>
<welcome-file>faces/login.xhtml</welcome-file>
</welcome-file-list>
<!-- JSF mapping -->
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- Map these files with JSF -->
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.faces</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<login-config>
<auth-method>FORM</auth-method>
<realm-name>karaf</realm-name>
<form-login-config>
<form-login-page>/faces/login.xhtml</form-login-page>
<form-error-page>/faces/login.xhtml</form-error-page>
</form-login-config>
</login-config>
I'm using karaf. I know when karaf is seen "j_security_check", it look "ldap-module.xml". And here is my ldap-module.xml ;
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:jaas="http://karaf.apache.org/xmlns/jaas/v1.0.0"
xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0">
<jaas:config name="karaf" rank="1">
<jaas:module className="org.apache.karaf.jaas.modules.ldap.LDAPLoginModule"
flags="required">
initialContextFactory=com.sun.jndi.ldap.LdapCtxFactory
connection.username=--valid username--
connection.password=--valid password--
connection.protocol=
connection.url=--valid url--
user.base.dn=cn=Users,dc=vmldapdevelop,dc=com
user.filter=(cn=%u)
user.search.subtree=true
role.base.dn=cn=Groups,dc=vmldapdevelop,dc=com
role.name.attribute=cn
role.filter=(uniquemember=%nsdn)
role.search.subtree=true
authentication=simple
</jaas:module>
</jaas:config>
</blueprint>
I try everything almost, but i don't change this error! When i delete from login.xhtml "j_security_check" part, its working.
Anybody help me?

Have I written an appropriate strut-config.xml file?

I am attempting to learn struts and have run into a problem. So here is the long and short of it:
The problem I am running into is I click the JSP submit button
The appropriate action is called.
The action jumps into the java classes and creates an appropriate response.
The response is returned to the action.
The action sets the ActionForm result to null, when the response was not originally null.
So my best guess so far is that I have mucked up the configuration somehow when I created a second action type or the web xml action mapping is incorrect. So can anyone tell me what is incorrect?
struts-config.xml
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_2.dtd">
<struts-config>
<form-beans>
<form-bean name="searchForm" type="com.agreen.struts.test.SearchForm" />
<form-bean name="addForm" type="com.agreen.struts.test.AddEmployeeForm" />
</form-beans>
<global-forwards>
<forward name="search" path="/search.jsp" redirect="false" />
<forward name="addEmployee" path="/addEmployee.jsp" redirect="false" />
</global-forwards>
<action-mappings>
<action path="/search"
type="com.agreen.struts.test.SearchAction"
name="searchForm"
scope="request"
validate="true"
input="/search.jsp"></action>
<action path="/addEmployee"
type="com.agreen.struts.test.AddEmployeeAction"
name="addForm"
scope="request"
validate="true"
input="/addEmployee.jsp"></action>
</action-mappings>
<message-resources parameter="MessageResources" />
</struts-config>
web.xml:
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app>
<!-- Action Servlet Configuration-->
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- Action Servlet Mapping -->
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<!-- The Welcome File List -->
<welcome-file-list>
<welcome-file>/index.jsp</welcome-file>
</welcome-file-list>
</web-app>