portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject svn commit: r692968 - in /portals/jetspeed-2/portal/branches/security-refactoring: components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/ jetspeed-api/src/main/java/org/apache/jetspeed/security/ jetspeed-api/src/main/java/org/apa...
Date Mon, 08 Sep 2008 01:09:53 GMT
Author: ate
Date: Sun Sep  7 18:09:52 2008
New Revision: 692968

URL: http://svn.apache.org/viewvc?rev=692968&view=rev
Log:
- making UserSubjectPrincipal an interface again
- adding new JetspeedSubjectFactory class to jetspeed-commons
- refining the Credential definitions: adding a readonly UserCredential and an implementation,
completing PassWordCredential
- refactoring AuthenticationProvider to return an AuthenticatedUser instance and providing
a base AuthenticatedUserImpl to jetspeed-commons

Added:
    portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/UserCredentialImpl.java
  (with props)
    portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/AuthenticatedUser.java
  (contents, props changed)
      - copied, changed from r692966, portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/spi/AuthenticatedUser.java
    portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/UserCredential.java
  (with props)
    portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-commons/src/main/java/org/apache/jetspeed/security/AuthenticatedUserImpl.java
  (with props)
    portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-commons/src/main/java/org/apache/jetspeed/security/JetspeedSubjectFactory.java
  (with props)
Removed:
    portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/spi/AuthenticatedUser.java
Modified:
    portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/AuthenticationProvider.java
    portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/Credential.java
    portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/PasswordCredential.java
    portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/UserSubjectPrincipal.java

Added: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/UserCredentialImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/UserCredentialImpl.java?rev=692968&view=auto
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/UserCredentialImpl.java
(added)
+++ portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/UserCredentialImpl.java
Sun Sep  7 18:09:52 2008
@@ -0,0 +1,105 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jetspeed.security.impl;
+
+import java.sql.Date;
+import java.sql.Timestamp;
+
+import org.apache.jetspeed.security.PasswordCredential;
+import org.apache.jetspeed.security.UserCredential;
+
+/**
+ * @version $Id$
+ *
+ */
+public class UserCredentialImpl implements UserCredential
+{
+    private static final long serialVersionUID = 8445207990171015069L;
+    private int authenticationFailures;
+    private Date expirationDate;
+    private Timestamp lastAuthenticationDate;
+    private String userName;
+    private Timestamp previousAuthenticationDate;
+    private boolean enabled;
+    private boolean expired;
+    private boolean updateAllowed;
+    private boolean updateRequired;
+    
+    public UserCredentialImpl(PasswordCredential pwc)
+    {
+        synchronize(pwc);
+    }
+    
+    public void synchronize(PasswordCredential pwc)
+    {
+        this.authenticationFailures = pwc.getAuthenticationFailures();
+        this.expirationDate = pwc.getExpirationDate();
+        this.lastAuthenticationDate = pwc.getLastAuthenticationDate();
+        this.userName = pwc.getUserName();
+        this.previousAuthenticationDate = pwc.getPreviousAuthenticationDate();
+        this.enabled = pwc.isEnabled();
+        this.expired = pwc.isExpired();
+        this.updateAllowed = pwc.isUpdateAllowed();
+        this.updateRequired = pwc.isUpdateRequired();
+    }
+    
+    public int getAuthenticationFailures()
+    {
+        return authenticationFailures;
+    }
+
+    public Date getExpirationDate()
+    {
+        return expirationDate;
+    }
+
+    public Timestamp getLastAuthenticationDate()
+    {
+        return lastAuthenticationDate;
+    }
+
+    public String getUserName()
+    {
+        return userName;
+    }
+
+    public Timestamp getPreviousAuthenticationDate()
+    {
+        return previousAuthenticationDate;
+    }
+
+    public boolean isEnabled()
+    {
+        return enabled;
+    }
+
+    public boolean isExpired()
+    {
+        return expired;
+    }
+
+    public boolean isUpdateAllowed()
+    {
+        return updateAllowed;
+    }
+
+    public boolean isUpdateRequired()
+    {
+        return updateRequired;
+    }
+}

Propchange: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/UserCredentialImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/UserCredentialImpl.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/UserCredentialImpl.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Copied: portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/AuthenticatedUser.java
(from r692966, portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/spi/AuthenticatedUser.java)
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/AuthenticatedUser.java?p2=portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/AuthenticatedUser.java&p1=portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/spi/AuthenticatedUser.java&r1=692966&r2=692968&rev=692968&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/spi/AuthenticatedUser.java
(original)
+++ portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/AuthenticatedUser.java
Sun Sep  7 18:09:52 2008
@@ -15,16 +15,18 @@
  * limitations under the License.
  */
 
-package org.apache.jetspeed.security.spi;
+package org.apache.jetspeed.security;
 
 import java.util.Set;
 
+
 /**
  * @version $Id$
  *
  */
 public interface AuthenticatedUser
 {
+    User getUser();
     String getUserName();
     Set<Object> getPublicCredentials();
     Set<Object> getPrivateCredentials();

Propchange: portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/AuthenticatedUser.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/AuthenticatedUser.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/AuthenticatedUser.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/AuthenticationProvider.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/AuthenticationProvider.java?rev=692968&r1=692967&r2=692968&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/AuthenticationProvider.java
(original)
+++ portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/AuthenticationProvider.java
Sun Sep  7 18:09:52 2008
@@ -15,6 +15,7 @@
  * limitations under the License.
  */
 package org.apache.jetspeed.security;
+
 
 /**
  * <p>
@@ -51,7 +52,7 @@
      * 
      * @param userName The user name.
      * @param password The user password.
-     * @return Whether or not a user is authenticated.
+     * @return the {@link AuthenticatedUser}
      */
-    boolean authenticate(String userName, String password) throws SecurityException;
+    AuthenticatedUser authenticate(String userName, String password) throws SecurityException;
 }

Modified: portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/Credential.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/Credential.java?rev=692968&r1=692967&r2=692968&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/Credential.java
(original)
+++ portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/Credential.java
Sun Sep  7 18:09:52 2008
@@ -16,8 +16,8 @@
 */
 package org.apache.jetspeed.security;
 
+import java.io.Serializable;
 
-public interface Credential
+public interface Credential extends Serializable
 {
-
 }

Modified: portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/PasswordCredential.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/PasswordCredential.java?rev=692968&r1=692967&r2=692968&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/PasswordCredential.java
(original)
+++ portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/PasswordCredential.java
Sun Sep  7 18:09:52 2008
@@ -17,7 +17,6 @@
 package org.apache.jetspeed.security;
 
 import java.sql.Date;
-import java.sql.Timestamp;
 
 /**
  * <p>
@@ -27,78 +26,58 @@
  * @author <a href="mailto:ate@apache.org">Ate Douma</a>
  * @version $Id$
  */
-public interface PasswordCredential extends Credential
+public interface PasswordCredential extends UserCredential
 {
     String PASSWORD_CREDENTIAL_DAYS_VALID_REQUEST_ATTR_KEY = PasswordCredential.class.getName()
+ ".check";
 
     /**
-     * @return The user this PasswordCredential belongs to
+     * @return The user the PasswordCredential belongs to
      */
-    User getUser();
-    /**
-     * @return The username.
-     */
-    String getName();
+    User getUser();    
     
     void setUserName(String name);
     
-    boolean isReadOnly();
-   
     /**
-     * @return The password.
+     * @return raw (possibly encoded) password.
      */
     char[] getPassword();
     
-    void setPassword(char[] password);
-
     /**
-     * @return true if update required.
+     * @return the temporary old (plain text) password provided when a new password is set
      */
-    boolean isUpdateRequired();
-    
-    void setUpdateRequired(boolean updateRequired);
+    String getOldPassword();
     
     /**
-     * @return true if enabled.
+     * @return the temporary new (plain text) password provided when a new password is set
      */
-    boolean isEnabled();
-    
-    void setEnabled(boolean enabled);
+    String getNewPassword();
     
     /**
-     * @return true if expired.
+     * Set a new raw (possibly encoded) password
+     * @param password
      */
-    boolean isExpired();
-    
-    void setExpired(boolean expired);
+    void setPassword(char[] password);
     
     /**
-     * @return when the password is (going to be) expired.
+     * Set a new (plain text) password also (optionally) providing the old (plain text) password
      */
-    Date getExpirationDate();
+    void setPassword(String oldPassword, String newPassword);
     
-    void setExpirationDate(Date expirationDate);
+    boolean isNewPasswordSet();
     
-    /**
-     * @return the previous time the user logged in 
-     */
-    Timestamp getPreviousAuthenticationDate();
-
-    /**
-     * @return the last time the user logged in 
-     */
-    Timestamp getLastAuthenticationDate();
+    boolean isPasswordEncoded();
+    
+    boolean setPasswordEncoded(boolean encoded);
+    
+    void setUpdateRequired(boolean updateRequired);
+    
+    boolean isStateReadOnly();
 
-    /**
-     * <p>Getter for the current number of authentication failures in a row.</p>
-     * <ul>
-     *   <li>-1: never tried yet</li>
-     *   <li> 0: none, or last attempt was successful</li>
-     *   <li>>0: number of failures</li>
-     * </ul>
-     * @return The number of authentication failures
-     */
-    int getAuthenticationFailures();
+    void setEnabled(boolean enabled);
+    
+    void setExpired(boolean expired);
+    
+    void setExpirationDate(Date expirationDate);
     
-    void resetAuthenticationFailured();
+    void resetAuthenticationFailures();
 }

Added: portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/UserCredential.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/UserCredential.java?rev=692968&view=auto
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/UserCredential.java
(added)
+++ portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/UserCredential.java
Sun Sep  7 18:09:52 2008
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jetspeed.security;
+
+import java.sql.Date;
+import java.sql.Timestamp;
+
+/**
+ * The (readonly) UserCredential accessible through the Subject (private) credentials
+ * @version $Id$
+ *
+ */
+public interface UserCredential extends Credential
+{
+    /**
+     * @return The user name.
+     */
+    String getUserName();
+    
+    boolean isUpdateAllowed();
+    
+    /**
+     * @return true if update required.
+     */
+    boolean isUpdateRequired();
+    
+    /**
+     * @return true if enabled.
+     */
+    boolean isEnabled();
+    
+    /**
+     * @return true if expired.
+     */
+    boolean isExpired();
+    
+    /**
+     * @return when the credential is (going to be) expired.
+     */
+    Date getExpirationDate();
+    
+    /**
+     * @return the previous time the user logged in 
+     */
+    Timestamp getPreviousAuthenticationDate();
+
+    /**
+     * @return the last time the user logged in 
+     */
+    Timestamp getLastAuthenticationDate();
+
+    /**
+     * <p>Getter for the current number of authentication failures in a row.</p>
+     * <ul>
+     *   <li>-1: never tried yet</li>
+     *   <li> 0: none, or last attempt was successful</li>
+     *   <li>>0: number of failures</li>
+     * </ul>
+     * @return The number of authentication failures
+     */
+    int getAuthenticationFailures();
+}

Propchange: portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/UserCredential.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/UserCredential.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/UserCredential.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/UserSubjectPrincipal.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/UserSubjectPrincipal.java?rev=692968&r1=692967&r2=692968&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/UserSubjectPrincipal.java
(original)
+++ portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/UserSubjectPrincipal.java
Sun Sep  7 18:09:52 2008
@@ -16,6 +16,7 @@
  */
 package org.apache.jetspeed.security;
 
+import java.io.Serializable;
 import java.security.Principal;
 
 import javax.security.auth.Subject;
@@ -25,30 +26,9 @@
  * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
  * @version $Id$
  */
-public class UserSubjectPrincipal implements Principal
+public interface UserSubjectPrincipal extends Principal, Serializable
 {
-    private final User user;
-    private Subject subject;
-    
-    public UserSubjectPrincipal(User user)
-    {
-        this.user = user;
-    }
-    public String getName()
-    {
-        return user.getName();
-    }
-    public User getUser()
-    {
-        return user;
-    }
-    public Subject getSubject()
-    {
-        return subject;
-    }
-    
-    public void setSubject(Subject subject)
-    {
-        this.subject = subject;
-    }
+    public String getName();
+    public User getUser();
+    public Subject getSubject();
 }

Added: portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-commons/src/main/java/org/apache/jetspeed/security/AuthenticatedUserImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-commons/src/main/java/org/apache/jetspeed/security/AuthenticatedUserImpl.java?rev=692968&view=auto
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-commons/src/main/java/org/apache/jetspeed/security/AuthenticatedUserImpl.java
(added)
+++ portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-commons/src/main/java/org/apache/jetspeed/security/AuthenticatedUserImpl.java
Sun Sep  7 18:09:52 2008
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jetspeed.security;
+
+import java.util.Set;
+
+
+/**
+ * @version $Id$
+ *
+ */
+public class AuthenticatedUserImpl implements AuthenticatedUser
+{
+    private User user;
+    private Set<Object> publicCredentials;
+    private Set<Object> privateCredentials;
+    
+    
+    public AuthenticatedUserImpl(User user, Set<Object> publicCredentials, Set<Object>
privateCredentials)
+    {
+        this.user = user;
+        this.publicCredentials = publicCredentials;
+        this.privateCredentials = privateCredentials;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.security.spi.AuthenticatedUser#getPrivateCredentials()
+     */
+    public Set<Object> getPrivateCredentials()
+    {
+        return privateCredentials;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.security.spi.AuthenticatedUser#getPublicCredentials()
+     */
+    public Set<Object> getPublicCredentials()
+    {
+        return publicCredentials;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.security.spi.AuthenticatedUser#getUser()
+     */
+    public User getUser()
+    {
+        return user;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.security.spi.AuthenticatedUser#getUserName()
+     */
+    public String getUserName()
+    {
+        return user.getName();
+    }
+}

Propchange: portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-commons/src/main/java/org/apache/jetspeed/security/AuthenticatedUserImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-commons/src/main/java/org/apache/jetspeed/security/AuthenticatedUserImpl.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-commons/src/main/java/org/apache/jetspeed/security/AuthenticatedUserImpl.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-commons/src/main/java/org/apache/jetspeed/security/JetspeedSubjectFactory.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-commons/src/main/java/org/apache/jetspeed/security/JetspeedSubjectFactory.java?rev=692968&view=auto
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-commons/src/main/java/org/apache/jetspeed/security/JetspeedSubjectFactory.java
(added)
+++ portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-commons/src/main/java/org/apache/jetspeed/security/JetspeedSubjectFactory.java
Sun Sep  7 18:09:52 2008
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jetspeed.security;
+
+import java.security.Principal;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.security.auth.Subject;
+
+
+/**
+ * @version $Id$
+ *
+ */
+public class JetspeedSubjectFactory
+{
+    private static class JetspeedUserSubjectPrincipal implements UserSubjectPrincipal
+    {
+        private static final long serialVersionUID = -2269455453318109892L;
+        private final User user;
+        private Subject subject;
+        
+        public JetspeedUserSubjectPrincipal(User user)
+        {
+            this.user = user;
+        }
+        public String getName()
+        {
+            return user.getName();
+        }
+        public User getUser()
+        {
+            return user;
+        }
+        public Subject getSubject()
+        {
+            return subject;
+        }
+        
+        public void setSubject(Subject subject)
+        {
+            this.subject = subject;
+        }
+    }
+    
+    public static Subject createSubject(AuthenticatedUser user, Set<Principal> principals)
+    {
+        return createSubject(user.getUser(), user.getPublicCredentials(), user.getPrivateCredentials(),
principals);
+    }
+    
+    public static Subject createSubject(User user, Set<Object> privateCredentials,
Set<Object> publicCredentials, Set<Principal> principals)
+    {
+        JetspeedUserSubjectPrincipal userPrincipal = new JetspeedUserSubjectPrincipal(user);
+        Set<Principal> subjectPrincipals = principals == null || principals.isEmpty()
? new HashSet<Principal>() : new PrincipalsSet();
+        subjectPrincipals.add(userPrincipal);
+        if (principals != null)
+        {
+            subjectPrincipals.addAll(principals);
+        }
+        Set<Object> pubCred = publicCredentials == null || publicCredentials.isEmpty()
? Collections.EMPTY_SET : new HashSet<Object>(publicCredentials);
+        Set<Object> privCred = privateCredentials == null || privateCredentials.isEmpty()
? Collections.EMPTY_SET : new HashSet<Object>(privateCredentials);
+        Subject subject = new Subject(true, subjectPrincipals, pubCred, privCred);
+        userPrincipal.setSubject(subject);
+        return subject;
+    }
+}

Propchange: portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-commons/src/main/java/org/apache/jetspeed/security/JetspeedSubjectFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-commons/src/main/java/org/apache/jetspeed/security/JetspeedSubjectFactory.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-commons/src/main/java/org/apache/jetspeed/security/JetspeedSubjectFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org


Mime
View raw message