-
Notifications
You must be signed in to change notification settings - Fork 283
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#2533 Basic auth by HTTPS for API httpds - added httpds-basic user
- Loading branch information
Showing
2 changed files
with
67 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/org/scada_lts/dao/migration/mysql/V2_7_5_3_1__AddHttpdsUser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package org.scada_lts.dao.migration.mysql; | ||
|
||
import com.serotonin.mango.Common; | ||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
import org.flywaydb.core.api.migration.BaseJavaMigration; | ||
import org.flywaydb.core.api.migration.Context; | ||
import org.scada_lts.dao.DAO; | ||
import org.springframework.jdbc.core.ArgumentPreparedStatementSetter; | ||
import org.springframework.jdbc.core.JdbcTemplate; | ||
|
||
import java.sql.PreparedStatement; | ||
import java.util.List; | ||
|
||
public class V2_7_5_3_1__AddHttpdsUser extends BaseJavaMigration { | ||
|
||
private static final Log LOG = LogFactory.getLog(V2_7_5_3_1__AddHttpdsUser.class); | ||
|
||
@Override | ||
public void migrate(Context context) throws Exception { | ||
|
||
try { | ||
final JdbcTemplate jdbcTemplate = DAO.getInstance().getJdbcTemp(); | ||
|
||
String userInsert = "insert into users (username, password, email, phone, admin, disabled, " + | ||
"homeUrl, receiveAlarmEmails, receiveOwnAuditEvents) values (?,?,?,?,?,?,?,?,?);"; | ||
addHttpdsBasicUser(jdbcTemplate, userInsert); | ||
} catch (Exception ex) { | ||
LOG.error(ex.getMessage(), ex); | ||
throw ex; | ||
} | ||
} | ||
|
||
private void addHttpdsBasicUser(JdbcTemplate jdbcTmp, String userInsert) { | ||
List<Integer> ids = jdbcTmp.queryForList("select id from users where username = ?", new Object[]{"httpds-basic"}, Integer.class); | ||
if(ids.isEmpty()) { | ||
jdbcTmp.update(connection -> { | ||
PreparedStatement preparedStatement = connection.prepareStatement(userInsert); | ||
new ArgumentPreparedStatementSetter(new Object[]{ | ||
"httpds-basic", | ||
Common.encrypt("httpds-basic"), | ||
"null@null.com", | ||
"", | ||
"N", | ||
"Y", | ||
"", | ||
0, | ||
"N" | ||
}).setValues(preparedStatement); | ||
return preparedStatement; | ||
}); | ||
} | ||
} | ||
} |