Change default registration behavior in Keycloak - java

We have recently switched to Keycloak to handle the login to our website.
It's still possible to register and Keycloak has a user registration page, but I basically need to change the definition of 'registrating'.
By default it means "insert a new user in the DB with the info given by the user through the registration form". But that's not what we want, we already have all the users that CAN register in our DB, and registrating as a user pretty much means updating a record in our DB.
I have already made changes to the a few classes and redeployed them by packaging them and then adding the Jar to the \deployments directory. But I can't seem to find the classes that I have to change to get the registration page to behave the way I want.
How can I change the default behavior of the registration page? What classes do I have to change?

I've never do this, but i'd take a look to the user store SPI and authenticator SPI.
I suggest you in writing directly in the Keycloak discourse forum (https://keycloak.discourse.group/) . They will surely give you a hand.
PS: with SPI you'll add features to Keycloak, but in your case i think that you'll need also to change the GUI. See Keycloak Themes in the official doc.

Related

Java Spring security does not appear to recognize disabled LDAP accounts

See Edit-1 below for sum-up question
I am using Spring Security libraries (v3.0.5) to handle authentication for a web application (deployed in JBoss AS7). The account management is handled by an IdM on top of OpenLDAP.
When a new account is created, by default it is created with the "nsaccountlock" operational attribute set to "true". We can confirm that the account is "Disabled" by logging into the IdM web portal and listing the users - new users are listed as Disabled.
The problem is that our web application seems to ignore that nsaccountlock attribute completely when it searches for a user entry. The springframework logs report "Enabled: true" for all accounts that attempt to authenticate, whether they have the nsaccountlock=true or false.
I have searched through as much of the springframework source code as I can find, and I can not find anything that is actually setting the "enabled" state to false (see org.springframework.security.ldap.userdetails.LdapUserDetailsImpl and any subclass). I would have expected it to happen in org.springframework.security.ldap.userdetails.LdapUserDetailsMapper.mapUserFromContext() but it definitely does not set the Enabled flag anywhere.
The LDAP lookup and entry retrieval is configured in several .xml files (which I am unfortunately unable to post here at the moment) that define the use of classes such as org.springframework.security.ldap.authentication.LdapAuthenticationProvider, org.springframework.security.ldap.search.FilterBasedLdapUserSearch, etc.
Should I be using a different type of org.springframework.security.core.userdetails.UserDetails implementation to capture the disabled state from LDAP? Am I missing some obvious configuration element that would indicate how Spring can determine the disabled state of the LDAP entry?
Note: I can configure the LDAP search to fetch the "nsaccountlock" as an attribute in the UserDetails response, and the attribute is logged correctly
(whether the value is true or false) but it still does not affect the "enabled" boolean value. It just acts as another bit of metadata (like phone, address, email, etc).
Edit-1
I may have been asking the wrong question up front. Ultimately, I would like to know this:
What would lead LdapUserDetailsImpl.isEnabled() to return false? i.e., What do we need to do in order to make sure Spring Security recognizes disabled accounts?
I'm hoping this a matter of configuration. I imagine it has something to do with the AuthenticationManager (we use org.jasig.cas.authentication.AuthenticatoinManagerImpl)
Thanks for the help, and I apologize for the messy question.
As far as I know OpenLDAP and the LDAP protocol, nsaccountlock is not an attribute which is used by OpenLDAP to keep track of locked account, it is an attribute which was used in Sun Directory Server (Sun LDAP Directory).
But from the point of view of OpenLDAP it is the same as any other informative attribute.
If you want to manage a password policy you have to implement the overlay ppolicy which is described here

Application server role-based access controll

I'm working on implementing a role-based authorization service under WS Liberty.
There are two main goals:
if the user without the correct user group tries to open a restricted url, show an error page
the user should see a menu, listing all pages available for him
My question is: are there best practices to implement this behaviour? Should I create the first part in server.xml AND the second part in the appropriate view?
(this way the "logic" will be stored in two different parts of the code, and for example if I have to add a new URL, I have to insert it into two different places)
So is there a way to store this role-URL mapping in one place?
Thanks,
krisy
In you application you can protect links checking roles (pseudo code, some frameworks have already custom tags for it):
if(request.isUserInRole("roleX")) {
// render menu item for roleX
}
By default, if user is already logged in and tries to access page that is restricted for him, he will receive 403 Not authorized, you can provide error page for that code via web.xml configuration.
In the server.xml via Application binding element you provide only mapping from your application roles to groups defined in the registry. Depending on the registry type you will be able to add/remove users to the given group granting or rejecting them right for example via server.xml or LDAP management tool in case of LDAP registry.

Read only scope for Google admin settings API

I was trying to retrieve the organization name of the user using the OAuth mechanism (in java on Google app engine). The scope that I used is
https://apps-apis.google.com/a/feeds/domain/
However this scope is giving Manage your domain settings option, which seems very scary for the end customers. Attached below is the screenshot of that.
so, is there is a read only version of this scope, so that it can be only View your domain settings
I tried using the following scopes in the OAuth playground,
https://apps-apis.google.com/a/feeds/domain.readonly
https://apps-apis.google.com/a/feeds/domain/#readonly
but every time I was bit by invalid oauth scopes URI. Attached below is the screenshot.
Any help is very much appreciated. Thanks in advance.
This is documented at [1]. You can use "https://www.googleapis.com/auth/admin.directory.user.readonly" scope. Org Unit will be listed under "orgUnitPath" of the returned user resource.
[1] - https://developers.google.com/admin-sdk/directory/v1/reference/users/list
To solve this problem what you can do is:
go to Admin Console > Security > API Controls > Domain Wide Delegation
Select you App, click on Edit and add your scope "https://apps-apis.google.com/a/feeds/domain"
Now click on Authorise. Done
Now you can generate access token by including this scope and access Google Admin Setting API.

SecureSocial: How to modify the signup system (UsernamePasswordProvider)?

I'm implementing a signup system by using UsernamePasswordProvider. I want a user to be able to signup directly instead of firstly putting his/her email and waiting for a token. Moreover, I want to modify the signup form by adding/deleting some input fields. However, I can't find any document mentioned how to achieve these requirements. Any help would be appreciated.
The current stable version - 2.1.3 as of this writing - does not make it easy to customize the flow. With the latest changes in master you can override the built in registration controller and add the changes you need.
To accomplish what you want the best would be to not include the default registration routes and add your own that point to your custom controllers directly.
Keep in mind that the default flow prevents leaking information about the user base. If you make your users fill a form and they enter an existing email address you will have to show an error saying the account exists. That can give information to a potential attacker to target specific emails.
You should create custom views that extend TemplatesPlugin (or ViewsPlugin, in the newest version). This information is explained in securesocial website.

spring security (3.0.x) and user impersonation

In my web application, there are times when an authenticated admin might want to impersonate another valid user of a system without having to know that user's password.
How can I use Spring Security to give admin users the ability to impersonate normal (non-admin) users of the system?
The Spring Security documentation is silent on this and I can't find anything anywhere. Surely someone must have solved this.
Thanks!
It's in the Spring Security 3 and Spring Security 4 docs aptly named, "Run-As Authentication Replacement."
The AbstractSecurityInterceptor is able to temporarily replace the Authentication object in the SecurityContext and SecurityContextHolder during the secure object callback phase.
I believe the recommended way to do this in Spring Security is with the Domain Access Control lists, see GrantedAuthoritySid #
http://static.springsource.org/spring-security/site/docs/3.1.x/reference/domain-acls.html
However, impersonating another user is more than just having a "delegate identity", you should also consider the implications on logging:
Do you want your logging to appear as Original User or Impersonated User (or both?)
Do you want the "impersonation" to show only what the impersonated user sees, or the superset of permissions of the Original User and Impersonated User?
Yet another possibility is to create a "log in as" feature, which essentially changes the principal identity of the current session - or starts a new session with the impersonated identity.
In all of the above, you may inadvertantly open up a security issue - so I think this is why impersonate-style features are not that common place. Rather, designs trend towards Role Based Access Control (RBAC) or Attribute Based Access Control (ABAC). Using RBAC / ABAC, you could create a delegate style feature where you create delegate attributes/roles - and in the special cases where you need to show the source/target of the delegation (e.g. for audit logs), you handle those as corner cases.
If you want an admin user to be able to impersonate another user (eg for QA/Testing purposes), have a look at the SwitchUserFilter
A decent example of the XML config you need is provided here

Categories