How to configure JsonPArser features in XML - jackson

I want to disable the CANONICALIZE_FIELD_NAMES feature and wanted to know how can I do that through xml http://cxf.apache.org/schemas/jaxrs.xsd. For example I would configure the providers as follows
<jaxrs:providers>
<bean class="org.codehaus.jackson.jaxrs.JacksonJsonProvider"/>
</jaxrs:providers>
I assume the features would also be configured in a similar fashion
<jaxrs:features>
----
</jaxrs:features>
I tried checking online did not find any solution

Related

MobileFirst 8 javascript adapters and messages

i have some questions about MobileFirst Adapters:
We are implementing javascript adapters on a MobileFirst 8 server.
Where is the best place to write javascript utils functions?
I also have some utils on java classes (called from javascript adapters) and i need to use the ConfigurationAPI class to get properties. The problem is that the configurationAPI variable (instantiated with the #Context annotation) is always null. Why? How can i get properties values from Java code?
I have a lot of properties (for example low-level backend endpoints) that should be shared between all the adapters. At the moment i used the <property name="" displayName="" defaultValue="" /> syntax, should i copy and paste them in all adapters?! Or where should i put them?
Thank you
We are implementing javascript adapters on a MobileFirst 8 server.
Where is the best place to write javascript utils functions?
JavaScript adapters allow for a single .js file, so your best place for any adapters JavaScript code is the same .js file...
I have a lot of properties (for example low-level backend endpoints)
that should be shared between all the adapters. At the moment i used
the <property name="" displayName="" defaultValue="" /> syntax, should
i copy and paste them in all adapters?! Or where should i put them?
See my answer to the following question. Once you add custom properties you should be able to handle them in the same way I mention handling other values from the adapter.xml file: Unable to build adapters using profiles and properties in Maven
I also have some utils on java classes (called from javascript
adapters) and i need to use the ConfigurationAPI class to get
properties. The problem is that the configurationAPI variable
(instantiated with the #Context annotation) is always null. Why? How
can i get properties values from Java code?
I've sent a question internally and will let you know once I get an answer.

how to configure the external properfiles into the OSGI

we are using the Jboss fuse 6.2 along with technical stack blueprint,camel ,activeMQ and Mybatis.
We need to know about how to configure the property files in OSGI ,
as per my knowledge we could configure .cfg files, but is there any simplest way to use like spring configuring the configuring.
In Our code we are reading from property files . using namespace ext:proeprtyplaceHolder giving that bean id and values we are giving .
Help to provide is there any simplest way to read the property files
There is several ways to add configuration, because OSGi services can access configuration via ConfigurationAdmin service. The blueprint also can access property values over it.
JBoss fuse using karaf, so you can use the following methods.
(There is some quotes from http://www.liquid-reality.de/display/liquid/2011/09/23/Karaf+Tutorial+Part+2+-+Using+the+Configuration+Admin+Service)
Configuration with Blueprint
The integration with our bean class is mostly a simple bean definition where we define the title property and assign the placeholder which will be resolved using the config admin service. The only special thing is the init-method. This is used to give us the chance to react after all changes were made like in the pure OSGi example.
For blueprint we do not need any maven dependencies as our Java Code is a pure Java bean. The blueprint context is simply activated by putting it in the OSGI-INF/blueprint directory and by having the blueprint extender loaded. As blueprint is always loaded in Karaf we do not need anything else.
<cm:property-placeholder persistent-id="ConfigApp" update-strategy="reload" >
<cm:default-properties>
<cm:property name="title" value="Default Title"/>
</cm:default-properties>
</cm:property-placeholder>
<bean id="myApp" init-method="refresh">
<property name="title" value="${title}"></property>
</bean>
After you can put a cfg file (which is a standard java property file) to
karaf's etc or deploy directory with the name of of the given persistent-id which is MyApp in our example. (For example: /etc/ConfigApp.cfg)
title=Configured title

How do I define a security realm in a JavaEE Stack in Cloudbees?

I'm trying to run a simple web application in a JavaEE stack in CloudBees. As part of this application, I define a security realm which is a DataSourceRealm
<login-config>
<auth-method>FORM</auth-method>
<realm-name>ResmanRealm</realm-name>
<form-login-config>
<form-login-page>/welcome.xhtml</form-login-page>
<form-error-page>/welcome.xhtml</form-error-page>
</form-login-config>
</login-config>
I've written this to date using a local Glassfish3 server, in which I define the ResmanRealm against a JDBC resource. In Glassfish3-config-speak, that ends up looking like this
<auth-realm classname="com.sun.enterprise.security.auth.realm.jdbc.JDBCRealm" name="ResmanRealm">
<property name="jaas-context" value="jdbcRealm"></property>
<property name="encoding" value="Hex"></property>
<property name="password-column" value="password"></property>
<property name="datasource-jndi" value="jdbc/ResManPool"></property>
<property name="group-table" value="V_USER_ROLE"></property>
<property name="user-table" value="USER"></property>
<property name="group-name-column" value="role"></property>
<property name="digest-algorithm" value="SHA-256"></property>
<property name="user-name-column" value="name"></property>
</auth-realm>
So, this all works locally. I saw that in Cloudbees, there's a cloudbees xml file which the doco states is legacy, but looked like it had some form of support to for this. What I cannot find is any examples of how to define a security realm as a Configuration Parameter. It looks like if could be a resource (in CloudBees-speak), and you could define it as you bind a database to an application. But, an example would be nice, as the existing resource examples (at least the ones I can find) are a bit general.
Also, the output log from my (currently unsuccessful) application startup don't show that DataSourceRealms are being loaded?
[#|2013-02-25T11:03:51.319+0000|INFO|glassfish3.1.2|javax.enterprise.system.core.security.com.sun.enterprise.security|_ThreadID=12;_ThreadName=AutoDeployer;|SEC1010: Entering Security Startup Service|#]
[#|2013-02-25T11:03:51.333+0000|INFO|glassfish3.1.2|javax.enterprise.system.core.security.com.sun.enterprise.security|_ThreadID=12;_ThreadName=AutoDeployer;|SEC1143: Loading policy provider com.sun.enterprise.security.provider.PolicyWrapper.|#]
[#|2013-02-25T11:03:51.452+0000|INFO|glassfish3.1.2|javax.enterprise.system.core.security.com.sun.enterprise.security.auth.realm|_ThreadID=12;_ThreadName=AutoDeployer;|SEC1115: Realm [admin-realm] of classtype [com.sun.enterprise.security.auth.realm.file.FileRealm] successfully created.|#]
[#|2013-02-25T11:03:51.461+0000|INFO|glassfish3.1.2|javax.enterprise.system.core.security.com.sun.enterprise.security.auth.realm|_ThreadID=12;_ThreadName=AutoDeployer;|SEC1115: Realm [file] of classtype [com.sun.enterprise.security.auth.realm.file.FileRealm] successfully created.|#]
[#|2013-02-25T11:03:51.483+0000|INFO|glassfish3.1.2|javax.enterprise.system.core.security.com.sun.enterprise.security.auth.realm|_ThreadID=12;_ThreadName=AutoDeployer;|SEC1115: Realm [certificate] of classtype [com.sun.enterprise.security.auth.realm.certificate.CertificateRealm] successfully created.|#]
[#|2013-02-25T11:03:51.498+0000|INFO|glassfish3.1.2|javax.enterprise.system.core.security.com.sun.enterprise.security|_ThreadID=12;_ThreadName=AutoDeployer;|SEC1011: Security Service(s) Started Successfully|#]
So, if anyone's had success with defining DataSourceRealms ina JavaEE stack in CloudBees, I'd appreciate any nudges in the right direction. Thanks for any info.
CloudBees now supports JaaS Authentication and Security Realms on the Glassfish3 and Glassfish4 stacks as documented here:
Glassfish3:
Docs: https://developer.cloudbees.com/bin/view/RUN/Glassfish3_JaaS_Authentication
Demo app: https://github.com/CloudBees-community/glassfish-clickstart
Glassfish4:
Docs: https://developer.cloudbees.com/bin/view/RUN/Glassfish4_JaaS_Authentication
Demo app: https://github.com/CloudBees-community/glassfish4-clickstart
Please not that CloudBees security realms for Glassfish3 and Glassfish4 are exclusively based on JdbcRealms which seems to be your need.
Container based authentication isn't available on CloudBees stacks, but the tomcat6 for legacy reasons. Preferred approach is to instrument application with a security framework (spring-security or any other)

Spring Encrypt Values from Properties File

I am currently using a UserDetailsService to get values from a user file:
<bean id="userDetailsService" class="org.springframework.security.userdetails.memory.InMemoryDaoImpl">
<property name="userProperties" value="users.properties"/>
</bean>
My properties file is meant to be edited by the admin and the username passwords are not encrypted:
bob=bobpassword
alice=alicepassword
Now, since I use a PasswordEncoder in my application, I need to encrypt the passwords and add them to the UserDetails. This can be done somewhere in the code, but is not very handy in my opinion.
I found the PropertyPlaceholderConfigurer with the method convertPropertyValue(String value), which can be overridden.
From what I understand, it should be possible to load the properties file into the PropertyPlaceholderConfigurer, where the properties could be encrypted in the convertPropertyValue method and then loaded by the UserDetailsService. Is that possible to do? If yes, hints would help me, otherwise I'd appreciate to see an alternative solution.
Take a look at Jasypt, it is a java library which allows the developer to add basic encryption capabilities to his/her projects with minimum effort, and without the need of having deep knowledge on how cryptography works.
You can see how to configure it with Spring here
As an alternative, you may also implement your own propertyPersister to do the (d)encryption:
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<value>classpath:com/foo/jdbc.properties</value>
</property>
<property name="propertiesPersister">
<bean class="com.mycompany.MyPropertyPersister" />
</property>
</bean>
Take a look at the example here
Similar to what you expect can be found in
http://kayalvizhiameen.blogspot.in/2014/04/handling-obfuscated-property-values-in.html

Setup resources for GlassFish2.x Cargo deployment

I'm trying to get integration testing working for a GlassFish 2.x project, using Maven2 and Cargo. I finally have Cargo attempting to deploy my EAR but it fails to start because the data source is not configured. The app also depends on a few JMS queues and a connection factory - how do I add these?
The Cargo Glassfish 2.x plugin says existing configurations are not supported, so I can't do that.
Using the maven-glassfish-plugin is an option, but we also run OC4J so a Cargo solution would be preferred.
edit: The resources are: 1 JDBC connection pool, 1 JDBC resource, 4 JMS queues, 2 JMS connection factories and a custom security realm (pear tree optional). The realm needs an entry in the login.conf like:
myRealm {
uk.co.mycom.MyGlassFishLoginModule required;
};
I'm not sure (I never used this) but IIRC, you should be able to put your datasource configuration in a sun-resources.xml file and package it under META-INF/sun-resources.xml in your EAR and GlassFish is supposed to create the resources at deploy time.
Here is an example sun-resources.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE resources PUBLIC "-//Sun Microsystems Inc.//DTD Application Server 9.0 Domain//EN" "sun-resources_1_3.dtd">
<resources>
<jdbc-connection-pool name="SPECjPool" steady-pool-size="100"
max-pool-size="150" max-wait-time-in-millis="60000"
pool-resize-quantity="2" idle-timeout-in-seconds="300"
is-isolation-level-guaranteed="true"
is-connection-validation-required="false"
connection-validation-method="auto-commit"
fail-all-connections="false"
datasource-classname="oracle.jdbc.pool.OracleDataSource">
<property name="URL"
value="jdbc:oracle:thin:#iasperfsol12:1521:specdb"/>
<property name="User" value="spec"/>
<property name="Password" value="spec"/>
<property name="MaxStatements" value="200"/>
<property name="ImplicitCachingEnabled" value="true"/>
</jdbc-connection-pool>
<jdbc-resource enabled="true" pool-name="SPECjPool"
jndi-name="jdbc/SPECjDB"/>
</resources>
Give it a try.
Resources
The sun-resources.xml File
Thanks, that worked. The datasource seems to have gone in okay and the app has deployed. However from the doc you linked, I can't see how to add the other things I need (edited more detail into my question about these). This solution also means that I will have to (use profiles to?) build my EAR differently for IT, which is imperfect.
I somehow missed that you wanted to create other resources than Datasources and I've seen several threads reporting that the suggested approach won't work with GlassFish v2 for any resources (like JMS resources). My bad.
So, given the current state, your options are (IMO):
contribute to Cargo to provide an "existing" configuration implementation for GlassFish v2
use the maven-glassfish-plugin as you suggested
I don't have any better suggestions.