|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| SecurityUtils | Line # 22 | 18 | 0% | 7 | 24 | 20% |
0.2
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (15) | |||
| Result | |||
|
0.2
|
org.kuali.student.core.comment.service.impl.TestCommentServiceImpl.testCommentCrud
org.kuali.student.core.comment.service.impl.TestCommentServiceImpl.testCommentCrud
|
1 PASS | |
|
0.2
|
org.kuali.student.core.comment.service.impl.TestCommentServiceImpl.testCreateDeleteTags
org.kuali.student.core.comment.service.impl.TestCommentServiceImpl.testCreateDeleteTags
|
1 PASS | |
|
0.2
|
org.kuali.student.core.organization.dao.TestOrganizationDao.testDeleteOrganizationByReference
org.kuali.student.core.organization.dao.TestOrganizationDao.testDeleteOrganizationByReference
|
1 PASS | |
|
0.2
|
org.kuali.student.core.document.service.impl.TestDocumentServiceImpl.testDocumentCrud
org.kuali.student.core.document.service.impl.TestDocumentServiceImpl.testDocumentCrud
|
1 PASS | |
|
0.2
|
org.kuali.student.core.organization.dao.TestOrganizationDao.testCreateOrganization
org.kuali.student.core.organization.dao.TestOrganizationDao.testCreateOrganization
|
1 PASS | |
|
0.2
|
org.kuali.student.core.organization.service.impl.TestOrganizationServiceImpl.testAddPositionRestriction
org.kuali.student.core.organization.service.impl.TestOrganizationServiceImpl.testAddPositionRestriction
|
1 PASS | |
|
0.2
|
org.kuali.student.core.organization.service.impl.TestOrganizationServiceImpl.testCreateDeleteOrgPersonRelation
org.kuali.student.core.organization.service.impl.TestOrganizationServiceImpl.testCreateDeleteOrgPersonRelation
|
1 PASS | |
|
0.2
|
org.kuali.student.core.proposal.service.impl.TestProposalServiceImpl.proposalCrud
org.kuali.student.core.proposal.service.impl.TestProposalServiceImpl.proposalCrud
|
1 PASS | |
|
0.2
|
org.kuali.student.core.document.service.impl.TestDocumentServiceImpl.testDocRelationsCrud
org.kuali.student.core.document.service.impl.TestDocumentServiceImpl.testDocRelationsCrud
|
1 PASS | |
|
0.2
|
org.kuali.student.core.comment.service.impl.TestCommentServiceImpl.testCommentsRemove
org.kuali.student.core.comment.service.impl.TestCommentServiceImpl.testCommentsRemove
|
1 PASS | |
|
0.2
|
org.kuali.student.core.organization.dao.TestOrganizationDao.testDeleteOrganizationByKey
org.kuali.student.core.organization.dao.TestOrganizationDao.testDeleteOrganizationByKey
|
1 PASS | |
|
0.2
|
org.kuali.student.core.document.service.impl.TestDocumentServiceImpl.testDocument
org.kuali.student.core.document.service.impl.TestDocumentServiceImpl.testDocument
|
1 PASS | |
|
0.2
|
org.kuali.student.core.atp.TestAtpService.TestCreateUpdateDelete
org.kuali.student.core.atp.TestAtpService.TestCreateUpdateDelete
|
1 PASS | |
|
0.2
|
org.kuali.student.core.comment.service.impl.TestCommentServiceImpl.testCreateDeleteTag
org.kuali.student.core.comment.service.impl.TestCommentServiceImpl.testCreateDeleteTag
|
1 PASS | |
|
0.2
|
org.kuali.student.core.organization.service.impl.TestOrganizationServiceImpl.testCreateUpdateOrg
org.kuali.student.core.organization.service.impl.TestOrganizationServiceImpl.testCreateUpdateOrg
|
1 PASS | |
| 1 | /** | |
| 2 | * Copyright 2010 The Kuali Foundation Licensed under the | |
| 3 | * Educational Community License, Version 2.0 (the "License"); you may | |
| 4 | * not use this file except in compliance with the License. You may | |
| 5 | * obtain a copy of the License at | |
| 6 | * | |
| 7 | * http://www.osedu.org/licenses/ECL-2.0 | |
| 8 | * | |
| 9 | * Unless required by applicable law or agreed to in writing, | |
| 10 | * software distributed under the License is distributed on an "AS IS" | |
| 11 | * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | |
| 12 | * or implied. See the License for the specific language governing | |
| 13 | * permissions and limitations under the License. | |
| 14 | */ | |
| 15 | ||
| 16 | package org.kuali.student.common.util.security; | |
| 17 | ||
| 18 | import org.springframework.security.Authentication; | |
| 19 | import org.springframework.security.context.SecurityContextHolder; | |
| 20 | import org.springframework.security.userdetails.UserDetails; | |
| 21 | ||
| 22 | public class SecurityUtils { | |
| 23 | ||
| 24 | /** | |
| 25 | * This can be used to get the current user id from security context | |
| 26 | * | |
| 27 | * @return userId | |
| 28 | */ | |
| 29 | 48 |
public static String getCurrentUserId() { |
| 30 | 48 | String username=null; |
| 31 | 48 | Authentication auth = SecurityContextHolder.getContext().getAuthentication(); |
| 32 | 48 | if(auth!=null){ |
| 33 | 0 | Object obj = auth.getPrincipal(); |
| 34 | 0 | if(obj instanceof UserWithId){ |
| 35 | //This is actually the user Id | |
| 36 | 0 | username = ((UserWithId)obj).getUserId(); |
| 37 | 0 | }else if (obj instanceof UserDetails) { |
| 38 | 0 | username = ((UserDetails)obj).getUsername(); |
| 39 | } else { | |
| 40 | 0 | username = obj.toString(); |
| 41 | } | |
| 42 | } | |
| 43 | 48 | return username; |
| 44 | } | |
| 45 | ||
| 46 | 0 |
public static String getPrincipalUserName(){ |
| 47 | 0 | String username = "unknown"; |
| 48 | ||
| 49 | 0 | Authentication auth = SecurityContextHolder.getContext().getAuthentication(); |
| 50 | 0 | if (auth != null) { |
| 51 | 0 | Object obj = auth.getPrincipal(); |
| 52 | 0 | if (obj instanceof UserDetails) { |
| 53 | 0 | username = ((UserDetails)obj).getUsername(); |
| 54 | } else { | |
| 55 | 0 | username = obj.toString(); |
| 56 | } | |
| 57 | } | |
| 58 | ||
| 59 | 0 | return username; |
| 60 | } | |
| 61 | ||
| 62 | } | |
|
||||||||||||