1 package org.apache.archiva.rest.api.v2.model;/*
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
20 * Licensed to the Apache Software Foundation (ASF) under one
21 * or more contributor license agreements. See the NOTICE file
22 * distributed with this work for additional information
23 * regarding copyright ownership. The ASF licenses this file
24 * to you under the Apache License, Version 2.0 (the
25 * "License"); you may not use this file except in compliance
26 * with the License. You may obtain a copy of the License at
28 * http://www.apache.org/licenses/LICENSE-2.0
29 * Unless required by applicable law or agreed to in writing,
30 * software distributed under the License is distributed on an
31 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
32 * KIND, either express or implied. See the License for the
33 * specific language governing permissions and limitations
37 import io.swagger.v3.oas.annotations.media.Schema;
38 import org.apache.archiva.admin.model.beans.RedbackRuntimeConfiguration;
40 import javax.xml.bind.annotation.XmlRootElement;
41 import java.io.Serializable;
42 import java.util.ArrayList;
43 import java.util.List;
45 import java.util.TreeMap;
48 * @author Martin Stockhammer <martin_s@apache.org>
50 @XmlRootElement(name = "securityConfiguration")
51 @Schema(name = "SecurityConfiguration", description = "Security configuration attributes.")
52 public class SecurityConfiguration implements Serializable
54 private static final long serialVersionUID = -4186866365979053029L;
56 private List<String> activeUserManagers = new ArrayList<>( );
57 private List<String> activeRbacManagers = new ArrayList<>( );
58 private Map<String,String> properties = new TreeMap<>( );
59 private boolean userCacheEnabled=false;
60 private boolean ldapActive=false;
62 public SecurityConfiguration() {
66 public static SecurityConfiguration ofRedbackConfiguration( RedbackRuntimeConfiguration configuration ) {
67 SecurityConfiguration secConfig = new SecurityConfiguration( );
68 secConfig.setActiveRbacManagers( configuration.getRbacManagerImpls() );
69 secConfig.setActiveUserManagers( configuration.getUserManagerImpls() );
70 secConfig.setProperties( configuration.getConfigurationProperties() );
71 boolean rbLdapActive = configuration.getUserManagerImpls( ).stream( ).anyMatch( um -> um.contains( "ldap" ) );
72 secConfig.setLdapActive( rbLdapActive );
73 secConfig.setUserCacheEnabled( configuration.isUseUsersCache() );
77 @Schema(name="active_user_managers", description = "List of ids of the active user managers")
78 public List<String> getActiveUserManagers( )
80 return activeUserManagers;
83 public void setActiveUserManagers( List<String> activeUserManagers )
85 this.activeUserManagers = new ArrayList<>( activeUserManagers );
88 public void addSelectedUserManager(String userManager) {
89 this.activeUserManagers.add( userManager );
92 @Schema(name="active_rbac_managers", description = "List of ids of the active rbac managers")
93 public List<String> getActiveRbacManagers( )
95 return activeRbacManagers;
98 public void setActiveRbacManagers( List<String> activeRbacManagers )
100 this.activeRbacManagers = new ArrayList<>( activeRbacManagers );
103 public void addSelectedRbacManager(String rbacManager) {
104 this.activeRbacManagers.add( rbacManager );
107 @Schema(description = "Map of all security properties")
108 public Map<String, String> getProperties( )
113 public void setProperties( Map<String, String> properties )
115 this.properties = new TreeMap<>( properties );
118 @Schema(name="user_cache_enabled", description = "True, if the user cache is active. It caches data from user backend.")
119 public boolean isUserCacheEnabled( )
121 return userCacheEnabled;
124 public void setUserCacheEnabled( boolean userCacheEnabled )
126 this.userCacheEnabled = userCacheEnabled;
129 @Schema(name="ldap_active", description = "True, if LDAP is used as user manager")
130 public boolean isLdapActive( )
135 public void setLdapActive( boolean ldapActive )
137 this.ldapActive = ldapActive;
141 public boolean equals( Object o )
143 if ( this == o ) return true;
144 if ( o == null || getClass( ) != o.getClass( ) ) return false;
146 SecurityConfiguration that = (SecurityConfiguration) o;
148 if ( userCacheEnabled != that.userCacheEnabled ) return false;
149 if ( ldapActive != that.ldapActive ) return false;
150 if ( !activeUserManagers.equals( that.activeUserManagers ) ) return false;
151 if ( !activeRbacManagers.equals( that.activeRbacManagers ) ) return false;
152 return properties.equals( that.properties );
156 public int hashCode( )
158 int result = activeUserManagers.hashCode( );
159 result = 31 * result + activeRbacManagers.hashCode( );
160 result = 31 * result + properties.hashCode( );
161 result = 31 * result + ( userCacheEnabled ? 1 : 0 );
162 result = 31 * result + ( ldapActive ? 1 : 0 );
166 @SuppressWarnings( "StringBufferReplaceableByString" )
168 public String toString( )
170 final StringBuilder sb = new StringBuilder( "SecurityConfiguration{" );
171 sb.append( "active_user_managers=" ).append( activeUserManagers );
172 sb.append( ", active_rbac_managers=" ).append( activeRbacManagers );
173 sb.append( ", properties=" ).append( properties );
174 sb.append( ", user_cache_enabled=" ).append( userCacheEnabled );
175 sb.append( ", ldap_active=" ).append( ldapActive );
177 return sb.toString( );