DataStore.java revision da2818d9363a5ce6d77d2273e2d5a1cb3d83bbe8
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2009 Sun Microsystems Inc. All Rights Reserved
*
* The contents of this file are subject to the terms
* of the Common Development and Distribution License
* (the License). You may not use this file except in
* compliance with the License.
*
* You can obtain a copy of the License at
* See the License for the specific language governing
* permission and limitations under the License.
*
* When distributing Covered Code, include this CDDL
* Header Notice in each file and include the License file
* at opensso/legal/CDDLv1.0.txt.
* If applicable, add the following below the CDDL Header,
* with the fields enclosed by brackets [] replaced by
* your own identifying information:
* "Portions Copyrighted [year] [name of copyright owner]"
*
* $Id: DataStore.java,v 1.13 2010/01/20 17:01:35 veiming Exp $
*
* Portions Copyrighted 2012-2016 ForgeRock AS.
*/
/**
* This class *talks* to SMS to get the configuration information.
*/
public class DataStore {
private static final String REALM_DN_TEMPLATE =
"ou={0},ou=default,ou=OrganizationConfig,ou=1.0,ou=" + SERVICE_NAME +
",ou=services,{1}";
private static final int NO_LIMIT = 0;
private static final boolean NOT_SORTED = false;
private static final String SUBJECT_FILTER_TEMPLATE =
private static final String HOST_FILTER_TEMPLATE =
private static final String PATH_FILTER_TEMPLATE =
private static final String PATH_PARENT_FILTER_TEMPLATE =
private static final NetworkMonitor DB_MONITOR_PRIVILEGE =
private static final NetworkMonitor DB_MONITOR_REFERRAL =
private static final String HIDDEN_REALM_DN =
"o=sunamhiddenrealmdelegationservicepermissions,ou=services,";
// count of number of policies per realm
static {
// Initialize statistics collection
}
private DataStore() {
}
public static DataStore getInstance() {
return instance;
}
/**
* Returns distingished name of a privilege.
*
* @param name Privilege name.
* @param realm Realm name.
* @param indexName Index name.
* @return the distingished name of a privilege.
*/
public static String getPrivilegeDistinguishedName(
}
/**
* Returns the base search DN.
*
* @param realm Realm name.
* @param indexName Index name.
* @return the base search DN.
*/
}
}
private String createDefaultSubConfig(
throws SMSException, SSOException {
}
}
return defSubConfig.getDN();
}
throws SMSException, SSOException {
}
return orgConf;
}
try {
if (referral) {
} else {
}
} finally {
}
}
try {
} else {
}
if (referral) {
} else {
}
} catch (NumberFormatException ex) {
} catch (SMSException ex) {
} catch (SSOException ex) {
} finally {
}
}
int count = 0;
if (adminToken != null) {
try {
}
}
} catch (NumberFormatException ex) {
} catch (SMSException ex) {
} catch (SSOException ex) {
}
}
return count;
}
public static int getNumberOfPolicies() {
return getCountInMap(policiesPerRealm);
}
public static int getNumberOfReferrals() {
return getCountInMap(referralsPerRealm);
}
try {
int total = 0;
}
return total;
} finally {
}
}
try {
int totalPolicies = 0;
} else {
}
return (totalPolicies);
} finally {
}
}
try {
int referralCnt = 0;
} else {
}
return (referralCnt);
} finally {
}
}
/**
* Adds a privilege.
*
* @param adminSubject Admin Subject who has the rights to write to
* datastore.
* @param realm Realm name.
* @param p Privilege object.
* @return the DN of added privilege.
* @throws com.sun.identity.entitlement.EntitlementException if privilege
* cannot be added.
*/
throws EntitlementException {
try {
}
}
}
}
for (String i : subjectIndexes) {
}
}
if (privilegeName != null) {
}
if (privilegeDesc != null) {
}
}
if (lastModifiedBy != null) {
}
long creationDate = p.getCreationDate();
if (creationDate > 0) {
}
long lastModifiedDate = p.getLastModifiedDate();
if (lastModifiedDate > 0) {
}
for (String a : p.getApplicationIndexes()) {
}
s.setAttributes(map);
s.save();
params);
} catch (JSONException e) {
throw new EntitlementException(210, e);
} catch (SSOException e) {
throw new EntitlementException(210, e);
} catch (SMSException e) {
throw new EntitlementException(210, e);
}
return dn;
}
/**
* Adds a referral.
*
* @param adminSubject Admin Subject who has the rights to write to
* datastore.
* @param realm Realm name.
* @param referral Referral Privilege object.
* @return the DN of added privilege.
* @throws EntitlementException if privilege cannot be added.
*/
public String addReferral(
) throws EntitlementException {
try {
}
}
}
}
if (privilegeName != null) {
}
if (privilegeDesc != null) {
}
}
if (lastModifiedBy != null) {
}
if (creationDate > 0) {
}
if (lastModifiedDate > 0) {
}
}
realm)) {
}
}
s.setAttributes(map);
s.save();
params);
} catch (SSOException e) {
throw new EntitlementException(270, e);
} catch (SMSException e) {
throw new EntitlementException(270, e);
}
return dn;
}
/**
* Removes privilege.
*
* @param adminSubject Admin Subject who has the rights to write to
* datastore.
* @param realm Realm name.
* @param name Privilege name.
* @throws com.sun.identity.entitlement.EntitlementException if privilege
* cannot be removed.
*/
public void remove(
) throws EntitlementException {
}
try {
s.delete();
params);
}
} catch (SMSException e) {
} catch (SSOException e) {
}
}
/**
* Removes referral privilege.
*
* @param adminSubject Admin Subject who has the rights to write to
* datastore.
* @param realm Realm name.
* @param name Referral privilege name.
* @throws EntitlementException if privilege cannot be removed.
*/
public void removeReferral(
) throws EntitlementException {
}
try {
s.delete();
params);
}
} catch (SMSException e) {
} catch (SSOException e) {
}
}
/**
* Returns a set of privilege names that satifies a search filter.
*
* @param adminSubject Subject who has the rights to read datastore.
* @param realm Realm name
* @param filter Search filter.
* @param numOfEntries Number of max entries.
* @param sortResults <code>true</code> to have result sorted.
* @param ascendingOrder <code>true</code> to have result sorted in
* ascending order.
* @return a set of privilege names that satifies a search filter.
* @throws EntitlementException if search failed.
*/
int numOfEntries,
boolean sortResults,
boolean ascendingOrder
) throws EntitlementException {
}
/**
* Returns a set of referral privilege names that satifies a search filter.
*
* @param adminSubject Subject who has the rights to read datastore.
* @param realm Realm name
* @param filter Search filter.
* @param numOfEntries Number of max entries.
* @param sortResults <code>true</code> to have result sorted.
* @param ascendingOrder <code>true</code> to have result sorted in
* ascending order.
* @return a set of privilege names that satifies a search filter.
* @throws EntitlementException if search failed.
*/
int numOfEntries,
boolean sortResults,
boolean ascendingOrder
) throws EntitlementException {
return search(adminSubject, realm, filter, numOfEntries, sortResults, ascendingOrder, REFERRAL_STORE);
}
private Set<String> search(Subject adminSubject, String realm, String filter, int numOfEntries, boolean sortResults, boolean ascendingOrder, String indexName) throws EntitlementException {
try {
}
} else {
return emptySet();
}
}
}
public boolean hasPrivilgesWithApplication(
) throws EntitlementException {
//Search privilege
applName + ")";
return true;
}
//Search referral privilege
return true;
}
//Search delegation privilege
return true;
}
return false;
}
private static String getHiddenRealmDN() {
}
throws EntitlementException {
try {
0, 0, false, false);
return true;
}
} catch (SMSException e) {
}
}
return false;
}
/**
* Returns a set of privilege that satifies the resource and subject
* indexes.
*
* @param adminSubject Subject who has the rights to read datastore.
* @param realm Realm name
* @param iterator Buffered iterator to have the result fed to it.
* @param indexes Resource search indexes.
* @param subjectIndexes Subject search indexes.
* @param bSubTree <code>true</code> to do sub tree search
* @param excludeDNs Set of DN to be excluded from the search results.
* @return a set of privilege that satifies the resource and subject
* indexes.
*/
boolean bSubTree,
) throws EntitlementException {
// Get referrals only if count is greater than 0
if (countInt > 0) {
}
return results;
}
/**
* Retrieves an individual privilege from the data store. The privilege is returned by the method and
* also added to the passed in iterator.
*
* @param realm Realm in which the privilege exists.
* @param privilegeIdentifier The identifier of the privilege to retrieve.
* @return the privilege.
* @throws EntitlementException if there were issues retrieving the privilege from the data store.
*/
throws EntitlementException {
try {
while (i.hasNext()) {
}
} catch (SMSException e) {
} catch (JSONException e) {
}
return privilege;
}
boolean bSubTree,
) throws EntitlementException {
"[PolicyEval] DataStore.searchPrivileges");
"[PolicyEval] search filter: " + filter);
"[PolicyEval] search DN: " + baseDN);
}
try {
while (i.hasNext()) {
new JSONObject(e.getAttributeValue(
}
} catch (JSONException e) {
} catch (SMSException e) {
}
}
}
return results;
}
}
List<Privilege> findPoliciesByRealmAndApplication(String realm, String application) throws EntitlementException {
return findPolicies(realm, String.format("(&(sunserviceID=indexes)(ou=application=%s))", application));
}
List<Privilege> findAllPoliciesByRealmAndSubjectIndex(String realm, Set<String> subjectIndexes) throws EntitlementException {
.append('=')
.append('=')
.append(')');
}
}
try {
@SuppressWarnings("unchecked")
}
} catch (JSONException | SMSException e) {
}
}
return results;
}
/**
* Returns a set of referral privilege that satifies the resource and
* subject indexes.
*
* @param adminToken Subject who has the rights to read datastore.
* @param realm Realm name
* @param iterator Buffered iterator to have the result fed to it.
* @param indexes Resource search indexes.
* @param bSubTree <code>true</code> to do sub tree search
* @param excludeDNs Set of DN to be excluded from the search results.
* @return a set of privilege that satifies the resource and subject
* indexes.
*/
boolean bSubTree,
) throws EntitlementException {
"[PolicyEval] DataStore.searchReferral");
"[PolicyEval] search filter: " + filter);
"[PolicyEval] search DN: " + baseDN);
}
try {
while (i.hasNext()) {
new JSONObject(e.getAttributeValue(
}
} catch (JSONException e) {
} catch (SMSException e) {
}
}
}
return results;
}
if (isNotEmpty(subjectIndexes)) {
}
}
return subjectFilter.toString();
}
boolean bSubTree
) {
}
}
}
for (String p : pathIndexes) {
}
}
if (bSubTree) {
for (String p : parentPathIndexes) {
}
}
}
}
}
) throws EntitlementException {
try {
while (i.hasNext()) {
new JSONObject(e.getAttributeValue(
}
} catch (JSONException e) {
} catch (SMSException e) {
}
}
return results;
}
return adminToken;
}
}
throws EntitlementException {
try {
}
return emptySet();
}
}
switch (nextChar) {
case '*':
break;
case '(':
break;
case ')':
break;
case '/':
break;
case '\\':
break;
case '\0':
break;
default:
break;
}
}
}
}