Add strong password check for users
[controller.git] / opendaylight / usermanager / api / src / main / java / org / opendaylight / controller / usermanager / AuthenticatedUser.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.controller.usermanager;
10
11 import java.io.Serializable;
12 import java.util.ArrayList;
13 import java.util.Date;
14 import java.util.List;
15
16 import org.opendaylight.controller.sal.authorization.UserLevel;
17 import org.springframework.security.core.GrantedAuthority;
18 import org.springframework.security.core.authority.SimpleGrantedAuthority;
19
20 /**
21  * Represents a user that was successfully authenticated and authorized
22  * It contains the user role for which the user was authorized and the
23  * date on which it was authenticated and authorized
24  */
25 public class AuthenticatedUser implements Serializable {
26     private static final long serialVersionUID = 1L;
27     private List<String> userRoles;
28     private Date accessDate;
29
30     public AuthenticatedUser(String name) {
31         userRoles = null;
32         accessDate = new Date();
33     }
34
35     public void setRoleList(List<String> roleList) {
36         this.userRoles = roleList;
37     }
38
39     public void setRoleList(String[] roleArray) {
40         userRoles = new ArrayList<String>(roleArray.length);
41         for (String role : roleArray) {
42             String target = role.trim();
43             if (!target.isEmpty()) {
44                 userRoles.add(target);
45             }
46         }
47     }
48
49     public List<String> getUserRoles() {
50         return userRoles;
51     }
52
53     public void addUserRole(String string) {
54         userRoles.add(string);
55     }
56
57     public String getAccessDate() {
58         return accessDate.toString();
59     }
60
61     public List<GrantedAuthority> getGrantedAuthorities(UserLevel usrLvl) {
62         List<GrantedAuthority> roles = new ArrayList<GrantedAuthority>();
63         roles.add(new SimpleGrantedAuthority(new ODLUserLevel(usrLvl)
64                 .getAuthority()));
65         return roles;
66     }
67
68 }