You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltaspike.apache.org by gp...@apache.org on 2012/07/29 23:39:28 UTC

[5/5] DELTASPIKE-249 remove packages authentication, credential, idm and permission

http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/79b06715/deltaspike/modules/security/impl/src/test/java/org/apache/deltaspike/test/security/impl/authentication/LoginLogoutTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/security/impl/src/test/java/org/apache/deltaspike/test/security/impl/authentication/LoginLogoutTest.java b/deltaspike/modules/security/impl/src/test/java/org/apache/deltaspike/test/security/impl/authentication/LoginLogoutTest.java
deleted file mode 100644
index fc78ecd..0000000
--- a/deltaspike/modules/security/impl/src/test/java/org/apache/deltaspike/test/security/impl/authentication/LoginLogoutTest.java
+++ /dev/null
@@ -1,166 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.deltaspike.test.security.impl.authentication;
-
-import org.apache.deltaspike.core.api.provider.BeanProvider;
-import org.apache.deltaspike.core.impl.exclude.extension.ExcludeExtension;
-import org.apache.deltaspike.security.api.Identity;
-import org.apache.deltaspike.security.api.authentication.UnexpectedCredentialException;
-import org.apache.deltaspike.security.api.credential.LoginCredentials;
-import org.apache.deltaspike.test.util.ArchiveUtils;
-import org.jboss.arquillian.container.test.api.Deployment;
-import org.jboss.arquillian.junit.Arquillian;
-import org.jboss.shrinkwrap.api.ShrinkWrap;
-import org.jboss.shrinkwrap.api.asset.EmptyAsset;
-import org.jboss.shrinkwrap.api.spec.JavaArchive;
-import org.jboss.shrinkwrap.api.spec.WebArchive;
-import org.junit.Assert;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-import javax.enterprise.inject.spi.Extension;
-import javax.inject.Inject;
-
-
-/**
- * Test for {@link org.apache.deltaspike.security.api.authorization.annotation.Secured}
- */
-@RunWith(Arquillian.class)
-public class LoginLogoutTest
-{
-    @Inject
-    private TestAuthenticator authenticator;
-
-    @Inject
-    private TestInquiryStorage testInquiryStorage;
-
-    @Inject
-    private ShopClient shopClient;
-
-    @Inject
-    private Identity identity;
-
-    @Inject
-    private FailedLoginFailedObserver failedLoginFailedObserver;
-
-    @Deployment
-    public static WebArchive deploy()
-    {
-        JavaArchive testJar = ShrinkWrap.create(JavaArchive.class, "loginLogoutTest.jar")
-                .addPackage("org.apache.deltaspike.test.security.impl.authentication")
-                .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
-
-        return ShrinkWrap.create(WebArchive.class, "login-logout-test.war")
-                .addAsLibraries(ArchiveUtils.getDeltaSpikeCoreAndSecurityArchive())
-                .addAsLibraries(testJar)
-                .addAsServiceProvider(Extension.class, ExcludeExtension.class)
-                .addAsWebInfResource(ArchiveUtils.getBeansXml(), "beans.xml");
-    }
-
-    @Test
-    public void loginAndLogout()
-    {
-        final String userName = "spike";
-        final String password = "apache";
-
-        //init
-        authenticator.register(userName, password);
-
-        //start
-        shopClient.login(userName, password);
-
-        Assert.assertTrue(identity.isLoggedIn());
-        Assert.assertEquals(userName, identity.getUser().getId());
-
-        Assert.assertNotNull(shopClient.requestNewProduct("Security module for DeltaSpike"));
-
-
-        shopClient.logout();
-        Assert.assertFalse(identity.isLoggedIn());
-
-
-        Assert.assertNotNull(shopClient.requestNewProduct("I18n module for DeltaSpike"));
-
-        Assert.assertEquals(1, testInquiryStorage.getUserInquiries().size());
-        Assert.assertEquals(userName, testInquiryStorage.getUserInquiries().iterator().next().getUserName());
-
-        Assert.assertEquals(1, testInquiryStorage.getAnonymInquiries().size());
-
-        Assert.assertFalse(testInquiryStorage.getUserInquiries().iterator().next().getInquiry()
-                .equals(testInquiryStorage.getAnonymInquiries().iterator()));
-    }
-
-    @Test
-    public void failedLogin()
-    {
-        final String userName = "spike";
-        final String password = "apache";
-
-        //init
-        authenticator.register(userName, password);
-
-        //start
-        shopClient.login(userName, "123");
-
-        Assert.assertFalse(identity.isLoggedIn());
-    }
-
-    //TODO use context-control
-    @Test
-    public void failedForcedReLogin()
-    {
-        final String userName = "spike";
-        final String password = "apache";
-
-        //init
-        authenticator.register(userName, password);
-
-        //start
-        shopClient.login(userName, password);
-
-        Assert.assertTrue(identity.isLoggedIn());
-        Assert.assertEquals(userName, identity.getUser().getId());
-
-        //X TODO stop and start new request via ContextControl - instead of:
-        BeanProvider.getContextualReference(LoginCredentials.class).invalidate();
-
-        try
-        {
-            shopClient.login("xyz", "123");
-        }
-        catch (UnexpectedCredentialException e)
-        {
-            //noinspection ThrowableResultOfMethodCallIgnored
-            Assert.assertTrue(failedLoginFailedObserver.getObservedException()
-                    instanceof UnexpectedCredentialException);
-
-            // still logged in
-            Assert.assertTrue(identity.isLoggedIn());
-            return;
-        }
-        finally
-        {
-            identity.logout();
-        }
-
-        Assert.fail();
-    }
-
-    //X TODO add tests for the events
-}

http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/79b06715/deltaspike/modules/security/impl/src/test/java/org/apache/deltaspike/test/security/impl/authentication/NewProductInquiry.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/security/impl/src/test/java/org/apache/deltaspike/test/security/impl/authentication/NewProductInquiry.java b/deltaspike/modules/security/impl/src/test/java/org/apache/deltaspike/test/security/impl/authentication/NewProductInquiry.java
deleted file mode 100644
index 4076b23..0000000
--- a/deltaspike/modules/security/impl/src/test/java/org/apache/deltaspike/test/security/impl/authentication/NewProductInquiry.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.deltaspike.test.security.impl.authentication;
-
-import java.util.UUID;
-
-class NewProductInquiry implements Inquiry
-{
-    private String question;
-
-    private String id;
-    
-    NewProductInquiry(String question)
-    {
-        this.question = question;
-        id = UUID.randomUUID().toString();
-    }
-
-    @Override
-    public String getInquiryId()
-    {
-        return id;
-    }
-
-    @Override
-    public String toString()
-    {
-        return question;
-    }
-
-    @Override
-    public int hashCode()
-    {
-        return id.hashCode();
-    }
-
-    @Override
-    public boolean equals(Object obj)
-    {
-        return obj instanceof NewProductInquiry && id.equals(((NewProductInquiry) obj).id);
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/79b06715/deltaspike/modules/security/impl/src/test/java/org/apache/deltaspike/test/security/impl/authentication/Shop.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/security/impl/src/test/java/org/apache/deltaspike/test/security/impl/authentication/Shop.java b/deltaspike/modules/security/impl/src/test/java/org/apache/deltaspike/test/security/impl/authentication/Shop.java
deleted file mode 100644
index 16f431c..0000000
--- a/deltaspike/modules/security/impl/src/test/java/org/apache/deltaspike/test/security/impl/authentication/Shop.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.deltaspike.test.security.impl.authentication;
-
-import javax.enterprise.context.ApplicationScoped;
-import javax.inject.Inject;
-
-/**
- *
- */
-@ApplicationScoped
-public class Shop
-{
-    @Inject
-    private InquiryStorage inquiryStorage;
-
-    public String sendInquiry(Inquiry inquiry)
-    {
-        if (inquiryStorage.addInquiry(inquiry))
-        {
-            return inquiry.getInquiryId();
-            //TODO e.g. send notification in case of inquiries of premium users,...
-        }
-
-        return null;
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/79b06715/deltaspike/modules/security/impl/src/test/java/org/apache/deltaspike/test/security/impl/authentication/ShopClient.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/security/impl/src/test/java/org/apache/deltaspike/test/security/impl/authentication/ShopClient.java b/deltaspike/modules/security/impl/src/test/java/org/apache/deltaspike/test/security/impl/authentication/ShopClient.java
deleted file mode 100644
index b4ae5c3..0000000
--- a/deltaspike/modules/security/impl/src/test/java/org/apache/deltaspike/test/security/impl/authentication/ShopClient.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.deltaspike.test.security.impl.authentication;
-
-import org.apache.deltaspike.security.api.Identity;
-import org.apache.deltaspike.security.api.credential.Credential;
-import org.apache.deltaspike.security.api.credential.LoginCredentials;
-
-import javax.enterprise.context.ApplicationScoped;
-import javax.inject.Inject;
-
-@ApplicationScoped
-public class ShopClient
-{
-    @Inject
-    private LoginCredentials loginCredential;
-
-    @Inject
-    private Identity identity;
-
-    @Inject
-    private Shop shop;
-
-    public void login(String userName, final String password)
-    {
-        loginCredential.setUserId(userName);
-        //TODO discuss #setSecurityToken
-        loginCredential.setCredential(new Credential<String>()
-        {
-            @Override
-            public String getValue()
-            {
-                return password;
-            }
-        });
-
-        identity.login();
-    }
-
-    public void logout()
-    {
-        identity.logout();
-    }
-
-    public String requestNewProduct(String customText)
-    {
-        return shop.sendInquiry(new NewProductInquiry(customText));
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/79b06715/deltaspike/modules/security/impl/src/test/java/org/apache/deltaspike/test/security/impl/authentication/TestAuthenticator.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/security/impl/src/test/java/org/apache/deltaspike/test/security/impl/authentication/TestAuthenticator.java b/deltaspike/modules/security/impl/src/test/java/org/apache/deltaspike/test/security/impl/authentication/TestAuthenticator.java
deleted file mode 100644
index 0908914..0000000
--- a/deltaspike/modules/security/impl/src/test/java/org/apache/deltaspike/test/security/impl/authentication/TestAuthenticator.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.deltaspike.test.security.impl.authentication;
-
-import org.apache.deltaspike.security.api.idm.SimpleUser;
-import org.apache.deltaspike.security.api.idm.User;
-import org.apache.deltaspike.security.api.credential.LoginCredentials;
-import org.apache.deltaspike.security.spi.authentication.BaseAuthenticator;
-
-import javax.enterprise.context.RequestScoped;
-import javax.inject.Inject;
-
-@RequestScoped
-public class TestAuthenticator extends BaseAuthenticator
-{
-    @Inject
-    private LoginCredentials loginCredential;
-
-    private User user;
-
-    @Override
-    public void authenticate()
-    {
-        String password = InMemoryUserStorage.getPassword(loginCredential.getUserId());
-
-        if (password != null && password.equals(loginCredential.getCredential().getValue()))
-        {
-            setStatus(AuthenticationStatus.SUCCESS);
-
-            this.user = new SimpleUser(this.loginCredential.getUserId());
-            return;
-        }
-
-        setStatus(AuthenticationStatus.FAILURE);
-    }
-
-    @Override
-    public User getUser()
-    {
-        return user;
-    }
-
-    void register(String userName, String password)
-    {
-        InMemoryUserStorage.setPassword(userName, password);
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/79b06715/deltaspike/modules/security/impl/src/test/java/org/apache/deltaspike/test/security/impl/authentication/TestInquiryStorage.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/security/impl/src/test/java/org/apache/deltaspike/test/security/impl/authentication/TestInquiryStorage.java b/deltaspike/modules/security/impl/src/test/java/org/apache/deltaspike/test/security/impl/authentication/TestInquiryStorage.java
deleted file mode 100644
index 9272d0c..0000000
--- a/deltaspike/modules/security/impl/src/test/java/org/apache/deltaspike/test/security/impl/authentication/TestInquiryStorage.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.deltaspike.test.security.impl.authentication;
-
-import org.apache.deltaspike.security.api.Identity;
-
-import javax.enterprise.context.ApplicationScoped;
-import javax.inject.Inject;
-import java.util.Collection;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-@ApplicationScoped
-public class TestInquiryStorage implements InquiryStorage
-{
-    private Map<String, InquiryEntry> userInquiries = new ConcurrentHashMap<String, InquiryEntry>();
-
-    private Map<String, Inquiry> anonymInquiries = new ConcurrentHashMap<String, Inquiry>();
-
-    @Inject
-    private Identity identity;
-
-    public boolean addInquiry(Inquiry inquiry)
-    {
-        if (identity.isLoggedIn())
-        {
-            userInquiries.put(inquiry.getInquiryId(), new InquiryEntry(identity.getUser().getId(), inquiry));
-        }
-        else
-        {
-            anonymInquiries.put(inquiry.getInquiryId(), inquiry);
-        }
-        return true;
-    }
-    
-    Collection<InquiryEntry> getUserInquiries()
-    {
-        return userInquiries.values();
-    }
-
-    Collection<Inquiry> getAnonymInquiries()
-    {
-        return anonymInquiries.values();
-    }
-}