jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r155394 - in incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core: jaas/ security/
Date Sat, 26 Feb 2005 10:16:06 GMT
Author: stefan
Date: Sat Feb 26 02:16:04 2005
New Revision: 155394

URL: http://svn.apache.org/viewcvs?view=rev&rev=155394
Log:
fixing last commit (rev155344, JAAS support)

Added:
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/security/
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/security/AccessManager.java
  (with props)
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/security/AnonymousPrincipal.java
  (with props)
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/security/CredentialsCallback.java
  (with props)
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/security/CredentialsCallbackHandler.java
  (with props)
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/security/SimpleAccessManager.java
  (with props)
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/security/SimpleLoginModule.java
  (with props)
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/security/SystemPrincipal.java
  (with props)
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/security/UserPrincipal.java
  (with props)
Removed:
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/jaas/

Added: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/security/AccessManager.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/security/AccessManager.java?view=auto&rev=155394
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/security/AccessManager.java
(added)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/security/AccessManager.java
Sat Feb 26 02:16:04 2005
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * 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.jackrabbit.core.security;
+
+import org.apache.jackrabbit.core.ItemId;
+
+import javax.jcr.AccessDeniedException;
+import javax.jcr.RepositoryException;
+import javax.jcr.ItemNotFoundException;
+
+/**
+ * The <code>AccessManager</code> can be queried to determines whether permission
+ * is granted to perform a specific action on a specific item.
+ */
+public interface AccessManager {
+
+    /** READ permission constant */
+    public static final int READ = 1;
+    /** WRITE permission constant */
+    public static final int WRITE = 2;
+
+    /**
+     * Determines whether the specified <code>permissions</code> are granted
+     * on the item with the specified <code>id</code> (i.e. the <i>target</i>
item).
+     *
+     * @param id the id of the target item
+     * @param permissions A combination of one or more of the following constants
+     * encoded as a bitmask value:
+     * <ul>
+     * <li><code>READ</code></li>
+     * <li><code>WRITE</code></li>
+     * </ul>
+     *
+     * @throws AccessDeniedException if permission is denied
+     * @throws ItemNotFoundException if the target item does not exist
+     * @throws RepositoryException it an error occurs
+     */
+    public void checkPermission(ItemId id, int permissions)
+            throws AccessDeniedException, ItemNotFoundException, RepositoryException;
+
+    /**
+     * Determines whether the specified <code>permissions</code> are granted
+     * on the item with the specified <code>id</code> (i.e. the <i>target</i>
item).
+     *
+     * @param id the id of the target item
+     * @param permissions A combination of one or more of the following constants
+     * @return <code>true</code> if permission is granted; otherwise <code>false</code>
+     * @throws ItemNotFoundException if the target item does not exist
+     * @throws RepositoryException it an error occurs
+     */
+    public boolean isGranted(ItemId id, int permissions)
+            throws ItemNotFoundException, RepositoryException;
+}

Propchange: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/security/AccessManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/security/AnonymousPrincipal.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/security/AnonymousPrincipal.java?view=auto&rev=155394
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/security/AnonymousPrincipal.java
(added)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/security/AnonymousPrincipal.java
Sat Feb 26 02:16:04 2005
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * 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.jackrabbit.core.security;
+
+import java.io.Serializable;
+import java.security.Principal;
+
+/**
+ * A <code>AnonymousPrincipal</code> ...
+ */
+public class AnonymousPrincipal implements Principal, Serializable {
+
+    private static final String ANONYMOUS_USER = "anonymous";
+
+    /**
+     * Creates an <code>AnonymousPrincipal</code>.
+     */
+    public AnonymousPrincipal() {
+    }
+
+    public String toString() {
+        return ("AnonymousPrincipal");
+    }
+
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj instanceof AnonymousPrincipal) {
+            return true;
+        }
+        return false;
+    }
+
+    public int hashCode() {
+        return ANONYMOUS_USER.hashCode();
+    }
+
+    //------------------------------------------------------------< Principal >
+    /**
+     * @see Principal#getName()
+     */
+    public String getName() {
+        return ANONYMOUS_USER;
+    }
+}

Propchange: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/security/AnonymousPrincipal.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/security/CredentialsCallback.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/security/CredentialsCallback.java?view=auto&rev=155394
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/security/CredentialsCallback.java
(added)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/security/CredentialsCallback.java
Sat Feb 26 02:16:04 2005
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * 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.jackrabbit.core.security;
+
+import javax.jcr.Credentials;
+import javax.security.auth.callback.Callback;
+import java.io.Serializable;
+
+/**
+ * A <code>CredentialsCallback</code> ...
+ */
+public class CredentialsCallback implements Callback, Serializable {
+
+    private Credentials credentials;
+
+    /**
+     * Constructor
+     */
+    public CredentialsCallback() {
+    }
+
+    /**
+     * Get the retrieved credentials.
+     *
+     * @return the retrieved credentials (which may be null)
+     */
+    public Credentials getCredentials() {
+        return credentials;
+    }
+
+    /**
+     * Set the retrieved credentials.
+     *
+     * @param credentials the retrieved credentials (which may be null)
+     */
+    public void setCredentials(Credentials credentials) {
+        this.credentials = credentials;
+    }
+}

Propchange: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/security/CredentialsCallback.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/security/CredentialsCallbackHandler.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/security/CredentialsCallbackHandler.java?view=auto&rev=155394
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/security/CredentialsCallbackHandler.java
(added)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/security/CredentialsCallbackHandler.java
Sat Feb 26 02:16:04 2005
@@ -0,0 +1,76 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * 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.jackrabbit.core.security;
+
+import org.apache.log4j.Logger;
+
+import javax.jcr.Credentials;
+import javax.jcr.SimpleCredentials;
+import javax.security.auth.callback.Callback;
+import javax.security.auth.callback.CallbackHandler;
+import javax.security.auth.callback.NameCallback;
+import javax.security.auth.callback.PasswordCallback;
+import javax.security.auth.callback.UnsupportedCallbackException;
+import java.io.IOException;
+
+/**
+ * A <code>CredentialsCallbackHandler</code> ...
+ */
+public class CredentialsCallbackHandler implements CallbackHandler {
+
+    private static Logger log = Logger.getLogger(CredentialsCallbackHandler.class);
+
+    protected final Credentials credentials;
+
+    /**
+     * Constructor
+     *
+     * @param credentials
+     */
+    public CredentialsCallbackHandler(Credentials credentials) {
+        this.credentials = credentials;
+    }
+
+    //------------------------------------------------------< CallbackHandler >
+    /**
+     * @see CallbackHandler#handle(Callback[])
+     */
+    public void handle(Callback[] callbacks) throws IOException,
+            UnsupportedCallbackException {
+        for (int i = 0; i < callbacks.length; i++) {
+            if (callbacks[i] instanceof CredentialsCallback) {
+                CredentialsCallback ccb = (CredentialsCallback) callbacks[i];
+                // supply credentials
+                ccb.setCredentials(credentials);
+            } else if (callbacks[i] instanceof NameCallback
+                    && credentials instanceof SimpleCredentials) {
+                NameCallback ncb = (NameCallback) callbacks[i];
+                SimpleCredentials sc = (SimpleCredentials) credentials;
+                // supply name
+                ncb.setName(sc.getUserId());
+            } else if (callbacks[i] instanceof PasswordCallback
+                    && credentials instanceof SimpleCredentials) {
+                PasswordCallback pcb = (PasswordCallback) callbacks[i];
+                SimpleCredentials sc = (SimpleCredentials) credentials;
+                // supply password
+                pcb.setPassword(sc.getPassword());
+            } else {
+                throw new UnsupportedCallbackException(callbacks[i], "Unrecognized Callback");
+            }
+        }
+    }
+}

Propchange: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/security/CredentialsCallbackHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/security/SimpleAccessManager.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/security/SimpleAccessManager.java?view=auto&rev=155394
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/security/SimpleAccessManager.java
(added)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/security/SimpleAccessManager.java
Sat Feb 26 02:16:04 2005
@@ -0,0 +1,98 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * 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.jackrabbit.core.security;
+
+import org.apache.jackrabbit.core.HierarchyManager;
+import org.apache.jackrabbit.core.ItemId;
+import org.apache.log4j.Logger;
+
+import javax.jcr.AccessDeniedException;
+import javax.jcr.ItemNotFoundException;
+import javax.jcr.RepositoryException;
+import javax.security.auth.Subject;
+
+/**
+ * <code>SimpleAccessManager</code> ...
+ */
+public class SimpleAccessManager implements AccessManager {
+
+    private static Logger log = Logger.getLogger(SimpleAccessManager.class);
+
+    /**
+     * Subject whose access rights this AccessManager should reflect
+     */
+    protected final Subject subject;
+
+    /**
+     * hierarchy manager used for ACL-based access control model
+     */
+    protected final HierarchyManager hierMgr;
+
+    protected final boolean system;
+    protected final boolean anonymous;
+
+    /**
+     * Constructor
+     *
+     * @param subject
+     * @param hierMgr
+     */
+    public SimpleAccessManager(Subject subject, HierarchyManager hierMgr) {
+        this.subject = subject;
+        this.hierMgr = hierMgr;
+        anonymous = !subject.getPrincipals(AnonymousPrincipal.class).isEmpty();
+        system = !subject.getPrincipals(SystemPrincipal.class).isEmpty();
+    }
+
+    //--------------------------------------------------------< AccessManager >
+    /**
+     * @see AccessManager#checkPermission(ItemId, int)
+     */
+    public void checkPermission(ItemId id, int permissions)
+            throws AccessDeniedException, ItemNotFoundException,
+            RepositoryException {
+        if (system) {
+            // system has always all permissions
+            return;
+        } else if (anonymous) {
+            // anonymous is always denied WRITE premission
+            if ((permissions & WRITE) == WRITE) {
+                throw new AccessDeniedException();
+            }
+        }
+        // @todo check permission based on principals
+    }
+
+    /**
+     * @see AccessManager#isGranted(ItemId, int)
+     */
+    public boolean isGranted(ItemId id, int permissions)
+            throws ItemNotFoundException, RepositoryException {
+        if (system) {
+            // system has always all permissions
+            return true;
+        } else if (anonymous) {
+            // anonymous is always denied WRITE premission
+            if ((permissions & WRITE) == WRITE) {
+                return false;
+            }
+        }
+
+        // @todo check permission based on principals
+        return true;
+    }
+}

Propchange: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/security/SimpleAccessManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/security/SimpleLoginModule.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/security/SimpleLoginModule.java?view=auto&rev=155394
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/security/SimpleLoginModule.java
(added)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/security/SimpleLoginModule.java
Sat Feb 26 02:16:04 2005
@@ -0,0 +1,157 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * 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.jackrabbit.core.security;
+
+import org.apache.log4j.Logger;
+
+import javax.jcr.Credentials;
+import javax.jcr.SimpleCredentials;
+import javax.security.auth.Subject;
+import javax.security.auth.callback.Callback;
+import javax.security.auth.callback.CallbackHandler;
+import javax.security.auth.callback.UnsupportedCallbackException;
+import javax.security.auth.login.FailedLoginException;
+import javax.security.auth.login.LoginException;
+import javax.security.auth.spi.LoginModule;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * A <code>SimpleLoginModule</code> ...
+ */
+public class SimpleLoginModule implements LoginModule {
+
+    private static Logger log = Logger.getLogger(SimpleLoginModule.class);
+
+    // initial state
+    private Subject subject;
+    private CallbackHandler callbackHandler;
+    private Map sharedState;
+    private Map options;
+
+    // configurable options
+    //private boolean someOpt = false;
+
+    // local authentication state:
+    // the principals, i.e. the authenticated identities
+    private final Set principals = new HashSet();
+
+    /**
+     * Constructor
+     */
+    public SimpleLoginModule() {
+    }
+
+    //----------------------------------------------------------< LoginModule >
+    /**
+     * @see LoginModule#initialize(Subject, CallbackHandler, Map, Map)
+     */
+    public void initialize(Subject subject, CallbackHandler callbackHandler,
+                           Map sharedState, Map options) {
+        this.subject = subject;
+        this.callbackHandler = callbackHandler;
+        this.sharedState = sharedState;
+        this.options = options;
+
+        // initialize any configured options
+        //someOpt = "true".equalsIgnoreCase((String)options.get("someOpt"));
+    }
+
+    /**
+     * @see LoginModule#login()
+     */
+    public boolean login() throws LoginException {
+        // prompt for a user name and password
+        if (callbackHandler == null) {
+            throw new LoginException("no CallbackHandler available");
+        }
+
+        Callback[] callbacks = new Callback[]{
+            new CredentialsCallback()
+        };
+
+        boolean authenticated = false;
+        principals.clear();
+        try {
+            callbackHandler.handle(callbacks);
+            // credentials
+            CredentialsCallback ccb = (CredentialsCallback) callbacks[0];
+            Credentials creds = ccb.getCredentials();
+            if (creds != null) {
+                if (creds instanceof SimpleCredentials) {
+                    SimpleCredentials sc = (SimpleCredentials) creds;
+                    // authenticate
+                    // @todo implement simple username/password authentication
+                    // assume the user we authenticated is the UserPrincipal
+                    principals.add(new UserPrincipal(sc.getUserId()));
+                    authenticated = true;
+                }
+            } else {
+                // null credentials, assume AnonymousPrincipal
+                principals.add(new AnonymousPrincipal());
+                authenticated = true;
+            }
+        } catch (java.io.IOException ioe) {
+            throw new LoginException(ioe.toString());
+        } catch (UnsupportedCallbackException uce) {
+            throw new LoginException(uce.getCallback().toString() + " not available");
+        }
+
+        if (authenticated) {
+            return !principals.isEmpty();
+        } else {
+            // authentication failed: clean out state
+            principals.clear();
+            throw new FailedLoginException();
+        }
+    }
+
+    /**
+     * @see LoginModule#commit()
+     */
+    public boolean commit() throws LoginException {
+        if (principals.isEmpty()) {
+            return false;
+        } else {
+            // add a principals (authenticated identities) to the Subject
+            subject.getPrincipals().addAll(principals);
+            return true;
+        }
+    }
+
+    /**
+     * @see LoginModule#abort()
+     */
+    public boolean abort() throws LoginException {
+        if (principals.isEmpty()) {
+            return false;
+        } else {
+            logout();
+        }
+        return true;
+    }
+
+    /**
+     * @see LoginModule#logout()
+     */
+    public boolean logout() throws LoginException {
+        subject.getPrincipals().removeAll(principals);
+        principals.clear();
+        return true;
+    }
+}

Propchange: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/security/SimpleLoginModule.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/security/SystemPrincipal.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/security/SystemPrincipal.java?view=auto&rev=155394
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/security/SystemPrincipal.java
(added)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/security/SystemPrincipal.java
Sat Feb 26 02:16:04 2005
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * 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.jackrabbit.core.security;
+
+import java.io.Serializable;
+import java.security.Principal;
+
+/**
+ * A <code>SystemPrincipal</code> ...
+ */
+public class SystemPrincipal implements Principal, Serializable {
+
+    private static final String SYSTEM_USER = "system";
+
+    /**
+     * Creates a <code>SystemPrincipal</code>.
+     */
+    public SystemPrincipal() {
+    }
+
+    public String toString() {
+        return ("SystemPrincipal");
+    }
+
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj instanceof SystemPrincipal) {
+            return true;
+        }
+        return false;
+    }
+
+    public int hashCode() {
+        return SYSTEM_USER.hashCode();
+    }
+
+    //------------------------------------------------------------< Principal >
+    /**
+     * @see Principal#getName()
+     */
+    public String getName() {
+        return SYSTEM_USER;
+    }
+}

Propchange: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/security/SystemPrincipal.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/security/UserPrincipal.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/security/UserPrincipal.java?view=auto&rev=155394
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/security/UserPrincipal.java
(added)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/security/UserPrincipal.java
Sat Feb 26 02:16:04 2005
@@ -0,0 +1,68 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * 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.jackrabbit.core.security;
+
+import java.io.Serializable;
+import java.security.Principal;
+
+/**
+ * A <code>UserPrincipal</code> ...
+ */
+public class UserPrincipal implements Principal, Serializable {
+
+    private final String name;
+
+    /**
+     * Creates a <code>UserPrincipal</code> with the given name.
+     *
+     * @param name the name of this principal
+     * @throws IllegalArgumentException if <code>name</code> is <code>null</code>.
+     */
+    public UserPrincipal(String name) {
+        if (name == null) {
+            throw new IllegalArgumentException("name can not be null");
+        }
+        this.name = name;
+    }
+
+    public String toString() {
+        return ("UserPrincipal: " + name);
+    }
+
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj instanceof UserPrincipal) {
+            UserPrincipal other = (UserPrincipal) obj;
+            return name.equals(other.name);
+        }
+        return false;
+    }
+
+    public int hashCode() {
+        return name.hashCode();
+    }
+
+    //------------------------------------------------------------< Principal >
+    /**
+     * @see Principal#getName()
+     */
+    public String getName() {
+        return name;
+    }
+}

Propchange: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/security/UserPrincipal.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message