In this paper we propose and study a continuous time stochastic model of optimal allocation for a defined contribution pension fund in the accumulation phase. The level of wealth is constrained to stay above a "solvency level". The fund manager can invest in a riskless asset and in a risky asset, but borrowing and short selling are prohibited. The model is naturally formulated as an optimal stochastic control problem with state constraints and is treated by the dynamic programming approach. We show that the value function of the problem is a continuous viscosity solution of the associated Hamilton-Jacobi-Bellman equation. In the special case when the boundary is absorbing we show that it is the unique viscosity solution of the Hamilton-Jacobi-Bellman equation.