Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Yi Sun
keycloak-flow-extension
Commits
78297cc0
Commit
78297cc0
authored
Oct 27, 2021
by
Yi Sun
Browse files
hash home dir
parent
693bad73
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/main/java/eu/eosc/life/keycloak/authentication/EoscCreateUserIfUniqueAuthenticator.java
View file @
78297cc0
...
@@ -48,6 +48,8 @@ import org.keycloak.storage.ldap.LDAPStorageProviderFactory;
...
@@ -48,6 +48,8 @@ import org.keycloak.storage.ldap.LDAPStorageProviderFactory;
import
org.keycloak.storage.user.ImportSynchronization
;
import
org.keycloak.storage.user.ImportSynchronization
;
import
org.keycloak.common.util.Time
;
import
org.keycloak.common.util.Time
;
import
java.nio.charset.StandardCharsets
;
public
class
EoscCreateUserIfUniqueAuthenticator
extends
IdpCreateUserIfUniqueAuthenticator
{
public
class
EoscCreateUserIfUniqueAuthenticator
extends
IdpCreateUserIfUniqueAuthenticator
{
private
static
Logger
logger
=
Logger
.
getLogger
(
EoscCreateUserIfUniqueAuthenticator
.
class
);
private
static
Logger
logger
=
Logger
.
getLogger
(
EoscCreateUserIfUniqueAuthenticator
.
class
);
private
DirContext
ctx
=
null
;
private
DirContext
ctx
=
null
;
...
@@ -199,9 +201,19 @@ public class EoscCreateUserIfUniqueAuthenticator extends IdpCreateUserIfUniqueAu
...
@@ -199,9 +201,19 @@ public class EoscCreateUserIfUniqueAuthenticator extends IdpCreateUserIfUniqueAu
//givenName
//givenName
attributes
.
put
(
"givenName"
,
firstname
);
attributes
.
put
(
"givenName"
,
firstname
);
//uid
//uid
MessageDigest
digest
=
MessageDigest
.
getInstance
(
"SHA-256"
);
byte
[]
bytes
=
digest
.
digest
(
username
.
getBytes
(
StandardCharsets
.
UTF_8
));
StringBuilder
sb
=
new
StringBuilder
();
for
(
int
i
=
0
;
i
<
bytes
.
length
;
i
++)
{
sb
.
append
(
Integer
.
toString
((
bytes
[
i
]
&
0xff
)
+
0x100
,
16
).
substring
(
1
));
}
String
hashed_un
=
sb
.
toString
();
attributes
.
put
(
"uid"
,
username
);
attributes
.
put
(
"uid"
,
username
);
//homedir
//homedir
attributes
.
put
(
"homeDirectory"
,
"/home/"
+
username
);
attributes
.
put
(
"homeDirectory"
,
"/home/"
+
hashed_un
.
substring
(
0
,
16
));
//shadowLastChange
//shadowLastChange
attributes
.
put
(
"shadowLastChange"
,
15140
+
""
);
attributes
.
put
(
"shadowLastChange"
,
15140
+
""
);
//shadowMin
//shadowMin
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment