tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ryan McGuinness (JIRA)" <j...@apache.org>
Subject [jira] [Comment Edited] (TOMEE-1490) Arquillian Test and Local context.xml file not loading correctly
Date Thu, 08 Jan 2015 23:08:37 GMT

    [ https://issues.apache.org/jira/browse/TOMEE-1490?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14270136#comment-14270136
] 

Ryan McGuinness edited comment on TOMEE-1490 at 1/8/15 11:08 PM:
-----------------------------------------------------------------

[~romain.manni-bucau], absolutely, this is based on work I have been doing with [~jlmonteiro].
It works fine in a normal deployment, just not in the arquillian test.

Based on: http://ci.apache.org/projects/openejb/examples-generated/cdi-realm/index.html

The injected AccountService is a singleton, and the Login is a SessionScoped bean.

@RequestScoped
public class SecurityRealm {
    @Inject
    private AccountService accountService;

    @Inject
    private Login login;

    public Principal authenticate(final String username, String password) {
        if (! login.isValid()) {
            Account account = accountService.findAccountByUsernameAndPassword(username, password);
            if (account != null) {
                login.setAccount(account);
                login.setLoginTime(new Date());
                if (login.isValid()) {
                    return login;
                }
            }
        } else if (login!=null && login.isValid()) {
            return login;
        }
        return null;
    }

    public boolean hasRole(Principal principal, String role) {
        if (principal instanceof Login) {
            return ((Login)principal).isUserInRole(role);
        }
        return false;
    }
}


was (Author: rmcguinness):
Absolutely, this is based on work I have been doing with [~jlmonteiro]. It works fine in a
normal deployment, just not in the arquillian test.

Based on: http://ci.apache.org/projects/openejb/examples-generated/cdi-realm/index.html

The injected AccountService is a singleton, and the Login is a SessionScoped bean.

@RequestScoped
public class SecurityRealm {
    @Inject
    private AccountService accountService;

    @Inject
    private Login login;

    public Principal authenticate(final String username, String password) {
        if (! login.isValid()) {
            Account account = accountService.findAccountByUsernameAndPassword(username, password);
            if (account != null) {
                login.setAccount(account);
                login.setLoginTime(new Date());
                if (login.isValid()) {
                    return login;
                }
            }
        } else if (login!=null && login.isValid()) {
            return login;
        }
        return null;
    }

    public boolean hasRole(Principal principal, String role) {
        if (principal instanceof Login) {
            return ((Login)principal).isUserInRole(role);
        }
        return false;
    }
}

> Arquillian Test and Local context.xml file not loading correctly
> ----------------------------------------------------------------
>
>                 Key: TOMEE-1490
>                 URL: https://issues.apache.org/jira/browse/TOMEE-1490
>             Project: TomEE
>          Issue Type: Bug
>          Components: TomEE Arquillian Adapters
>    Affects Versions: 1.7.1
>            Reporter: Ryan McGuinness
>              Labels: arquillian, test
>
> When using a custom "webapp/META-INF/context.xml
> <Context>
>     <Realm className="org.apache.catalina.realm.LockOutRealm">
>         <Realm
>             cdi="true"
>             className="org.apache.tomee.catalina.realm.LazyRealm"
>             realmClass="example.service.SecurityRealm" />
>     </Realm>
> </Context>
> Then build the shrink wrap to include it in deployment:
> @Deployment(testable = true)
>     public static WebArchive createDeployment() {
>         WebAppDescriptor descriptor = Descriptors.create(WebAppDescriptor.class)
>                 .version("3.0");
>         File[] files = new File("src/main/resources/META-INF").listFiles();
>         WebArchive war = ShrinkWrap.create(WebArchive.class, "example.war")
>                 .setWebXML(new StringAsset(descriptor.exportAsString()))
>                 .addPackages(true, "example")
>                 .addAsManifestResource(new File("src/main/webapp/META-INF/context.xml"))
>                 .addAsWebInfResource(EmptyAsset.INSTANCE, ArchivePaths.create("beans.xml"));
>         for (File f : files) {
>             war.addAsManifestResource(f);
>         }
>         System.out.println(war.toString(true));
>         return war;
>     }
> The following error is thrown (regardless the realm definition):
> Caused by: org.apache.catalina.LifecycleException: Failed to start component [Realm[LockOutRealm]]
> 	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
> 	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5373)
> 	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
> 	... 99 more



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message