How do I add "Terms and Conditions" (i.e. Required Actions) for users in Keycloak admin console via importing realm.json? - keycloak

I have imported realm.json (In admin console, Create Realm-> browse resource file) where existing users are also present.
"users" : [ {
"id" : "id",
"createdTimestamp" : 1622625059225,
"username" : "username",
"enabled" : true,
"totp" : false,
"emailVerified" : true,
"email" : "sample#test.com",
"credentials" : [ {
"id" : "credential_id",
"type" : "password",
"createdDate" : 1622625153395,
"secretData" : "{...}",
"credentialData" : "...":{}}"
} ],
"disableableCredentialTypes" : [ ],
**"requiredActions" : [ "terms_and_conditions"],**
"realmRoles" : [ "user" ],
"clientRoles" : {
"account" : [ "view", "manage" ]
},
"notBefore" : 0,
"groups" : [ "/groups" ]
}
I have enable "Terms and Conditions" from root requiredActions
"requiredActions" : [ {
"alias" : "terms_and_conditions",
"name" : "Terms and Conditions",
"providerId" : "terms_and_conditions",
"enabled" : true,
"defaultAction" : true,
"priority" : 10,
"config" : { }
}]
Now after importing the realm.json, I am able to see the "Terms and Conditions" in Users details tab.
But "Terms and Conditions" page is not appearing while Login to application.
Note: If I explicitly add terms and conditions from required actions dropdown then only it works fine.

Related

How to find documents using a field of an embedded document that is inside an array?

I have the Data/Schema for my student records:
{
"_id" : ObjectId("579ed0ba7d509178a97fae8f"),
"fullName" : "ABC",
"enroll" : "AB1234",
"profile" : {
"isCompleted" : true,
"verification" : [
{
"pro" : true,
"verifiedBy" : "ProAct",
"verifiedOn" : ISODate("2016-09-12T07:36:53.680Z")
},
],
"isChecked" : false,
"fullName" : "ABC",
"gender" : "Male",
"emergencyContactPerson" : {
"name" : "Father",
"mobile" : "9412345678",
"email" : "example#gmail.com",
},
},
"contact" : {
"emailID" : {
"isVerified" : true,
"isChecked" : false,
"verificationTokenExpiresIn" : ISODate("2016-08-01T05:35:00.218Z"),
"verifiedOn" : ISODate("2016-08-01T04:35:10.992Z")
},
"mobileID" : {
"isVerified" : true,
"isChecked" : false,
"verificationTokenExpiresIn" : ISODate("2016-08-01T04:42:45.206Z"),
"verifiedOn" : ISODate("2016-08-01T04:33:36.692Z")
}
},
"services" : [
{
"applied" : true,
"appliedOn" : ISODate("2016-09-17T03:01:49.829Z"),
"status" : "Created",
"mac" : "70-77-88-00-AA-BB",
"createdBy" : "Example"
},
]
}
How can I build query, to get student info with the help of mac address 70-77-88-00-AA-BB. i only know mac address value?
i am new here please help me out
Query
services.mac is an array of all the mac addresses members of services
in querying(not in aggregation $eq) an array is equal with a value if it contains that value, so the above will work
the bellow query returns all the students, that have that mac adrress on the services array
if you want to make it fast you can also create an index on "services.mac"
*read mongodb documentation its very good and with examples
Test code here
db.collection.find({
"services.mac": "70-77-88-00-AA-BB"
})

mongodb find $elemMatch with Multiple Fields

everyone. I need your help. For a script I have to search for users by their ldap id, but I have the problem that I get no output when searching.
a user has the following output.
db.users.find({"name" : "John Sample"} ).toArray()
[
{
"_id" : "testid",
"createdAt" : ISODate("2017-05-11T13:49:35.125Z"),
"services" : {
"password" : {
"bcrypt" : ""
},
"ldap" : {
"id" : "12345678",
"idAttribute" : "uid"
},
"resume" : {
"loginTokens" : [ ]
}
},
"username" : "john",
"emails" : [
{
"address" : "john.sample#test.com",
"verified" : true
}
],
"type" : "user",
"status" : "offline",
"active" : true,
"name" : "John Sample",
"_updatedAt" : ISODate("2018-07-05T18:44:22.061Z"),
"roles" : [
"user"
],
"ldap" : true,
"lastLogin" : ISODate("2018-07-05T10:33:00.712Z"),
"statusConnection" : "offline",
"utcOffset" : 2,
"statusDefault" : "offline"
}
]
I used this command but without success.
db.users.find({"services" : {"$elemMatch": {"ldap" : {"$elemMatch": {"id" : "12345678"}}}}}} ).toArray();
[ ]
$elemMatch is used to find elements that match criteria in an array. But services is an document (sub document), not an array. Just use dot notation to query :
db.users.find({"services.ldap.id":"12345678"})

How to get a list of nested object only if condition match in mongodb?

I am developing application which had company and there are 2 users reviewer & admin inside that company. Now as a super admin I want to display only Reviewer of the all company. with following information
Company Name,
Reviewer Name,
Reviewer Email
My collection is
{
"_id" : ObjectId("58830988b9c5f808fc307ec4"),
"createdat" : ISODate("2017-01-21T07:11:04.218+0000"),
"isActive" : true,
"users" : [
{
"_id" : ObjectId("58830988b9c5f808fc307ec5"),
"createdat" : ISODate("2017-01-21T07:11:04.219+0000"),
"role" : "admin",
"password" : "test",
"email" : "email3#email.com",
"name" : "test"
},
{
"name" : "test",
"email" : "email2#email.com",
"password" : "test",
"role" : "admin",
"createdat" : ISODate("2017-01-21T07:24:42.559+0000"),
"_id" : ObjectId("58830cba24ebfa04f812e544")
},
{
"name" : "test",
"email" : "email1#email.com",
"password" : "test",
"role" : "admin",
"isActive" : true,
"createdat" : ISODate("2017-01-21T07:36:37.337+0000"),
"_id" : ObjectId("58830f85d92f1808e0984306")
},
{
"name" : "reviewName 1",
"email" : "reviewName1#gmail.com",
"password" : "test",
"role" : "reviewer",
"isActive" : true,
"createdat" : ISODate("2017-01-21T07:55:39.727+0000"),
"_id" : ObjectId("588313fba001380a383e077e")
},
{
"name" : "test",
"email" : "test",
"password" : "test",
"role" : "admin",
"isActive" : true,
"createdat" : ISODate("2017-01-21T07:56:52.963+0000"),
"_id" : ObjectId("588314447bbc230c306804c1")
}
],
"companyname" : "Test Company 1",
"__v" : NumberInt(0)
}
{
"_id" : ObjectId("58830988b9c5f808fc307ec4"),
"createdat" : ISODate("2017-01-21T07:11:04.218+0000"),
"isActive" : true,
"users" : [
{
"_id" : ObjectId("58830988b9c5f808fc307ec5"),
"createdat" : ISODate("2017-01-21T07:11:04.219+0000"),
"role" : "admin",
"password" : "test",
"email" : "test4#email.com",
"name" : "test"
},
{
"name" : "test",
"email" : "test3#email.com",
"password" : "test",
"role" : "admin",
"createdat" : ISODate("2017-01-21T07:24:42.559+0000"),
"_id" : ObjectId("58830cba24ebfa04f812e544")
},
{
"name" : "test",
"email" : "test2#email.com",
"password" : "test",
"role" : "admin",
"isActive" : true,
"createdat" : ISODate("2017-01-21T07:36:37.337+0000"),
"_id" : ObjectId("58830f85d92f1808e0984306")
},
{
"name" : "reviewName 2_1",
"email" : "reviewName2_1#gmail.com",
"password" : "test",
"role" : "reviewer",
"isActive" : true,
"createdat" : ISODate("2017-01-21T07:55:39.727+0000"),
"_id" : ObjectId("588313fba001380a383e077e")
},
{
"name" : "reviewName 2_2",
"email" : "reviewName2_2#gmail.com",
"password" : "test",
"role" : "reviewer",
"isActive" : true,
"createdat" : ISODate("2017-01-21T07:56:52.963+0000"),
"_id" : ObjectId("588314447bbc230c306804c1")
}
],
"companyname" : "Test Company 2",
"__v" : NumberInt(0)
}
So I would Like to get Following Data
Company Name : Test Company 1,
Reviewer Name : reviewName 1,
Reviewr Email : reviewName1#gmail.com
Company Name : Test Company 2,
Reviewer Name : reviewName 2_1,
Reviewer Email : reviewName2_1#gmail.com
Company Name : Test Company 2,
Reviewer Name : reviewName 2_2,
Reviewer Email : reviewName2_2#gmail.com
There will be lot's of companies, so I don't want to go through with loop and use require information in array. because there will be thousands of company and each company have hundreds of reviewer and admin. So If we go through loop then it will be time consuming. I want to get this data only from collection. So I am looking for the query or condition which gives me only require information.
Can someone help me to get these data-only.
You need to use MongoDB aggregation framework for getting the data according to your requirement.
This query will return data in the desired form.
db.collection.aggregate([
{
"$unwind": "$users"
},
{
"$match": {
"users.role":"reviewer"
}
},
{
"$project": {
"_id":0,
"Company Name" : "$companyname",
"Reviewer Name" : "$users.name",
"Reviewer Email" : "$users.email"
}
}
])

Users are getting logged out

I have a Drupal commerce install, with commerce entity membership among other modules. Everything is working fine from my computer, I tested with all kinds of users and roles, but my client (in Belgium) and his new users experience many issues, they get logged out when accessing views where I restricted access to specific roles. The site is in production, customers are coming, they join as members but this issue will cause troubles I fear. I used .htaccess to redirect www to domain, again on my home computers and mobile phone it's working fine... I don't know what to do. Can someone help ?
Edit : I created a rule to redirect users on first login (one-time-login link provided in welcome email) to the account edit page
{ "rules_first_time_login" : { "LABEL" : "first time login", "PLUGIN" : "reaction rule", "WEIGHT" : "0", "OWNER" : "rules", "REQUIRES" : [ "rules" ], "ON" : { "user_login" : [] }, "IF" : [ { "data_is_empty" : { "data" : [ "site:current-user:last-access" ] } } ], "DO" : [ { "redirect" : { "url" : "user\/[account:uid]\/edit" } } ] } }
Another rule is triggered for these users to be redirected to members' area
{ "rules_redirect_user_on_password_change" : { "LABEL" : "Redirect user on password change", "PLUGIN" : "reaction rule", "OWNER" : "rules", "REQUIRES" : [ "rules" ], "ON" : { "user_update" : [] }, "IF" : [
{ "NOT data_is_empty" : { "data" : [ "account:last-login" ] } },
{ "user_has_role" : {
"account" : [ "account" ],
"roles" : { "value" : { "4" : "4", "5" : "5" } },
"operation" : "OR"
}
} ], "DO" : [ { "redirect" : { "url" : "[site:url]members" } } ] } }
A third rule for normal users after login
{ "rules_redirect_to_members" : { "LABEL" : "redirect to members", "PLUGIN" : "reaction rule", "WEIGHT" : "1", "OWNER" : "rules", "REQUIRES" : [ "rules" ], "ON" : { "user_login" : [] }, "IF" : [
{ "user_has_role" : {
"account" : [ "account" ],
"roles" : { "value" : { "4" : "4", "5" : "5" } },
"operation" : "OR"
}
},
{ "NOT text_matches" : { "text" : [ "site:current-page:path" ], "match" : "user\/reset" } } ], "DO" : [ { "redirect" : { "url" : "[site:url]members" } } ] } }
Do you see any misconfiguration ?
Some browsers, as Firefox for example are treating subdomains as www as totally different domains. So, if user logs in at www.domain.com and you re-direct it to domain.com it will not be logged in any more on some browsers. Try it your self with Firefox - I don't think it's location, but browser related.

How to modify Accounts.createUser in Meteor?

I am new in meteor and working with existing mongodb. When I execute Accounts.createUser in meteor it creates user in mongodb. The default user creation structure is.
{
"createdAt" : ISODate("2015-04-28T06:25:24.584Z"),
"services" : {
"google" : {
"accessToken" : "...",
"idToken" : "eyJh...",
"expiresAt" : 1430205913568,
"email" : "zxy#abc.com",
"verified_email" : true,
"name" : "ABC XYZ",
"given_name" : "ABC",
"family_name" : "XYZ",
"picture" : "photo.jpg",
"locale" : "en"
},
"resume" : {
"loginTokens" : [
{
"when" : ISODate("2015-04-28T06:25:24.618Z"),
"hashedToken" : "QWTfTNUEcZwb4OvU"
}
]
}
}
}
Now I need to modify the structure like.
{
"email" : "zxy#abc.com",
"password" : "xyz",
"loginType": "google",
"country" : "US",
"state" : "California",
"profile_image" : "photo.jpg",
"fullname" : "ABC XYZ",
"status" : "active",
"timestamp" : NumberLong(1420780653),
}
How or where should I modify the default user creation structure?
You can try onCreateUser:
//server code
Accounts.onCreateUser(function(options, user) {
//here you can modify user
if (options.profile)
user.profile = options.profile;
return user;
});
But be careful, if you remove services field, user will probably not be able to log in with external services.