You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by at...@apache.org on 2008/09/09 01:15:50 UTC
svn commit: r693313 - in
/portals/jetspeed-2/portal/branches/security-refactoring:
components/jetspeed-security/src/main/java/JETSPEED-INF/ojb/
components/jetspeed-security/src/main/java/org/apache/jetspeed/security/
components/jetspeed-security/src/ma...
Author: ate
Date: Mon Sep 8 16:15:50 2008
New Revision: 693313
URL: http://svn.apache.org/viewvc?rev=693313&view=rev
Log:
Adding an (jetspeed-security) internal UserPasswordCredentialAccessManager SPI interface.
This allows loading a PasswordCredential by userName only (useful for default authenticationProvider implementation).
Additionally, the User reference in the PasswordCredential is *not* automatically loaded anymore, to be as lightweight as possible, again for authentication purposes.
And adding a PasswordCredential type field for storing historic credentials values and separating the (internal only) retrieval of them.
Added:
portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/UserPasswordCredentialAccessManager.java (with props)
Modified:
portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/JETSPEED-INF/ojb/security_repository.xml
portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/JetspeedSecurityPersistenceManager.java
portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/PasswordCredentialImpl.java
portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/PasswordCredential.java
Modified: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/JETSPEED-INF/ojb/security_repository.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/JETSPEED-INF/ojb/security_repository.xml?rev=693313&r1=693312&r2=693313&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/JETSPEED-INF/ojb/security_repository.xml (original)
+++ portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/JETSPEED-INF/ojb/security_repository.xml Mon Sep 8 16:15:50 2008
@@ -19,20 +19,20 @@
<descriptor-repository version="1.0">
<!--
- - S E C U R I T Y C R E D E N T I A L
+ - P A S S W O R D C R E D E N T I A L
-->
<class-descriptor
- class="org.apache.jetspeed.security.om.impl.InternalCredentialImpl"
+ class="org.apache.jetspeed.security.spi.impl.PasswordCredentialImpl"
proxy="dynamic"
table="SECURITY_CREDENTIAL"
>
<field-descriptor
- name="credentialId"
+ name="id"
column="credential_id"
jdbc-type="BIGINT"
primarykey="true"
- indexed="true"
autoincrement="true"
+ access="anonymous"
>
</field-descriptor>
<field-descriptor
@@ -57,14 +57,6 @@
>
</field-descriptor>
<field-descriptor
- name="classname"
- column="classname"
- jdbc-type="VARCHAR"
- nullable="true"
- length="254"
- >
- </field-descriptor>
- <field-descriptor
name="creationDate"
column="creation_date"
jdbc-type="TIMESTAMP"
@@ -138,6 +130,13 @@
nullable="true"
>
</field-descriptor>
+ <reference-descriptor
+ name="user"
+ class-ref="org.apache.jetspeed.security.impl.PersistentJetspeedPrincipal"
+ auto-retrieve="false"
+ >
+ <foreignkey field-ref="principalId"/>
+ </reference-descriptor>
</class-descriptor>
<!--
Added: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/UserPasswordCredentialAccessManager.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/UserPasswordCredentialAccessManager.java?rev=693313&view=auto
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/UserPasswordCredentialAccessManager.java (added)
+++ portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/UserPasswordCredentialAccessManager.java Mon Sep 8 16:15:50 2008
@@ -0,0 +1,30 @@
+/*
+ * 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.List;
+
+/**
+ * @version $Id$
+ *
+ */
+public interface UserPasswordCredentialAccessManager
+{
+ PasswordCredential getPasswordCredential(String userName);
+ List<PasswordCredential> getHistoricPasswordCredentials(User user);
+}
Propchange: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/UserPasswordCredentialAccessManager.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/UserPasswordCredentialAccessManager.java
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/UserPasswordCredentialAccessManager.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/JetspeedSecurityPersistenceManager.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/JetspeedSecurityPersistenceManager.java?rev=693313&r1=693312&r2=693313&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/JetspeedSecurityPersistenceManager.java (original)
+++ portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/JetspeedSecurityPersistenceManager.java Mon Sep 8 16:15:50 2008
@@ -35,6 +35,7 @@
import org.apache.jetspeed.security.PrincipalUpdateException;
import org.apache.jetspeed.security.SecurityException;
import org.apache.jetspeed.security.User;
+import org.apache.jetspeed.security.UserPasswordCredentialAccessManager;
import org.apache.jetspeed.security.impl.PersistentJetspeedPrincipal;
import org.apache.jetspeed.security.spi.JetspeedPermissionStorageManager;
import org.apache.jetspeed.security.spi.JetspeedPrincipalAccessManager;
@@ -56,7 +57,7 @@
public class JetspeedSecurityPersistenceManager
extends InitablePersistenceBrokerDaoSupport
implements JetspeedPrincipalAccessManager,
- JetspeedPrincipalStorageManager, UserPasswordCredentialStorageManager,
+ JetspeedPrincipalStorageManager, UserPasswordCredentialStorageManager, UserPasswordCredentialAccessManager,
JetspeedPrincipalAssociationStorageManager, JetspeedPrincipalPermissionStorageManager,
JetspeedPermissionStorageManager
{
@@ -175,7 +176,7 @@
Criteria criteria = new Criteria();
criteria.addEqualTo("name", principalName);
Query query = QueryFactory.newQuery(type.getPrincipalClass(),criteria);
- return (JetspeedPrincipal)getPersistenceBrokerTemplate().getObjectByQuery(query);
+ return (JetspeedPrincipal)getPersistenceBroker(true).getObjectByQuery(query);
}
public List<String> getPrincipalNames(String nameFilter, JetspeedPrincipalType type)
@@ -332,18 +333,68 @@
}
//
- // JetspeedPrincipalStorageManager interface implementation
+ // UserPasswordCredentialStorageManager interface implementation
//
public PasswordCredential getPasswordCredential(User user)
{
- // TODO Auto-generated method stub
- return null;
+ Criteria criteria = new Criteria();
+ criteria.addEqualTo("principalId", user.getId());
+ criteria.addEqualTo("type", PasswordCredential.TYPE_CURRENT);
+ Query query = QueryFactory.newQuery(PasswordCredentialImpl.class,criteria);
+ PasswordCredentialImpl pwc = (PasswordCredentialImpl)getPersistenceBroker(true).getObjectByQuery(query);
+ if (pwc != null)
+ {
+ // store the user by hand as its configured as auto-retrieve="false"
+ pwc.setUser(user);
+ }
+ return pwc;
}
public void storePasswordCredential(PasswordCredential credential) throws SecurityException
{
+ if (credential.isNewPasswordSet())
+ {
+ if (credential.getNewPassword() != null)
+ {
+ credential.setPassword(credential.getNewPassword().toCharArray(), credential.isPasswordEncoded());
+ }
+ }
+ getPersistenceBroker(true).store(credential);
+ }
+
+ //
+ // UserPasswordCredentialAccessManager interface implementation
+ //
+ /**
+ * <p>
+ * Retrieves the current PasswordCredential by userName
+ * </p>
+ * <p>
+ * Warning: the User reference is configured with auto-retrieve="false".
+ * This is intentionally done to allow retrieving the credential for authentication purposes only
+ * so no User is loaded when authentication fails.
+ * The user reference can be materialized by OJB using persistenceBroker.retrieveReference(credential, "user").
+ * </p>
+ */
+ public PasswordCredential getPasswordCredential(String userName)
+ {
+ Criteria criteria = new Criteria();
+ criteria.addEqualTo("user.name", userName);
+ criteria.addEqualTo("type", PasswordCredential.TYPE_CURRENT);
+ Query query = QueryFactory.newQuery(PasswordCredentialImpl.class,criteria);
+ PasswordCredentialImpl pwc = (PasswordCredentialImpl)getPersistenceBroker(true).getObjectByQuery(query);
+ if (pwc != null)
+ {
+ // store the userName by hand as the user is configured as auto-retrieve="false"
+ pwc.setUserName(userName);
+ }
+ return pwc;
+ }
+
+ public List<PasswordCredential> getHistoricPasswordCredentials(User user)
+ {
// TODO Auto-generated method stub
-
+ return null;
}
//
Modified: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/PasswordCredentialImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/PasswordCredentialImpl.java?rev=693313&r1=693312&r2=693313&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/PasswordCredentialImpl.java (original)
+++ portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/PasswordCredentialImpl.java Mon Sep 8 16:15:50 2008
@@ -34,6 +34,8 @@
private static final long serialVersionUID = -4975305752376365096L;
private User user;
+
+ private String userName;
/** The "raw" password value */
private char[] password;
@@ -57,9 +59,9 @@
*/
private boolean passwordEncoded;
- private boolean updateAllowed;
+ private boolean updateAllowed = true;
- private boolean stateReadOnly;
+ private boolean stateReadOnly = false;
/** The update required state */
private boolean updateRequired;
@@ -81,6 +83,12 @@
/** The number of authentication failures */
private int authenticationFailures;
+
+ /**
+ * The type mapping field
+ */
+ @SuppressWarnings("unused")
+ private Integer type = TYPE_CURRENT;
public PasswordCredentialImpl()
{
@@ -108,18 +116,33 @@
}
}
+ public void setUser(User user)
+ {
+ this.user = user;
+ }
+
+ public void setUserName(String userName)
+ {
+ this.userName = userName;
+ }
+
/**
* @return The username.
*/
public String getUserName()
{
- return user.getName();
+ return user != null ? user.getName() : userName;
}
public User getUser()
{
return user;
}
+
+ public Integer getType()
+ {
+ return type;
+ }
/**
* @return The password.
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=693313&r1=693312&r2=693313&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 Mon Sep 8 16:15:50 2008
@@ -29,11 +29,15 @@
public interface PasswordCredential extends UserCredential
{
String PASSWORD_CREDENTIAL_DAYS_VALID_REQUEST_ATTR_KEY = PasswordCredential.class.getName() + ".check";
+ public static final Integer TYPE_CURRENT = new Integer(0);
+ public static final Integer TYPE_HISTORICAL = new Integer(1);
/**
* @return The user the PasswordCredential belongs to
*/
- User getUser();
+ User getUser();
+
+ Integer getType();
/**
* @return raw (possibly encoded) password.
---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org