use of org.keycloak.userprofile.UserProfileProvider in project keycloak by keycloak.
the class UserProfileResource method update.
@PUT
@Consumes(MediaType.APPLICATION_JSON)
public Response update(String text) {
auth.realm().requireManageRealm();
UserProfileProvider t = session.getProvider(UserProfileProvider.class);
try {
t.setConfiguration(text);
} catch (ComponentValidationException e) {
// show validation result containing details about error
return ErrorResponse.error(e.getMessage(), Response.Status.BAD_REQUEST);
}
return Response.ok(t.getConfiguration()).type(MediaType.APPLICATION_JSON).build();
}
use of org.keycloak.userprofile.UserProfileProvider in project keycloak by keycloak.
the class AbstractUserProfileBean method init.
/**
* Subclass have to call this method at the end of constructor to init user profile data.
*
* @param session
* @param writeableOnly if true then only writeable (no read-only) attributes are put into template, if false then all readable attributes are there
*/
protected void init(KeycloakSession session, boolean writeableOnly) {
UserProfileProvider provider = session.getProvider(UserProfileProvider.class);
this.profile = createUserProfile(provider);
this.attributes = toAttributes(profile.getAttributes().getReadable(), writeableOnly);
if (this.attributes != null)
this.attributesByName = attributes.stream().collect(Collectors.toMap((a) -> a.getName(), (a) -> a));
}
use of org.keycloak.userprofile.UserProfileProvider in project keycloak by keycloak.
the class AccountRestService method account.
/**
* Get account information.
*
* @return
*/
@Path("/")
@GET
@Produces(MediaType.APPLICATION_JSON)
@NoCache
public UserRepresentation account(@QueryParam("userProfileMetadata") final Boolean userProfileMetadata) {
auth.requireOneOf(AccountRoles.MANAGE_ACCOUNT, AccountRoles.VIEW_PROFILE);
UserModel user = auth.getUser();
UserRepresentation rep = new UserRepresentation();
rep.setId(user.getId());
rep.setUsername(user.getUsername());
rep.setFirstName(user.getFirstName());
rep.setLastName(user.getLastName());
rep.setEmail(user.getEmail());
rep.setEmailVerified(user.isEmailVerified());
UserProfileProvider provider = session.getProvider(UserProfileProvider.class);
UserProfile profile = provider.create(UserProfileContext.ACCOUNT, user);
rep.setAttributes(profile.getAttributes().getReadable(false));
if (userProfileMetadata == null || userProfileMetadata.booleanValue())
rep.setUserProfileMetadata(createUserProfileMetadata(profile));
return rep;
}
use of org.keycloak.userprofile.UserProfileProvider in project keycloak by keycloak.
the class AccountRestService method updateAccount.
@Path("/")
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@NoCache
public Response updateAccount(UserRepresentation rep) {
auth.require(AccountRoles.MANAGE_ACCOUNT);
event.event(EventType.UPDATE_PROFILE).client(auth.getClient()).user(auth.getUser()).detail(Details.CONTEXT, UserProfileContext.ACCOUNT.name());
UserProfileProvider profileProvider = session.getProvider(UserProfileProvider.class);
UserProfile profile = profileProvider.create(UserProfileContext.ACCOUNT, rep.toAttributes(), auth.getUser());
try {
profile.update(new EventAuditingAttributeChangeListener(profile, event));
event.success();
return Response.noContent().build();
} catch (ValidationException pve) {
List<ErrorRepresentation> errors = new ArrayList<>();
for (Error err : pve.getErrors()) {
errors.add(new ErrorRepresentation(err.getAttribute(), err.getMessage(), validationErrorParamsToString(err.getMessageParameters(), profile.getAttributes())));
}
return ErrorResponse.errors(errors, pve.getStatusCode(), false);
} catch (ReadOnlyException e) {
return ErrorResponse.error(Messages.READ_ONLY_USER, Response.Status.BAD_REQUEST);
}
}
use of org.keycloak.userprofile.UserProfileProvider in project keycloak by keycloak.
the class DeclarativeUserTest method testDefaultUserProfileProviderIsActive.
@Test
public void testDefaultUserProfileProviderIsActive() {
getTestingClient().server(TEST_REALM_NAME).run(session -> {
Set<UserProfileProvider> providers = session.getAllProviders(UserProfileProvider.class);
assertThat(providers, notNullValue());
assertThat(providers.isEmpty(), is(false));
UserProfileProvider provider = session.getProvider(UserProfileProvider.class);
assertThat(provider, notNullValue());
assertThat(DeclarativeUserProfileProvider.class.getName(), is(provider.getClass().getName()));
assertThat(provider, instanceOf(DeclarativeUserProfileProvider.class));
});
}
Aggregations