Yii2: Cannot perform RBAC migration (You should configure "authManager"...) - configuration

As it is described here I'm trying to do the migration in order to let yii create the user authentication tables. However I get the error:
Exception 'yii\base\InvalidConfigException' with message 'You should
configure "authManager" component to use database before executing
this migration.'
The authManager is present in the configuration but I still get that error. Configuration:
'components' => [
...
'db' => $db,
'authManager' => [
'class' => 'yii\rbac\DbManager',
// 'defaultRoles' => ['guest'],
],
...
],
What's the problem?

Problem was quite simple: The configuration was not used. yii migrate is a console command and usually the configuration for such commands is placed in a seperated file.
In case of yii2-app-base template, from which I have created my application, there is a config/console.php configuration file where the authManager needs to be declared. It is not sufficient to have it in the config/web.php declared only.
In case of yii2-app-advanced the authManager should be declared in console/config/main.php and not in the backend or frontend configuration files.

Related

Error while connecting MYSQL with logstash

I am facing this error while starting logstash.
I have configured MYSQL db as input in logstash.
Pipeline_id:main
Plugin: <LogStash::Inputs::Jdbc jdbc_user=>"admin", jdbc_password=><password>, statement=>"SELECT * from table", jdbc_driver_library=>"/usr/s$
Error: Permission denied - /.logstash_jdbc_last_run
Exception: Errno::EACCES
Stack: org/jruby/RubyIO.java:1237:in `sysopen'
org/jruby/RubyIO.java:3800:in `write'
The last_run_metadata_path option defaults to "#{ENV['HOME']}/.logstash_jdbc_last_run", and it looks like that evaluates to /.logstash_jdbc_last_run. You are getting EACCES because you do not have write access to the root directory.
To fix it, set the last_run_metadata_path option to a file in a directory that you have write access to. If you have an input configuration that starts with
input {
jdbc {
jdbc_driver_library => "mysql-connector-java-5.1.36-bin.jar"
jdbc_driver_class => "com.mysql.jdbc.Driver"
you can just add an additional line there
last_run_metadata_path => "/tmp/.logstash_jdbc_last_run"
using some path that you know you can write to and that nobody else will be using.

Using logstash Elasticsearch output plugin error: NameError: SSLConnectionSocketFactory not found

I am trying to import data from MySQL to Elasticsearch using logstash version.
Versions of software used:
Java/JRE 1.8
Elasticsearch 6.1.0
Logstash 6.1.0
My conf contents are as follows:
file: simple-out.conf
input {
jdbc {
# MySQL jdbc connection string to our database, mydb
jdbc_connection_string => "jdbc:mysql://valid/validDBNAME?useSSL=false"
# The user we wish to execute our statement as
jdbc_user => "MY USER"
jdbc_password => "MY PWD"
# The path to our downloaded jdbc driver
jdbc_driver_library => "C:\JavaDevelopment\TomcatServer\apache-tomcat-8.5.20\lib\mysql-connector-java-5.1.45-bin.jar"
# The name of the driver class for Postgresql
jdbc_driver_class => "com.mysql.jdbc.Driver"
# our query
statement => "SELECT * from testtable"
jdbc_paging_enabled => "true"
jdbc_page_size => "50000"
}
}
output {
stdout { codec => json_lines }
elasticsearch {
hosts => "http://localhost:9200"
index => "test-migrate"
document_type => "data"
}
}
When I run logstash I get the following error:
[2017-12-19T16:50:08,055][ERROR][logstash.pipeline ] Pipeline aborted due to error {:pipeline_id=>"main", :exception=>#<NameError: SSLConnectionSocketFactory not found ERROR
Please suggest how to get past this.
Thanks
Try adding httpclient-VERSION.jar, httpcore-VERSION.jar files to LOGSTASH_HOME/vendor/jruby/lib/ folder.
I had same problem, the solution is:
add LOGSTASH_HOME variable path in environment variables in mycomputer properities to C:\some_path\logstash-6.3.0
then add these files to C:\some_path\logstash-6.3.0\logstash-core\lib\jars
files:
httpclient-4.5.2.jar
log4j-1.2.17.jar
httpcore-VERSION.jar
this is because logstash doesn't come with ssl jar file and you need to add this to jar folder and set the environment so as logstash can read those jar files
and try using gitbash rather than cmd or powershell!
and try to close and restart your logstash and elasticsearch
follow this link to see which index are comming to elasticsearch.
http://localhost:9200/_cat/indices?v
if you are running on diff. port please change port number
addidional tips
and it didn't work for me on jdk 10.x so use jdk 8.x
and maybe installer wont work even so just unzip file and run elasticsearch.bat and logstash -f cong_filepath\configfile.config in bin folders
windows user can type cmd in top of path
Please make sure MySQL is running, (doesn't mean open) on server
Learn # https://www.elastic.co/blog/logstash-jdbc-input-plugin
To resolve it yourself in future:
open logstash/bin folder and right click and gitbash (need git)
type "vi log" and press tab 3 times till all logstahsh files are shown up
a new line will appear, type "vi logstash" and press enter to open source file
you'll have code to understand flow,.. if you look carefully Logstash_home and javacmd (at bottom) are important that execute jar, javacmd should be set to your java_home variable in env variables to jdk8.x and Logstash_home has a path for jar directory, either change it or put you jar to this folder.
Hope this helps!

How to change database of yii2 advanced template

How can i change the database information of my yii2 advanced template?
i cant find the database settings.
http://www.yiiframework.com/doc-2.0/guide-index.html
In /common/config/main-local.php you set your database settings:
'components' => [
'db' => [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=DATABASE_NAME',
'username' => 'DATABASE_USER',
'password' => 'DATABASE_PASSWORD',
'charset' => 'utf8',
],
The installation guide for advanced template is here: https://github.com/yiisoft/yii2-app-advanced/blob/master/docs/guide/start-installation.md
The advanced template has environments that each define the target specific configuration. Basically after cloning the template you need to make sure you setup the files under the environments-folder correctly (it comes with dev and prod predefined configurations - for development and production environments).
In the config subfolders you'll find the *-local.php files that indicate configuration specific to that environment.
For the database you have to look in common/config/main-local.php.
After you're done with that, just navigate back to the templates' root folder and run ./init. It will ask you which environment you want and put the files in place. Switching to another environment is just an ./init call away.
Obviously you're not obligated to keep on using the environments if you don't have use for it, you might as well modify the /common/config/main.php file and add the connection info there. But given that the advanced template assumes multiple deployment stages for your application it is a very good setup.

Yii2 Gii : You are not allowed to access this page

I'm using Yii2 advance template and I can access gii tool successfully in my local machine.
But when I upload it into real server, there is a message "You are not allowed to access this page."
Could you tell me which file should I have to config and could you print screen or paste the whole content of that config file?
Thanks you before hand.
You should simply add your IP address in gii config :
'gii' => [
'class' => 'yii\gii\Module',
'allowedIPs' => ['127.0.0.1', '::1'] // adjust this to your needs
],
http://www.yiiframework.com/doc-2.0/guide-start-gii.html
EDIT : in advanced app, gii conf is in
environments/dev/backend/config/main-local.php
environments/dev/frontend/config/main-local.php

Configuring MySql inWildFly

I followed the steps trying to configure MySQL in WildFly. I have two questions for your help with:
1) I downloaded the mysql-connector-java-5.1.33-bin.jar and placed it under modules/system/layers/base/com/mysql/main/. Do I need to download the actual MySql? Or the connector jar is sufficient?
2) In creating a new data source in WildFly console, I was not able to create a new data source. Part of the information I need to fill in is a pair of user name and password to access the database. Where should I create this user name and password first? I am guessing this is where I got the problem from.
I got this error message when testing the connection in wildfly console:
Unexpected HTTP response: 500
Request
{
"address" => [
("subsystem" => "datasources"),
("data-source" => "mysqlDSPool")
],
"operation" => "test-connection-in-pool"
}
Response
Internal Server Error
{
"outcome" => "failed",
"failure-description" => "JBAS010440: failed to invoke operation: JBAS010447: Connection is not valid",
"rolled-back" => true
}
first you need to install Mysql server and a JDBC 4-compliant driver, normally all new JDBCs provided by Mysql.org are JDBC 4-compliant, find a platform independant one here, then you need to add a datasource here in this file standalone/configuration/standalone.xml or using this command
data-source add --name=myDataSource--jndi-name="java:jboss/datasources/myDataSource" \
--connection-url="jdbc:mysql://localhost:3306/myDB" \
--driver-name=h2 --user-name="myDB_Username" --password="myPassword"
username and password are those used to connect to Mysql database.
1) You need to download the jdbc-driver jar which, I think, is the connector jar. But please don't place it under modules/system/... but directly under modules since the system folder is reserved for internal modules that are delivered with the server.
2) Here is an example (configures an Oracle datasource):
/subsystem=datasources/jdbc-driver=OracleJdbcDriver:add(driver-module-name=oracle.jdbcaq,driver-name=OracleJdbcDriver)
/subsystem=datasources/data-source=OracleDS:add(jndi-name=java:jboss/datasources/OracleDS,enabled=true,jta=true,use-java-context=true,connection-url=jdbc:oracle:oci:#dbms:1523/DEV,driver-name=OracleJdbcDriver,min-pool-size=5,max-pool-size=100,user-name=username,password=password,prepared-statements-cache-size=100,exception-sorter-class-name=org.jboss.jca.adapters.jdbc.extensions.oracle.OracleExceptionSorter)