View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
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  }