Initial commit
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
package com.example.keycloak;
|
||||
|
||||
import org.keycloak.component.ComponentModel;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
import org.keycloak.models.RealmModel;
|
||||
import org.keycloak.storage.ReadOnlyException;
|
||||
import org.keycloak.storage.adapter.AbstractUserAdapterFederatedStorage;
|
||||
|
||||
public class MetaUserModel extends AbstractUserAdapterFederatedStorage {
|
||||
|
||||
private final String userId;
|
||||
private final String username;
|
||||
private final String email;
|
||||
private final String fullName;
|
||||
private final boolean enabled;
|
||||
|
||||
public MetaUserModel(KeycloakSession session, RealmModel realm, ComponentModel storageProviderModel,
|
||||
String userId, String username, String email, String fullName, boolean enabled) {
|
||||
super(session, realm, storageProviderModel);
|
||||
this.userId = userId;
|
||||
this.username = username;
|
||||
this.email = email;
|
||||
this.fullName = fullName;
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFirstName() {
|
||||
// Извлекаем первое слово из full_name как имя
|
||||
if (fullName != null && !fullName.trim().isEmpty()) {
|
||||
String[] names = fullName.split("\\s+");
|
||||
return names.length > 0 ? names[0] : "";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLastName() {
|
||||
// Извлекаем все кроме первого слова как фамилию
|
||||
if (fullName != null && !fullName.trim().isEmpty()) {
|
||||
String[] names = fullName.split("\\s+");
|
||||
if (names.length > 1) {
|
||||
StringBuilder lastName = new StringBuilder();
|
||||
for (int i = 1; i < names.length; i++) {
|
||||
if (i > 1) lastName.append(" ");
|
||||
lastName.append(names[i]);
|
||||
}
|
||||
return lastName.toString();
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEmail(String email) {
|
||||
throw new ReadOnlyException("User is read-only");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUsername(String username) {
|
||||
throw new ReadOnlyException("User is read-only");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFirstName(String firstName) {
|
||||
throw new ReadOnlyException("User is read-only");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLastName(String lastName) {
|
||||
throw new ReadOnlyException("User is read-only");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEnabled(boolean enabled) {
|
||||
throw new ReadOnlyException("User is read-only");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user