org.apache.shiro.authc.credential.PasswordService Java Examples

The following examples show how to use org.apache.shiro.authc.credential.PasswordService. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PasswordAuthorizingRealm.java    From onedev with MIT License 6 votes vote down vote up
@Inject
  public PasswordAuthorizingRealm(UserManager userManager, SettingManager settingManager, 
  		MembershipManager membershipManager, GroupManager groupManager, 
  		ProjectManager projectManager, SessionManager sessionManager, 
  		TransactionManager transactionManager, SshKeyManager sshKeyManager, 
  		PasswordService passwordService) {
super(userManager, groupManager, projectManager, sessionManager);

   PasswordMatcher passwordMatcher = new PasswordMatcher();
   passwordMatcher.setPasswordService(passwordService);
setCredentialsMatcher(passwordMatcher);

  	this.settingManager = settingManager;
  	this.transactionManager = transactionManager;
  	this.membershipManager = membershipManager;
  	this.sshKeyManager = sshKeyManager;
  }
 
Example #2
Source File: CoreModule.java    From onedev with MIT License 6 votes vote down vote up
private void configureSecurity() {
	contributeFromPackage(Realm.class, AbstractAuthorizingRealm.class);
	
	bind(RememberMeManager.class).to(OneRememberMeManager.class);
	bind(WebSecurityManager.class).to(OneWebSecurityManager.class);
	bind(FilterChainResolver.class).to(OneFilterChainResolver.class);
	bind(BasicAuthenticationFilter.class);
	bind(BearerAuthenticationFilter.class);
	bind(PasswordService.class).to(OnePasswordService.class);
	bind(ShiroFilter.class);
	install(new ShiroAopModule());
       contribute(FilterChainConfigurator.class, new FilterChainConfigurator() {

           @Override
           public void configure(FilterChainManager filterChainManager) {
               filterChainManager.createChain("/**/info/refs", "noSessionCreation, authcBasic, authcBearer");
               filterChainManager.createChain("/**/git-upload-pack", "noSessionCreation, authcBasic, authcBearer");
               filterChainManager.createChain("/**/git-receive-pack", "noSessionCreation, authcBasic, authcBearer");
           }
           
       });
       contributeFromPackage(Authenticator.class, Authenticator.class);
}
 
Example #3
Source File: PasswordEditPanel.java    From onedev with MIT License 5 votes vote down vote up
@Override
protected void onInitialize() {
	super.onInitialize();
	
	PasswordEditBean bean = new PasswordEditBean();
	
	Set<String> excludedProperties = new HashSet<>();
	
	// in case administrator changes password we do not ask for old password
	if (SecurityUtils.isAdministrator()) 
		excludedProperties.add("oldPassword");
	
	Form<?> form = new Form<Void>("form") {

		@Override
		protected void onSubmit() {
			super.onSubmit();
			getUser().setPassword(AppLoader.getInstance(PasswordService.class).encryptPassword(bean.getNewPassword()));
			OneDev.getInstance(UserManager.class).save(getUser(), null);
			Session.get().success("Password has been changed");

			bean.setOldPassword(null);
			
			setResponsePage(getPage().getClass(), getPage().getPageParameters());
		}

	};
	add(form);
	
	form.add(BeanContext.edit("editor", bean, excludedProperties, true));
}
 
Example #4
Source File: AuthenticatingRealmImplTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void setUp() throws Exception {
  super.setUp();

  realm = (AuthenticatingRealmImpl) lookup(Realm.class, AuthenticatingRealmImpl.NAME);
  configurationManager = lookup(SecurityConfigurationManagerImpl.class);
  passwordService = lookup(PasswordService.class, "default");
}
 
Example #5
Source File: ResetAdminPassword.java    From onedev with MIT License 5 votes vote down vote up
@Inject
public ResetAdminPassword(PhysicalNamingStrategy physicalNamingStrategy, HibernateProperties properties, 
		Interceptor interceptor, IdManager idManager, Dao dao, 
		EntityValidator validator, UserManager userManager, PasswordService passwordService, 
		TransactionManager transactionManager) {
	super(physicalNamingStrategy, properties, interceptor, idManager, dao, validator, transactionManager);
	this.userManager = userManager;
	this.passwordService = passwordService;
}
 
Example #6
Source File: DefaultDataManager.java    From onedev with MIT License 5 votes vote down vote up
@Inject
public DefaultDataManager(UserManager userManager, 
		SettingManager settingManager, PersistManager persistManager, 
		MailManager mailManager, Validator validator, TaskScheduler taskScheduler, 
		PasswordService passwordService, RoleManager roleManager) {
	this.userManager = userManager;
	this.settingManager = settingManager;
	this.validator = validator;
	this.taskScheduler = taskScheduler;
	this.persistManager = persistManager;
	this.mailManager = mailManager;
	this.passwordService = passwordService;
	this.roleManager = roleManager;
}
 
Example #7
Source File: ShiroAutoConfiguration.java    From utils with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnMissingBean
public PasswordService passwordService() {
    DefaultPasswordService service = new DefaultPasswordService();

    DefaultHashService hashService = new DefaultHashService();
    hashService.setHashAlgorithmName(shiroProperties.getHashAlgorithmName());
    hashService.setHashIterations(shiroProperties.getHashIterations());
    service.setHashService(hashService);

    return service;
}
 
Example #8
Source File: RoleXOTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void configure(final Binder binder) {
  super.configure(binder);
  binder.install(new ValidationModule());
  binder.install(new WebSecurityModule(mock(ServletContext.class)));
  binder.bind(EventManager.class).toInstance(mock(EventManager.class));
  binder.bind(AnonymousManager.class).toInstance(mock(AnonymousManager.class));

  binder.bind(PasswordService.class).toInstance(mock(PasswordService.class));

  ApplicationDirectories directories = mock(ApplicationDirectories.class);
  when(directories.getWorkDirectory()).thenAnswer(i -> tmp.newFolder());
  binder.bind(ApplicationDirectories.class).toInstance(directories);
}
 
Example #9
Source File: SecurityConfigurationManagerImpl.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Inject
public SecurityConfigurationManagerImpl(final SecurityConfigurationSource configurationSource,
                                        final SecurityConfigurationCleaner configCleaner,
                                        final PasswordService passwordService,
                                        final EventManager eventManager)
{
  this.configurationSource = configurationSource;
  this.eventManager = eventManager;
  this.configCleaner = configCleaner;
  this.passwordService = passwordService;
}
 
Example #10
Source File: UserManagerImpl.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Inject
public UserManagerImpl(final EventManager eventManager,
                       final SecurityConfigurationManager configuration,
                       final SecuritySystem securitySystem,
                       final PasswordService passwordService,
                       final PasswordValidator passwordValidator)
{
  this.eventManager = checkNotNull(eventManager);
  this.configuration = configuration;
  this.securitySystem = securitySystem;
  this.passwordService = passwordService;
  this.passwordValidator = passwordValidator;
}
 
Example #11
Source File: DefaultSecurityPasswordService.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Inject
public DefaultSecurityPasswordService(@Named("legacy") final PasswordService legacyPasswordService) {
  this.passwordService = new DefaultPasswordService();
  this.legacyPasswordService = checkNotNull(legacyPasswordService);

  //Create and set a hash service according to our hashing policies
  DefaultHashService hashService = new DefaultHashService();
  hashService.setHashAlgorithmName(DEFAULT_HASH_ALGORITHM);
  hashService.setHashIterations(DEFAULT_HASH_ITERATIONS);
  hashService.setGeneratePublicSalt(true);
  this.passwordService.setHashService(hashService);
}
 
Example #12
Source File: AuthenticatingRealmImpl.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Inject
public AuthenticatingRealmImpl(
    final SecurityConfigurationManager configuration,
    final PasswordService passwordService)
{
  this.configuration = configuration;
  this.passwordService = passwordService;

  PasswordMatcher passwordMatcher = new PasswordMatcher();
  passwordMatcher.setPasswordService(this.passwordService);
  setCredentialsMatcher(passwordMatcher);
  setName(NAME);
  setAuthenticationCachingEnabled(true);
}
 
Example #13
Source File: SecurityProducer.java    From shiro-jwt with MIT License 4 votes vote down vote up
@Produces
@ShiroIni
@Named
public PasswordService passwordService() {
    return new DefaultPasswordService();
}
 
Example #14
Source File: UserManagerTest.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
@Override
protected void setUp() throws Exception {
  super.setUp();
  passwordService = lookup(PasswordService.class, "default");
}
 
Example #15
Source File: NewUserPage.java    From onedev with MIT License 4 votes vote down vote up
@Override
protected void onInitialize() {
	super.onInitialize();
	
	BeanEditor editor = BeanContext.edit("editor", user);
	
	Form<?> form = new Form<Void>("form") {

		@Override
		protected void onSubmit() {
			super.onSubmit();
			
			UserManager userManager = OneDev.getInstance(UserManager.class);
			User userWithSameName = userManager.findByName(user.getName());
			if (userWithSameName != null) {
				editor.error(new Path(new PathNode.Named("name")),
						"This name has already been used by another user.");
			} 
			User userWithSameEmail = userManager.findByEmail(user.getEmail());
			if (userWithSameEmail != null) {
				editor.error(new Path(new PathNode.Named("email")),
						"This email has already been used by another user.");
			} 
			if (editor.isValid()){
				user.setPassword(AppLoader.getInstance(PasswordService.class).encryptPassword(user.getPassword()));
				userManager.save(user, null);
				Session.get().success("New user created");
				if (continueToAdd) {
					user = new User();
					replace(BeanContext.edit("editor", user));
				} else {
					setResponsePage(UserMembershipsPage.class, UserMembershipsPage.paramsOf(user));
				}
			}
		}
		
	};
	form.add(editor);
	form.add(new CheckBox("continueToAdd", new IModel<Boolean>() {

		@Override
		public void detach() {
		}

		@Override
		public Boolean getObject() {
			return continueToAdd;
		}

		@Override
		public void setObject(Boolean object) {
			continueToAdd = object;
		}
		
	}));
	add(form);
}
 
Example #16
Source File: ForgetPage.java    From onedev with MIT License 4 votes vote down vote up
@Override
protected void onInitialize() {
	super.onInitialize();
	
	HelperBean bean = new HelperBean();
	Form<?> form = new Form<Void>("form");
	form.add(new NotificationPanel("feedback", form));		
	form.add(BeanContext.edit("editor", bean));
	
	form.add(new TaskButton("resettingPassword") {
		
		@Override
		protected String runTask(JobLogger logger) {
			UserManager userManager = OneDev.getInstance(UserManager.class);
			User user = userManager.findByName(bean.getUserNameOrEmailAddress());
			if (user == null) {
				user = userManager.findByEmail(bean.getUserNameOrEmailAddress());
			}
			if (user == null) {
				throw new OneException("No user found with name or email: " + bean.getUserNameOrEmailAddress());
			} else {
				SettingManager settingManager = OneDev.getInstance(SettingManager.class);
				if (settingManager.getMailSetting() != null) {
					String password = RandomStringUtils.random(10, true, true);								
					user.setPassword(AppLoader.getInstance(PasswordService.class).encryptPassword(password));
					userManager.save(user);
					
					MailManager mailManager = OneDev.getInstance(MailManager.class);
					
					String serverUrl = settingManager.getSystemSetting().getServerUrl();
					
					String htmlBody = String.format("Dear %s, "
						+ "<p style='margin: 16px 0;'>"
						+ "Per your request, password of your login \"%s\" at <a href=\"%s\">%s</a> has been reset to:<br>"
						+ "%s<br><br>"
						+ "Please login and change the password in your earliest convenience.",
						user.getDisplayName(), user.getName(), serverUrl, serverUrl, password);

					String textBody = String.format("Dear %s,\n\n"
							+ "Per your request, password of your login \"%s\" at %s has been reset to:\n"
							+ "%s\n\n"
							+ "Please login and change the password in your earliest convenience.",
							user.getDisplayName(), user.getName(), serverUrl, password);
					
					mailManager.sendMail(settingManager.getMailSetting(), Arrays.asList(user.getEmail()), 
							"Your OneDev password has been reset", htmlBody, textBody);
					return "Please check your email " + user.getEmail() + " for the reset password";
				} else {
					throw new OneException("Unable to send password reset email as smtp setting is not defined");
				}
			}
		}
		
	});
	
	add(form);
}
 
Example #17
Source File: RegisterPage.java    From onedev with MIT License 4 votes vote down vote up
@Override
protected void onInitialize() {
	super.onInitialize();

	final User user = new User();
	final BeanEditor editor = BeanContext.edit("editor", user);
	
	Form<?> form = new Form<Void>("form") {

		@Override
		protected void onSubmit() {
			super.onSubmit();
			
			UserManager userManager = OneDev.getInstance(UserManager.class);
			User userWithSameName = userManager.findByName(user.getName());
			if (userWithSameName != null) {
				editor.error(new Path(new PathNode.Named("name")),
						"This name has already been used by another user.");
			} 
			User userWithSameEmail = userManager.findByEmail(user.getEmail());
			if (userWithSameEmail != null) {
				editor.error(new Path(new PathNode.Named("email")),
						"This email has already been used by another user.");
			} 
			if (editor.isValid()) {
				user.setPassword(AppLoader.getInstance(PasswordService.class).encryptPassword(user.getPassword()));
				userManager.save(user, null);
				Session.get().success("New user registered");
				SecurityUtils.getSubject().runAs(user.getPrincipals());
				setResponsePage(MyAvatarPage.class);
			}
		}
		
	};
	form.add(editor);
	
	form.add(new SubmitLink("save"));
	form.add(new Link<Void>("cancel") {

		@Override
		public void onClick() {
			setResponsePage(ProjectListPage.class);
		}
		
	});
	add(form);
}