2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.controller.usermanager;
11 import java.io.Serializable;
12 import java.util.ArrayList;
13 import java.util.Date;
14 import java.util.List;
16 import org.opendaylight.controller.sal.authorization.UserLevel;
17 import org.springframework.security.core.GrantedAuthority;
18 import org.springframework.security.core.authority.SimpleGrantedAuthority;
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
25 public class AuthenticatedUser implements Serializable {
26 private static final long serialVersionUID = 1L;
27 private List<String> userRoles;
28 private Date accessDate;
30 public AuthenticatedUser(String name) {
32 accessDate = new Date();
35 public void setRoleList(List<String> roleList) {
36 this.userRoles = roleList;
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);
49 public List<String> getUserRoles() {
53 public void addUserRole(String string) {
54 userRoles.add(string);
57 public String getAccessDate() {
58 return accessDate.toString();
61 public List<GrantedAuthority> getGrantedAuthorities(UserLevel usrLvl) {
62 List<GrantedAuthority> roles = new ArrayList<GrantedAuthority>();
63 roles.add(new SimpleGrantedAuthority(new ODLUserLevel(usrLvl)