Can not delete User with FOSOAuthBundle enabled - symfony

I try to delete a user in my symfony 3 app. I use the FOSOAuthBundle and the FOSUserBundle.
I tried this code:
$em = $this->getDoctrine()->getManager();
$em->remove($user);
$em->flush();
But I get this error:
An exception occurred while executing 'DELETE FROM user WHERE id = ?' with params [1]:\n\nSQLSTATE[23000]:
Integrity constraint violation: 1451 Cannot delete or update a parent row:
a foreign key constraint fails (`database`.`access_token`, CONSTRAINT `FK_B6A2DD68A76ED395` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`))
I have this configuration:
# FOSOAuthServerBundle configuration
fos_oauth_server:
db_driver: orm
client_class: OAuthBundle\Entity\Client
access_token_class: OAuthBundle\Entity\AccessToken
refresh_token_class: OAuthBundle\Entity\RefreshToken
auth_code_class: OAuthBundle\Entity\AuthCode
service:
user_provider: fos_user.user_provider.username_email
options:
access_token_lifetime: 86400
refresh_token_lifetime: 2.628e+6
If I get a access token the user field is always null though in the database the correct id is saved and it is possible to login with this token.

YOu need to configure cascade operations. You need to decide what do you want to happen on access_token table when you delete an user. You can delete de token or set the related user as null.
More info here

Related

I'm getting "Parameters: [unauthRoleName] must have values" when adding cognito authorization ans api key authorization to my data model in amplify

I have a graphql api with the following model:
type NewFeatureNotification #model #auth(rules: [{allow: public, operations: [read]}, {allow: groups, groups: ["AdminPortal"], operations: [read, create, update, delete]}]) {
id: ID!
title: String
description: String
date: AWSDate
featureType: String
productIdentifier: Int
}
I added an authentication option with an existing user pool and that worked fine, I also created a user group to restrict permissions. The issue appeared when I tried to add authorization rules to my model, the rules should allow access to read action with the api key and read, create, update and delete can be access with an authenticated user that belongs to the AdminPortal Group
rules: [{allow: public, operations: [read]}, {allow: groups, groups: ["AdminPortal"], operations: [read, create, update, delete]}]
but when I try to deploy this change with amplify push I get the following error:
Parameters: [unauthRoleName] must have values .
I also try to do the same thing from the amplify studio but I get the same error.

Is there a way to override AppSync auto generated input types when using Amplify?

Let's say we have the following graphql schema
type Customer
#model
#auth(
rules: [
{ allow: owner }
{ allow: groups, groups: ["Admin"] }
{ allow: public, provider: iam }
]
) {
id: ID! #primaryKey
owner: ID!
customer_last_name: String
}
When pushing above schema to AppSync via AWS Amplify, the following is created in the autogenerated graphql schema.
type Query {
getCustomer(id: ID!): Customer
#aws_iam
#aws_cognito_user_pools
listCustomers(
id: ID,
filter: ModelCustomerFilterInput,
limit: Int,
nextToken: String,
sortDirection: ModelSortDirection
): ModelCustomerConnection
#aws_iam
#aws_cognito_user_pools
}
Is it possible to pass and enforce a custom argument for the query input, such as
getCustomer(id: ID!, owner:ID!): Customer instead of the autogenerated getCustomer(id: ID!): Customer ?
This can be done by editing the autogenerated schema directly in the Appsync console, but in the case of a new Amplify push, the changes will be lost.
There can be only one Hash Key(aka Partition key or Primary Key) in dynamoDB. If you want multiple keys to be your Hash Key, you need to concatenate those keys into one Hash Key. The key pattern you want is called composite primary key.
For more information,
https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.CoreComponents.html#HowItWorks.CoreComponents.PrimaryKey
For creating a composite key with amplify graphql schema, please check details on this link. (Assuming you are using amplify graphql transformer v1)
https://docs.amplify.aws/cli-legacy/graphql-transformer/key/

can't update database symfony 4 with sonataClassificationBundle

im using Symfony 4.1
When you install SonataMediaBundle and SonataClassificationBundle after configure the both of them.
and you want execute the commande
php bin/console doctrine:schema:update --force
you got this Error
The table with name 'shop.classification__collection' already exists.
same for all other table of classification like category and tag
if you try to change the name of table in the entity of classification__collection to classification_collection
you will get a second error like
An exception occurred while executing 'CREATE UNIQUE INDEX tag_collection ON classification__collection (slug, context):
SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes
I run in this problem recently and find the solution.
The issue is address here
https://github.com/sonata-project/SonataClassificationBundle/issues/407
You just need to remove the entity created in App/Entity by classification or remapped the class to the App/Entity in sonata.yaml and sonata_classification.yaml
If you deleted the entities in App/Entity add the following cofiguration to your sonata.yaml and sonata_classification.yaml
/** sonata_classification.yaml**/
sonata_classification:
class:
tag: App\Application\Sonata\ClassificationBundle\Entity\Tag
category: App\Application\Sonata\ClassificationBundle\Entity\Category
media: App\Application\Sonata\MediaBundle\Entity\Media
collection: App\Application\Sonata\ClassificationBundle\Entity\Collection
context: App\Application\Sonata\ClassificationBundle\Entity\Context
/** sonata.yaml**/
class:
media: App\Application\Sonata\MediaBundle\Entity\Media
gallery: App\Application\Sonata\MediaBundle\Entity\Gallery
gallery_has_media: App\Application\Sonata\MediaBundle\Entity\GalleryHasMedia
category: App\Application\Sonata\ClassificationBundle\Entity\Category

FR3DLdapBundle Login with email

I'm new on LDAP concept and i have to make a integration with LDAP and FosUserBundle.
I've installed both bundles, fosuser and FR3DLdapBundle, fosuser is working but i'm missing something about LDAP login.
I need to login with email.
I have the following config: http://pastebin.com/USkJqtbD
I'm using this website for tests: http://www.forumsys.com/tutorials/integration-how-to/ldap/online-ldap-test-server/
I'm using email: riemann#ldap.forumsys.com and password: password
But i have the following error
[2015-05-18 16:36:58] ldap_driver.DEBUG: ldap_search(cn=read-only-admin,dc=example,dc=com, (&(objectClass=*)(uid=riemann#ldap.forumsys.com)), uid,mail) [] []
[2015-05-18 16:36:58] security.INFO: User riemann#ldap.forumsys.com not found on ldap [] []
Thank you in advance for you help
With the FR3D Ldap bundle the first attribute that you add in the attributes list is then one that it uses to search by.
In your config the first attribute is uid, so I would suspect that if you used the uid as the username then it would properly. To sort it you will just need to switch up the order so the your mail attribute is first in the list.
fr3d_ldap:
// ...
user:
// ...
attributes: # Specify ldap attributes mapping [ldap attribute, user object method]
- { ldap_attr: mail, user_method: setEmail } # Default
- { ldap_attr: uid, user_method: setUsername }
You have to adapt the search query for find by email.
https://github.com/Maks3w/FR3DLdapBundle/blob/master/Resources/doc/index.md#4-configure-configyml
# app/config/config.yml
fr3d_ldap:
driver:
accountFilterFormat: (&(email=%s)) # Optional. sprintf format %s will be the username

How to generate entities from database view with doctrine and symfony2

I am trying to generate entities from database using standard console commands as described in Symfony2 documentation here: http://symfony.com/doc/current/cookbook/doctrine/reverse_engineering.html.
php app/console doctrine:mapping:convert --from-database --force yml "src/My/HomeBundle/Resources/config/doctrine/metadata/orm"
php app/console doctrine:mapping:import MyHomeBundle yml
php app/console doctrine:generate:entities MyHomeBundle
After this, all tables are generated correctly. The problem is that this won't generate entities for database views. When I add yml files myself into src/My/HomeBundle/Resources/config/doctrine/metadata/orm for example:
UserInGroup:
type: entity
table: user_in_group_view
fields:
id:
id: true
type: integer
unsigned: false
nullable: false
generator:
strategy: IDENTITY
userId:
type: integer
unsigned: false
nullable: false
column: user_id
userGroupId:
type: integer
unsigned: false
nullable: false
column: user_group_id
lifecycleCallbacks: { }
I get this exception when running php app/console doctrine:generate:entities MyHomeBundle:
Notice: Undefined index: My\HomeBundle\Entity\UserInGroup in C:\Users\ThisIsMe\Projects\SymfonyTestProject\vendor\doctrine\lib\Doctrine\ORM\Mapping\Driver\AbstractFileDriver.php line 121
Similar question was posted here: How to set up entity (doctrine) for database view in Symfony 2
I know I can create Entity class, but I was hoping that I could get this generated so if I change my view, I could just regenerate entity classes. Any suggestions?
Now you create your orm files only. You need to follow 2 more steps. I will give you the complete steps from begining.
Before doing this delete all yml files in your orm directory that you had created early.
I hope MyHomeBundle is your bundle name
1).php app/console doctrine:mapping:convert yml ./src/My/HomeBundle/Resources/config/doctrine --from-database --force
Symfony2 generate entity from Database
2).php app/console doctrine:mapping:import MyHomeBundle yml
3).php app/console doctrine:generate:entities MyHomeBundle
Hope this helps you.
Got the same issue, i use xml instead of yml but must be the same.
Check in your orm entity if the name include the correct route, exemple:
<entity name="Myapp\MyrBundle\Entity\MyEntity" table="myentity">
Because when i generate my orm from database the name was like that:
<entity name="MyEntity" table="myentity">
So doctrine didn't understand the right path.
Hope i'm clear and this will help you!
I know it's an old question but I found the trick (Symfony 6) to generate entities from SQL view (I use a SQL server database).
So I modified two methods of the SQLServerPlatform.php file of the doctrine bundle.
public function getListTablesSQL()
{
// "sysdiagrams" table must be ignored as it's internal SQL Server table for Database Diagrams
// Category 2 must be ignored as it is "MS SQL Server 'pseudo-system' object[s]" for replication
return 'SELECT name, SCHEMA_NAME (uid) AS schema_name FROM sysobjects'
. " WHERE type = 'V' AND name != 'sysdiagrams' AND category != 2 ORDER BY name";
}
I changed the where condition parameter 'U' by 'V' for view.
Same operation for the method getListTableColumnsSQL(), we change here the 'U' parameter of the where condition by 'V'.
public function getListTableColumnsSQL($table, $database = null)
{
return "SELECT col.name,
type.name AS type,
col.max_length AS length,
~col.is_nullable AS notnull,
def.definition AS [default],
col.scale,
col.precision,
col.is_identity AS autoincrement,
col.collation_name AS collation,
CAST(prop.value AS NVARCHAR(MAX)) AS comment -- CAST avoids driver error for sql_variant type
FROM sys.columns AS col
JOIN sys.types AS type
ON col.user_type_id = type.user_type_id
JOIN sys.objects AS obj
ON col.object_id = obj.object_id
JOIN sys.schemas AS scm
ON obj.schema_id = scm.schema_id
LEFT JOIN sys.default_constraints def
ON col.default_object_id = def.object_id
AND col.object_id = def.parent_object_id
LEFT JOIN sys.extended_properties AS prop
ON obj.object_id = prop.major_id
AND col.column_id = prop.minor_id
AND prop.name = 'MS_Description'
WHERE obj.type = 'V'
AND " . $this->getTableWhereClause($table, 'scm.name', 'obj.name');
}
Maybe this will help someone.
As you can see here:
http://symfony.com/doc/current/cookbook/doctrine/reverse_engineering.html
the reverse engineering process from db to entity is not fully implemented yet:
"As the Doctrine tools documentation says, reverse engineering is a one-time process to get started on a project. Doctrine is able to convert approximately 70-80% of the necessary mapping information based on fields, indexes and foreign key constraints. Doctrine can't discover inverse associations, inheritance types, entities with foreign keys as primary keys or semantical operations on associations such as cascade or lifecycle events. Some additional work on the generated entities will be necessary afterwards to design each to fit your domain model specificities."

Resources