You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by er...@apache.org on 2005/07/06 09:49:21 UTC
svn commit: r209422 - in
/directory/sandbox/trunk/osgi-spec/trunk/useradmin/src: ./ main/ main/java/
main/java/org/ main/java/org/apache/ main/java/org/apache/useradmin/
main/java/org/apache/useradmin/operations/
main/java/org/apache/useradmin/service/...
Author: erodriguez
Date: Wed Jul 6 00:49:18 2005
New Revision: 209422
URL: http://svn.apache.org/viewcvs?rev=209422&view=rev
Log:
OSGi UserAdmin service implementation.
Added:
directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/
directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/
directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/
directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/
directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/
directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/
directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/Activator.java (with props)
directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/LDAPQuery.java (with props)
directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/MemberStore.java (with props)
directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/RoleStore.java (with props)
directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/UserAdminService.java (with props)
directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/operations/
directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/operations/AddMember.java (with props)
directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/operations/AddRequiredMember.java (with props)
directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/operations/CreateGroup.java (with props)
directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/operations/CreateUser.java (with props)
directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/operations/DeleteRole.java (with props)
directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/operations/GroupTransaction.java (with props)
directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/operations/RemoveMember.java (with props)
directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/operations/RoleTransaction.java (with props)
directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/service/
directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/service/AnyoneGroup.java (with props)
directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/service/AuthorizationImpl.java (with props)
directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/service/GroupImpl.java (with props)
directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/service/RoleImpl.java (with props)
directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/service/RoleListener.java (with props)
directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/service/UserImpl.java (with props)
directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/store/
directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/store/InMemoryRoleStore.java (with props)
directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/store/PrevalentGroup.java (with props)
directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/store/PrevalentRoleStore.java (with props)
Added: directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/Activator.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/Activator.java?rev=209422&view=auto
==============================================================================
--- directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/Activator.java (added)
+++ directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/Activator.java Wed Jul 6 00:49:18 2005
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed 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.useradmin;
+
+import java.util.Hashtable;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+import org.osgi.service.useradmin.UserAdmin;
+import org.apache.useradmin.store.InMemoryRoleStore;
+
+
+public class Activator implements BundleActivator
+{
+ public void start( BundleContext context ) throws BundleException
+ {
+ RoleStore store = new InMemoryRoleStore();
+ UserAdminService userAdmin = new UserAdminService( context, store );
+ context.registerService( UserAdmin.class.getName(), userAdmin, new Hashtable() );
+ }
+
+ public void stop( BundleContext context ) throws BundleException
+ {
+ // do nothing
+ }
+}
+
Propchange: directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/Activator.java
------------------------------------------------------------------------------
svn:executable = *
Added: directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/LDAPQuery.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/LDAPQuery.java?rev=209422&view=auto
==============================================================================
--- directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/LDAPQuery.java (added)
+++ directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/LDAPQuery.java Wed Jul 6 00:49:18 2005
@@ -0,0 +1,374 @@
+/*
+ * Copyright (c) 2003, KNOPFLERFISH project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * - Neither the name of the KNOPFLERFISH project nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.apache.useradmin;
+
+import java.lang.reflect.Array;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+import java.math.BigInteger;
+import java.util.Dictionary;
+import java.util.Enumeration;
+import java.util.Vector;
+
+import org.osgi.framework.InvalidSyntaxException;
+
+/**
+ * LDAP filter functions.
+ *
+ * @author Tommy Bohlin
+ * @author Jan Stein
+ * @version $Revision: 1.1.1.1 $
+ */
+public class LDAPQuery {
+ private static final char WILDCARD=65535;
+ private static final String WILDCARD_STRING= new String(new char [] { WILDCARD });
+
+ private static final String NULL ="Null query";
+ private static final String GARBAGE ="Trailing garbage";
+ private static final String MALFORMED="Malformed query";
+ private static final String EMPTY ="Empty list";
+ private static final String SUBEXPR ="No subexpression";
+ private static final String OPERATOR ="Undefined operator";
+ private static final String TRUNCATED="Truncated expression";
+ private static final String EQUALITY ="Only equality supported";
+
+ private static final int EQ = 0;
+ private static final int LE = 1;
+ private static final int GE = 2;
+ private static final int APPROX = 3;
+
+ private static final Class[] classArg=new Class[] { String.class };
+ private static final Class[] objectArg=new Class[] { Object.class };
+
+ private static Class classBigDecimal;
+ private static Constructor consBigDecimal;
+ private static Method compBigDecimal;
+
+ static {
+ try {
+ classBigDecimal = Class.forName("java.math.BigDecimal");
+ consBigDecimal = classBigDecimal.getConstructor(new Class [] { String.class });
+ compBigDecimal = classBigDecimal.getMethod("compareTo", new Class [] { classBigDecimal });
+ } catch (Exception ignore) {
+ classBigDecimal = null;
+ }
+ }
+
+ boolean val;
+ String tail;
+ Dictionary prop;
+
+ public static void check(String q) throws InvalidSyntaxException {
+ query(q, null);
+ }
+
+ public static boolean query(String q, Dictionary p)
+ throws InvalidSyntaxException {
+ LDAPQuery lq=new LDAPQuery(q,p);
+ lq.doQuery();
+ if(lq.tail.length()>0) lq.error(GARBAGE);
+ return lq.val;
+ }
+
+ LDAPQuery(String q, Dictionary p) throws InvalidSyntaxException {
+ if(q==null || q.length()==0) error(NULL);
+ tail=q;
+ prop=p;
+ }
+
+ void doQuery() throws InvalidSyntaxException {
+ if(tail.length()<3 || !prefix("(")) error(MALFORMED);
+
+ switch(tail.charAt(0)) {
+ case '&': doAnd(); break;
+ case '|': doOr(); break;
+ case '!': doNot(); break;
+ default: doSimple(); break;
+ }
+
+ if(!prefix(")")) error(MALFORMED);
+ }
+
+ private void doAnd() throws InvalidSyntaxException {
+ tail=tail.substring(1);
+ boolean val1=true;
+ if(!tail.startsWith("(")) error(EMPTY);
+ do {
+ doQuery();
+ if(!val) val1=false;
+ } while(tail.startsWith("("));
+ val=val1;
+ }
+
+ private void doOr() throws InvalidSyntaxException {
+ tail=tail.substring(1);
+ boolean val1=false;
+ if(!tail.startsWith("(")) error(EMPTY);
+ do {
+ doQuery();
+ if(val) val1=true;
+ } while(tail.startsWith("("));
+ val=val1;
+ }
+
+ private void doNot() throws InvalidSyntaxException {
+ tail=tail.substring(1);
+ if(!tail.startsWith("(")) error(SUBEXPR);
+ doQuery();
+ val=!val;
+ }
+
+ private void doSimple() throws InvalidSyntaxException {
+ int op=0;
+ Object attr=getAttr();
+
+ if(prefix("=" )) op=EQ;
+ else if(prefix("<=")) op=LE;
+ else if(prefix(">=")) op=GE;
+ else if(prefix("~=")) op=APPROX;
+ else error(OPERATOR);
+
+ val=compare(attr,op,getValue());
+ }
+
+ private boolean prefix(String pre) {
+ if(!tail.startsWith(pre)) return false;
+ tail=tail.substring(pre.length());
+ return true;
+ }
+
+ private Object getAttr() {
+ int len=tail.length();
+ int ix=0;
+ label:for(;ix<len;ix++) {
+ switch(tail.charAt(ix)) {
+ case '(':
+ case ')':
+ case '<':
+ case '>':
+ case '=':
+ case '~':
+ case '*':
+ case '\\':
+ break label;
+ }
+ }
+ String attr=tail.substring(0,ix);
+ tail=tail.substring(ix);
+ return prop != null ? prop.get(attr) : null;
+ }
+
+ private String getValue() {
+ StringBuffer sb=new StringBuffer();
+ int len=tail.length();
+ int ix=0;
+ label:for(;ix<len;ix++) {
+ char c=tail.charAt(ix);
+ switch(c) {
+ case '(':
+ case ')':
+ break label;
+ case '*':
+ sb.append(WILDCARD);
+ break;
+ case '\\':
+ if(ix==len-1) break label;
+ sb.append(tail.charAt(++ix));
+ break;
+ default:
+ sb.append(c);
+ break;
+ }
+ }
+ tail=tail.substring(ix);
+ return sb.toString();
+ }
+
+ private void error(String m) throws InvalidSyntaxException {
+ throw new InvalidSyntaxException(m,tail);
+ }
+
+ private boolean compare(Object obj, int op, String s) {
+ if(obj==null) return false;
+ if(op==EQ && s.equals(WILDCARD_STRING)) return true;
+ try {
+ if(obj instanceof String) {
+ return compareString((String)obj,op,s);
+ } else if(obj instanceof Character) {
+ return compareString(obj.toString(),op,s);
+ } else if(obj instanceof Boolean) {
+ if (op==LE || op==GE)
+ return false;
+ return ((Boolean)obj).equals(new Boolean(s));
+ } else if (obj instanceof Number) {
+ if (obj instanceof Byte) {
+ switch(op) {
+ case LE:
+ return ((Byte)obj).byteValue() <= Byte.parseByte(s);
+ case GE:
+ return ((Byte)obj).byteValue() >= Byte.parseByte(s);
+ default: /*APPROX and EQ*/
+ return (new Byte(s)).equals(obj);
+ }
+ } else if (obj instanceof Integer) {
+ switch(op) {
+ case LE:
+ return ((Integer)obj).intValue() <= Integer.parseInt(s);
+ case GE:
+ return ((Integer)obj).intValue() >= Integer.parseInt(s);
+ default: /*APPROX and EQ*/
+ return (new Integer(s)).equals(obj);
+ }
+ } else if (obj instanceof Short) {
+ switch(op) {
+ case LE:
+ return ((Short)obj).shortValue() <= Short.parseShort(s);
+ case GE:
+ return ((Short)obj).shortValue() >= Short.parseShort(s);
+ default: /*APPROX and EQ*/
+ return (new Short(s)).equals(obj);
+ }
+ } else if (obj instanceof Long) {
+ switch(op) {
+ case LE:
+ return ((Long)obj).longValue() <= Long.parseLong(s);
+ case GE:
+ return ((Long)obj).longValue() >= Long.parseLong(s);
+ default: /*APPROX and EQ*/
+ return (new Long(s)).equals(obj);
+ }
+ } else if (obj instanceof Float) {
+ switch(op) {
+ case LE:
+ return ((Float)obj).floatValue() <= (new Float(s)).floatValue();
+ case GE:
+ return ((Float)obj).floatValue() >= (new Float(s)).floatValue();
+ default: /*APPROX and EQ*/
+ return (new Float(s)).equals(obj);
+ }
+ } else if (obj instanceof Double) {
+ switch(op) {
+ case LE:
+ return ((Double)obj).doubleValue() <= (new Double(s)).doubleValue();
+ case GE:
+ return ((Double)obj).doubleValue() >= (new Double(s)).doubleValue();
+ default: /*APPROX and EQ*/
+ return (new Double(s)).equals(obj);
+ }
+ } else if (obj instanceof BigInteger) {
+ int c = ((BigInteger)obj).compareTo(new BigInteger(s));
+ switch(op) {
+ case LE:
+ return c <= 0;
+ case GE:
+ return c >= 0;
+ default: /*APPROX and EQ*/
+ return c == 0;
+ }
+ } else if (classBigDecimal != null && classBigDecimal.isInstance(obj)) {
+ Object n = consBigDecimal.newInstance(new Object [] { s });
+ int c = ((Integer)compBigDecimal.invoke(obj, new Object [] { n })).intValue();
+ switch(op) {
+ case LE:
+ return c <= 0;
+ case GE:
+ return c >= 0;
+ default: /*APPROX and EQ*/
+ return c == 0;
+ }
+ }
+ } else if(obj instanceof Vector) {
+ for(Enumeration e=((Vector)obj).elements();e.hasMoreElements();)
+ if(compare(e.nextElement(),op,s)) return true;
+ } else if(obj.getClass().isArray()) {
+ int len=Array.getLength(obj);
+ for(int i=0;i<len;i++)
+ if(compare(Array.get(obj,i),op,s)) return true;
+ }
+ } catch(Exception e) { }
+ return false;
+ }
+
+ static boolean compareString(String s1, int op, String s2) {
+ switch(op) {
+ case LE:
+ return s1.compareTo(s2) <= 0;
+ case GE:
+ return s1.compareTo(s2) >= 0;
+ case EQ:
+ return patSubstr(s1,s2);
+ case APPROX:
+ return fixupString(s2).equals(fixupString(s1));
+ default:
+ return false;
+ }
+ }
+
+ static String fixupString(String s) {
+ StringBuffer sb=new StringBuffer();
+ int len=s.length();
+ boolean isStart=true;
+ boolean isWhite=false;
+ for(int i=0;i<len;i++) {
+ char c=s.charAt(i);
+ if(Character.isWhitespace(c)) {
+ isWhite=true;
+ } else {
+ if(!isStart && isWhite) sb.append(' ');
+ if(Character.isUpperCase(c)) c=Character.toLowerCase(c);
+ sb.append(c);
+ isStart=false;
+ isWhite=false;
+ }
+ }
+ return sb.toString();
+ }
+
+ static boolean patSubstr(String s, String pat) {
+ if(s==null) return false;
+ if(pat.length()==0) return s.length()==0;
+ if(pat.charAt(0)==WILDCARD) {
+ pat=pat.substring(1);
+ for(;;) {
+ if(patSubstr(s,pat)) return true;
+ if(s.length()==0) return false;
+ s=s.substring(1);
+ }
+ } else {
+ if(s.length()==0 || s.charAt(0)!=pat.charAt(0)) return false;
+ return patSubstr(s.substring(1),pat.substring(1));
+ }
+ }
+}
+
Propchange: directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/LDAPQuery.java
------------------------------------------------------------------------------
svn:executable = *
Added: directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/MemberStore.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/MemberStore.java?rev=209422&view=auto
==============================================================================
--- directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/MemberStore.java (added)
+++ directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/MemberStore.java Wed Jul 6 00:49:18 2005
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed 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.useradmin;
+
+import org.osgi.service.useradmin.Group;
+import org.osgi.service.useradmin.Role;
+import org.apache.useradmin.service.RoleListener;
+
+
+public interface MemberStore
+{
+ public void addMember( Group group, Role role );
+
+ public void addRequiredMember( Group group, Role role );
+
+ public void removeMember( Group group, Role role );
+
+ public void setRoleListener( RoleListener roleListener );
+}
+
Propchange: directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/MemberStore.java
------------------------------------------------------------------------------
svn:executable = *
Added: directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/RoleStore.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/RoleStore.java?rev=209422&view=auto
==============================================================================
--- directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/RoleStore.java (added)
+++ directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/RoleStore.java Wed Jul 6 00:49:18 2005
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed 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.useradmin;
+
+import java.util.List;
+
+import org.osgi.service.useradmin.Group;
+import org.osgi.service.useradmin.Role;
+import org.osgi.service.useradmin.User;
+import org.apache.useradmin.service.RoleListener;
+
+
+public interface RoleStore extends MemberStore
+{
+ public User createUser( String name );
+
+ public Group createGroup( String name );
+
+ public Role findRole( String name );
+
+ public Role removeRole( String name );
+
+ public boolean containsRole( String name );
+
+ public List roles();
+
+ public void setRoleListener( RoleListener roleListener );
+}
+
Propchange: directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/RoleStore.java
------------------------------------------------------------------------------
svn:executable = *
Added: directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/UserAdminService.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/UserAdminService.java?rev=209422&view=auto
==============================================================================
--- directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/UserAdminService.java (added)
+++ directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/UserAdminService.java Wed Jul 6 00:49:18 2005
@@ -0,0 +1,280 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed 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.useradmin;
+
+import java.security.AccessController;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceEvent;
+import org.osgi.framework.ServiceFactory;
+import org.osgi.framework.ServiceListener;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.useradmin.Authorization;
+import org.osgi.service.useradmin.Role;
+import org.osgi.service.useradmin.User;
+import org.osgi.service.useradmin.UserAdmin;
+import org.osgi.service.useradmin.UserAdminEvent;
+import org.osgi.service.useradmin.UserAdminListener;
+import org.osgi.service.useradmin.UserAdminPermission;
+import org.apache.useradmin.service.AuthorizationImpl;
+import org.apache.useradmin.service.RoleImpl;
+import org.apache.useradmin.service.RoleListener;
+import org.apache.useradmin.service.UserImpl;
+
+
+public class UserAdminService implements UserAdmin, ServiceFactory, ServiceListener, RoleListener
+{
+ public static final UserAdminPermission adminPermission
+ = new UserAdminPermission( UserAdminPermission.ADMIN, null );
+
+ protected ServiceReference reference;
+ protected RoleStore store;
+ protected List listeners = new ArrayList();
+
+ BundleContext bundleContext;
+
+ UserAdminService( BundleContext context, RoleStore store )
+ {
+ bundleContext = context;
+ this.store = store;
+ }
+
+ private void init( ServiceReference sr )
+ {
+ this.reference = sr;
+ // Listen for UserAdminListeners, collect those already registered
+ try
+ {
+ String clazz = UserAdminListener.class.getName();
+ bundleContext.addServiceListener( this, "(objectClass=" + clazz + ")" );
+ ServiceReference[] srs = bundleContext.getServiceReferences( clazz, null );
+ if (srs != null)
+ {
+ for ( int ii = 0; ii < srs.length; ii++ )
+ {
+ listeners.add( srs[ii] );
+ }
+ }
+ }
+ catch (InvalidSyntaxException ex)
+ {
+ }
+ }
+
+ void sendEvent( int type, Role role )
+ {
+ UserAdminEvent event = new UserAdminEvent( reference, type, role );
+
+ Iterator it = listeners.iterator();
+ while ( it.hasNext() )
+ {
+ ServiceReference reference = (ServiceReference)it.next();
+ UserAdminListener ual =(UserAdminListener)bundleContext.getService( reference );
+ if ( ual != null )
+ {
+ ual.roleChanged( event );
+ }
+ bundleContext.ungetService( reference );
+ }
+ }
+
+ // ServiceFactory methods
+ public synchronized Object getService( Bundle bundle, ServiceRegistration registration )
+ {
+ // Factory is only used to be able to register and then later
+ // get hold of our own ServiceReference before any bundle have
+ // a chance to use the service.
+ if ( reference == null )
+ {
+ // initialize ourself with the service reference the first time
+ // the service is used by a bundle
+ init( registration.getReference() );
+ }
+ return this;
+ }
+
+ public void ungetService( Bundle bundle, ServiceRegistration registration, Object service )
+ {
+ // do nothing
+ }
+
+ // RoleListener methods
+ public void roleCreated( Role role )
+ {
+ sendEvent( UserAdminEvent.ROLE_CREATED, role );
+ }
+
+ public void roleChanged( Role role )
+ {
+ sendEvent( UserAdminEvent.ROLE_CHANGED, role );
+ }
+
+ public void roleRemoved( Role role )
+ {
+ sendEvent( UserAdminEvent.ROLE_REMOVED, role );
+ }
+
+ // UserAdmin methods
+ public Role createRole( String name, int type )
+ {
+ if ( System.getSecurityManager() != null )
+ {
+ AccessController.checkPermission( adminPermission );
+ }
+
+ if ( store.containsRole( name ) )
+ {
+ return null;
+ }
+
+ Role role = null;
+
+ switch ( type )
+ {
+ case Role.USER:
+ role = store.createUser( name );
+ break;
+ case Role.GROUP:
+ role = store.createGroup( name );
+ break;
+ default:
+ throw new IllegalArgumentException( "UserAdminService: Unknown type '" + type + "'." );
+ }
+
+ sendEvent( UserAdminEvent.ROLE_CREATED, role );
+ ( (RoleImpl)role ).addRoleListener( this );
+
+ return role;
+ }
+
+ public boolean removeRole( String name )
+ {
+ if ( System.getSecurityManager() != null )
+ {
+ AccessController.checkPermission( adminPermission );
+ }
+
+ Role deletedRole = store.removeRole( name );
+
+ if ( deletedRole != null )
+ {
+ sendEvent( UserAdminEvent.ROLE_REMOVED, deletedRole );
+ return true;
+ }
+
+ return false;
+ }
+
+ public Role getRole( String name )
+ {
+ return store.findRole( name );
+ }
+
+ public Role[] getRoles( String filter )
+ throws InvalidSyntaxException
+ {
+ List results = new ArrayList();
+ Iterator it = store.roles().iterator();
+ while ( it.hasNext() )
+ {
+ RoleImpl role = (RoleImpl) it.next();
+ if ( filter == null || LDAPQuery.query(filter, role.getProperties() ) )
+ {
+ results.add( role );
+ }
+ }
+ Role[] roles = new Role[ results.size() ];
+ return (Role[])results.toArray( roles );
+ }
+
+ public User getUser( String key, String value )
+ {
+ User[] users = getUsers( key, value );
+
+ return users.length == 1 ? users[0] : null;
+ }
+
+ private User[] getUsers( String key, String value )
+ {
+ List results = new ArrayList();
+ Iterator it = store.roles().iterator();
+ while ( it.hasNext() )
+ {
+ Object o = it.next();
+ if ( o instanceof UserImpl )
+ {
+ UserImpl user = (UserImpl)o;
+ Object content = user.getProperties().get( key );
+ if ( content instanceof String && value.equals( content ) )
+ {
+ results.add( user );
+ }
+ }
+ }
+ User[] users = new User[ results.size() ];
+ return (User[])results.toArray( users );
+ }
+
+ public Authorization getAuthorization( User user )
+ {
+ String userName;
+ if ( user == null )
+ {
+ userName = "user.anyone";
+ }
+ else
+ {
+ userName = user.getName();
+ }
+
+ List roles = new ArrayList();
+
+ Iterator it = store.roles().iterator();
+ while ( it.hasNext() )
+ {
+ RoleImpl role = (RoleImpl)it.next();
+ if ( role.hasMember( userName, new HashSet() ) )
+ {
+ roles.add( role.getName() );
+ }
+ }
+ return new AuthorizationImpl( userName, roles );
+ }
+
+ // ServiceListener methods
+ public void serviceChanged( ServiceEvent event )
+ {
+ ServiceReference sr = event.getServiceReference();
+ switch ( event.getType() )
+ {
+ case ServiceEvent.REGISTERED:
+ listeners.add( sr );
+ break;
+ case ServiceEvent.UNREGISTERING:
+ break;
+ }
+ }
+}
+
Propchange: directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/UserAdminService.java
------------------------------------------------------------------------------
svn:executable = *
Added: directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/operations/AddMember.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/operations/AddMember.java?rev=209422&view=auto
==============================================================================
--- directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/operations/AddMember.java (added)
+++ directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/operations/AddMember.java Wed Jul 6 00:49:18 2005
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed 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.useradmin.transactions;
+
+import java.util.Date;
+
+import org.osgi.service.useradmin.Group;
+import org.osgi.service.useradmin.Role;
+
+
+public class AddMember extends GroupTransaction
+{
+ private Role role;
+
+ public AddMember( Group group, Role role )
+ {
+ super( group );
+ this.role = role;
+ }
+
+ public void executeAndQuery( Group group, Date timestamp )
+ throws Exception
+ {
+ group.addMember( role );
+ }
+}
+
Propchange: directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/operations/AddMember.java
------------------------------------------------------------------------------
svn:executable = *
Added: directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/operations/AddRequiredMember.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/operations/AddRequiredMember.java?rev=209422&view=auto
==============================================================================
--- directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/operations/AddRequiredMember.java (added)
+++ directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/operations/AddRequiredMember.java Wed Jul 6 00:49:18 2005
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed 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.useradmin.transactions;
+
+import java.util.Date;
+
+import org.osgi.service.useradmin.Group;
+import org.osgi.service.useradmin.Role;
+
+
+public class AddRequiredMember extends GroupTransaction
+{
+ private Role role;
+
+ public AddRequiredMember( Group group, Role role )
+ {
+ super( group );
+ this.role = role;
+ }
+
+ public void executeAndQuery( Group group, Date timestamp )
+ throws Exception
+ {
+ group.addRequiredMember( role );
+ }
+}
+
Propchange: directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/operations/AddRequiredMember.java
------------------------------------------------------------------------------
svn:executable = *
Added: directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/operations/CreateGroup.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/operations/CreateGroup.java?rev=209422&view=auto
==============================================================================
--- directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/operations/CreateGroup.java (added)
+++ directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/operations/CreateGroup.java Wed Jul 6 00:49:18 2005
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed 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.useradmin.transactions;
+
+import java.util.Date;
+
+import org.apache.useradmin.RoleStore;
+
+
+public class CreateGroup extends RoleTransaction
+{
+ private String name;
+
+ public CreateGroup( String name )
+ {
+ this.name = name;
+ }
+
+ protected Object executeAndQuery( RoleStore store, Date ignored )
+ throws Exception
+ {
+ return store.createGroup( name );
+ }
+}
+
Propchange: directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/operations/CreateGroup.java
------------------------------------------------------------------------------
svn:executable = *
Added: directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/operations/CreateUser.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/operations/CreateUser.java?rev=209422&view=auto
==============================================================================
--- directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/operations/CreateUser.java (added)
+++ directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/operations/CreateUser.java Wed Jul 6 00:49:18 2005
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed 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.useradmin.transactions;
+
+import java.util.Date;
+
+import org.apache.useradmin.RoleStore;
+
+
+public class CreateUser extends RoleTransaction
+{
+ private String name;
+
+ public CreateUser( String name )
+ {
+ this.name = name;
+ }
+
+ protected Object executeAndQuery( RoleStore store, Date ignored )
+ throws Exception
+ {
+ return store.createUser( name );
+ }
+}
+
Propchange: directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/operations/CreateUser.java
------------------------------------------------------------------------------
svn:executable = *
Added: directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/operations/DeleteRole.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/operations/DeleteRole.java?rev=209422&view=auto
==============================================================================
--- directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/operations/DeleteRole.java (added)
+++ directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/operations/DeleteRole.java Wed Jul 6 00:49:18 2005
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed 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.useradmin.transactions;
+
+import java.util.Date;
+
+import org.apache.useradmin.RoleStore;
+
+
+public class DeleteRole extends RoleTransaction
+{
+ private String name;
+
+ public DeleteRole( String name )
+ {
+ this.name = name;
+ }
+
+ protected Object executeAndQuery( RoleStore role, Date ignored )
+ throws Exception
+ {
+ return role.removeRole( name );
+ }
+}
+
Propchange: directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/operations/DeleteRole.java
------------------------------------------------------------------------------
svn:executable = *
Added: directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/operations/GroupTransaction.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/operations/GroupTransaction.java?rev=209422&view=auto
==============================================================================
--- directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/operations/GroupTransaction.java (added)
+++ directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/operations/GroupTransaction.java Wed Jul 6 00:49:18 2005
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed 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.useradmin.transactions;
+
+import java.util.Date;
+
+import org.osgi.service.useradmin.Group;
+import org.apache.useradmin.RoleStore;
+
+
+abstract class GroupTransaction extends RoleTransaction
+{
+ private String name;
+
+ protected GroupTransaction( Group group )
+ {
+ name = group.getName();
+ }
+
+ protected Object executeAndQuery( RoleStore store, Date timestamp )
+ throws Exception
+ {
+ executeAndQuery( (Group) store.findRole( name ), timestamp );
+ return null;
+ }
+
+ protected abstract void executeAndQuery( Group group, Date timestamp )
+ throws Exception;
+}
+
Propchange: directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/operations/GroupTransaction.java
------------------------------------------------------------------------------
svn:executable = *
Added: directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/operations/RemoveMember.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/operations/RemoveMember.java?rev=209422&view=auto
==============================================================================
--- directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/operations/RemoveMember.java (added)
+++ directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/operations/RemoveMember.java Wed Jul 6 00:49:18 2005
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed 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.useradmin.transactions;
+
+import java.util.Date;
+
+import org.osgi.service.useradmin.Group;
+import org.osgi.service.useradmin.Role;
+
+
+public class RemoveMember extends GroupTransaction
+{
+ private Role role;
+
+ public RemoveMember( Group group, Role role )
+ {
+ super( group );
+ this.role = role;
+ }
+
+ public void executeAndQuery( Group group, Date timestamp )
+ throws Exception
+ {
+ group.removeMember( role );
+ }
+}
+
Propchange: directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/operations/RemoveMember.java
------------------------------------------------------------------------------
svn:executable = *
Added: directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/operations/RoleTransaction.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/operations/RoleTransaction.java?rev=209422&view=auto
==============================================================================
--- directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/operations/RoleTransaction.java (added)
+++ directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/operations/RoleTransaction.java Wed Jul 6 00:49:18 2005
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed 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.useradmin.transactions;
+
+import java.util.Date;
+
+import org.prevayler.TransactionWithQuery;
+import org.apache.useradmin.RoleStore;
+
+
+public abstract class RoleTransaction implements TransactionWithQuery
+{
+ public Object executeAndQuery( Object role, Date timestamp )
+ throws Exception
+ {
+ return executeAndQuery( (RoleStore) role, timestamp );
+ }
+
+ protected abstract Object executeAndQuery( RoleStore role, Date timestamp )
+ throws Exception;
+}
+
Propchange: directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/operations/RoleTransaction.java
------------------------------------------------------------------------------
svn:executable = *
Added: directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/service/AnyoneGroup.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/service/AnyoneGroup.java?rev=209422&view=auto
==============================================================================
--- directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/service/AnyoneGroup.java (added)
+++ directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/service/AnyoneGroup.java Wed Jul 6 00:49:18 2005
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed 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.useradmin.service;
+
+import java.util.Set;
+
+import org.osgi.service.useradmin.Role;
+
+
+public class AnyoneGroup extends GroupImpl
+{
+ public AnyoneGroup()
+ {
+ super( "user.anyone" );
+ }
+
+ public boolean hasMember( String name, Set visited )
+ {
+ return true;
+ }
+
+ public boolean canBeVisited()
+ {
+ return false;
+ }
+
+ public boolean canBeDeleted()
+ {
+ return false;
+ }
+
+ public boolean addMember( Role role )
+ {
+ return false;
+ }
+
+ public boolean addRequiredMember( Role role )
+ {
+ return false;
+ }
+
+ public boolean removeMember( Role role )
+ {
+ return false;
+ }
+}
+
Propchange: directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/service/AnyoneGroup.java
------------------------------------------------------------------------------
svn:executable = *
Added: directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/service/AuthorizationImpl.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/service/AuthorizationImpl.java?rev=209422&view=auto
==============================================================================
--- directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/service/AuthorizationImpl.java (added)
+++ directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/service/AuthorizationImpl.java Wed Jul 6 00:49:18 2005
@@ -0,0 +1,86 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed 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.useradmin.service;
+
+import java.io.Serializable;
+import java.util.Iterator;
+import java.util.List;
+
+import org.osgi.service.useradmin.Authorization;
+
+
+public class AuthorizationImpl implements Authorization, Serializable
+{
+ private String name;
+ private List roles;
+
+ public AuthorizationImpl( String name, List roles )
+ {
+ this.name = name;
+ this.roles = roles;
+ }
+
+ // Authorization methods
+ public String getName()
+ {
+ return name;
+ }
+
+ public String[] getRoles()
+ {
+ if ( roles.isEmpty() )
+ {
+ return null;
+ }
+
+ return (String[])roles.toArray();
+ }
+
+ public boolean hasRole( String roleName )
+ {
+ return roles.contains( roleName );
+ }
+
+ // Object methods
+ public String toString()
+ {
+ StringBuffer sb = new StringBuffer();
+ sb.append( "USER = " + name + ", ROLES = {" );
+ sb.append( listToString( roles ) );
+ sb.append( "}" );
+
+ return sb.toString();
+ }
+
+ private StringBuffer listToString( List list )
+ {
+ StringBuffer sb = new StringBuffer();
+ Iterator it = list.iterator();
+ while ( it.hasNext() )
+ {
+ Object role = it.next();
+ sb.append( role );
+ if ( it.hasNext() )
+ {
+ sb.append( ", " );
+ }
+ }
+ return sb;
+ }
+}
+
Propchange: directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/service/AuthorizationImpl.java
------------------------------------------------------------------------------
svn:executable = *
Added: directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/service/GroupImpl.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/service/GroupImpl.java?rev=209422&view=auto
==============================================================================
--- directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/service/GroupImpl.java (added)
+++ directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/service/GroupImpl.java Wed Jul 6 00:49:18 2005
@@ -0,0 +1,212 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed 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.useradmin.service;
+
+import java.security.AccessController;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+import org.osgi.service.useradmin.Group;
+import org.osgi.service.useradmin.Role;
+import org.apache.useradmin.UserAdminService;
+
+
+public class GroupImpl extends UserImpl implements Group
+{
+ protected Set basicMembers = new HashSet();
+ protected Set requiredMembers = new HashSet();
+
+ public GroupImpl( String name )
+ {
+ super( name );
+ }
+
+ public int getType()
+ {
+ return Role.GROUP;
+ }
+
+ public boolean hasMember( String name, Set visited )
+ {
+ boolean atLeastOneBasicMember = hasBasicMembers( basicMembers, name, visited );
+ boolean allRequiredMembers = hasRequiredMembers( requiredMembers, name, visited );
+
+ return atLeastOneBasicMember && allRequiredMembers;
+ }
+
+ private boolean hasBasicMembers( Set members, String name, Set visited )
+ {
+ boolean hasBasic = false;
+
+ if ( members.isEmpty() )
+ {
+ return false;
+ }
+
+ Iterator it = members.iterator();
+ while ( it.hasNext() )
+ {
+ Object role = it.next();
+ if ( role instanceof GroupImpl )
+ {
+ GroupImpl group = (GroupImpl)role;
+ if ( visited.contains( group ) )
+ {
+ return false;
+ }
+
+ if ( group.canBeVisited() )
+ {
+ visited.add( group );
+ }
+ hasBasic = hasBasic || group.hasMember( name, visited );
+ }
+ else
+ {
+ if ( role instanceof UserImpl )
+ {
+ hasBasic = hasBasic || ( (UserImpl) role ).hasMember( name, visited );
+ }
+ }
+ }
+ return hasBasic;
+ }
+
+ private boolean hasRequiredMembers( Set members, String name, Set visited )
+ {
+ boolean hasRequired = true;
+
+ if ( members.isEmpty() )
+ {
+ return true;
+ }
+
+ Iterator it = members.iterator();
+ while ( it.hasNext() )
+ {
+ Object role = it.next();
+ if ( role instanceof GroupImpl )
+ {
+ GroupImpl group = (GroupImpl)role;
+ if ( visited.contains( group ) )
+ {
+ return false;
+ }
+ if ( group.canBeVisited() )
+ {
+ visited.add( group );
+ }
+ hasRequired = hasRequired && group.hasMember( name, visited );
+ }
+ else
+ {
+ if ( role instanceof UserImpl )
+ {
+ hasRequired = hasRequired && ( (UserImpl) role ).hasMember( name, visited );
+ }
+ }
+ }
+ return hasRequired;
+ }
+
+ public String toString()
+ {
+ StringBuffer sb = new StringBuffer();
+ sb.append( "GROUP = " + name + ", BASIC = {" );
+ sb.append( rolesToString( basicMembers ) );
+ sb.append( "}, REQUIRED = {" );
+ sb.append( rolesToString( requiredMembers ) );
+ sb.append( "}" );
+
+ return sb.toString();
+ }
+
+ private StringBuffer rolesToString( Collection c )
+ {
+ StringBuffer sb = new StringBuffer();
+ Iterator it = c.iterator();
+ while ( it.hasNext() )
+ {
+ Role role = (Role)it.next();
+ sb.append( role.getName() );
+ if ( it.hasNext() )
+ {
+ sb.append( ", " );
+ }
+ }
+ return sb;
+ }
+
+ // Group methods
+ public boolean addMember( Role role )
+ {
+ if ( checkPermissions )
+ {
+ AccessController.checkPermission( UserAdminService.adminPermission );
+ }
+
+ return basicMembers.add( role );
+ }
+
+ public boolean addRequiredMember( Role role )
+ {
+ if ( checkPermissions )
+ {
+ AccessController.checkPermission( UserAdminService.adminPermission );
+ }
+
+ return requiredMembers.add( role );
+ }
+
+ public boolean removeMember( Role role )
+ {
+ if ( checkPermissions )
+ {
+ AccessController.checkPermission( UserAdminService.adminPermission );
+ }
+
+ boolean wasRemoved = false;
+
+ if ( basicMembers.remove( role ) )
+ {
+ wasRemoved = true;
+ }
+
+ if ( requiredMembers.remove( role ) )
+ {
+ wasRemoved = true;
+ }
+
+ return wasRemoved;
+ }
+
+ public Role[] getMembers()
+ {
+ Role[] roles = new Role[ basicMembers.size() ];
+ return (Role[])basicMembers.toArray( roles );
+ }
+
+ public Role[] getRequiredMembers()
+ {
+ Role[] roles = new Role[ requiredMembers.size() ];
+ return (Role[])requiredMembers.toArray( roles );
+ }
+}
+
Propchange: directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/service/GroupImpl.java
------------------------------------------------------------------------------
svn:executable = *
Added: directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/service/RoleImpl.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/service/RoleImpl.java?rev=209422&view=auto
==============================================================================
--- directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/service/RoleImpl.java (added)
+++ directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/service/RoleImpl.java Wed Jul 6 00:49:18 2005
@@ -0,0 +1,217 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed 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.useradmin.service;
+
+import java.io.Serializable;
+import java.security.AccessController;
+import java.util.Dictionary;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.Set;
+
+import org.osgi.service.useradmin.Role;
+import org.osgi.service.useradmin.UserAdminPermission;
+
+
+public abstract class RoleImpl implements Role, Serializable, Comparable
+{
+ protected String name;
+ protected SecureProperties props = new SecureProperties( this );
+
+ protected transient boolean checkPermissions = System.getSecurityManager() != null;
+ private transient Set listeners;
+
+ public RoleImpl( String name )
+ {
+ this.name = name;
+ }
+
+ abstract public boolean hasMember( String name, Set visited );
+
+ public boolean canBeVisited()
+ {
+ return true;
+ }
+
+ public boolean canBeDeleted()
+ {
+ return true;
+ }
+
+ public boolean equals( Object o )
+ {
+ return ( (Role) o ).getName().equals( name );
+ }
+
+ public int hashCode()
+ {
+ return name.hashCode();
+ }
+
+ public String toString()
+ {
+ return name;
+ }
+
+ // Role methods
+ public String getName()
+ {
+ return name;
+ }
+
+ public int getType()
+ {
+ return Role.ROLE;
+ }
+
+ public Dictionary getProperties()
+ {
+ return props;
+ }
+
+ public int compareTo( Object o )
+ {
+ return name.compareTo( ( (Role) o ).getName() );
+ }
+
+ public void addRoleListener( RoleListener listener )
+ {
+ listeners().add( listener );
+ }
+
+ public void removeRoleListener( RoleListener listener )
+ {
+ listeners().remove( listener );
+ }
+
+ private Set listeners()
+ {
+ if ( listeners == null )
+ {
+ listeners = new HashSet();
+ }
+
+ return listeners;
+ }
+
+ private void notifyListeners( Role role )
+ {
+ Iterator it = listeners().iterator();
+ while ( it.hasNext() )
+ {
+ ( (RoleListener) it.next() ).roleChanged( role );
+ }
+ }
+
+ protected class SecureProperties extends Dictionary implements Serializable
+ {
+ protected RoleImpl role;
+ protected Hashtable properties = new Hashtable();
+
+ protected SecureProperties( RoleImpl role )
+ {
+ this.role = role;
+ }
+
+ public Enumeration elements()
+ {
+ return properties.elements();
+ }
+
+ // No security check for properties
+ public Object get( Object key )
+ {
+ return properties.get( key );
+ }
+
+ public boolean isEmpty()
+ {
+ return properties.isEmpty();
+ }
+
+ public Enumeration keys()
+ {
+ return properties.keys();
+ }
+
+ public int size()
+ {
+ return properties.size();
+ }
+
+ public Object remove( Object key )
+ {
+ if ( key instanceof String )
+ {
+ if ( checkPermissions )
+ {
+ AccessController.checkPermission( new UserAdminPermission( (String) key,
+ UserAdminPermission.CHANGE_PROPERTY ) );
+ }
+
+ Object res = properties.remove( key );
+ notifyListeners( role );
+ return res;
+ }
+ throw new IllegalArgumentException( "The key must be a String, got " + key.getClass() );
+ }
+
+ public Object put( Object key, Object value )
+ {
+ if ( key instanceof String )
+ {
+ if ( checkPermissions )
+ {
+ AccessController.checkPermission( new UserAdminPermission( (String) key,
+ UserAdminPermission.CHANGE_PROPERTY ) );
+ }
+ Object res;
+ // value of type byte[] or String is ok
+ if ( value instanceof byte[] )
+ {
+ res = properties.put( key, ( (byte[]) value ).clone() );
+ }
+ else
+ {
+ if ( value instanceof String )
+ {
+ res = properties.put(key, value);
+ }
+ else
+ {
+ throw new IllegalArgumentException( "The value must be of type byte[]"
+ + " or String, got " + value.getClass() );
+ }
+ }
+
+ notifyListeners( role );
+
+ return res;
+ }
+ throw new IllegalArgumentException( "The key must be a String, got " + key.getClass() );
+ }
+
+ public String toString()
+ {
+ return "#Properties#";
+ }
+ }
+}
+
Propchange: directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/service/RoleImpl.java
------------------------------------------------------------------------------
svn:executable = *
Added: directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/service/RoleListener.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/service/RoleListener.java?rev=209422&view=auto
==============================================================================
--- directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/service/RoleListener.java (added)
+++ directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/service/RoleListener.java Wed Jul 6 00:49:18 2005
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed 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.useradmin.service;
+
+import org.osgi.service.useradmin.Role;
+
+
+public interface RoleListener
+{
+ public void roleCreated( Role role );
+ public void roleChanged( Role role );
+ public void roleRemoved( Role role );
+}
+
Propchange: directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/service/RoleListener.java
------------------------------------------------------------------------------
svn:executable = *
Added: directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/service/UserImpl.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/service/UserImpl.java?rev=209422&view=auto
==============================================================================
--- directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/service/UserImpl.java (added)
+++ directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/service/UserImpl.java Wed Jul 6 00:49:18 2005
@@ -0,0 +1,113 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed 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.useradmin.service;
+
+import java.io.Serializable;
+import java.security.AccessController;
+import java.util.Arrays;
+import java.util.Dictionary;
+import java.util.Set;
+
+import org.osgi.service.useradmin.Role;
+import org.osgi.service.useradmin.User;
+import org.osgi.service.useradmin.UserAdminPermission;
+
+
+public class UserImpl extends RoleImpl implements User
+{
+ protected SecureCredentials creds = new SecureCredentials( this );
+
+ public UserImpl( String name )
+ {
+ super( name );
+ }
+
+ public boolean hasMember( String name, Set visited )
+ {
+ return this.name.equals( name );
+ }
+
+ public int getType()
+ {
+ return Role.USER;
+ }
+
+ // User methods
+ public Dictionary getCredentials()
+ {
+ return creds;
+ }
+
+ public boolean hasCredential( String key, Object value )
+ {
+ if ( checkPermissions )
+ {
+ AccessController.checkPermission( new UserAdminPermission( key,
+ UserAdminPermission.GET_CREDENTIAL ) );
+ }
+
+ Object val = creds.get( key );
+ if ( val instanceof byte[] && value instanceof byte[] )
+ {
+ return Arrays.equals( (byte[]) val, (byte[]) value );
+ }
+
+ if ( val instanceof String && value instanceof String)
+ {
+ return val.equals( value );
+ }
+
+ return false;
+ }
+
+ private class SecureCredentials extends SecureProperties implements Serializable
+ {
+ UserImpl user;
+
+ protected SecureCredentials( UserImpl user )
+ {
+ super( user );
+ this.user = user;
+ }
+
+ protected String getChangeAction()
+ {
+ return UserAdminPermission.CHANGE_CREDENTIAL;
+ }
+
+ public Object get( Object key )
+ {
+ if ( key instanceof String )
+ {
+ if ( checkPermissions )
+ {
+ AccessController.checkPermission( new UserAdminPermission( (String) key,
+ UserAdminPermission.GET_CREDENTIAL ) );
+ }
+ return super.get( key );
+ }
+ throw new IllegalArgumentException( "The key must be a String, got " + key.getClass() );
+ }
+
+ public String toString()
+ {
+ return "#Credentials#";
+ }
+ }
+}
+
Propchange: directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/service/UserImpl.java
------------------------------------------------------------------------------
svn:executable = *
Added: directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/store/InMemoryRoleStore.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/store/InMemoryRoleStore.java?rev=209422&view=auto
==============================================================================
--- directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/store/InMemoryRoleStore.java (added)
+++ directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/store/InMemoryRoleStore.java Wed Jul 6 00:49:18 2005
@@ -0,0 +1,139 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed 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.useradmin.store;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.osgi.service.useradmin.Group;
+import org.osgi.service.useradmin.Role;
+import org.osgi.service.useradmin.User;
+import org.apache.useradmin.RoleStore;
+import org.apache.useradmin.service.AnyoneGroup;
+import org.apache.useradmin.service.GroupImpl;
+import org.apache.useradmin.service.RoleImpl;
+import org.apache.useradmin.service.RoleListener;
+import org.apache.useradmin.service.UserImpl;
+
+
+public class InMemoryRoleStore implements RoleStore, Serializable
+{
+ private Map roles = new HashMap();
+ private static final GroupImpl USER_ANYONE = new AnyoneGroup();
+
+ private transient RoleListener roleListener;
+
+ public InMemoryRoleStore()
+ {
+ if ( !roles.containsKey( USER_ANYONE.getName() ) )
+ {
+ roles.put( USER_ANYONE.getName(), USER_ANYONE );
+ }
+ }
+
+ public User createUser( String name )
+ {
+ User user = new UserImpl( name );
+ roles.put( name, user );
+
+ if ( roleListener != null )
+ {
+ roleListener.roleCreated( user );
+ }
+
+ return user;
+ }
+
+ public Group createGroup( String name )
+ {
+ Group group = new GroupImpl( name );
+ roles.put( name, group );
+
+ if ( roleListener != null)
+ {
+ roleListener.roleCreated( group );
+ }
+
+ return group;
+ }
+
+ public Role findRole( String name )
+ {
+ Role role = searchRole( name );
+ return role;
+ }
+
+ private Role searchRole( String name )
+ {
+ return (Role) roles.get( name );
+ }
+
+ public Role removeRole( String name )
+ {
+ Role role = findRole( name );
+ if ( ( (RoleImpl) role ).canBeDeleted() )
+ {
+ roles.remove( name );
+ if ( roleListener != null )
+ {
+ roleListener.roleRemoved( role );
+ }
+ return role;
+ }
+ return null;
+ }
+
+ public boolean containsRole( String name )
+ {
+ return roles.containsKey( name );
+ }
+
+ public List roles()
+ {
+ List roleList = new ArrayList( roles.values() );
+
+ Collections.sort( roleList );
+
+ return roleList;
+ }
+
+ public void addMember( Group group, Role role )
+ {
+ group.addMember( role );
+ }
+
+ public void addRequiredMember( Group group, Role role )
+ {
+ group.addRequiredMember( role );
+ }
+
+ public void removeMember( Group group, Role role )
+ {
+ group.removeMember( role );
+ }
+
+ public void setRoleListener( RoleListener roleListener )
+ {
+ this.roleListener = roleListener;
+ }
+}
+
Propchange: directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/store/InMemoryRoleStore.java
------------------------------------------------------------------------------
svn:executable = *
Added: directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/store/PrevalentGroup.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/store/PrevalentGroup.java?rev=209422&view=auto
==============================================================================
--- directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/store/PrevalentGroup.java (added)
+++ directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/store/PrevalentGroup.java Wed Jul 6 00:49:18 2005
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed 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.useradmin.store;
+
+import org.osgi.service.useradmin.Group;
+import org.osgi.service.useradmin.Role;
+import org.apache.useradmin.MemberStore;
+import org.apache.useradmin.service.RoleListener;
+
+
+public class PrevalentGroup implements MemberStore
+{
+ public void addMember( Group group, Role role )
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void addRequiredMember( Group group, Role role )
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void removeMember( Group group, Role role )
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void setRoleListener( RoleListener roleListener )
+ {
+ // TODO Auto-generated method stub
+
+ }
+}
+
Propchange: directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/store/PrevalentGroup.java
------------------------------------------------------------------------------
svn:executable = *
Added: directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/store/PrevalentRoleStore.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/store/PrevalentRoleStore.java?rev=209422&view=auto
==============================================================================
--- directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/store/PrevalentRoleStore.java (added)
+++ directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/store/PrevalentRoleStore.java Wed Jul 6 00:49:18 2005
@@ -0,0 +1,147 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed 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.useradmin.store;
+
+import java.util.List;
+
+import org.osgi.service.useradmin.Group;
+import org.osgi.service.useradmin.Role;
+import org.osgi.service.useradmin.User;
+import org.prevayler.Prevayler;
+import org.prevayler.PrevaylerFactory;
+import org.apache.useradmin.RoleStore;
+import org.apache.useradmin.service.RoleListener;
+import org.apache.useradmin.transactions.AddMember;
+import org.apache.useradmin.transactions.AddRequiredMember;
+import org.apache.useradmin.transactions.CreateGroup;
+import org.apache.useradmin.transactions.CreateUser;
+import org.apache.useradmin.transactions.DeleteRole;
+import org.apache.useradmin.transactions.RemoveMember;
+
+
+public class PrevalentRoleStore implements RoleStore
+{
+ private final Prevayler prevayler;
+
+ public PrevalentRoleStore() throws Exception
+ {
+ prevayler = PrevaylerFactory.createPrevayler( new InMemoryRoleStore(), "roleStore" );
+ }
+
+ public User createUser( String name )
+ {
+ User user = null;
+ try {
+ user = (User)prevayler.execute( new CreateUser( name ) );
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException();
+ }
+ return user;
+ }
+
+ public Group createGroup( String name )
+ {
+ Group group = null;
+ try
+ {
+ group = (Group)prevayler.execute( new CreateGroup( name ) );
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException();
+ }
+ return group;
+ }
+
+ public Role findRole( String name )
+ {
+ return store().findRole(name);
+ }
+
+ public Role removeRole( String name )
+ {
+ Role role = null;
+ try
+ {
+ role = (Role)prevayler.execute( new DeleteRole( name ) );
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException();
+ }
+ return role;
+ }
+
+ public boolean containsRole( String name )
+ {
+ return store().containsRole( name );
+ }
+
+ public List roles()
+ {
+ return store().roles();
+ }
+
+ public void addMember( Group group, Role role )
+ {
+ try
+ {
+ prevayler.execute( new AddMember( group, role ) );
+ } catch (Exception e)
+ {
+ throw new RuntimeException();
+ }
+ }
+
+ public void addRequiredMember( Group group, Role role )
+ {
+ try
+ {
+ prevayler.execute( new AddRequiredMember( group, role ) );
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException();
+ }
+ }
+
+ public void removeMember( Group group, Role role )
+ {
+ try
+ {
+ prevayler.execute( new RemoveMember( group, role ) );
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException();
+ }
+ }
+
+ public void setRoleListener( RoleListener roleListener )
+ {
+ store().setRoleListener( roleListener );
+ }
+
+ private RoleStore store()
+ {
+ return (RoleStore)prevayler.prevalentSystem();
+ }
+}
+
Propchange: directory/sandbox/trunk/osgi-spec/trunk/useradmin/src/main/java/org/apache/useradmin/store/PrevalentRoleStore.java
------------------------------------------------------------------------------
svn:executable = *