1 package org.apache.archiva.rest.api.model.v2;/*
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
10 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing,
12 * software distributed under the License is distributed on an
13 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 * KIND, either express or implied. See the License for the
15 * specific language governing permissions and limitations
19 import io.swagger.v3.oas.annotations.media.Schema;
20 import org.apache.archiva.admin.model.beans.RedbackRuntimeConfiguration;
22 import javax.xml.bind.annotation.XmlRootElement;
23 import java.io.Serializable;
24 import java.util.ArrayList;
25 import java.util.List;
27 import java.util.TreeMap;
30 * @author Martin Stockhammer <martin_s@apache.org>
32 @XmlRootElement(name = "securityConfiguration")
33 @Schema(name = "SecurityConfiguration", description = "Security configuration attributes.")
34 public class SecurityConfiguration implements Serializable
36 private static final long serialVersionUID = -4186866365979053029L;
38 private final List<String> activeUserManagers = new ArrayList<>( );
39 private final List<String> activeRbacManagers = new ArrayList<>( );
40 private final Map<String,String> properties = new TreeMap<>( );
41 private boolean userCacheEnabled=false;
42 private boolean ldapActive=false;
44 public SecurityConfiguration() {
48 public static SecurityConfiguration ofRedbackConfiguration( RedbackRuntimeConfiguration configuration ) {
49 SecurityConfiguration secConfig = new SecurityConfiguration( );
50 secConfig.setActiveRbacManagers( configuration.getRbacManagerImpls() );
51 secConfig.setActiveUserManagers( configuration.getUserManagerImpls() );
52 secConfig.setProperties( configuration.getConfigurationProperties() );
53 boolean rbLdapActive = configuration.getUserManagerImpls( ).stream( ).anyMatch( um -> um.contains( "ldap" ) );
54 secConfig.setLdapActive( rbLdapActive );
55 secConfig.setUserCacheEnabled( configuration.isUseUsersCache() );
59 @Schema(name="active_user_managers", description = "List of ids of the active user managers")
60 public List<String> getActiveUserManagers( )
62 return activeUserManagers;
65 public void setActiveUserManagers( List<String> activeUserManagers )
67 this.activeUserManagers.clear();
68 this.activeUserManagers.addAll( activeUserManagers );
71 public void addSelectedUserManager(String userManager) {
72 this.activeUserManagers.add( userManager );
75 @Schema(name="active_rbac_managers", description = "List of ids of the active rbac managers")
76 public List<String> getActiveRbacManagers( )
78 return activeRbacManagers;
81 public void setActiveRbacManagers( List<String> activeRbacManagers )
83 this.activeRbacManagers.clear();
84 this.activeRbacManagers.addAll( activeRbacManagers );
87 public void addSelectedRbacManager(String rbacManager) {
88 this.activeRbacManagers.add( rbacManager );
91 @Schema(description = "Map of all security properties")
92 public Map<String, String> getProperties( )
97 public void setProperties( Map<String, String> properties )
99 this.properties.clear();
100 this.properties.putAll( properties );
103 @Schema(name="user_cache_enabled", description = "True, if the user cache is active. It caches data from user backend.")
104 public boolean isUserCacheEnabled( )
106 return userCacheEnabled;
109 public void setUserCacheEnabled( boolean userCacheEnabled )
111 this.userCacheEnabled = userCacheEnabled;
114 @Schema(name="ldap_active", description = "True, if LDAP is used as user manager")
115 public boolean isLdapActive( )
120 public void setLdapActive( boolean ldapActive )
122 this.ldapActive = ldapActive;
126 public boolean equals( Object o )
128 if ( this == o ) return true;
129 if ( o == null || getClass( ) != o.getClass( ) ) return false;
131 SecurityConfiguration that = (SecurityConfiguration) o;
133 if ( userCacheEnabled != that.userCacheEnabled ) return false;
134 if ( ldapActive != that.ldapActive ) return false;
135 if ( !activeUserManagers.equals( that.activeUserManagers ) ) return false;
136 if ( !activeRbacManagers.equals( that.activeRbacManagers ) ) return false;
137 return properties.equals( that.properties );
141 public int hashCode( )
143 int result = activeUserManagers.hashCode( );
144 result = 31 * result + activeRbacManagers.hashCode( );
145 result = 31 * result + properties.hashCode( );
146 result = 31 * result + ( userCacheEnabled ? 1 : 0 );
147 result = 31 * result + ( ldapActive ? 1 : 0 );
151 @SuppressWarnings( "StringBufferReplaceableByString" )
153 public String toString( )
155 final StringBuilder sb = new StringBuilder( "SecurityConfiguration{" );
156 sb.append( "active_user_managers=" ).append( activeUserManagers );
157 sb.append( ", active_rbac_managers=" ).append( activeRbacManagers );
158 sb.append( ", properties=" ).append( properties );
159 sb.append( ", user_cache_nabled=" ).append( userCacheEnabled );
160 sb.append( ", ldap_active=" ).append( ldapActive );
162 return sb.toString( );