001/*
002 *  Copyright 2016 Anyware Services
003 *
004 *  Licensed under the Apache License, Version 2.0 (the "License");
005 *  you may not use this file except in compliance with the License.
006 *  You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 *  Unless required by applicable law or agreed to in writing, software
011 *  distributed under the License is distributed on an "AS IS" BASIS,
012 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 *  See the License for the specific language governing permissions and
014 *  limitations under the License.
015 */
016package org.ametys.core.authentication;
017
018import java.util.Map;
019
020import org.apache.avalon.framework.configuration.Configuration;
021
022import org.ametys.runtime.i18n.I18nizableText;
023import org.ametys.runtime.parameter.Parameter;
024import org.ametys.runtime.parameter.ParameterCheckerDescriptor;
025import org.ametys.runtime.parameter.ParameterHelper.ParameterType;
026
027/**
028 * Default implementation of {@link CredentialProviderModel}
029 */
030public class DefaultCredentialProviderModel implements CredentialProviderModel
031{
032    private String _id;
033    private Class<CredentialProvider> _cpClass;
034    private Configuration _cpConfig;
035    private I18nizableText _label;
036    private I18nizableText _description;
037    private I18nizableText _connectionLabel;
038    private String _iconGlyph;
039    private String _iconDecorator;
040    private String _iconSmall;
041    private String _iconMedium;
042    private String _iconLarge;
043    private String _color;
044    private Map<String, ? extends Parameter<ParameterType>> _parameters;
045    private Map<String, ? extends ParameterCheckerDescriptor> _parameterCheckers;
046    private String _pluginName;
047    
048    /**
049     * Constructor
050     * @param id The unique identifier of this credential provider model
051     * @param udClass The {@link CredentialProvider} class
052     * @param cpConfig Additional configuration for {@link CredentialProvider} class. Can be empty.
053     * @param label The i18n label
054     * @param description The i18n description
055     * @param connectionLabel The i18n label for the connection screen
056     * @param iconGlyph The CSS class for glyph icon 
057     * @param iconDecorator The CSS class for glyph decorator icon
058     * @param iconSmall The path of the small icon resource
059     * @param iconMedium The path of the medium icon resource
060     * @param iconLarge The path of the large icon resource
061     * @param color The string representation of the color which will be used for the button in the connection screen
062     * @param parameters The parameters
063     * @param parameterCheckers the parameter checkers
064     * @param pluginName The plugin's name of declaration (for debug purpose)
065     */
066    public DefaultCredentialProviderModel (String id, Class<CredentialProvider> udClass, Configuration cpConfig, I18nizableText label, I18nizableText description, I18nizableText connectionLabel, String iconGlyph, String iconDecorator, String iconSmall, String iconMedium, String iconLarge, String color, Map<String, ? extends Parameter<ParameterType>> parameters, Map<String, ? extends ParameterCheckerDescriptor> parameterCheckers, String pluginName)
067    {
068        _id = id;
069        _cpClass = udClass;
070        _cpConfig = cpConfig;
071        _label = label;
072        _description = description;
073        _connectionLabel = connectionLabel;
074        _iconGlyph = iconGlyph;
075        _iconDecorator = iconDecorator;
076        _iconSmall = iconSmall;
077        _iconLarge = iconLarge;
078        _color = color;
079        _parameters = parameters;
080        _parameterCheckers = parameterCheckers;
081        _pluginName = pluginName;
082    }
083    
084    @Override
085    public String getId()
086    {
087        return _id;
088    }
089    
090    @Override
091    public I18nizableText getLabel()
092    {
093        return _label;
094    }
095    
096    @Override
097    public I18nizableText getDescription()
098    {
099        return _description;
100    }
101    
102    @Override
103    public I18nizableText getConnectionLabel()
104    {
105        return _connectionLabel;
106    }
107
108    @Override
109    public String getIconGlyph()
110    {
111        return _iconGlyph;
112    }
113
114    @Override
115    public String getIconDecorator()
116    {
117        return _iconDecorator;
118    }
119
120    @Override
121    public String getIconSmall()
122    {
123        return _iconSmall;
124    }
125
126    @Override
127    public String getIconMedium()
128    {
129        return _iconMedium;
130    }
131
132    @Override
133    public String getIconLarge()
134    {
135        return _iconLarge;
136    }
137
138    @Override
139    public String getColor()
140    {
141        return _color;
142    }
143
144    @Override
145    public Map<String, ? extends Parameter<ParameterType>> getParameters()
146    {
147        return _parameters;
148    }
149    
150    @Override
151    public Map<String, ? extends ParameterCheckerDescriptor> getParameterCheckers()
152    {
153        return _parameterCheckers;
154    }
155    
156    @Override
157    public String getPluginName()
158    {
159        return _pluginName;
160    }
161    
162    @Override
163    public Class<CredentialProvider> getCredentialProviderClass()
164    {
165        return _cpClass;
166    }
167    
168    @Override
169    public Configuration getCredentialProviderConfiguration ()
170    {
171        return _cpConfig;
172    }
173
174}