background image

Modifying Runtime Properties

<< Modifying ConverterBean | confidentiality Element >>
<< Modifying ConverterBean | confidentiality Element >>

Modifying Runtime Properties

private BigDecimal yenRate = new BigDecimal(
"115.3100");
private BigDecimal euroRate = new BigDecimal(
"0.0071");
@RolesAllowed("BeanUser")
public BigDecimal dollarToYen(BigDecimal dollars) {
BigDecimal result = new BigDecimal("0.0");
Principal callerPrincipal = ctx.getCallerPrincipal();
if (ctx.isCallerInRole("BeanUser")) {
result = dollars.multiply(yenRate);
return result.setScale(2, BigDecimal.ROUND_UP);
}else{
return result.setScale(2, BigDecimal.ROUND_UP);
}
}
@RolesAllowed("BeanUser")
public BigDecimal yenToEuro(BigDecimal yen) {
BigDecimal result = new BigDecimal("0.0");
Principal callerPrincipal = ctx.getCallerPrincipal();
if (ctx.isCallerInRole("BeanUser")) {
result = yen.multiply(euroRate);
return result.setScale(2, BigDecimal.ROUND_UP);
}else{
return result.setScale(2, BigDecimal.ROUND_UP);
}
}
}
Modifying Runtime Properties for the Secure Converter Example
Secure connections, username-password login, and the mapping of application roles to
Application Server groups and principals are specified in the runtime deployment descriptor
file sun-ejb-jar.xml. The original converter application that did not include any security
mechanisms did not have a need for this file: it has been added specifically for this application.
To map the role of BeanUser that is defined for this application to the group with the name of
user
in the file realm of the Application Server, specify the security-role-mapping element as
shown below. Make sure that the role-name and group-name elements are specified exactly as
they are used (the mapping is case-sensitive).
To specify username-password login and a secure connection, use the ior-security-config
element. The IOR security elements are described in more detail in
"Configuring IOR Security"
on page 817
.
The following sun-ejb-jar.xml file demonstrates how to specify a secure connection,
username-password login, and security role mapping. The completed version of this file can be
found in
tut-install/javaeetutorial5/examples/ejb/converter-secure/converter-secure-ejb/
src/conf/sun-ejb-jar.xml
.
Enterprise Bean Example Applications
The Java EE 5 Tutorial · September 2007
828