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.internal;
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.opendaylight.controller.usermanager.ODLUserLevel;
18 import org.springframework.security.core.GrantedAuthority;
19 import org.springframework.security.core.authority.SimpleGrantedAuthority;
22 * Represents a user that was successfully authenticated and authorized
23 * It contains the user role for which the user was authorized and the
24 * date on which it was authenticated and authorized
26 public class AuthenticatedUser implements Serializable {
27 private static final long serialVersionUID = 1L;
28 private List<String> userRoles;
29 private Date accessDate;
31 public AuthenticatedUser(String name) {
33 accessDate = new Date();
36 public void setRoleList(List<String> roleList) {
37 this.userRoles = roleList;
40 public void setRoleList(String[] roleArray) {
41 userRoles = new ArrayList<String>(roleArray.length);
42 for (String role : roleArray) {
47 public List<String> getUserRoles() {
51 public void addUserRole(String string) {
52 userRoles.add(string);
55 public String getAccessDate() {
56 return accessDate.toString();
59 public List<GrantedAuthority> getGrantedAuthorities(UserLevel usrLvl) {
60 List<GrantedAuthority> roles = new ArrayList<GrantedAuthority>();
61 roles.add(new SimpleGrantedAuthority(new ODLUserLevel(usrLvl)