google Analytics

Showing posts with label JBOSS. Show all posts
Showing posts with label JBOSS. Show all posts

Wednesday, November 17, 2010

configuring security domains for authentication and authorization in JBoss

configuring security domains for authentication and authorization in JBoss
Securing Ejb Using JBOSS
EJB Security in JBOSS or securing Web Application in JBOSS
Setup security-domain For JBoss

=============================================================



=============================================================

To enable security in the JBoss application server, you need to create a security domain .
A security domain is a repository for users, passwords, and the roles with which each user is associated.
The EJB container delegates to the security domain when performing authentication and authorization



============================================================
Security domains are configured in the
jboss/server/default/conf/login-config.xml
Add the following entry in under the Poplict Tag

<application-policy name="testSecurityDomain">
  <authentication>
      <login-module code="org.jboss.security.auth.spi.UsersRolesLoginModule"     flag = "required">
         <module-option name="usersProperties">
                   users.properties
         </module-option>
         <module-option name="rolesProperties">
                   roles.properties
         </module-option>
      </login-module>
  </authentication>
</application-policy>




The user-test.properties files
users.properties
anish=anish
nath=nath



roles-test.properties
wburke=AUTHORIZED
richard=UNAUTHORIZED



-----
The Bean Class
@Stateless
@SecurityDomain("testSecurityDomain")  //Configured in
login-config.xml
@RolesAllowed("AUTHORIZED")

public class TestBean implements TestBeanRemote,
                                           TestBeanLocal
{

@RolesAllowed({"AUTHORIZED", "CHECK_FRAUD_ENABLED"})
public voidsayHello(){}   
}


@PermitAll
public voidsayHelloWorld(){}   
}

}

}


=====================================
The client Class will hold the following information
Properties env = new Properties( );
env.setProperty(Context.SECURITY_PRINCIPAL, "anish");
env.setProperty(Context.SECURITY_CREDENTIALS, "anish");
env.setProperty(Context.INITIAL_CONTEXT_FACTORY,
"org.jboss.security.jndi.JndiLoginInitialContextFactory");



---------------------------------------
Configure JBoss Security
------------------------------------
ANish

Tuesday, October 12, 2010

JBOSS Clustering

JBOSS JMS clustering
----------------------


=============================================================



=============================================================
run.bat -c node1 -g PartitionA -u 239.255.100.100 -b localhost -Djboss.messaging.ServerPeerID=1
run.bat -c node2 -g PartitionB -u 239.255.100.100 -b localhost -Djboss.messaging.ServerPeerID=2

=============================================================



=============================================================
JBoss Messaging clusters JMS queues and topics transparently  across the cluster. Messages sent to
a distributed queue or topic on one node are consumable on other nodes. To designate that a particular destination is clustered, simply set the Clustered attribute in the destination deployment descriptor to true:
=============================================================



=============================================================
<mbean code="org.jboss.jms.server.destination.QueueService"
name="jboss.messaging.destination:service=Queue,name=clusteredQueue"
xmbean-dd="xmdesc/Queue-xmbean.xml">
<depends optional-attribute-name="ServerPeer">
jboss.messaging:service=ServerPeer
</depends>
<depends>jboss.messaging:service=PostOffice</depends>
<attribute name="Clustered">true</attribute>
</mbean>
=============================================================
 

=============================================================
Configuring EJB 3.0 Stateful Session Bean cache
The @org.jboss.ejb3.annotation.CacheConfig Annotation

@Stateful
@Clustered
@CacheConfig(name="new-sfsb-cache")
@Remote(StatefulRemote.class)

Configuring entity caching

<properties>
<property name="hibernate.cache.use_second_level_cache" value="true"/>
<property name="hibernate.cache.use_query_cache" value="true"/>
<property name="hibernate.cache.region.factory_class"
value="org.hibernate.cache.jbc2.JndiMultiplexedJBossCacheRegionFactory"/>
<property name="hibernate.cache.region.jbc2.cachefactory" value="java:CacheManager"/>
<property name="hibernate.cache.region.jbc2.cfg.entity" value="mvcc-entity"/>
<property name="hibernate.cache.region.jbc2.cfg.collection" value="mvcc-entity"/>
</properties>



=============================================================



=============================================================

import javax.persistence.*;
import org.hibernate.annotations.*;
@Entity
@Cache (usage=CacheConcurrencyStrategy.TRANSACTIONAL)
public class ProductEntity implements Serializable {
}
Refer
//deploy\cluster\jboss-cache-manager.sar\META-INF\jboss-cache-configs.xml & jboss-cache-manager-jboss-beans.xml

=============================================================
 

=============================================================
Clustering web applications

Configuring HTTP replication

In web.xml add adding the<distributable /> tag

<web-app>
. . . . .
<distributable />
</web-app>

Refer :jbossweb.deployer\META-INF\war-deployers-jboss-beans.xml

The jboss-web.xml

<!DOCTYPE jboss-web PUBLIC
-//JBoss//DTD Web Application 5.0//EN
http://www.jboss.org/j2ee/dtd/jboss-web_5_0.dtd>
<jboss-web>
<replication-config>
<cache-name>custom-web-cache</cache-name>
<replication-trigger>SET</replication-trigger>
<replication-granularity>ATTRIBUTE</replication-granularity>
<max-unreplicated-interval>30</max-unreplicated-interval>
<snapshot-mode>instant</snapshot-mode>
<snapshot-interval>1000</snapshot-interval>
</replication-config>
</jboss-web>


=============================================================
 

=============================================================

Jboss  clustering Example
Clustering Web Using Jboss
JMS Clustering Example
Running Jboss in Clustering Mode

--
Anish

Monday, September 20, 2010

Jboss Cluster Configuration


Jboss Cluster Configuration



=============================================================
 

Starting with a newly unzipped copy of JBoss, navigate into the server
directory and copy the
 all directory twice: once to a directory called
node1 and once to a directory called node2. The contents of your server
directory should now look like that




Issue the following command

run -c node1 -g  cluster1 -u 239.255.100.100 -b localhost -Djboss.messaging.ServerPeerID=1 -Djboss.service.binding.set=ports-01
run  -c node2 -g cluster2 -u 239.255.100.100 -b localhost -Djboss.messaging.ServerPeerID=1 -Djboss.service.binding.set=ports-02





=============================================================

Creating a clustered EJB

The remote interface for a clustered SLSB
import javax.ejb.Remote;
@Remote
public interface TestRemote {
  public void sayHello(String msg);
}

The bean code for a clustered SLSB
import javax.ejb.Stateless;
import org.jboss.ejb3.annotation.Clustered;
@Stateless
@Clustered
public class TestBean implements Counter {
  public void sayHello(String msg) {
    System.out.println(countNumber);
  }
}
 
@org.jboss.ejb3.annotation.Clustered annotation defined.
This annotation tells the server that this bean is clustered and should be load balanced.



Calling the clustered EJB
The client code that calls the clustered SFSB

import javax.naming.Context;
import javax.naming.InitialContext;
public class Client {
  public static void main(String[] args) throws Exception {
    InitialContext ctx = new InitialContext();
    TestRemote s = (TestRemote) ctx.lookup("TestBean/remote");
    for (int i = 0; i < 100; i++) {
      s.sayHello("Anish")
      Thread.sleep(1000);
    }
  }
}


includes the client/jbossallclient.jar in your classpath
The Jndi.properties file
java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.factory.url.pkgs=org.jboss.naming

=========================================
jboss clustering example/clustering with JBOSS 5.0/ejb
jboss clustering step by step
jboss clustering step by step
@clustered annotation
EJB Clustering Example
===============================================

ANish

Wednesday, August 11, 2010

Jboss Loading multiple ear with one class laoder

META-INF\jboss-app.xml

<?xml version="1.0" encoding="UTF-8"?>
<jboss-app>
<loader-repository>
org.myapp:loader=MyClassLoader
<loader-repository-config>
java2ParentDelegation=false
</loader-repository-config>
</loader-repository>
</jboss-app>

Thursday, July 15, 2010

Jboss Management Interface Example

import javax.interceptor.Interceptors;
import org.jboss.ejb3.annotation.Clustered;
import org.jboss.ejb3.annotation.Depends;
import org.jboss.ejb3.annotation.Management;
import org.jboss.ejb3.annotation.Service;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.ejb.interceptor.SpringBeanAutowiringInterceptor;

/**
* @author Anish
*
*/
@Service (name = "AnishService")
@Management (PlcService.class)
@Clustered
@Depends ({"jboss.ha:service=HASingletonDeployer,type=Barrier"})
@Interceptors(SpringBeanAutowiringInterceptor.class)
public class AnishServiceBean implements AnishService{

private CISLogger logger = new CISLogger(getClass().getName());

@Override
public void create() throws Exception {
logger.info("Anish service created");
}

@Override
public void destroy() {
logger.info("Anish service destroyed");
}

@Override
public void start() throws Exception {
logger.info("Anish Cluster Wide Singleton Started");

/*
* deploys all spring beans.
* setting the application context will let other projects to use these beans.
*/


ApplicationContext applicationContext = new ClassPathXmlApplicationContext(
AnishConstants.SPRING_CONTEXT_PATH);

ApplicationContext AnishContext = (ApplicationContext) applicationContext
.getBean(AnishConstants.Anish_CONTEXT_BEAN_NAME);

for(String name : AnishContext.getBeanDefinitionNames())
logger.debug(name + " spring bean loaded");

AnishApplicationManager applicationManager = (AnishApplicationManager) AnishContext
.getBean("AnishApplicationManager");


}

@Override
public void stop() {
logger.info("Anish Cluster Wide Singleton Stoped");
}

}

public interface AnishService {

void create() throws Exception;
void start() throws Exception;
void stop();
void destroy();
}

Thursday, July 8, 2010

Running Jboss in Cluster Commands

TITLE node 1 (8080)

rem cd /../-5.1.0.GA/bin


cd bin

run -c node1 -g CISDocsPartition -u 239.255.100.100 -b localhost -Djboss.messaging.ServerPeerID=1 -Djboss.service.binding.set=ports-01

pause


TITLE node 2 (8080)

rem cd jboss-5.1.0.GA/bin

set JAVA_HOME=C:\Program Files\Java\jdk1.6.0_04

cd bin

run -c node2 -g CISDocsPartition -u 239.255.100.100 -b localhost -Djboss.messaging.ServerPeerID=1 -Djboss.service.binding.set=ports-02

paus

JBOSS Tree chache Service Examples