I am working on a Grails appplication, In this I have to copy all production server database to local database first. I am having DataSource.groovy as follows :
dataSource {
pooled = true
driverClassName = "com.mysql.jdbc.Driver"
dialect = org.hibernate.dialect.MySQLDialect
username = "xxxx"
password = "xxxx"
}
hibernate {
cache.use_second_level_cache = true
cache.use_query_cache = false
cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory'
}
// environment specific settings
environments {
development {
dataSource {
url = "jdbc:mysql://xxxx"
username = "xxxx"
password = "xxxx"
}
}
test {
dataSource {
//dbCreate = "update"
url = "jdbc:mysql://xxxx"
}
}
production {
dataSource {
url = "jdbc:mysql://xxxx_production"
username = "xxxx"
password = "xxxx%"
}
}
staging {
dataSource {
url = "jdbc:mysql://xxxx"_staging"
username = "xxxx"
password = "xxxx%"
}
}
}
Is there any command in Grails for copy production environment database to local or staging environment database.
Thanks.
Use tools for your current production database to create and apply dumps. Database management is not a grails job.
We create sql dumps or backups of the production database, and then you just restore it locally.
You can use Grails Database Migration Plugin.
For further details refer http://grails-plugins.github.io/grails-database-migration/docs/manual/guide/gettingStarted.html
Related
I have the following terraform config.
# Terraform Block
terraform {
required_version = ">= 1.0.0"
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = ">= 3.0"
}
}
}
# Provider Block
provider "azurerm" {
features {}
}
# Datasources
# https://registry.terraform.io/providers/hashicorp/azuread/latest/docs/data-sources/client_config
data "azuread_client_config" "current" {}
output "object_id" {
value = data.azuread_client_config.current.object_id
}
output "client_id" {
value = data.azuread_client_config.current.client_id
}
output "tenant_id" {
value = data.azuread_client_config.current.tenant_id
}
When I plan and then apply, I get the following output.
Outputs:
client_id = "04b07795-8ddb-YYYY-bbee-XXXXXXXXXXXX"
object_id = "3603657a-34b8-YYYY-b7df-XXXXXXXXXXXX"
tenant_id = "35b02984-c026-YYYY-8cb3-XXXXXXXXXXXX"
I could figure out where object_id and tenant_id come from. See below, I have screen shots to show.
But I could not figure out client_id source.
Here is where object_id and tenant_id come from.
First the object id.
And now the tenant id.
So the question again, what is this client id and where does this come from?
Update
I dont see anything in the enterprise applications tab of the AD. What am I missing?
I checked the clientId that resulted from the below output
data "azuread_client_config" "current" {}
output "object_id" {
value = data.azuread_client_config.current.object_id
}
output "client_id" {
value = data.azuread_client_config.current.client_id
}
output "tenant_id" {
value = data.azuread_client_config.current.tenant_id
}
If I check with that Id in azure Ad applications, it the Microsoft Azure CLIs applicationId
This client ID or (application ID) is the appId of the one which
used to authenticate to ( i.e; the application used for delegated
authentication.) or is linked to the authenticated principal.
As in azure to deploy Terraform configurations , we need to complete
authentication.
Terraform can actually use the current account logged into Azure CLI
for authentication which is my case.
Reference: client_config#attributes-reference | registry.terraform.io
I have SQLite dababase in my assets folder.
How to connect the existing SQLite database to Flutter and get all items from the table?
To connect in existing database is :
var dbDir = await getDatabasesPath();
var dbPath = join(dbDir, "app.db");
final myDB = await rootBundle.load('assets/myDb.SQLITE');
List<int> bytes = myDB.buffer.asUint8List(myDB.offsetInBytes, myDB.lengthInBytes);
await File(dbPath).writeAsBytes(bytes);
var db = await openDatabase(dbPath);
can you read here :
https://stackoverflow.com/a/53128435/10649115
And for a complete example you can see this gist:
https://gist.github.com/sergiotucano/57be4db96bfa5d23d68d242d392a9f7d
I've a question!.. I need implement IdentityServer with N-tenant and its authentication provider(Azure AD all..).
For example:
Tenant1 ... AzureAD-1
Tenant2 ... AzureAD-2
Tenant3 ... AzureAD-3
(...)
TenantN ... Redirect AzureAD-N
Is possible it?
In addition, I need get information tenant from data base(it's clientId, client secret, callbackPath, etc..).
My first approach is:
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
(...)
IEnumerable<AuthenticationSchema> schemas = repository.GetAuthenticationSchemas();
if (schemas != null && schemas.Count() > 0)
{
foreach (AuthenticationSchema schema in schemas)
builder.AddOpenIdConnect(schema.Id, options =>
{
options.Authority = schema.Authority;
options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = false };
options.ClientId = schema.ClientId;
options.ClientSecret = schema.ClientSecret;
options.CallbackPath = schema.CallBackPath;
});
}
(...)
}
}
this approach has problem that if i add a new openidconnect in database i need reset server bacause the registration is in startup application..
Is it possible do it dinamically?
Do they could help me ?
I think you can better solve the business need with multitenant application and here are some resources that would help you on multi tenant application.
Authentication flows and application scenarios
Sign in any Azure Active Directory user using the multi-tenant application pattern
Code sample
Recorded walkthrough
Requirement - I am trying to connect to azure SQL DB from a asp.net MVC application and the connection type to azure SQL DB is "token based" and below are the set up done from my end.
a. Created an AAD application( ex : MTSLocal ) with certificate based authentication.
b. Added permission to the above AAD in SQL.
CREATE USER [MTSLocal] FROM external provider;
c.In code level I am trying to get a access token by using Client ID( obtained from step a.) and certificate and the resource I am connecting to is "https://database.windows.net". Please refer the sample code -
string authority = string.Format(System.Globalization.CultureInfo.InvariantCulture, "https://login.windows.net/{0}",
"xxxx.onmicrosoft.com");
var authContext = new AuthenticationContext(authority);
AuthenticationResult result = null;
result = await authContext.AcquireTokenAsync("https://database.windows.net", AssertionCert);
token = result.AccessToken;
d. I am able to retrieve the access token but when I am trying to open the SQL connection.I am getting the above said error.
sqlBuilder["Data Source"] = serverName;
sqlBuilder["Initial Catalog"] = databaseName;
sqlBuilder["Connect Timeout"] = 30;
string accesstoken = GetAccessToken();
using (SqlConnection connection = new SqlConnection(sqlBuilder.ConnectionString))
{
try
{
connection.AccessToken = accesstoken;
connection.Open();
}
catch (Exception ex)
{
}
}
Any help on this would be really helpful.
Here is some rough and ready code on how I solved this. I had to supply the host tenant (see in the code below.
private async Task<string> SqlServerVersion()
{
var provider = new AzureServiceTokenProvider();
var token = await provider.GetAccessTokenAsync("https://database.windows.net/", "<host tenant>.onmicrosoft.com").ConfigureAwait(false);
SqlConnectionStringBuilder csb = new SqlConnectionStringBuilder
{
csb.DataSource = "<your server>.database.windows.net";
csb.InitialCatalog = "<your database>";
};
using (var conn = new SqlConnection(csb.ConnectionString))
{
conn.AccessToken = token;
await conn.OpenAsync().ConfigureAwait(false);
using (var sqlCommand = new SqlCommand("SELECT ##VERSION", conn))
{
var result = await sqlCommand.ExecuteScalarAsync().ConfigureAwait(false);
return result.ToString();
}
}
}
The Application Registered in the AAD should be added to the users list of the DB and respective roles should be given to DB USER.
For suppose the name of the App registered is "App_AAD_Register_Name". add this user to the corresponding DB like executing the below query. With this the user will be added to Principal Users list of the DB server.
CREATE USER [App_AAD_Register_Name] FROM EXTERNAL PROVIDER.
Create some generic Role like below
CREATE ROLE [RoleUser]
GO
GRANT SELECT ON SCHEMA :: dbo TO [RoleUser]
GO
GRANT INSERT ON SCHEMA :: dbo TO [RoleUser]
GO
Once Role is created and respective permissions are given, assign the role to the user created in the first step.
EXEC sp_addrolemember N'RoleUser', N'App_AAD_Register_Name'.
Once all these steps are done you will be able to connect to DB with the token.
These steps worked for me.
I have some sample code that is successfully connecting to SQL Server using Microsoft SQL Server user name and password. But I was wondering if there is a way to use integrated security with this script. Basically which means use the logged in user's credentials without supplying a password in the script.
var sql = require('mssql');
var config = {
server: '127.0.0.1',
database: 'master',
user: 'xx',
password: 'xxx',
options : {
trustedConnection : true
}
}
var connection = new sql.Connection(config, function(err) {
// ... error checks
if(err) {
return console.log("Could not connect to sql: ", err);
}
// Query
var request = new sql.Request(connection);
request.query('select * from dbo.spt_monitor (nolock)', function(err, recordset) {
// ... error checks
console.dir(recordset);
});
// Stored Procedure
});
Wish I could add this as a comment but don't have enough reputation yet... but what happens when you run this without providing a username/password in the config object?
Windows Authentication happens at the login level so there is no need to provide it at the application level.
Just browsed the documentation and looks like you cannot provide a raw connection string to connect, but to connect you want to build something that looks like this:
var connectionString= 'Server=MyServer;Database=MyDb;Trusted_Connection=Yes;'
The source code of the mssql module is here: https://github.com/patriksimek/node-mssql/blob/master/src/msnodesql.coffee... maybe you can fork and do a pull request that would provide an optional flag whether to use Windows Authentication or not, and that flag would remove the Uid={#{user}};Pwd={#{password}} (as it's unneeded for Windows Authentication) from the CONNECTION_STRING_PORT variable in the module's source code.