1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.syncope.core.keymaster.rest.security;
20
21 import org.apache.syncope.common.keymaster.client.api.DomainOps;
22 import org.apache.syncope.common.keymaster.client.api.KeymasterProperties;
23 import org.apache.syncope.core.provisioning.api.UserProvisioningManager;
24 import org.apache.syncope.core.spring.security.AuthDataAccessor;
25 import org.apache.syncope.core.spring.security.DefaultCredentialChecker;
26 import org.apache.syncope.core.spring.security.SecurityProperties;
27 import org.apache.syncope.core.spring.security.SyncopeAuthenticationDetails;
28 import org.apache.syncope.core.spring.security.UsernamePasswordAuthenticationProvider;
29 import org.springframework.security.core.Authentication;
30
31 public class SelfKeymasterUsernamePasswordAuthenticationProvider extends UsernamePasswordAuthenticationProvider {
32
33 protected final KeymasterProperties keymasterProperties;
34
35 public SelfKeymasterUsernamePasswordAuthenticationProvider(
36 final DomainOps domainOps,
37 final AuthDataAccessor dataAccessor,
38 final UserProvisioningManager provisioningManager,
39 final DefaultCredentialChecker credentialChecker,
40 final SecurityProperties securityProperties,
41 final KeymasterProperties keymasterProperties) {
42
43 super(domainOps, dataAccessor, provisioningManager, credentialChecker, securityProperties);
44 this.keymasterProperties = keymasterProperties;
45 }
46
47 @Override
48 public Authentication authenticate(final Authentication authentication) {
49 if (keymasterProperties.getUsername().equals(authentication.getName())) {
50 return finalizeAuthentication(
51 authentication.getCredentials().toString().equals(keymasterProperties.getPassword()),
52 SyncopeAuthenticationDetails.class.cast(authentication.getDetails()).getDomain(),
53 keymasterProperties.getUsername(),
54 null,
55 authentication);
56 }
57
58 return super.authenticate(authentication);
59 }
60 }