You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by rm...@apache.org on 2012/08/26 15:47:18 UTC

svn commit: r1377439 - in /openejb/trunk/openejb/examples: ./ cdi-realm/ cdi-realm/src/ cdi-realm/src/main/ cdi-realm/src/main/java/ cdi-realm/src/main/java/org/ cdi-realm/src/main/java/org/superbiz/ cdi-realm/src/main/webapp/ cdi-realm/src/main/webapp...

Author: rmannibucau
Date: Sun Aug 26 13:47:17 2012
New Revision: 1377439

URL: http://svn.apache.org/viewvc?rev=1377439&view=rev
Log:
TOMEE-404 sample using low typed realm, thanks Enrico Olivelli

Added:
    openejb/trunk/openejb/examples/cdi-realm/
    openejb/trunk/openejb/examples/cdi-realm/pom.xml
    openejb/trunk/openejb/examples/cdi-realm/src/
    openejb/trunk/openejb/examples/cdi-realm/src/main/
    openejb/trunk/openejb/examples/cdi-realm/src/main/java/
    openejb/trunk/openejb/examples/cdi-realm/src/main/java/org/
    openejb/trunk/openejb/examples/cdi-realm/src/main/java/org/superbiz/
    openejb/trunk/openejb/examples/cdi-realm/src/main/java/org/superbiz/AuthBean.java
    openejb/trunk/openejb/examples/cdi-realm/src/main/webapp/
    openejb/trunk/openejb/examples/cdi-realm/src/main/webapp/META-INF/
    openejb/trunk/openejb/examples/cdi-realm/src/main/webapp/META-INF/context.xml
    openejb/trunk/openejb/examples/cdi-realm/src/main/webapp/WEB-INF/
    openejb/trunk/openejb/examples/cdi-realm/src/main/webapp/WEB-INF/beans.xml
Modified:
    openejb/trunk/openejb/examples/pom.xml

Added: openejb/trunk/openejb/examples/cdi-realm/pom.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/cdi-realm/pom.xml?rev=1377439&view=auto
==============================================================================
--- openejb/trunk/openejb/examples/cdi-realm/pom.xml (added)
+++ openejb/trunk/openejb/examples/cdi-realm/pom.xml Sun Aug 26 13:47:17 2012
@@ -0,0 +1,88 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    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.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.superbiz</groupId>
+  <artifactId>cdi-basic</artifactId>
+  <packaging>war</packaging>
+  <version>1.1-SNAPSHOT</version>
+  <name>OpenEJB :: Examples :: CDI Realm</name>
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+  </properties>
+  <build>
+    <defaultGoal>install</defaultGoal>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <version>2.4</version>
+        <configuration>
+          <source>1.6</source>
+          <target>1.6</target>
+        </configuration>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-war-plugin</artifactId>
+        <version>2.2</version>
+        <configuration>
+          <failOnMissingWebXml>false</failOnMissingWebXml>
+        </configuration>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.openejb.maven</groupId>
+        <artifactId>tomee-maven-plugin</artifactId>
+        <version>1.0.0-SNAPSHOT</version>
+      </plugin>
+    </plugins>
+  </build>
+  <repositories>
+    <repository>
+      <id>apache-m2-snapshot</id>
+      <name>Apache Snapshot Repository</name>
+      <url>http://repository.apache.org/snapshots</url>
+    </repository>
+  </repositories>
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.openejb</groupId>
+      <artifactId>javaee-api</artifactId>
+      <version>6.0-4</version>
+      <scope>provided</scope>
+    </dependency>
+  </dependencies>
+
+  <!-- This section allows you to configure where to publish libraries for
+    sharing. It is not required and may be deleted. For more information see:
+    http://maven.apache.org/plugins/maven-deploy-plugin/ -->
+  <distributionManagement>
+    <repository>
+      <id>localhost</id>
+      <url>file://${basedir}/target/repo/</url>
+    </repository>
+    <snapshotRepository>
+      <id>localhost</id>
+      <url>file://${basedir}/target/snapshot-repo/</url>
+    </snapshotRepository>
+  </distributionManagement>
+
+</project>
+

Added: openejb/trunk/openejb/examples/cdi-realm/src/main/java/org/superbiz/AuthBean.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/cdi-realm/src/main/java/org/superbiz/AuthBean.java?rev=1377439&view=auto
==============================================================================
--- openejb/trunk/openejb/examples/cdi-realm/src/main/java/org/superbiz/AuthBean.java (added)
+++ openejb/trunk/openejb/examples/cdi-realm/src/main/java/org/superbiz/AuthBean.java Sun Aug 26 13:47:17 2012
@@ -0,0 +1,54 @@
+/**
+ * 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.superbiz;
+
+import javax.enterprise.context.RequestScoped;
+import java.security.Principal;
+
+@RequestScoped
+public class AuthBean {
+
+    public Principal authenticate(final String username, String password) {
+        if (("userA".equals(username)||"userB".equals(username)) && "test".equals(password)) {
+            return new Principal() {
+                @Override
+                public String getName() {
+                    return username;
+                }
+                @Override
+                public String toString() {
+                    return username;
+                }
+            };
+        }
+        return null;
+    }
+
+
+    public boolean hasRole(Principal principal, String role) {
+        if (principal == null) {
+            return false;
+        }
+        if(principal.getName().equals("userA") && (role.equals("admin")||role.equals("user"))) {
+            return true;
+        }
+        if(principal.getName().equals("userB") && (role.equals("user"))) {
+            return true;
+        }
+        return false;
+    }
+}

Added: openejb/trunk/openejb/examples/cdi-realm/src/main/webapp/META-INF/context.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/cdi-realm/src/main/webapp/META-INF/context.xml?rev=1377439&view=auto
==============================================================================
--- openejb/trunk/openejb/examples/cdi-realm/src/main/webapp/META-INF/context.xml (added)
+++ openejb/trunk/openejb/examples/cdi-realm/src/main/webapp/META-INF/context.xml Sun Aug 26 13:47:17 2012
@@ -0,0 +1,3 @@
+<Context>
+  <Realm cdi="true" className="org.apache.tomee.catalina.realm.LazyRealm" realmClass="org.superbiz.AuthBean" />
+</Context>
\ No newline at end of file

Added: openejb/trunk/openejb/examples/cdi-realm/src/main/webapp/WEB-INF/beans.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/cdi-realm/src/main/webapp/WEB-INF/beans.xml?rev=1377439&view=auto
==============================================================================
--- openejb/trunk/openejb/examples/cdi-realm/src/main/webapp/WEB-INF/beans.xml (added)
+++ openejb/trunk/openejb/examples/cdi-realm/src/main/webapp/WEB-INF/beans.xml Sun Aug 26 13:47:17 2012
@@ -0,0 +1,18 @@
+<!--
+
+    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.
+-->
+<beans />

Modified: openejb/trunk/openejb/examples/pom.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/pom.xml?rev=1377439&r1=1377438&r2=1377439&view=diff
==============================================================================
--- openejb/trunk/openejb/examples/pom.xml (original)
+++ openejb/trunk/openejb/examples/pom.xml Sun Aug 26 13:47:17 2012
@@ -47,6 +47,7 @@
     <module>cdi-produces-disposes</module>
     <module>cdi-produces-field</module>
     <module>cdi-query</module>
+    <module>cdi-realm</module>
     <module>change-jaxws-url</module>
     <module>component-interfaces</module>
     <module>client-resource-lookup-preview</module>