Java Code Examples for org.keycloak.models.RealmModel#getId()

The following examples show how to use org.keycloak.models.RealmModel#getId() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CachedUser.java    From keycloak with Apache License 2.0 6 votes vote down vote up
public CachedUser(Long revision, RealmModel realm, UserModel user, int notBefore) {
    super(revision, user.getId());
    this.realm = realm.getId();
    this.username = user.getUsername();
    this.createdTimestamp = user.getCreatedTimestamp();
    this.email = user.getEmail();
    this.emailVerified = user.isEmailVerified();
    this.enabled = user.isEnabled();
    this.federationLink = user.getFederationLink();
    this.serviceAccountClientLink = user.getServiceAccountClientLink();
    this.notBefore = notBefore;
    this.requiredActions = new DefaultLazyLoader<>(UserModel::getRequiredActions, Collections::emptySet);
    this.attributes = new DefaultLazyLoader<>(userModel -> new MultivaluedHashMap<>(userModel.getAttributes()), MultivaluedHashMap::new);
    this.roleMappings = new DefaultLazyLoader<>(userModel -> userModel.getRoleMappings().stream().map(RoleModel::getId).collect(Collectors.toSet()), Collections::emptySet);
    this.groups = new DefaultLazyLoader<>(userModel -> userModel.getGroups().stream().map(GroupModel::getId).collect(Collectors.toCollection(LinkedHashSet::new)), LinkedHashSet::new);
}
 
Example 2
Source File: DefaultBruteForceProtector.java    From keycloak with Apache License 2.0 5 votes vote down vote up
@Override
public void successfulLogin(final RealmModel realm, final UserModel user, final ClientConnection clientConnection) {
    try {
        SuccessfulLogin event = new SuccessfulLogin(realm.getId(), user.getId(), clientConnection.getRemoteAddr());
        queue.offer(event);

        event.latch.await(5, TimeUnit.SECONDS);
    } catch (InterruptedException e) {
    }
    logger.trace("sent success event");
}
 
Example 3
Source File: InfinispanUserSessionProvider.java    From keycloak with Apache License 2.0 5 votes vote down vote up
@Override
public UserLoginFailureModel addUserLoginFailure(RealmModel realm, String userId) {
    LoginFailureKey key = new LoginFailureKey(realm.getId(), userId);
    LoginFailureEntity entity = new LoginFailureEntity();
    entity.setRealmId(realm.getId());
    entity.setUserId(userId);

    SessionUpdateTask<LoginFailureEntity> createLoginFailureTask = Tasks.addIfAbsentSync();
    loginFailuresTx.addTask(key, createLoginFailureTask, entity);

    return wrap(key, entity);
}
 
Example 4
Source File: DefaultBruteForceProtector.java    From keycloak with Apache License 2.0 5 votes vote down vote up
@Override
public void failedLogin(RealmModel realm, UserModel user, ClientConnection clientConnection) {
    try {
        FailedLogin event = new FailedLogin(realm.getId(), user.getId(), clientConnection.getRemoteAddr());
        queue.offer(event);
        // wait a minimum of seconds for type to process so that a hacker
        // cannot flood with failed logins and overwhelm the queue and not have notBefore updated to block next requests
        // todo failure HTTP responses should be queued via async HTTP
        event.latch.await(5, TimeUnit.SECONDS);
    } catch (InterruptedException e) {
    }
    logger.trace("sent failure event");
}
 
Example 5
Source File: CachedClientScope.java    From keycloak with Apache License 2.0 5 votes vote down vote up
public CachedClientScope(Long revision, RealmModel realm, ClientScopeModel model) {
    super(revision, model.getId());
    name = model.getName();
    description = model.getDescription();
    this.realm = realm.getId();
    protocol = model.getProtocol();
    for (ProtocolMapperModel mapper : model.getProtocolMappers()) {
        this.protocolMappers.add(mapper);
    }
    for (RoleModel role : model.getScopeMappings())  {
        scope.add(role.getId());
    }
    attributes.putAll(model.getAttributes());
}
 
Example 6
Source File: CachedRole.java    From keycloak with Apache License 2.0 5 votes vote down vote up
public CachedRole(Long revision, RoleModel model, RealmModel realm) {
    super(revision, model.getId());
    composite = model.isComposite();
    description = model.getDescription();
    name = model.getName();
    this.realm = realm.getId();
    if (composite) {
        for (RoleModel child : model.getComposites()) {
            composites.add(child.getId());
        }
    }
    attributes = new DefaultLazyLoader<>(roleModel -> new MultivaluedHashMap<>(roleModel.getAttributes()), MultivaluedHashMap::new);
}
 
Example 7
Source File: CachedGroup.java    From keycloak with Apache License 2.0 5 votes vote down vote up
public CachedGroup(Long revision, RealmModel realm, GroupModel group) {
    super(revision, group.getId());
    this.realm = realm.getId();
    this.name = group.getName();
    this.parentId = group.getParentId();
    this.attributes = new DefaultLazyLoader<>(source -> new MultivaluedHashMap<>(source.getAttributes()), MultivaluedHashMap::new);
    this.roleMappings = new DefaultLazyLoader<>(source -> source.getRoleMappings().stream().map(RoleModel::getId).collect(Collectors.toSet()), Collections::emptySet);
    this.subGroups = new DefaultLazyLoader<>(source -> source.getSubGroups().stream().map(GroupModel::getId).collect(Collectors.toSet()), Collections::emptySet);
}
 
Example 8
Source File: RoleListQuery.java    From keycloak with Apache License 2.0 5 votes vote down vote up
public RoleListQuery(Long revisioned, String id, RealmModel realm, String role) {
    super(revisioned, id);
    this.realm = realm.getId();
    this.realmName = realm.getName();
    this.roles = new HashSet<>();
    this.roles.add(role);
}
 
Example 9
Source File: ClientListQuery.java    From keycloak with Apache License 2.0 5 votes vote down vote up
public ClientListQuery(Long revisioned, String id, RealmModel realm, String client) {
    super(revisioned, id);
    this.realm = realm.getId();
    this.realmName = realm.getName();
    this.clients = new HashSet<>();
    this.clients.add(client);
}
 
Example 10
Source File: UserListQuery.java    From keycloak with Apache License 2.0 5 votes vote down vote up
public UserListQuery(Long revisioned, String id, RealmModel realm, String user) {
    super(revisioned, id);
    this.realm = realm.getId();
    this.realmName = realm.getName();
    this.users = new HashSet<>();
    this.users.add(user);
}
 
Example 11
Source File: CachedUserConsents.java    From keycloak with Apache License 2.0 5 votes vote down vote up
public CachedUserConsents(Long revision, String id, RealmModel realm,
                          List<UserConsentModel> consents) {
    super(revision, id);
    this.realmId = realm.getId();
    if (consents != null) {
        for (UserConsentModel consent : consents) {
            this.consents.put(consent.getClient().getId(), new CachedUserConsent(consent));
        }
    }
}
 
Example 12
Source File: CachedFederatedIdentityLinks.java    From keycloak with Apache License 2.0 4 votes vote down vote up
public CachedFederatedIdentityLinks(Long revision, String id, RealmModel realm, Set<FederatedIdentityModel> federatedIdentities) {
    super(revision, id);
    this.realmId = realm.getId();
    this.federatedIdentities.addAll(federatedIdentities);
}
 
Example 13
Source File: ClientListQuery.java    From keycloak with Apache License 2.0 4 votes vote down vote up
public ClientListQuery(Long revisioned, String id, RealmModel realm, Set<String> clients) {
    super(revisioned, id);
    this.realm = realm.getId();
    this.realmName = realm.getName();
    this.clients = clients;
}
 
Example 14
Source File: UserListQuery.java    From keycloak with Apache License 2.0 4 votes vote down vote up
public UserListQuery(Long revisioned, String id, RealmModel realm, Set<String> users) {
    super(revisioned, id);
    this.realm = realm.getId();
    this.realmName = realm.getName();
    this.users = users;
}
 
Example 15
Source File: UserMapStorage.java    From keycloak with Apache License 2.0 4 votes vote down vote up
private static String getUserIdInMap(RealmModel realm, String userId) {
    return realm.getId() + "/" + userId;
}
 
Example 16
Source File: RoleListQuery.java    From keycloak with Apache License 2.0 4 votes vote down vote up
public RoleListQuery(Long revisioned, String id, RealmModel realm, Set<String> roles) {
    super(revisioned, id);
    this.realm = realm.getId();
    this.realmName = realm.getName();
    this.roles = roles;
}
 
Example 17
Source File: GroupListQuery.java    From keycloak with Apache License 2.0 4 votes vote down vote up
public GroupListQuery(Long revisioned, String id, RealmModel realm, Set<String> groups) {
    super(revisioned, id);
    this.realm = realm.getId();
    this.realmName = realm.getName();
    this.groups = groups;
}
 
Example 18
Source File: InfinispanUserSessionProvider.java    From keycloak with Apache License 2.0 4 votes vote down vote up
@Override
public UserLoginFailureModel getUserLoginFailure(RealmModel realm, String userId) {
    LoginFailureKey key = new LoginFailureKey(realm.getId(), userId);
    LoginFailureEntity entity = getLoginFailureEntity(key);
    return wrap(key, entity);
}