start moving configuration keys to a constant class
git-svn-id: https://svn.apache.org/repos/asf/archiva/redback/redback-core/trunk@1417395 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
59dd656a88
commit
eef9c73382
@ -0,0 +1,53 @@
|
||||
package org.apache.archiva.redback.configuration;
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @author Olivier Lamy
|
||||
* @since 2.1
|
||||
*/
|
||||
public interface UserConfigurationKeys
|
||||
{
|
||||
static final String USER_MANAGER_IMPL = "user.manager.impl";
|
||||
|
||||
static final String DEFAULT_ADMIN = "redback.default.admin";
|
||||
|
||||
static final String EMAIL_FROM_ADDRESS = "email.from.address";
|
||||
|
||||
static final String EMAIL_FROM_NAME = "email.from.name";
|
||||
|
||||
static final String EMAIL_FEEDBACK_PATH = "email.feedback.path";
|
||||
|
||||
static final String APPLICATION_TIMESTAMP = "application.timestamp";
|
||||
|
||||
static final String PASSWORD_ENCODER = "security.policy.password.encoder";
|
||||
|
||||
|
||||
static final String EMAIL_VALIDATION_SUBJECT = "email.validation.subject";
|
||||
|
||||
static final String REMEMBER_ME_PATH = "security.rememberme.path";
|
||||
|
||||
static final String REMEMBER_ME_DOMAIN = "security.rememberme.domain";
|
||||
|
||||
static final String SIGNON_DOMAIN = "security.signon.domain";
|
||||
|
||||
static final String SIGNON_PATH = "security.signon.path";
|
||||
|
||||
static final String USER_MANAGER_IMPL = "user.manager.impl";
|
||||
}
|
@ -21,6 +21,7 @@
|
||||
|
||||
import org.apache.archiva.redback.authentication.PasswordBasedAuthenticationDataSource;
|
||||
import org.apache.archiva.redback.configuration.UserConfiguration;
|
||||
import org.apache.archiva.redback.configuration.UserConfigurationKeys;
|
||||
import org.apache.archiva.redback.rbac.RBACManager;
|
||||
import org.apache.archiva.redback.role.RoleManager;
|
||||
import org.apache.archiva.redback.role.RoleManagerException;
|
||||
@ -48,7 +49,7 @@
|
||||
* @author Olivier Lamy
|
||||
* @since 2.0
|
||||
*/
|
||||
@Service ("environmentCheck#adminAutoCreateCheck")
|
||||
@Service( "environmentCheck#adminAutoCreateCheck" )
|
||||
public class AdminAutoCreateCheck
|
||||
implements EnvironmentCheck
|
||||
{
|
||||
@ -64,7 +65,7 @@ public class AdminAutoCreateCheck
|
||||
public static final String ADMIN_PASSWORD_KEY = "redback.admin.password";
|
||||
|
||||
@Inject
|
||||
@Named (value = "userManager#configurable")
|
||||
@Named( value = "userManager#configurable" )
|
||||
private UserManager userManager;
|
||||
|
||||
@Inject
|
||||
@ -77,7 +78,7 @@ public class AdminAutoCreateCheck
|
||||
private RoleManager roleManager;
|
||||
|
||||
@Inject
|
||||
@Named (value = "rBACManager#cached")
|
||||
@Named( value = "rBACManager#cached" )
|
||||
private RBACManager rbacManager;
|
||||
|
||||
public void validateEnvironment( List<String> violations )
|
||||
@ -193,6 +194,6 @@ private void assignAdminRole( User user )
|
||||
|
||||
private String getAdminUid()
|
||||
{
|
||||
return config.getString( "redback.default.admin" );
|
||||
return config.getString( UserConfigurationKeys.DEFAULT_ADMIN );
|
||||
}
|
||||
}
|
||||
|
@ -34,6 +34,7 @@
|
||||
import javax.mail.internet.MimeMessage;
|
||||
|
||||
import org.apache.archiva.redback.configuration.UserConfiguration;
|
||||
import org.apache.archiva.redback.configuration.UserConfigurationKeys;
|
||||
import org.apache.archiva.redback.keys.AuthenticationKey;
|
||||
import org.apache.archiva.redback.policy.UserSecurityPolicy;
|
||||
import org.apache.archiva.redback.policy.UserValidationSettings;
|
||||
@ -48,24 +49,26 @@
|
||||
* Mailer
|
||||
*
|
||||
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
|
||||
*
|
||||
*/
|
||||
@Service("mailer")
|
||||
@Service( "mailer" )
|
||||
public class MailerImpl
|
||||
implements Mailer
|
||||
{
|
||||
protected Logger log = LoggerFactory.getLogger( getClass() );
|
||||
|
||||
@Inject @Named(value="mailGenerator#velocity")
|
||||
|
||||
@Inject
|
||||
@Named( value = "mailGenerator#velocity" )
|
||||
private MailGenerator generator;
|
||||
|
||||
@Inject @Named(value="mailSender")
|
||||
@Inject
|
||||
@Named( value = "mailSender" )
|
||||
private JavaMailSender javaMailSender;
|
||||
|
||||
@Inject
|
||||
private SecuritySystem securitySystem;
|
||||
|
||||
@Inject @Named(value="userConfiguration")
|
||||
@Inject
|
||||
@Named( value = "userConfiguration" )
|
||||
private UserConfiguration config;
|
||||
|
||||
public void sendAccountValidationEmail( Collection<String> recipients, AuthenticationKey authkey, String baseUrl )
|
||||
@ -94,23 +97,21 @@ public void sendMessage( Collection<String> recipients, String subject, String c
|
||||
return;
|
||||
}
|
||||
|
||||
String fromAddress = config.getString( "email.from.address" );
|
||||
String fromName = config.getString( "email.from.name" );
|
||||
String fromAddress = config.getString( UserConfigurationKeys.EMAIL_FROM_ADDRESS );
|
||||
String fromName = config.getString( UserConfigurationKeys.EMAIL_FROM_NAME );
|
||||
|
||||
if ( StringUtils.isEmpty( fromAddress ) )
|
||||
{
|
||||
fromAddress = System.getProperty( "user.name" ) + "@localhost";
|
||||
}
|
||||
|
||||
|
||||
|
||||
// TODO: Allow for configurable message headers.
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
|
||||
MimeMessage message = javaMailSender.createMimeMessage();
|
||||
|
||||
|
||||
message.setSubject( subject );
|
||||
message.setText( content );
|
||||
|
||||
@ -119,17 +120,17 @@ public void sendMessage( Collection<String> recipients, String subject, String c
|
||||
message.setFrom( from );
|
||||
|
||||
List<Address> tos = new ArrayList<Address>();
|
||||
|
||||
|
||||
for ( String mailbox : recipients )
|
||||
{
|
||||
InternetAddress to = new InternetAddress( mailbox.trim() );
|
||||
|
||||
tos.add( to );
|
||||
tos.add( to );
|
||||
}
|
||||
|
||||
message.setRecipients(Message.RecipientType.TO, tos.toArray(new Address[tos.size()]));
|
||||
message.setRecipients( Message.RecipientType.TO, tos.toArray( new Address[tos.size()] ) );
|
||||
|
||||
log.debug("mail content {}", content );
|
||||
log.debug( "mail content {}", content );
|
||||
|
||||
javaMailSender.send( message );
|
||||
}
|
||||
@ -140,10 +141,10 @@ public void sendMessage( Collection<String> recipients, String subject, String c
|
||||
catch ( MessagingException e )
|
||||
{
|
||||
log.error( "Unable to send message, subject [" + subject + "]", e );
|
||||
}
|
||||
}
|
||||
catch ( UnsupportedEncodingException e )
|
||||
{
|
||||
log.error( "Unable to send message, subject [" + subject + "]", e );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,6 +20,7 @@
|
||||
*/
|
||||
|
||||
import org.apache.archiva.redback.configuration.UserConfiguration;
|
||||
import org.apache.archiva.redback.configuration.UserConfigurationKeys;
|
||||
import org.apache.archiva.redback.keys.AuthenticationKey;
|
||||
import org.apache.velocity.VelocityContext;
|
||||
import org.apache.velocity.app.VelocityEngine;
|
||||
@ -40,21 +41,20 @@
|
||||
* Mail generator component implementation using velocity.
|
||||
*
|
||||
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
|
||||
*
|
||||
*/
|
||||
@Service( "mailGenerator#velocity" )
|
||||
@Service("mailGenerator#velocity")
|
||||
public class VelocityMailGenerator
|
||||
implements MailGenerator
|
||||
{
|
||||
private Logger log = LoggerFactory.getLogger( VelocityMailGenerator.class );
|
||||
|
||||
@Inject
|
||||
@Named( value = "userConfiguration" )
|
||||
@Named(value = "userConfiguration")
|
||||
private UserConfiguration config;
|
||||
|
||||
// FIXME use the spring directly
|
||||
@Inject
|
||||
@Named( value = "velocityEngine#redback" )
|
||||
@Named(value = "velocityEngine#redback")
|
||||
private VelocityEngine velocityEngine;
|
||||
|
||||
public String generateMail( String templateName, AuthenticationKey authkey, String baseUrl )
|
||||
@ -96,7 +96,7 @@ private VelocityContext createVelocityContext( AuthenticationKey authkey, String
|
||||
|
||||
context.put( "applicationUrl", config.getString( "application.url", appUrl ) );
|
||||
|
||||
String feedback = config.getString( "email.feedback.path" );
|
||||
String feedback = config.getString( UserConfigurationKeys.EMAIL_FEEDBACK_PATH );
|
||||
|
||||
if ( feedback != null )
|
||||
{
|
||||
@ -114,7 +114,8 @@ private VelocityContext createVelocityContext( AuthenticationKey authkey, String
|
||||
|
||||
context.put( "accountId", authkey.getForPrincipal() );
|
||||
|
||||
SimpleDateFormat dateformatter = new SimpleDateFormat( config.getString( "application.timestamp" ), Locale.US );
|
||||
SimpleDateFormat dateformatter =
|
||||
new SimpleDateFormat( config.getString( UserConfigurationKeys.APPLICATION_TIMESTAMP ), Locale.US );
|
||||
|
||||
context.put( "requestedOn", dateformatter.format( authkey.getDateCreated() ) );
|
||||
|
||||
|
@ -24,6 +24,7 @@
|
||||
import org.apache.archiva.redback.authentication.TokenBasedAuthenticationDataSource;
|
||||
import org.apache.archiva.redback.components.cache.Cache;
|
||||
import org.apache.archiva.redback.configuration.UserConfiguration;
|
||||
import org.apache.archiva.redback.configuration.UserConfigurationKeys;
|
||||
import org.apache.archiva.redback.integration.filter.authentication.HttpAuthenticator;
|
||||
import org.apache.archiva.redback.integration.mail.Mailer;
|
||||
import org.apache.archiva.redback.integration.security.role.RedbackRoleConstants;
|
||||
@ -493,7 +494,7 @@ public Boolean isAdminUserExists()
|
||||
{
|
||||
try
|
||||
{
|
||||
userManager.findUser( config.getString( "redback.default.admin" ) );
|
||||
userManager.findUser( config.getString( UserConfigurationKeys.DEFAULT_ADMIN ) );
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
catch ( UserNotFoundException e )
|
||||
@ -609,7 +610,7 @@ public RegistrationKey registerUser( UserRegistrationRequest userRegistrationReq
|
||||
baseUrl = getBaseUrl();
|
||||
}
|
||||
|
||||
log.debug("register user {} with email {} and app url {}", u.getUsername(), u.getEmail(), baseUrl);
|
||||
log.debug( "register user {} with email {} and app url {}", u.getUsername(), u.getEmail(), baseUrl );
|
||||
|
||||
mailer.sendAccountValidationEmail( Arrays.asList( u.getEmail() ), authkey, baseUrl );
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
*/
|
||||
|
||||
import org.apache.archiva.redback.configuration.UserConfiguration;
|
||||
import org.apache.archiva.redback.configuration.UserConfigurationKeys;
|
||||
import org.apache.archiva.redback.users.User;
|
||||
import org.apache.archiva.redback.policy.rules.MustHavePasswordRule;
|
||||
import org.slf4j.Logger;
|
||||
@ -39,7 +40,6 @@
|
||||
* User Security Policy.
|
||||
*
|
||||
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
|
||||
*
|
||||
*/
|
||||
@Service( "userSecurityPolicy" )
|
||||
public class DefaultUserSecurityPolicy
|
||||
@ -55,7 +55,6 @@ public class DefaultUserSecurityPolicy
|
||||
|
||||
public static final String PASSWORD_EXPIRATION = "security.policy.password.expiration.days";
|
||||
|
||||
public static final String PASSWORD_ENCODER = "security.policy.password.encoder";
|
||||
|
||||
public static final String UNLOCKABLE_ACCOUNTS = "security.policy.unlockable.accounts";
|
||||
|
||||
@ -132,7 +131,7 @@ public void initialize()
|
||||
|
||||
private void configureEncoder()
|
||||
{
|
||||
String encoder = config.getString( PASSWORD_ENCODER );
|
||||
String encoder = config.getString( UserConfigurationKeys.PASSWORD_ENCODER );
|
||||
|
||||
if ( encoder != null )
|
||||
{
|
||||
|
@ -20,6 +20,7 @@
|
||||
*/
|
||||
|
||||
import org.apache.archiva.redback.configuration.UserConfiguration;
|
||||
import org.apache.archiva.redback.configuration.UserConfigurationKeys;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
@ -29,13 +30,12 @@
|
||||
* DefaultUserValidationSettings
|
||||
*
|
||||
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
|
||||
*
|
||||
*/
|
||||
@Service("userValidationSettings")
|
||||
@Service( "userValidationSettings" )
|
||||
public class DefaultUserValidationSettings
|
||||
implements UserValidationSettings
|
||||
{
|
||||
@Resource (name="userConfiguration")
|
||||
@Resource( name = "userConfiguration" )
|
||||
private UserConfiguration config;
|
||||
|
||||
private boolean emailValidationRequired;
|
||||
@ -64,6 +64,6 @@ public void initialize()
|
||||
{
|
||||
this.emailValidationRequired = config.getBoolean( "email.validation.required" );
|
||||
this.emailValidationTimeout = config.getInt( "email.validation.timeout" );
|
||||
this.emailSubject = config.getString( "email.validation.subject" );
|
||||
this.emailSubject = config.getString( UserConfigurationKeys.EMAIL_VALIDATION_SUBJECT );
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,7 @@
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import org.apache.archiva.redback.configuration.UserConfigurationKeys;
|
||||
import org.apache.archiva.redback.policy.AbstractCookieSettings;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@ -28,9 +29,8 @@
|
||||
* RememberMeCookieSettings
|
||||
*
|
||||
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
|
||||
*
|
||||
*/
|
||||
@Service("cookieSettings#rememberMe")
|
||||
@Service( "cookieSettings#rememberMe" )
|
||||
public class RememberMeCookieSettings
|
||||
extends AbstractCookieSettings
|
||||
{
|
||||
@ -45,8 +45,8 @@ public boolean isEnabled()
|
||||
public void initialize()
|
||||
{
|
||||
this.cookieTimeout = config.getInt( "security.rememberme.timeout" );
|
||||
this.domain = config.getString( "security.rememberme.domain" );
|
||||
this.path = config.getString( "security.rememberme.path" );
|
||||
this.domain = config.getString( UserConfigurationKeys.REMEMBER_ME_DOMAIN );
|
||||
this.path = config.getString( UserConfigurationKeys.REMEMBER_ME_PATH );
|
||||
this.enabled = config.getBoolean( "security.rememberme.enabled" );
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,7 @@
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import org.apache.archiva.redback.configuration.UserConfigurationKeys;
|
||||
import org.apache.archiva.redback.policy.AbstractCookieSettings;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@ -28,9 +29,8 @@
|
||||
* SignonCookieSettings
|
||||
*
|
||||
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
|
||||
*
|
||||
*/
|
||||
@Service("cookieSettings#signon")
|
||||
@Service( "cookieSettings#signon" )
|
||||
public class SignonCookieSettings
|
||||
extends AbstractCookieSettings
|
||||
{
|
||||
@ -39,8 +39,8 @@ public void initialize()
|
||||
{
|
||||
// cookie timeouts in the configuration settings is labeled to be in minutes, so adjust to minutes
|
||||
cookieTimeout = config.getInt( "security.signon.timeout" ) * 60;
|
||||
domain = config.getString( "security.signon.domain" );
|
||||
path = config.getString( "security.signon.path" );
|
||||
domain = config.getString( UserConfigurationKeys.SIGNON_DOMAIN );
|
||||
path = config.getString( UserConfigurationKeys.SIGNON_PATH );
|
||||
}
|
||||
|
||||
public boolean isEnabled()
|
||||
|
@ -17,6 +17,7 @@
|
||||
*/
|
||||
|
||||
import org.apache.archiva.redback.configuration.UserConfiguration;
|
||||
import org.apache.archiva.redback.configuration.UserConfigurationKeys;
|
||||
import org.apache.archiva.redback.users.AbstractUserManager;
|
||||
import org.apache.archiva.redback.users.User;
|
||||
import org.apache.archiva.redback.users.UserManager;
|
||||
@ -47,17 +48,16 @@ public class ConfigurableUserManager
|
||||
|
||||
private UserManager userManagerImpl;
|
||||
|
||||
public static final String USER_MANAGER_IMPL = "user.manager.impl";
|
||||
|
||||
@PostConstruct
|
||||
public void initialize()
|
||||
{
|
||||
String userManagerRole = config.getString( USER_MANAGER_IMPL );
|
||||
String userManagerRole = config.getString();
|
||||
|
||||
if ( userManagerRole == null )
|
||||
{
|
||||
throw new RuntimeException(
|
||||
"User Manager Configuration Missing: " + USER_MANAGER_IMPL + " configuration property" );
|
||||
throw new RuntimeException( "User Manager Configuration Missing: " + UserConfigurationKeys.USER_MANAGER_IMPL
|
||||
+ " configuration property" );
|
||||
}
|
||||
|
||||
log.info( "use userManager impl with key: '{}'", userManagerRole );
|
||||
|
Loading…
x
Reference in New Issue
Block a user