Skip to content

Commit b5dc009

Browse files
authored
Fail fast when updating OpenDJ schema on OpenAM setup (#849)
1 parent 281a23d commit b5dc009

File tree

1 file changed

+19
-8
lines changed
  • openam-ldap-utils/src/main/java/org/forgerock/openam/ldap

1 file changed

+19
-8
lines changed

openam-ldap-utils/src/main/java/org/forgerock/openam/ldap/LdifUtils.java

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
* $Id: LDAPUtils.java,v 1.9 2009/08/05 20:39:01 hengming Exp $
2727
*
2828
* Portions Copyrighted 2015-2016 ForgeRock AS.
29+
* Portions Copyrighted 2025 3A Systems LLC.
2930
*/
3031
//@Checkstyle:on
3132

@@ -99,9 +100,9 @@ public static void createSchemaFromLDIF(InputStream stream, Connection ld) throw
99100
public static void createSchemaFromLDIF(LDIFChangeRecordReader ldif, final Connection ld) throws IOException {
100101
while (ldif.hasNext()) {
101102
final ChangeRecord changeRecord = ldif.readChangeRecord();
102-
changeRecord.accept(new ChangeRecordVisitor<Void, Void>() {
103+
final IOException resultException = changeRecord.accept(new ChangeRecordVisitor<IOException, Void>() {
103104
@Override
104-
public Void visitChangeRecord(Void aVoid, AddRequest change) {
105+
public IOException visitChangeRecord(Void aVoid, AddRequest change) {
105106
try {
106107
change.addControl(TransactionIdControl.newControl(
107108
AuditRequestContext.createSubTransactionIdValue()));
@@ -114,41 +115,51 @@ public Void visitChangeRecord(Void aVoid, AddRequest change) {
114115
try {
115116
ld.modify(modifyRequest);
116117
} catch (LdapException ex) {
117-
DEBUG.warning("LDAPUtils.createSchemaFromLDIF - Could not modify schema: {}",
118+
DEBUG.error("LDAPUtils.createSchemaFromLDIF - Could not modify schema: {}",
118119
modifyRequest, ex);
120+
return new IOException(String.format("LDAPUtils.createSchemaFromLDIF - " +
121+
"Could not modify schema: %s; ex: %s", modifyRequest, ex));
119122
}
120123
}
121124
} else {
122-
DEBUG.warning("LDAPUtils.createSchemaFromLDIF - Could not add to schema: {}", change, e);
125+
DEBUG.error("LDAPUtils.createSchemaFromLDIF - Could not add to schema: {}", change, e);
126+
return new IOException(String.format("LDAPUtils.createSchemaFromLDIF - " +
127+
"Could not add to schema: %s; ex: %s", change, e));
123128
}
124129
}
125130
return null;
126131
}
127132

128133
@Override
129-
public Void visitChangeRecord(Void aVoid, ModifyRequest change) {
134+
public IOException visitChangeRecord(Void aVoid, ModifyRequest change) {
130135
try {
131136
change.addControl(TransactionIdControl.newControl(
132137
AuditRequestContext.createSubTransactionIdValue()));
133138
ld.modify(change);
134139
} catch (LdapException e) {
135-
DEBUG.warning("LDAPUtils.createSchemaFromLDIF - Could not modify schema: {}", change, e);
140+
DEBUG.error("LDAPUtils.createSchemaFromLDIF - Could not modify schema: {}", change, e);
141+
return new IOException(String.format("LDAPUtils.createSchemaFromLDIF - " +
142+
"Could not modify schema: %s; ex: %s", change, e));
136143
}
137144
return null;
138145
}
139146

140147
@Override
141-
public Void visitChangeRecord(Void aVoid, ModifyDNRequest change) {
148+
public IOException visitChangeRecord(Void aVoid, ModifyDNRequest change) {
142149
return null;
143150
}
144151

145152
@Override
146-
public Void visitChangeRecord(Void aVoid, DeleteRequest change) {
153+
public IOException visitChangeRecord(Void aVoid, DeleteRequest change) {
147154
DEBUG.message("Delete request ignored: {}", changeRecord);
148155
return null;
149156
}
150157

151158
}, null);
159+
160+
if (resultException != null) {
161+
throw resultException;
162+
}
152163
}
153164
}
154165

0 commit comments

Comments
 (0)