Saturday, June 10, 2017

WebLogic: avoiding anonymous user calls

Servlet or JSP initialization


weblogic.xml

<servlet-descriptor>
       <servlet-name>MyServletName</servlet-name>
       <init-as-principal-name>MySERVLET.INIT.USER</init-as-principal-name>
   </servlet-descriptor>


Where MyServletName needs to be replaced with the name of your Servlet, as declared in the web.xml file.

ServletContextListener


config.xml
  <app-deployment>
    <name>myapp</name>
    <target>webInitServer</target>
    <source-path>./deploy/presear</source-path>
    <deployment-principal-name>MY.DEPLOYMENT.PRINCIPAL</deployment-principal-name>
    <security-dd-model>Advanced</security-dd-model>
    <staging-mode>nostage</staging-mode>
  </app-deployment>



EJB create method


weblogic-ejb-jar.xml
<?xml version="1.0" encoding="UTF-8"?>
<weblogic-ejb-jar xmlns="http://www.bea.com/ns/weblogic/90" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.bea.com/ns/weblogic/90 http://www.bea.com/ns/weblogic/910/weblogic-ejb-jar.xsd">
  <weblogic-enterprise-bean>
    <ejb-name>MyEJB</ejb-name>
    <stateless-session-descriptor>
      <business-interface-jndi-name-map>
        <business-remote>acme.ejb.test.MyEJB</business-remote>
        <jndi-name>pippo</jndi-name>
      </business-interface-jndi-name-map>
      <pool>
        <max-beans-in-free-pool>5</max-beans-in-free-pool>
        <initial-beans-in-free-pool>1</initial-beans-in-free-pool>
      </pool>
       <stateless-bean-is-clusterable>True</stateless-bean-is-clusterable>
      </stateless-clustering>
    </stateless-session-descriptor>
    <create-as-principal-name>MY.EJB.CREATE.PRINCIPAL</create-as-principal-name>
</weblogic-ejb-jar>



EJB timer


ejb-jar.xml

<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar id="ejb-jar" 
 xmlns="http://java.sun.com/xml/ns/javaee" version="3.0"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd">
  <enterprise-beans>
    <session>
      <ejb-name>CDRTimer</ejb-name>
      <ejb-class>acme.ejb.timer.test.CDRTimerBean</ejb-class>
      <session-type>Stateless</session-type>
      <security-identity>
        <run-as>
          <role-name>TimerExecutor</role-name>
        </run-as>
      </security-identity>
    </session>
  </enterprise-beans>
  <assembly-descriptor>
    <security-role>
      <description></description>
      <role-name>TimerExecutor</role-name>
    </security-role>
  </assembly-descriptor>
  <ejb-client-jar>CDRTimerEJBclientjar.jar</ejb-client-jar>
</ejb-jar>



weblogic-ejb-jar.xml

  <run-as-role-assignment>
    <role-name>TimerExecutor</role-name>
    <run-as-principal-name>CDRTIMER.RUN.PRINCIPAL.NAME</run-as-principal-name>
  </run-as-role-assignment>








No comments: