0 Replies Latest reply on Nov 1, 2016 12:58 PM by evdvdf eeefdf

    Error loading... java.lang.ClassNotFoundException: com.sertux.searchit.api.shiro.ShiroSecuredInterceptor

    evdvdf eeefdf Newbie

      I have this class in a ejb module application but produces the next output when i deploy in my new server machine.

      The programs works ok with netbeans but no works in the new server machine.

       

      This class is located at the first module app:

       

      package com.sertux.searchit.api.shiro;

       

      import java.io.Serializable;

      import java.lang.annotation.Annotation;

      import java.lang.reflect.Method;

      import java.util.Arrays;

       

      import javax.interceptor.AroundInvoke;

      import javax.interceptor.Interceptor;

      import javax.interceptor.InvocationContext;

       

      import org.apache.shiro.SecurityUtils;

      import org.apache.shiro.authz.UnauthenticatedException;

      import org.apache.shiro.authz.annotation.RequiresAuthentication;

      import org.apache.shiro.authz.annotation.RequiresGuest;

      import org.apache.shiro.authz.annotation.RequiresPermissions;

      import org.apache.shiro.authz.annotation.RequiresRoles;

      import org.apache.shiro.authz.annotation.RequiresUser;

      import org.apache.shiro.subject.Subject;

       

      @Interceptor

      @ShiroSecured

      public class ShiroSecuredInterceptor implements Serializable {

       

          private static final long serialVersionUID = 1L;

       

          @AroundInvoke

          public Object interceptShiroSecurity(InvocationContext context) throws Exception {

              Subject subject = SecurityUtils.getSubject();

              Class<?> c = context.getTarget().getClass();

              Method m = context.getMethod();

       

              if (!subject.isAuthenticated() && hasAnnotation(c, m, RequiresAuthentication.class)) {

                  throw new UnauthenticatedException("Authentication required");

              }

       

              if (subject.getPrincipal() != null && hasAnnotation(c, m, RequiresGuest.class)) {

                  throw new UnauthenticatedException("Guest required");

              }

       

              if (subject.getPrincipal() == null && hasAnnotation(c, m, RequiresUser.class)) {

                  throw new UnauthenticatedException("User required");

              }

       

              RequiresRoles roles = getAnnotation(c, m, RequiresRoles.class);

       

              if (roles != null) {

                  subject.checkRoles(Arrays.asList(roles.value()));

              }

       

              RequiresPermissions permissions = getAnnotation(c, m, RequiresPermissions.class);

       

              if (permissions != null) {

                  subject.checkPermissions(permissions.value());

              }

       

              return context.proceed();

          }

       

          private static boolean hasAnnotation(Class<?> c, Method m, Class<? extends Annotation> a) {

              return m.isAnnotationPresent(a)

                      || c.isAnnotationPresent(a)

                      || c.getSuperclass().isAnnotationPresent(a);

          }

       

          private static <A extends Annotation> A getAnnotation(Class<?> c, Method m, Class<A> a) {

              return m.isAnnotationPresent(a) ? m.getAnnotation(a)

                      : c.isAnnotationPresent(a) ? c.getAnnotation(a)

                              : c.getSuperclass().getAnnotation(a);

          }

       

      }

       

       

      ----------------------------------------ejb-jar.xml------------------------

      <?xml version="1.0" encoding="UTF-8"?>

      <ejb-jar

          xmlns="http://java.sun.com/xml/ns/javaee"

          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_1.xsd"

          version="3.1"

      >

          <interceptors>

              <interceptor>

                  <interceptor-class>com.sertux.searchit.api.shiro.ShiroSecuredInterceptor</interceptor-class>

              </interceptor>

          </interceptors>

          <assembly-descriptor>

              <interceptor-binding>

                  <ejb-name>*</ejb-name>

                  <interceptor-class>com.sertux.searchit.api.shiro.ShiroSecuredInterceptor</interceptor-class>

              </interceptor-binding>

          </assembly-descriptor>

      </ejb-jar>

      -------------------------------------------------------------------------

      ------------beans.xml---------------------------------------------

      <?xml version="1.0" encoding="UTF-8"?>

      <beans 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/beans_1_1.xsd"

             bean-discovery-mode="annotated">

          <interceptors>

              <class>com.sertux.searchit.api.shiro.ShiroSecuredInterceptor</class>

          </interceptors>

      </beans>

       

      ---------------------------------ERROR OUTPUT------------------------------------------------

      17:30:56,691 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-1) MSC000001: Failed to start service jboss.deployment.unit."SertuxSearchIt-web-1.0-SNAPSHOT.war".WeldStartService: org.jboss.msc.service.StartException in service jboss.deployment.unit."SertuxSearchIt-web-1.0-SNAPSHOT.war".WeldStartService: Failed to start service

          at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1904) [jboss-msc-1.2.2.Final.jar:1.2.2.Final]

          at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [rt.jar:1.8.0_101]

          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [rt.jar:1.8.0_101]

          at java.lang.Thread.run(Thread.java:745) [rt.jar:1.8.0_101]

      Caused by: org.jboss.weld.exceptions.DeploymentException: WELD-000123: Error loading com.sertux.searchit.api.shiro.ShiroSecuredInterceptor defined in <class>com.sertux.searchit.api.shiro.ShiroSecuredInterceptor</class> in vfs:/content/SertuxSearchIt-web-1.0-SNAPSHOT.war/WEB-INF/beans.xml@7

          at org.jboss.weld.bootstrap.enablement.GlobalEnablementBuilder$ClassLoader.apply(GlobalEnablementBuilder.java:265)

          at org.jboss.weld.bootstrap.enablement.GlobalEnablementBuilder$ClassLoader.apply(GlobalEnablementBuilder.java:252)

          at com.google.common.collect.Lists$TransformingRandomAccessList$1.transform(Lists.java:582)

          at com.google.common.collect.TransformedIterator.next(TransformedIterator.java:48)

          at com.google.common.collect.ImmutableCollection$Builder.addAll(ImmutableCollection.java:281)

          at com.google.common.collect.ImmutableCollection$ArrayBasedBuilder.addAll(ImmutableCollection.java:360)

          at com.google.common.collect.ImmutableList$Builder.addAll(ImmutableList.java:665)

          at org.jboss.weld.bootstrap.enablement.GlobalEnablementBuilder.createModuleEnablement(GlobalEnablementBuilder.java:224)

          at org.jboss.weld.bootstrap.BeanDeployment.createEnabled(BeanDeployment.java:217)

          at org.jboss.weld.bootstrap.WeldStartup.startInitialization(WeldStartup.java:344)

          at org.jboss.weld.bootstrap.WeldBootstrap.startInitialization(WeldBootstrap.java:73)

          at org.jboss.as.weld.WeldStartService.start(WeldStartService.java:91)

          at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1948) [jboss-msc-1.2.2.Final.jar:1.2.2.Final]

          at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1881) [jboss-msc-1.2.2.Final.jar:1.2.2.Final]

          ... 3 more

      Caused by: java.lang.ClassNotFoundException: com.sertux.searchit.api.shiro.ShiroSecuredInterceptor from [Module "deployment.SertuxSearchIt-web-1.0-SNAPSHOT.war:main" from Service Module Loader]

          at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:213) [jboss-modules.jar:1.3.3.Final]

          at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:459) [jboss-modules.jar:1.3.3.Final]

          at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:408) [jboss-modules.jar:1.3.3.Final]

          at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:389) [jboss-modules.jar:1.3.3.Final]

          at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:134) [jboss-modules.jar:1.3.3.Final]

          at org.jboss.as.weld.WeldModuleResourceLoader.classForName(WeldModuleResourceLoader.java:68)

          at org.jboss.weld.bootstrap.enablement.GlobalEnablementBuilder$ClassLoader.apply(GlobalEnablementBuilder.java:263)

          ... 16 more